예제 #1
0
파일: Post.php 프로젝트: hosivan90/toxotes
 public function executeEdit()
 {
     $post = \Posts::retrieveById($this->request()->get('id'));
     $taxonomy = $this->request()->get('taxonomy');
     if (!$post) {
         Session::getInstance()->setFlash('post_error', t('Post not found'));
         $this->redirect($this->createUrl('post/default', array('taxonomy' => $taxonomy)));
     }
     if (null == $taxonomy) {
         $taxonomy = $post->getTaxonomy();
     }
     $error = array();
     if ($this->request()->isPostRequest()) {
         if ($this->_save($post, $error)) {
             Session::getInstance()->setFlash('post_message', t($post->getTitle() . ' was saved'));
             $this->redirect($this->createUrl('post/default', array('taxonomy' => $taxonomy)));
         }
     }
     $images = \PostPeer::getPostImg($post->getId());
     $files = \PostPeer::getPostAttachments($post->getId());
     //Hydrate
     $jsData = $post->toArray();
     $jsData['images'] = [];
     foreach ($images as $img) {
         $t = $img->toArray();
         $t['thumb_url'] = $img->getThumbs(96, 96);
         $t['url'] = $img->getUrl();
         $jsData['images'][] = $t;
     }
     $jsData['files'] = [];
     foreach ($files as $f) {
         $jsData['files'] = $f->toArray();
     }
     $this->document()->addJsVar('post', $jsData);
     //JS URL
     $this->document()->addJsVar('img_upload_url', $this->createUrl('post_img/upload'));
     $this->document()->addJsVar('img_remove_url', $this->createUrl('post_img/remove'));
     $this->document()->addJsVar('img_set_main_url', $this->createUrl('post_img/make_star'));
     $this->document()->addJsVar('img_update_url', $this->createUrl('post_img/update'));
     $this->setView('Post/form');
     $this->view()->assign(array('post' => $post, 'taxonomy' => $taxonomy, 'error' => $error, 'page_title' => t('Edit ' . $post->getTitle())));
     return $this->renderComponent();
 }
예제 #2
0
 public function executeRemove()
 {
     $this->validAjaxRequest();
     $res = new \AjaxResponse();
     if (!($postImg = \PostImages::retrieveById($this->request()->post('id')))) {
         $res->type = \AjaxResponse::ERROR;
         $res->message = t("Image not found");
         return $this->renderText($res->toString());
     }
     if ($postImg->delete()) {
         $otherImages = [];
         if (($otherImages = \PostPeer::getPostImg($postImg->getPostId())) && $postImg->getIsMain()) {
             $otherImages[0]->setIsMain(true);
             $otherImages[0]->save();
         }
         $result = [];
         foreach ($otherImages as $image) {
             $t = $image->toArray();
             $t['thumb_url'] = $image->getThumbs(96, 96);
             $t['url'] = $image->getUrl();
             $result[] = $t;
         }
         $res->images = $result;
         $res->postImg = $postImg->toArray();
         $res->type = \AjaxResponse::SUCCESS;
         return $this->renderText($res->toString());
     }
     $res->type = \AjaxResponse::ERROR;
     $res->message = t("Unknown error");
     return $this->renderText($res->toString());
 }