Ejemplo n.º 1
0
 /**
  * Add new slide show
  *
  * @return bool|\Phalcon\Http\ResponseInterface
  */
 public function newAction()
 {
     $this->_toolbar->addSaveButton();
     $this->_toolbar->addCancelButton('index');
     $form = new SlideShowForm();
     $this->view->setVar('form', $form);
     if ($this->request->isPost()) {
         $slideShow = new SlideShows();
         if ($form->isValid($_POST, $slideShow)) {
             if ($slideShow->save()) {
                 $imageStatus = ZImageHelper::uploadImages($this->request->getUploadedFiles(), self::SLIDE_SHOW_FOLDER_UPLOAD . '/' . $slideShow->slide_show_id, 'image');
                 if ($imageStatus['status']) {
                     $slideShow->image = $imageStatus['imageUrl'];
                     $slideShow->save();
                 } else {
                     if ($imageStatus['message']) {
                         $this->flashSession->notice($imageStatus['message']);
                     }
                     if ($imageStatus['bugMessage']) {
                         $this->flashSession->notice($imageStatus['bugMessage']);
                     }
                 }
                 $this->flashSession->success(__('m_admin_slide_message_add_new_slide_show_successfully', [$slideShow->title]));
                 return $this->response->redirect('/admin/slide/index/edit/' . $slideShow->slide_show_id . '/');
             } else {
                 $this->setFlashSession($slideShow->getMessages(), 'notice');
             }
         }
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * Edit slide show item
  *
  * @param $slideID
  * @param $slideItemID
  * @return bool|\Phalcon\Http\ResponseInterface
  */
 public function editAction($slideID, $slideItemID)
 {
     $this->view->pick('manage-slide/new');
     $slideID = intval($slideID);
     /**
      * @var $slideShow SlideShows
      */
     $slideShow = SlideShows::findFirst(['conditions' => 'slide_show_id = ?0', 'bind' => [$slideID]]);
     if (!$slideShow) {
         return $this->response->redirect('/admin/slide/');
     }
     $slideItemID = intval($slideItemID);
     /**
      * @var $slideShowItems SlideShowItems
      */
     $slideShowItems = SlideShowItems::findFirst(['conditions' => 'slide_show_item_id = ?0', 'bind' => [$slideItemID]]);
     if (!$slideShowItems) {
         return $this->response->redirect('/admin/slide/');
     }
     $this->_toolbar->addHeaderPrimary(__('m_admin_manage_slide_edit_slide_item') . ': <i>' . $slideShow->title . '</i>');
     $this->_toolbar->addSaveButton();
     $this->_toolbar->addCancelButton('index', '/admin/slide/manage-slide/slide/' . $slideID . '/');
     $form = new SlideShowItemForm($slideShowItems);
     $this->view->setVar('slideShowItems', $slideShowItems);
     $this->view->setVar('form', $form);
     if ($this->request->isPost()) {
         if ($form->isValid($_POST, $slideShowItems)) {
             if ($slideShowItems->save()) {
                 $imageStatus = ZImageHelper::uploadImages($this->request->getUploadedFiles(), self::SLIDE_SHOW_FOLDER_UPLOAD . '/' . $slideShow->slide_show_id . '/slide-item', 'image', null, $slideShowItems->image);
                 if ($imageStatus['status']) {
                     $slideShowItems->image = $imageStatus['imageUrl'];
                     $slideShowItems->save();
                 } else {
                     if ($imageStatus['message']) {
                         $this->flashSession->notice($imageStatus['message']);
                     }
                     if ($imageStatus['bugMessage']) {
                         $this->flashSession->notice($imageStatus['bugMessage']);
                     }
                 }
                 $this->flashSession->success('Add new slide show successfully');
                 return $this->response->redirect('/admin/slide/manage-slide/edit/' . $slideShow->slide_show_id . '/' . $slideShowItems->slide_show_item_id . '/');
             } else {
                 $this->setFlashSession($slideShowItems->getMessages(), 'notice');
             }
         }
     }
     return null;
 }