/** * @return string */ public function __toString() { $pages = $this->paginator->getPages($this->type); $routeMatch = $this->getApp()->getMvcEvent()->getRouteMatch(); $routeName = $routeMatch->getMatchedRouteName(); $params = $routeMatch->getParams(); $paramName = $this->paramName; $paramType = $this->paramType; $url = function ($page) use($routeName, $params, $paramName, $paramType) { if (method_exists($this->view, 'plugin')) { /** @var Url $url */ $url = $this->view->plugin('url'); $query = $_GET; if ($paramType == 'query') { $query[$paramName] = $page; } else { if ($paramName == 'route') { $params[$paramName] = $page; } else { throw new \RuntimeException('Currently only `query` and `route` param type supported by pagination helper.'); } } // filter controller name: // transforms e.g. '\Some\Module\IndexController' into just 'index' if (isset($params['controller']) && isset($params['__CONTROLLER__'])) { $params['controller'] = $params['__CONTROLLER__']; } else { if (isset($params['controller']) && strpos($params['controller'], '\\') !== false) { $parts = array_reverse(explode('\\', $params['controller'])); $filteredParts = []; foreach ($parts as $part) { if (strtolower($part) == 'controller' || strtolower($part) == 'controllers') { break; } $tmp = $part; if (substr($part, -10) == 'Controller') { $tmp = substr($part, 0, -10); } array_unshift($filteredParts, strtolower($this->getCamelCaseToDashFilter()->filter($tmp))); } $params['controller'] = join('/', $filteredParts); } } return $url($routeName, $params, compact('query')); } throw new \Exception('Could not resolve URL helper.'); }; $viewModel = new ViewModel(compact('pages', 'url')); $viewModel->setTemplate($this->template); return $this->getView()->render($viewModel); }
public function testNoPagesBeforeSecondLastPageEqualsPageRangeMinTwo() { $this->paginator->setPageRange(3); $this->paginator->setCurrentPageNumber(19); $pages = $this->paginator->getPages('Elastic'); $this->assertEquals(5, count($pages->pagesInRange)); }
/** * Return the HTML string of this HTML element * * @return string */ public function render() { $paginationData = $this->paginator->getPages($this->scrollingStyle); $unorderedList = $this->getElement()->spawnChild('ul'); $previous = $unorderedList->spawnChild('li'); $previousAnchor = $previous->spawnChild('a')->setContent('«'); $unorderedList->setAttributes($this->getListAttributes()); $previous->setAttributes($this->getListItemAttributes()); $previous->addAttributes($this->getPreviousAttributes()); $previousAnchor->setAttributes($this->getAnchorAttributes()); if (empty($paginationData->previous)) { $previous->addClass('disabled'); } else { $previousAnchor->addAttribute('href', $this->getUrl($this->getRoute(), array_merge(array('page' => $paginationData->previous), $this->getRouteParams()))); } foreach ($paginationData->pagesInRange as $page) { $pageNumberElement = $unorderedList->spawnChild('li'); $pageHref = $this->getUrl($this->getRoute(), array_merge(array('page' => $page), $this->getRouteParams())); $pageNumberElement->setAttributes($this->getListItemAttributes()); if ($page === $paginationData->current) { $pageNumberElement->addClass('active'); } $anchorElement = $pageNumberElement->spawnChild('a')->addAttribute('href', $pageHref)->setContent($page); $anchorElement->addAttribute('data-page', $page); } $next = $unorderedList->spawnChild('li'); $nextAnchor = $next->spawnChild('a')->setContent('»'); $next->setAttributes($this->getNextAttributes()); if (empty($paginationData->next)) { $next->addClass('disabled'); } else { $nextAnchor->addAttribute('href', $this->getUrl($this->getRoute(), array_merge(array('page' => $paginationData->next), $this->getRouteParams()))); } return $this->getElement()->render(); }
/** * Return the HTML string of this HTML element * * @return string */ public function render() { $paginationData = $this->paginator->getPages(); $previous = $this->getElement()->spawnChild('li'); $next = $this->getElement()->spawnChild('li'); $previousAnchor = $previous->spawnChild('a')->setContent($this->getPrevLabel()); $nextAnchor = $next->spawnChild('a')->setContent($this->getNextLabel()); $this->getElement()->addAttributes($this->getListAttributes()); $previousAnchor->setAttributes($this->getPreviousAttributes()); $nextAnchor->setAttributes($this->getNextAttributes()); if (empty($paginationData->previous)) { $previous->addClass('disabled'); } else { $previousAnchor->addAttribute('data-page', $paginationData->previous); $previousAnchor->addAttribute('href', $this->getUrl($this->getRoute(), array_merge(array('page' => $paginationData->previous), $this->getRouteParams()))); } if (empty($paginationData->next)) { $next->addClass('disabled'); } else { $nextAnchor->addAttribute('data-page', $paginationData->next); $nextAnchor->addAttribute('href', $this->getUrl($this->getRoute(), array_merge(array('page' => $paginationData->next), $this->getRouteParams()))); } if ($this->align) { $previous->addClass('previous'); $next->addClass('next'); } return $this->getElement()->render(); }
/** * @group ZF-3873 */ public function testAdapterReturnsCorrectValues() { $paginator = new Paginator\Paginator(new Adapter\Null(2)); $paginator->setCurrentPageNumber(1); $paginator->setItemCountPerPage(5); $pages = $paginator->getPages(); $this->assertEquals(2, $pages->currentItemCount); $this->assertEquals(2, $pages->lastItemNumber); $paginator = new Paginator\Paginator(new Adapter\Null(19)); $paginator->setCurrentPageNumber(4); $paginator->setItemCountPerPage(5); $pages = $paginator->getPages(); $this->assertEquals(4, $pages->currentItemCount); $this->assertEquals(19, $pages->lastItemNumber); }
public function search($value, $page = 1, $count = null, $sort = null) { if (!empty($value)) { $qb = $this->createQueryBuilder('u'); $qb->where($qb->expr()->like('u.username', '?1'))->orWhere($qb->expr()->like('u.email', '?2'))->setParameter(1, $value . '%')->setParameter(2, $value . '%'); if ($sort) { $qb->orderBy("p." . $sort["column"], $sort["type"]); } $paginator = new Paginator(new DoctrineAdapter(new ORMPaginator($qb))); if ($count) { $paginator->setDefaultItemCountPerPage($count); } $paginator->setCurrentPageNumber($page); $paginator->getPages()->pageCount; return $paginator; } else { throw new \InvalidArgumentException("The search value can't be empty."); } }
public function testGetsPagesForPageTwo() { $expected = new stdClass(); $expected->pageCount = 11; $expected->itemCountPerPage = 10; $expected->first = 1; $expected->current = 2; $expected->last = 11; $expected->previous = 1; $expected->next = 3; $expected->pagesInRange = array_combine(range(1, 10), range(1, 10)); $expected->firstPageInRange = 1; $expected->lastPageInRange = 10; $expected->currentItemCount = 10; $expected->totalItemCount = 101; $expected->firstItemNumber = 11; $expected->lastItemNumber = 20; $this->paginator->setCurrentPageNumber(2); $actual = $this->paginator->getPages(); $this->assertEquals($expected, $actual); }
public function testAcceptsPageRangeLargerThanPageCount() { $this->paginator->setPageRange(100); $pages = $this->paginator->getPages(); $this->assertEquals(11, $pages->last); }
function getClientProjectListAction() { $currentUserId = User::currentLoginId(); $currentUser = $this->find('User\\Entity\\User', $currentUserId); $employer = $currentUser->getEmployer(); if ($employer) { $user_id = $currentUser->getId(); } else { $user_id = null; } $params = $this->getRequest()->getQuery(); foreach ($params as $key => $value) { if (strpos($value, '{') !== false) { $params->{$key} = json_decode($value); } } //var_dump($params); exit; $entityManager = $this->getEntityManager(); $projectList = $entityManager->getRepository('User\\Entity\\Project'); $queryBuilder = $projectList->createQueryBuilder('project'); // Sửa lại chổ này, tạm để đó $queryBuilder->where("project.client=?1")->setParameter(1, $user_id); $queryBuilder->andWhere('project.is_deleted = 0'); // Unpaid Task if ($params->payStatus != null && $params->payStatus != '') { $queryBuilder->andWhere('project.payStatus = :payStatus'); $queryBuilder->setParameter('payStatus', $params->payStatus); } if ($params->bsearch != null && $params->bsearch != '') { $queryBuilder->andWhere('project.reference LIKE :reference'); $queryBuilder->setParameter('reference', "%" . $params->bsearch . "%"); } else { // Advance Search if ($params->reference != null && $params->reference != '') { $queryBuilder->andWhere('project.reference LIKE :reference'); $queryBuilder->setParameter('reference', "%" . $params->reference . "%"); } if ($params->projectId != null && $params->projectId != '') { $queryBuilder->andWhere('project.id LIKE :projectId'); $queryBuilder->setParameter('projectId', "%" . $params->projectId . "%"); } if ($params->startDate != null && $params->startDate != '') { $time = strtotime($params->startDate); $time = date("Y-m-d", $time); $begin = $time . " 00:00:00"; $end = $time . " 23:59:59"; $queryBuilder->andWhere('project.startDate BETWEEN ?6 AND ?7')->setParameter(6, $begin)->setParameter(7, $end); } if ($params->dueDate != null && $params->dueDate != '') { $time = strtotime($params->dueDate); $time = date("Y-m-d", $time); $begin = $time . " 00:00:00"; $end = $time . " 23:59:59"; $queryBuilder->andWhere('project.dueDate BETWEEN ?8 AND ?9')->setParameter(8, $begin)->setParameter(9, $end); } if ($params->dueMonth != null && $params->dueMonth != '') { $time = strtotime($params->dueMonth); //$time = date("Y-m-d", $time); $begin = date("Y-m-d", $time) . " 00:00:00"; $end = date("Y-m-t", $time) . " 23:59:59"; //var_dump($begin); var_dump($end); exit; $queryBuilder->andWhere('project.dueDate BETWEEN :begin AND :end')->setParameter('begin', $begin)->setParameter('end', $end); } } $query = $queryBuilder->getQuery(); //$result = $query->getArrayResult(); //var_dump($result); exit; $adapter = new DoctrineAdapter(new ORMPaginator($query)); $paginator = new Paginator($adapter); $paginator->setDefaultItemCountPerPage(10); $page = (int) $this->getRequest()->getQuery('page'); if ($page) { $paginator->setCurrentPageNumber($page); } $data = array(); foreach ($paginator as $project) { $data[] = $project->getData(); } return new JsonModel(array('projects' => $data, 'pages' => $paginator->getPages())); }
public function getList() { $entityManager = $this->getEntityManager(); $employerGroup = $entityManager->find('User\\Entity\\UserGroup', UserGroup::EMPLOYER_GROUP_ID); $employerList = $entityManager->getRepository('User\\Entity\\User'); $queryBuilder = $employerList->createQueryBuilder('user'); $request = $this->getRequest(); if ($request->getQuery('search') && $request->getQuery('company')) { $company = $entityManager->getRepository('User\\Entity\\Company')->findBy(array('id' => $request->getQuery('company'))); $queryBuilder->leftJoin('user.employer', 'employer')->where('employer.company=?1')->setParameter(1, $company); $queryBuilder->andWhere("user.group=?2")->setParameter(2, $employerGroup); } else { $queryBuilder->where("user.group=?1")->setParameter(1, $employerGroup); } if ($request->getQuery('search')) { if ($arrayNames = $this->params()->fromQuery('name')) { $arrayName = explode(' ', $arrayNames); if (count($arrayName) != 2) { $queryBuilder->andWhere($queryBuilder->expr()->like('user.firstName', "'%" . $arrayName[0] . "%'")); } else { $queryBuilder->andWhere($queryBuilder->expr()->like('user.firstName', "'%" . $arrayName[0] . "%'")); $queryBuilder->andWhere($queryBuilder->expr()->like('user.lastName', "'%" . $arrayName[1] . "%'")); } } if ($request->getQuery('idEmployer')) { $queryBuilder->andWhere($queryBuilder->expr()->eq("user.id", (int) $request->getQuery('idEmployer'))); } if ($request->getQuery('email')) { $queryBuilder->andWhere($queryBuilder->expr()->like('user.email', "'%" . $request->getQuery('email') . "%'")); } if ($request->getQuery('currency')) { $queryBuilder->andWhere($queryBuilder->expr()->eq("user.currency", $queryBuilder->expr()->literal($request->getQuery('currency')))); } if ($request->getQuery('country')) { $queryBuilder->andWhere($queryBuilder->expr()->eq("user.country", (int) $request->getQuery('country'))); } if (!$request->getQuery('includeInactive') || $request->getQuery('includeInactive') && $request->getQuery('includeInactive') == 'false') { $queryBuilder->andWhere($queryBuilder->expr()->eq("user.isActive", 1)); } } $queryBuilder->orderBy('user.createdTime', 'ASC'); $adapter = new DoctrineAdapter(new ORMPaginator($queryBuilder)); $paginator = new ZendPaginator($adapter); $paginator->setDefaultItemCountPerPage(10); $page = (int) $this->getRequest()->getQuery('page'); if ($page) { $paginator->setCurrentPageNumber($page); } $data = array(); $helper = new Helper(); foreach ($paginator as $user) { $userData = $user->getData(); $userData['employer'] = $user->getEmployer()->getData(); $userData['createdTime'] = $helper->formatDate($userData['createdTime']); // Count TaskDone $taskCount = $entityManager->getRepository('User\\Entity\\Task'); $taskQueryBuilder = $taskCount->createQueryBuilder('task'); $taskQueryBuilder->select('COUNT(task.id)'); $taskQueryBuilder->innerJoin('User\\Entity\\Project', 'p', 'WITH', 'task.project = p.id'); $taskQueryBuilder->andWhere('p.client = ?1')->setParameter(1, $userData['id']); // user.id $taskQueryBuilder->andWhere('task.status = ?2')->setParameter(2, 1); $taskquery = $taskQueryBuilder->getQuery(); $task_result = $taskquery->getArrayResult(); $userData['taskDone'] = $task_result[0][1]; // End Count TaskDone $data[] = $userData; } return new JsonModel(array('employers' => $data, 'pages' => $paginator->getPages())); }
public function getList() { error_reporting(E_ALL); ini_set('display_errors', 1); $projectId = $this->params()->fromQuery('project_id'); $params = $this->getRequest()->getQuery(); foreach ($params as $key => $value) { if (strpos($value, '{') !== false) { $params->{$key} = json_decode($value); } } if ($projectId) { $tasks = $this->getAllDataBy('\\User\\Entity\\Task', ['is_deleted' => false, 'project' => $projectId], ['id' => 'ASC']); $data = array(); $entityManager = $this->getEntityManager(); foreach ($tasks as $task) { $freelancerId = $task['assignee']['id']; $userData = $task; if ($freelancerId != null) { $user = $entityManager->getRepository('User\\Entity\\User')->findOneBy(array('freelancer' => $freelancerId)); $userData['assignee'] = $user->getData(); } $data[] = $userData; } return new JsonModel(['tasks' => $data]); } else { $entityManager = $this->getEntityManager(); $projectList = $entityManager->getRepository('User\\Entity\\Task'); //->findBy(array('group' => $freelancerGroup)); $queryBuilder = $projectList->createQueryBuilder('task'); $queryBuilder->andWhere('task.is_deleted = 0'); if ($params->search == 1) { // Unpaid Task if ($params->payStatus != null && $params->payStatus != '') { $queryBuilder->andWhere('task.payStatus = :paystatus'); $queryBuilder->setParameter('paystatus', $params->payStatus->id); } //get task base on status if ($params->status != null && $params->statustask != '') { $queryBuilder->andWhere('task.status = :status'); $queryBuilder->setParameter('status', $params->status); } if ($params->task_id != null && $params->task_id != '') { $queryBuilder->andWhere('task.id = :task_id'); $queryBuilder->setParameter('task_id', $params->task_id); //$queryBuilder_tmp->distinct(); } if ($params->startDate != null && $params->startDate != '') { $time = strtotime($params->startDate); $time = date("Y-m-d", $time); $begin = $time . " 00:00:00"; $end = $time . " 23:59:59"; $queryBuilder->andWhere('task.startDate BETWEEN ?6 AND ?7')->setParameter(6, $begin)->setParameter(7, $end); } if ($params->dueDate != null && $params->dueDate != '') { $time = strtotime($params->dueDate); $time = date("Y-m-d", $time); $begin = $time . " 00:00:00"; $end = $time . " 23:59:59"; $queryBuilder->andWhere('task.dueDate BETWEEN ?8 AND ?9')->setParameter(8, $begin)->setParameter(9, $end); } if ($params->reference != null && $params->reference != '') { $entityManagerP = $this->getEntityManager(); $ProjectList = $entityManagerP->getRepository('User\\Entity\\Project'); $queryBuilderProject = $ProjectList->createQueryBuilder('project'); $queryBuilderProject->where("project.reference LIKE :reference")->setParameter('reference', '%' . $params->reference . '%'); $queryProject = $queryBuilderProject->getQuery(); $resultProject = $queryProject->getArrayResult(); $statement = ""; foreach ($resultProject as $project) { //echo $project['id']; $statement = $statement . "task.project = " . $project['id'] . " OR "; } $statement = substr($statement, 0, -3); $queryBuilder->andWhere($statement); //var_dump($statement); exit; } } $adapter = new DoctrineAdapter(new ORMPaginator($queryBuilder)); $paginator = new Paginator($adapter); $paginator->setDefaultItemCountPerPage(10); $page = (int) $this->getRequest()->getQuery('page'); if ($page) { $paginator->setCurrentPageNumber($page); } $data = array(); //$helper = new Helper(); foreach ($paginator as $task) { $userData = $task->getData(); // Get Employer $freelancerId = $userData['assignee']['id']; if ($freelancerId != null) { $user = $entityManager->getRepository('User\\Entity\\User')->findOneBy(array('freelancer' => $freelancerId)); $userData['assignee'] = $user->getData(); $project = $this->find('User\\Entity\\Project', $userData['project']); $userData['project'] = $project->getData(); // Get Project //var_dump($user); } $data[] = $userData; } return new JsonModel(array('tasks' => $data, 'pages' => $paginator->getPages())); } }
/** * @return int */ public function getPrevPage() { return $this->zendPaginator->getPages()->current - 1; }
public function getList() { //error_reporting(E_ALL); //ini_set('display_errors', 1); $entityManager = $this->getEntityManager(); //var_dump($this->params()->fromQuery()); exit; // Get freelancer group $projectList = $entityManager->getRepository('User\\Entity\\Project'); //->findBy(array('group' => $freelancerGroup)); $queryBuilder = $projectList->createQueryBuilder('project'); $queryBuilder->andWhere('project.is_deleted = 0'); if ($q = $this->params()->fromQuery('q')) { $queryBuilder->andWhere($queryBuilder->expr()->orX($queryBuilder->expr()->like('project.reference', $queryBuilder->expr()->literal("%{$q}%")), $queryBuilder->expr()->like('project.id', $queryBuilder->expr()->literal("%{$q}%")))); } /** start filter */ if ($project_id = $this->params()->fromQuery('project_id')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.id', $project_id)); } if ($project_no = $this->params()->fromQuery('project_no')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.project_no', $project_no)); //$queryBuilder->expr()->like('project.project_no', $project_no); } if ($reference = $this->params()->fromQuery('reference')) { $queryBuilder->andWhere($queryBuilder->expr()->like('project.reference', $queryBuilder->expr()->literal("%{$reference}%"))); } if ($field = $this->params()->fromQuery('field')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.field', $field['id'])); } if ($status = $this->params()->fromQuery('status')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.status', $status['id'])); } if ($payStatus = $this->params()->fromQuery('payStatus')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.payStatus', $payStatus['id'])); } if ($unpay = $this->params()->fromQuery('unpay')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.payStatus', $unpay)); } if ($sale = $this->params()->fromQuery('sale')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.sale', $sale['id'])); } if ($pm = $this->params()->fromQuery('pm')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.pm', $pm['id'])); } $currentUserId = User::currentLoginId(); $currentUser = $this->find('User\\Entity\\User', $currentUserId); if ($currentUser->isEmployer()) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.client', $currentUserId)); } if ($clientId = $this->params()->fromQuery('clientId')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.client', $clientId)); } if ($statusproject = $this->params()->fromQuery('statusproject')) { if ($statusproject == '7and8') { $queryBuilder->andWhere("project.status = 7 or project.status = 8"); } else { if ($statusproject == 'client') { $queryBuilder->andWhere("project.status = 0 or project.status = 1 or project.status = 2 or project.status = 3 or project.status = 4"); } else { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.status', $statusproject)); } } } if ($getQuote = $this->params()->fromQuery('quote')) { //echo 'hi'; exit; if ($getQuote == 1) { $queryBuilder->andWhere("project.status = 1 or project.status = 0"); } else { $queryBuilder->andWhere($queryBuilder->expr()->like('project.status', $getQuote)); } //$queryBuilder->andWhere("project.status = 2"); } if ($startDate = $this->params()->fromQuery('startDate')) { $queryBuilder->andWhere($queryBuilder->expr()->gte('project.startDate', $startDate)); } if ($dueDate = $this->params()->fromQuery('dueDate')) { $queryBuilder->andWhere($queryBuilder->expr()->gte('project.dueDate', $dueDate)); } if ($source = $this->params()->fromQuery('source')) { $queryBuilder->andWhere($queryBuilder->expr()->gte('project.sourceLanguage', $source['id'])); } if ($target = $this->params()->fromQuery('target')) { // TODO: Many to many problem } /** end filter */ $queryBuilder->orderBy('project.id', 'DESC'); $adapter = new DoctrineAdapter(new ORMPaginator($queryBuilder)); $paginator = new Paginator($adapter); $number = $this->params()->fromQuery('number'); if (!$number) { $number = 10; } $paginator->setDefaultItemCountPerPage($number); $page = (int) $this->getRequest()->getQuery('page'); if ($page) { $paginator->setCurrentPageNumber($page); } $data = array(); $helper = new Helper(); foreach ($paginator as $user) { $userData = $user->getData(); // var_dump($userData); exit; $data[] = $userData; } //var_dump($paginator);die; return new JsonModel(array('projects' => $data, 'pages' => $paginator->getPages())); }
public function getFreelancerOutTransactionListAction() { error_reporting(E_ALL); ini_set('display_errors', 1); $params = $this->getRequest()->getQuery(); foreach ($params as $key => $value) { if (strpos($value, '{') !== false) { $params->{$key} = json_decode($value); } } //var_dump($params);exit; $currentUserId = User::currentLoginId(); $currentUser = $this->find('User\\Entity\\User', $currentUserId); $freelancer = $currentUser->getFreelancer(); $freelancer_id = $freelancer->getId(); $entityManager = $this->getEntityManager(); $freelancerList = $entityManager->getRepository('User\\Entity\\Transaction'); $queryBuilder = $freelancerList->createQueryBuilder('outtr'); $queryBuilder->where('outtr.freelancer = ?1')->setParameter(1, $currentUser); //$queryBuilder->where("outtr.client=?1")->setParameter(1,$freelancer_id); // 4 = Pooling $queryBuilder->andWhere('outtr.is_deleted = 0'); if ($params->bsearch != null && $params->bsearch != '') { $queryBuilder->andWhere('outtr.intrans_no LIKE :outtrId'); $queryBuilder->setParameter('outtrId', '%' . $params->bsearch . '%'); } else { // Advance Search if ($params->outtrId != null && $params->outtrId != '') { $queryBuilder->andWhere('outtr.intrans_no LIKE :outtrId'); $queryBuilder->setParameter('outtrId', '%' . $params->outtrId . '%'); //echo 'hi';exit; //$queryBuilder_tmp->distinct(); } if ($params->payMonth != null && $params->payMonth != '') { $time = strtotime($params->payMonth); //$time = date("Y-m-d", $time); $begin = date("Y-m-d", $time) . " 00:00:00"; $end = date("Y-m-t", $time) . " 23:59:59"; $queryBuilder->andWhere('outtr.payDate BETWEEN :begin AND :end')->setParameter('begin', $begin)->setParameter('end', $end); } } $query = $queryBuilder->getQuery(); //$result = $query->getArrayResult(); //var_dump($result); exit; $adapter = new DoctrineAdapter(new ORMPaginator($query)); $paginator = new Paginator($adapter); $paginator->setDefaultItemCountPerPage(10); $page = (int) $this->getRequest()->getQuery('page'); if ($page) { $paginator->setCurrentPageNumber($page); } $data = array(); foreach ($paginator as $outtransaction) { //var_dump($outtransaction); exit; //$data[] = $outtransaction->getData(); $outtr = array(); $outtr = $outtransaction->getData(); // Get Currency //$taskIDs = $outtransaction->getTasks(); //$taskID = $taskIDs[0]; //$task = $this->find('User\Entity\Task',$taskID); //$project = $task->getProject(); //$currency = $project->getCurrency(); //if($currency==null) $currency='CNY'; //$outtr['currency'] =$currency; $data[] = $outtr; //var_dump($currency); exit; } return new JsonModel(array('outtrs' => $data, 'pages' => $paginator->getPages())); }
public function getList() { //error_reporting(E_ALL); //ini_set('display_errors', 1); $entityManager = $this->getEntityManager(); // Get freelancer group $projectList = $entityManager->getRepository('User\\Entity\\Project'); //->findBy(array('group' => $freelancerGroup)); $queryBuilder = $projectList->createQueryBuilder('project'); $queryBuilder->andWhere('project.is_deleted = 0'); /** start filter */ if ($project_id = $this->params()->fromQuery('project_id')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.id', $project_id)); } if ($reference = $this->params()->fromQuery('reference')) { $queryBuilder->andWhere($queryBuilder->expr()->like('project.reference', $queryBuilder->expr()->literal("%{$reference}%"))); } if ($field = $this->params()->fromQuery('field')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.field', $field['id'])); } if ($status = $this->params()->fromQuery('status')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.status', $status['id'])); } if ($payStatus = $this->params()->fromQuery('payStatus')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.payStatus', $payStatus['id'])); } if ($sale = $this->params()->fromQuery('sale')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.sale', $sale['id'])); } if ($pm = $this->params()->fromQuery('pm')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.pm', $pm['id'])); } if ($clientId = $this->params()->fromQuery('clientId')) { $queryBuilder->andWhere($queryBuilder->expr()->eq('project.client', $clientId)); } if ($startDate = $this->params()->fromQuery('startDate')) { $queryBuilder->andWhere($queryBuilder->expr()->gte('project.startDate', $startDate)); } if ($dueDate = $this->params()->fromQuery('dueDate')) { $queryBuilder->andWhere($queryBuilder->expr()->gte('project.dueDate', $dueDate)); } if ($source = $this->params()->fromQuery('source')) { $queryBuilder->andWhere($queryBuilder->expr()->gte('project.sourceLanguage', $source['id'])); } if ($target = $this->params()->fromQuery('target')) { // TODO: Many to many problem } /** end filter */ $queryBuilder->orderBy('project.id', 'DESC'); $adapter = new DoctrineAdapter(new ORMPaginator($queryBuilder)); $paginator = new Paginator($adapter); $paginator->setDefaultItemCountPerPage(10); $page = (int) $this->getRequest()->getQuery('page'); if ($page) { $paginator->setCurrentPageNumber($page); } $data = array(); $helper = new Helper(); foreach ($paginator as $user) { $userData = $user->getData(); $data[] = $userData; } //var_dump($paginator);die; return new JsonModel(array('projects' => $data, 'pages' => $paginator->getPages())); }
public function getTaskPoolListAction() { $entityManager = $this->getEntityManager(); $freelancerList = $entityManager->getRepository('User\\Entity\\Task'); $queryBuilder = $freelancerList->createQueryBuilder('task'); $queryBuilder->where("task.status=?1")->setParameter(1, '4'); // 4 = Pooling $queryBuilder->andWhere('task.is_deleted = 0'); $query = $queryBuilder->getQuery(); //$result = $query->getArrayResult(); //var_dump($result); exit; $adapter = new DoctrineAdapter(new ORMPaginator($query)); $paginator = new Paginator($adapter); $paginator->setDefaultItemCountPerPage(10); $page = (int) $this->getRequest()->getQuery('page'); if ($page) { $paginator->setCurrentPageNumber($page); } $data = array(); foreach ($paginator as $task) { $task_data = $task->getData(); $project = $this->find('User\\Entity\\Project', $task_data['project']); $task_data['project'] = $project->getData(); $data[] = $task_data; } return new JsonModel(array('tasks' => $data, 'pages' => $paginator->getPages())); }
public function testGetsNextAndPreviousPageForLastPage() { $this->paginator->setCurrentPageNumber(11); $pages = $this->paginator->getPages('Jumping'); $this->assertEquals(10, $pages->previous); }
/** * Renders a pagination control, for a $paginator given. * Optionaly $template and $style can be specified to * override default from configuration. * * @param Zend\Paginator\Paginator $paginator * @param string $template * @param array $custom - custom parameters * @param array $routeparams - params for the route * @param string $route * @return string */ public function paginate(Paginator $paginator, $template = null, $custom = array(), $routeparams = array(), $route = null) { if ($template) { $this->template = $template; } if (null === $route) { $route = $this->route; } $params = get_object_vars($paginator->getPages($this->scrollingStyle)); $params['route'] = $route; $params['alias'] = $this->getAlias($paginator); $params['query'] = array_merge($this->params, $routeparams); $params['custom'] = $custom; return $this->engine->render($this->template, $params); }