예제 #1
0
 public function executeMakeStar()
 {
     $this->validAjaxRequest();
     $res = new \AjaxResponse();
     if (!($postImg = \PostImages::retrieveById($this->post('id')))) {
         $res->type = \AjaxResponse::ERROR;
         $res->message = t("Image not found");
         return $this->renderText($res->toString());
     }
     if (!$postImg->getIsMain()) {
         $postImg->beginTransaction();
         try {
             $currentMain = \PostPeer::getPostMainImg($postImg->getPostId());
             $postImg->setIsMain(true);
             if ($postImg->save(false)) {
                 $currentMain->setIsMain(false);
                 $currentMain->save(false);
             }
             $postImg->commit();
         } catch (\Exception $e) {
             $postImg->rollBack();
             throw $e;
         }
     }
     $result = [];
     $images = \PostPeer::getPostImg($postImg->getPostId());
     foreach ($images as $image) {
         $t = $image->toArray();
         $t['thumb_url'] = $image->getThumbs(96, 96);
         $t['url'] = $image->getUrl();
         $result[] = $t;
     }
     $res->images = $result;
     $res->type = \AjaxResponse::SUCCESS;
     return $this->renderText($res->toString());
 }
예제 #2
0
파일: Posts.php 프로젝트: hosivan90/toxotes
 /**
  * @return null|\PostImages
  */
 public function getMainImg()
 {
     return $mainImg = \PostPeer::getPostMainImg($this->getId());
 }