Skip to content

Commit

Permalink
Added followersTotal and followingTotal
Browse files Browse the repository at this point in the history
  • Loading branch information
bymayo committed Jun 19, 2020
1 parent e3eeb9f commit 5929ecc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Follow Changelog

## 1.0.3 - 2020-06-19
### Added
- `followingTotal` and `followersTotal` method

## 1.0.2 - 2020-06-19
### Changed
- Updated documentation URL
Expand All @@ -8,8 +12,6 @@
### Added
- `following` method can now be output as a string or array. This works well when trying to get a count for amount of followers & following.

### Updated

## 1.0.1 - 2019-03-27
### Changed
- Updated Icon
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bymayo/follow",
"description": "Let users follow other users and elements (Categories, Tags etc) to generate lists & feeds.",
"type": "craft-plugin",
"version": "1.0.2",
"version": "1.0.3",
"keywords": [
"craft",
"cms",
Expand Down
14 changes: 10 additions & 4 deletions src/services/ElementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ public function outputType($type)
// |length could be used
}

public function followingTotal()
public function followingTotal($params)
{

$params['output'] = 'array';
return count($this->following($params));

}

public function followerTotal()
public function followersTotal($elementId)
{

return count($this->followers($elementId, 'array'));

}

Expand Down Expand Up @@ -76,10 +81,11 @@ public function following($params)

}

public function followers($elementId)
public function followers($elementId, $output = null)
{

$elementId = $elementId ?? Craft::$app->getUser()->getIdentity()->id;
$output = isset($output) ? $output: 'string';

try {

Expand All @@ -100,7 +106,7 @@ public function followers($elementId)
array_push($results, $result['userId']);
}

return $this->arrayToString($queryResult, 'userId');
return $output == 'array' ? $queryResult : $this->arrayToString($queryResult, 'userId');

}
catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/variables/FollowVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function followingTotal($params = null)

public function followersTotal($elementId = null)
{
return Follow::getInstance()->elementService->followingTotal($elementId);
return Follow::getInstance()->elementService->followersTotal($elementId);
}

}

0 comments on commit 5929ecc

Please sign in to comment.