/** * All the user to search for feeds in the application based on a start and end date. * * @return ViewModel */ public function searchAction() { $formManager = $this->serviceLocator->get('FormElementManager'); $form = $formManager->get('BabyMonitor\\Forms\\SearchForm'); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { return $this->redirect()->toRoute('feeds/search', array('startDate' => $form->getInputFilter()->getValue('startDate'), 'endDate' => $form->getInputFilter()->getValue('endDate'))); } } if ($this->getRequest()->isGet()) { $form->setData($this->params()->fromRoute()); if ($form->isValid()) { $resultset = $this->_feedTable->fetchByDateRange(new \DateTime($form->getInputFilter()->getValue('startDate')), new \DateTime($form->getInputFilter()->getValue('endDate', null))); $paginator = $this->getPaginator($resultset); $paginator->setCurrentPageNumber($this->params()->fromRoute('page', self::DEFAULT_PAGE)); $paginator->setItemCountPerPage($this->params()->fromRoute('perPage', self::DEFAULT_RECORDS_PER_PAGE)); } return new ViewModel(array('form' => $form, 'paginator' => isset($paginator) ? $paginator : $this->getPaginator(array()))); } }
public function testFetchByDateRangeCanSearchAfterToADate() { $resultSet = new ResultSet(); $record = new FeedModel(); $record->exchangeArray($this->_recordData); $where = new Where(); $resultSet->initialize(array($record)); $startDate = new \DateTime('2000-01-01'); $mockSql = \Mockery::mock('Zend\\Db\\Sql\\Select'); $mockSql->shouldReceive('select')->andReturn($mockSql); $mockSql->shouldReceive('where')->with(array($where->greaterThanOrEqualTo('feedDate', $startDate->format(FeedTable::DATETIME_FORMAT))))->times(1)->andReturn($mockSql); $mockSql->shouldReceive('order')->times(1)->with("feedDate DESC, feedTime DESC")->andReturn($resultSet); $mockTableGateway = \Mockery::mock('Zend\\Db\\TableGateway\\TableGateway'); $mockTableGateway->shouldReceive('getSql')->andReturn($mockSql); $mockTableGateway->shouldReceive('selectWith')->times(1)->with($mockSql)->andReturn($resultSet); $mockFeedTable = new FeedTable($mockTableGateway); $this->assertEquals($resultSet, $mockFeedTable->fetchByDateRange($startDate)); }