Ejemplo n.º 1
0
 /**
  * 
  * @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;
 }
Ejemplo n.º 2
0
 public function votersAction()
 {
     $result = array('success' => false);
     $siteId = -1;
     $from = null;
     $to = null;
     if ($this->getCommonParams($siteId, $from, $to)) {
         $page = (int) $this->params()->fromQuery('page', 1);
         $perPage = (int) $this->params()->fromQuery('perPage', 10);
         $orderBy = $this->params()->fromQuery('orderBy');
         if (!$orderBy || $orderBy !== 'Votes' && !DbViewVotes::hasField($orderBy)) {
             $orderBy = 'Votes';
             $order = Order::DESCENDING;
         } else {
             if ($this->params()->fromQuery('ascending', true)) {
                 $order = Order::ASCENDING;
             } else {
                 $order = Order::DESCENDING;
             }
         }
         $voters = $this->getVotersPaginator($siteId, $from, $to, $orderBy, $order, $page, $perPage);
         $table = PaginatedTableFactory::createVotersTable($voters);
         $renderer = $this->getServiceLocator()->get('ViewHelperManager')->get('partial');
         $table->getColumns()->setOrder($orderBy, $order === Order::ASCENDING);
         if ($renderer) {
             $result['success'] = true;
             $result['content'] = $renderer('partial/tables/table.phtml', array('table' => $table, 'data' => array()));
         }
     }
     return new JsonModel($result);
 }