Beispiel #1
0
 /**
  * Saves the given media object to the db
  *
  * @param \Media\Model\Media $media
  *
  * @throws \Exception
  */
 public function saveMedia(Media $media)
 {
     $data = ['account_id' => $media->getAccountId(), 'title' => $media->getTitle(), 'url' => $media->getUrl(), 'date_posted' => $media->getDatePosted()];
     $id = (int) $media->getId();
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getMedia($id)) {
             $this->tableGateway->update($data, ['id' => $id]);
         } else {
             throw new \Exception('Media id does not exist');
         }
     }
 }
 /**
  * Adds a new News to the db or opens up the form for adding, if it isn't opened yet.
  *
  * @return array|\Zend\Http\Response
  * @throws \Exception
  */
 public function addAction()
 {
     if (!PermissionChecker::check(Role::MEMBER)) {
         return $this->redirect()->toRoute('account', ['action' => 'noright']);
     }
     $form = new MediaForm();
     $session = new Container('user');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $media = new Media();
         $form->setInputFilter($media->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $media->exchangeArray($form->getData());
             $media->setUrl($this->embedVideo($media->getUrl()));
             $this->getMediaTable()->saveMedia($media);
             return $this->redirect()->toRoute('media');
         } else {
             $errors = $form->getMessages();
             return ['form' => $form, 'accountId' => $session->id, 'errors' => $errors];
         }
     }
     return ['form' => $form, 'accountId' => $session->id];
 }