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()); }
/** * @return null|\PostImages */ public function getMainImg() { return $mainImg = \PostPeer::getPostMainImg($this->getId()); }