public function actionIndex() { if (Yii::app()->user->isGuest) { if (Yii::app()->request->isPostRequest && isset($_POST["login"])) { $user = new User("login"); $user->setAttributes($_POST["login"]); $user->remember = true; if ($user->login()) { $this->redirect("/"); } else { Yii::app()->user->setFlash("error", $user->getError("pass")); } } if (p()['registerType'] == "INVITE") { $this->layout = "empty"; $this->render("index_guest"); return; } } $this->layout = "column1"; $hot_key = sprintf("hot.%d.%d.%d", Yii::app()->user->ini["hot.s_lang"], Yii::app()->user->ini["hot.t_lang"], Yii::app()->user->ini["hot.img"]); if (!($hot = Yii::app()->cache->get($hot_key))) { $C = new CDbCriteria(array("condition" => "t.ac_read = 'a'", "order" => "t.last_tr DESC NULLS LAST")); $C->limit = Yii::app()->user->ini["hot.img"] ? 12 : 36; if (Yii::app()->user->ini["hot.s_lang"]) { $C->addCondition("t.s_lang = " . Yii::app()->user->ini["hot.s_lang"]); } if (Yii::app()->user->ini["hot.t_lang"]) { $C->addCondition("t.t_lang = " . Yii::app()->user->ini["hot.t_lang"]); } $hot = Book::model()->findAll($C); Yii::app()->cache->set($hot_key, $hot, 60); } if (!($announces = Yii::app()->cache->get("announces"))) { $announces = Announce::model()->with("book.cat", "book.owner", "seen")->findAll(array("condition" => "t.topics BETWEEN 80 AND 89 AND book.ac_read = 'a'", "order" => "t.cdate desc", "limit" => 5)); Yii::app()->cache->set("announces", $announces, 90); } if (!($blog = Yii::app()->cache->get("blog"))) { $blog = BlogPost::model()->common()->findAll(["limit" => 10]); Yii::app()->cache->set("blog", $blog, 105); } $this->render('index', array("hot" => $hot, "searchTop" => $this->getSearchTop(), "announces" => $announces, "blog" => $blog)); }
/** * The index handler. * * @access public * @return string The HTML code. */ public function index() { $Announce = new Announce(); $this->getView()->set('Announces', $Announce->findList(array('Type = ' . $this->getAnnounceType()), 'PostedAt desc, Id desc')); return $this->getView()->render(); }
protected function getAnnounces(&$announces) { $announces = Announce::orderBy('wy_announce_time', 'desc')->paginate(PERPAGE_COUNT_20); foreach ($announces as $index => $announce) { $announceTime = $announce->wy_announce_time; $announce->wy_announce_date = Carbon::parse($announceTime)->toDateString(); } }
public function actionEdit($book_id, $post_id = 0) { $post_id = (int) $post_id; $book = $this->loadBook($book_id); if (!$book->can("announce") && !Yii::app()->user->can("blog_moderate")) { throw new CHttpException(403, "Вы не можете анонсировать этот перевод. " . $book->getWhoCanDoIt("announce")); } if ($post_id != 0) { $post = Announce::model()->findByPk($post_id, "t.topics BETWEEN 80 AND 89 AND book_id = :book_id", array(":book_id" => $book->id)); if (!$post) { throw new CHttpException(404, "Анонса не существует. Возможно, его удалили."); } } else { $post = new Announce(); $post->user_id = Yii::app()->user->id; $post->book_id = $book->id; $post->cdate = date("Y-m-d H:i:s"); if ($post->wasToday) { Yii::app()->user->setFlash("warning", "Внимание! <span title='По московскому времени'>Сегодня</span> уже был опубликован анонс этого перевода. Вы сможете разместить следующий анонс только завтра."); } } $post->book = $book; if (isset($_POST["Announce"])) { $post->attributes = $_POST["Announce"]; if ($post->save()) { // Добавляем пост в мои обсуждения $post->setTrack(); $this->redirect($post->url); } } $this->side_view = array("edit_side" => array("book" => $book)); $this->render("edit", array("book" => $book, "post" => $post)); }