コード例 #1
0
 /**
  * All a user to add and update a feed in the application
  *
  * @return ViewModel
  */
 public function manageAction()
 {
     $formManager = $this->serviceLocator->get('FormElementManager');
     $form = $formManager->get('BabyMonitor\\Forms\\ManageRecordForm');
     $feedId = (int) $this->params()->fromRoute('id');
     if ($this->getRequest()->isGet()) {
         if (!empty($feedId)) {
             if ($feed = $this->_feedTable->fetchById($feedId)) {
                 $form->setData($feed->getArrayCopy());
             } else {
                 $this->flashMessenger()->addInfoMessage('Unable to find that feed. Perhaps a new one?');
                 return $this->redirect()->toRoute(self::DEFAULT_ROUTE, array('action' => 'manage'));
             }
         }
     }
     if ($this->getRequest()->isPost()) {
         $form->setData($this->getRequest()->getPost());
         if ($form->isValid()) {
             $feed = new FeedModel();
             $feed->exchangeArray($form->getData());
             $this->_feedTable->save($feed);
             if (!is_null($this->_cache)) {
                 $this->_cache->removeItem(self::KEY_ALL_RESULTS);
             }
             $this->getEventManager()->trigger('Feed.Modify', $this, array('feedData' => $feed));
             return $this->redirect()->toRoute(self::DEFAULT_ROUTE, array());
         }
     }
     return new ViewModel(array('form' => $form, 'cancelTitle' => $feedId ? "Don't update the record" : "Don't create the record", 'messages' => array('info' => $this->flashMessenger()->hasInfoMessages())));
 }
コード例 #2
0
 public function save(FeedModel $feed)
 {
     /*
     * Left because you could also approach it this way
     *
             $data = array(
        'userId' => $feed->userId,
        'feedDate' => $feed->feedDate,
        'feedTime' => $feed->feedTime,
        'feedAmount' => $feed->feedAmount,
        'feedNotes' => $feed->feedNotes,
        'feedTemperature' => $feed->feedTemperature,
             );
     */
     $data = $feed->getArrayCopy();
     unset($data['feedId']);
     if ((int) $feed->feedId == 0) {
         if ($this->tableGateway->insert($data)) {
             return $this->tableGateway->getLastInsertValue();
         }
     } else {
         if ($retstat = $this->tableGateway->update($data, array('feedId' => (int) $feed->feedId))) {
             return $retstat;
         }
     }
 }
コード例 #3
0
 public function testSaveUserWillUpdateExistingUsersIfTheyAlreadyHaveAnId()
 {
     $recordData = $this->_recordData;
     $feedId = $recordData['feedId'];
     $feed = new FeedModel();
     $feed->exchangeArray($this->_recordData);
     $resultSet = new ResultSet();
     $resultSet->setArrayObjectPrototype(new FeedModel());
     $resultSet->initialize(array($feed));
     $mockTableGateway = \Mockery::mock('Zend\\Db\\TableGateway\\TableGateway');
     $mockTableGateway->shouldReceive('update')->with(array('userId' => 21, 'feedDate' => "2012-01-01", 'feedTime' => "12:00:00", 'feedAmount' => 21.04, 'feedTemperature' => 14, 'feedNotes' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mattis vitae nisi eget suscipit. Suspendisse condimentum sapien purus, eu porta dolor elementum vel. Praesent quis nunc dolor. Phasellus in luctus lorem, a tempus velit. Proin varius magna urna, id accumsan ante eleifend eleifend. Nullam id nulla ligula. Praesent id felis vel felis tempor vestibulum. Nulla pretium, tortor eu placerat suscipit, purus ipsum aliquet eros, non dictum mi odio in odio. Morbi ac porta enim. In non purus at dui consequat rhoncus. Nullam libero nisl, rutrum non mi vel, molestie gravida lectus. Sed laoreet vitae sem at tincidunt. Etiam volutpat nunc ut nunc fringilla, at imperdiet urna congue. Sed lacinia sit amet leo id vehicula. Aenean interdum purus id gravida varius."), array('feedId' => $feedId))->andReturn($this->_recordData);
     $feedTable = new FeedTable($mockTableGateway);
     $feedTable->save($feed, $feedId);
 }
コード例 #4
0
 public function testCanGetNotificationBodyForValidDeletion()
 {
     $service = $this->getMock('SlmMail\\Service\\MandrillService', array(), array('my-secret-key'));
     $transport = new HttpTransport($service);
     $this->notifier = new EmailNotifier($this->defaultConfigData, $transport);
     $feed = new FeedModel();
     $feed->exchangeArray($this->defaultFeedData);
     $this->assertSame(sprintf('Feed %d has been deleted', $this->defaultFeedData['feedId']), $this->notifier->getNotificationBody($feed, EmailNotifier::NOTIFY_DELETE), 'Returned notification body was not correctly generated');
 }