Пример #1
0
 public function manageAction()
 {
     $formManager = $this->serviceLocator->get('FormElementManager');
     $form = $formManager->get('VideoManager\\Forms\\ManageRecordForm');
     $videoId = (int) $this->params()->fromRoute('id');
     if ($this->getRequest()->isGet()) {
         if (!empty($videoId)) {
             if ($video = $this->videoTable->fetchById($videoId)) {
                 $form->setData($video->getArrayCopy());
             } else {
                 $this->flashMessenger()->addInfoMessage('Unable to find that video. Perhaps a new one?');
                 return $this->redirect()->toRoute('video', array('action' => 'manage'));
             }
         }
     }
     if ($this->getRequest()->isPost()) {
         $form->setData($this->getRequest()->getPost());
         if ($form->isValid()) {
             $video = new Video();
             $video->exchangeArray($form->getData());
             if ($this->videoTable->save($video)) {
                 if ($video->videoId) {
                     $this->flashMessenger()->addInfoMessage('Video updated');
                 } else {
                     $this->flashMessenger()->addInfoMessage('New video created');
                 }
             }
             return $this->redirect()->toRoute('video', array());
         }
     }
     return new ViewModel(array('form' => $form, 'messages' => array('info' => $this->flashMessenger()->hasInfoMessages())));
 }
Пример #2
0
 public function save(Video $video)
 {
     if (!$video->videoId) {
         $data = $video->getArrayCopy();
         unset($data['videoId']);
         if ($this->tableGateway->insert($data)) {
             return $this->tableGateway->getLastInsertValue();
         }
     } else {
         $retstat = $this->tableGateway->update($video->getArrayCopy(), array('videoId' => (int) $video->videoId));
         if ($retstat) {
             return $retstat;
         }
     }
     return false;
 }