/** * * @param int $siteId * @param string $orderBy * @param int $order * @param int $page * @param int $perPage * @return Application\Component\TableInterface */ protected function getVotersTable($siteId, $orderBy, $order, $page, $perPage) { $aggregates = array(new Aggregate(DbViewVotes::USERID, Aggregate::NONE, null, true), new Aggregate(DbViewVotes::USERNAME, Aggregate::NONE, null, true), new Aggregate(DbViewVotes::USERDISPLAYNAME, Aggregate::NONE, null, true), new Aggregate(DbViewVotes::USERDELETED, Aggregate::NONE, null, true), new Aggregate('*', Aggregate::COUNT, 'Votes'), new Aggregate(DbViewVotes::VALUE, Aggregate::SUM, 'Sum')); $voters = $this->services->getVoteService()->getAggregatedForSite($siteId, $aggregates, null, null, array($orderBy => $order), true); $voters->setCurrentPageNumber($page); $voters->setItemCountPerPage($perPage); $table = PaginatedTableFactory::createVotersTable($voters); $table->getColumns()->setOrder($orderBy, $order === Order::ASCENDING); return $table; }
public function ratingChartAction() { $result = array('success' => false); $userId = (int) $this->params()->fromQuery('userId'); $siteId = (int) $this->params()->fromQuery('siteId'); $user = $this->services->getUserService()->find($userId); if ($user) { $byDate = new DateAggregate(DbViewVotes::DATETIME, 'Date'); $count = new Aggregate(DbViewVotes::VALUE, Aggregate::SUM, 'Votes'); $votes = $this->services->getVoteService()->getAggregatedVotesOnUser($userId, $siteId, array($byDate, $count)); $resVotes = array(); foreach ($votes as $vote) { $resVotes[] = array($vote['Date']->format(\DateTime::ISO8601), (int) $vote['Votes']); } $authorships = $this->services->getUserService()->findAuthorshipsOfUser($userId, $siteId); $milestones = array(); foreach ($authorships as $auth) { $name = $auth->getPage()->getTitle(); if (mb_strlen($name) > 11) { $name = mb_substr($name, 0, 8) . '...'; } $milestones[] = array($auth->getPage()->getCreationDate()->format(\DateTime::ISO8601), array('name' => $name, 'text' => $auth->getPage()->getTitle())); } $result = array('success' => true, 'votes' => $resVotes, 'milestones' => $milestones); } return new JsonModel($result); }
public function ratingChartAction() { $pageId = (int) $this->params()->fromQuery('pageId'); $byDate = new DateAggregate(DbViewVotes::DATETIME, 'Date'); $count = new Aggregate(DbViewVotes::VALUE, Aggregate::SUM, 'Votes'); $votes = $this->services->getVoteService()->getAggregatedForPage($pageId, array($byDate, $count), true); $resVotes = array(); foreach ($votes as $vote) { $resVotes[] = array($vote['Date']->format(\DateTime::ISO8601), (int) $vote['Votes']); } $revisions = $this->services->getRevisionService()->findRevisionsOfPage($pageId); $resRevisions = array(); foreach ($revisions as $rev) { $resRevisions[] = array($rev->getDateTime()->format(\DateTime::ISO8601), array('name' => (string) ($rev->getIndex() + 1), 'text' => $rev->getComments() === '' ? $rev->getUser()->getDisplayName() : sprintf('%s: "%s"', $rev->getUser()->getDisplayName(), $rev->getComments()))); } return new JsonModel(array('success' => true, 'votes' => $resVotes, 'milestones' => $resRevisions)); }