Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
related #659 readercountupdater completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
delirehberi committed May 27, 2015
1 parent b9d1ba6 commit 728a962
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Ojs/AnalyticsBundle/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private function updateCommonData()
// 'DeclinedArticleCount',
// 'RevisedArticleCount',
'UserCount',
// 'ReaderCount',
'ReaderCount',
// 'MemberCount',
// 'PublishedIssueCount',
];
Expand Down
27 changes: 25 additions & 2 deletions src/Ojs/AnalyticsBundle/Updater/ReaderCountUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
*/
namespace Ojs\AnalyticsBundle\Updater;

class ReaderCountUpdater implements UpdaterInterface
use Ojs\UserBundle\Entity\UserJournalRole;
use Ojs\UserBundle\Entity\UserRepository;

class ReaderCountUpdater extends Updater implements UpdaterInterface
{
public function update()
{
Expand All @@ -13,6 +16,26 @@ public function update()

public function count()
{
// TODO: Implement count() method.
$readerRole = $this->em->getRepository("OjsUserBundle:Role")->findOneBy(['role'=>'ROLE_READER']);
/** @var UserRepository $ue */
$ue = $this->em->getRepository('Ojs\UserBundle\Entity\UserJournalRole');
$all = $ue->findBy(['roleId'=>$readerRole->getId()]);
$journalUsers = [];
foreach ($all as $r) {
/** @var UserJournalRole $r */
if (isset($journalUsers[$r->getJournalId()])
and in_array($r->getUserId(), $journalUsers[$r->getJournalId()])
) {
continue;
}
$journalUsers[$r->getJournalId()][] = $r->getUserId();
}

return $journalUsers;
}

public function getObject()
{
return 'Ojs\JournalBundle\Entity\Journal';
}
}
2 changes: 1 addition & 1 deletion src/Ojs/AnalyticsBundle/Updater/UpdaterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public function update();

public function count();

public function getObject($id);
public function getObject();
}
3 changes: 1 addition & 2 deletions src/Ojs/AnalyticsBundle/Updater/UserCountUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public function count()
}

/**
* @param $id
* @return string
*/
public function getObject($id)
public function getObject()
{
return "Ojs\JournalBundle\Entity\Journal";
}
Expand Down

0 comments on commit 728a962

Please sign in to comment.