Exemplo n.º 1
0
 /**
  * @param $book_id
  * @param $chap_id
  * @param int $show
  * @param null $show_user
  * @param null $tt
  * @param null $to
  * @throws CHttpException
  */
 public function actionIndex($book_id, $chap_id, $show = 0, $show_user = null, $tt = null, $to = null)
 {
     $this->layout = "column1";
     $chap = $this->loadChapter($book_id, $chap_id);
     $filter = new TrFilter();
     $filter->setAttributes($_GET);
     $filter->validate();
     $f = new Orig();
     $f->with("seen", "bookmark", "trs.user")->chapter($chap->id);
     $crit = new CDbCriteria(array("order" => $chap->book->typ == "S" ? "t.t1" : "t.ord"));
     // $crit->mergeWith($filter->getCriteria()) или $filter->modifyCriteria($crit)
     if ($filter->show == 1) {
         // Непереведённое
         $crit->addCondition("t.n_trs = 0");
     } elseif ($filter->show == 7) {
         // >1 варианта
         $crit->addCondition("t.n_trs > 1");
     } elseif ($filter->show == 2) {
         // От пользователя
         $u = User::model()->findByAttributes(array("login" => $filter->show_user));
         if (!$u) {
             $filter->show = 0;
             Yii::app()->user->setFlash("error", "Пользователя " . CHtml::encode($filter->show_user) . " не существует.");
         } else {
             $crit->addCondition("trs.user_id = {$u->id}");
             $f->together();
         }
     } elseif ($filter->show == 3) {
         // С комментариями
         $crit->mergeWith(array("condition" => "t.n_comments > 0"));
     } elseif ($filter->show == 4) {
         // С новыми комментариями
         $crit->mergeWith(array("condition" => "COALESCE(seen.n_comments, 0) < t.n_comments"));
     } elseif ($filter->show == 5) {
         // Оригинал содержит
         $to = trim(strip_tags($to));
         if ($to == "") {
             $filter->show = 0;
         } else {
             $crit->mergeWith(array("condition" => "t.body ILIKE :like", "params" => array(":like" => "%" . addcslashes($to, "%_") . "%")));
         }
     } elseif ($filter->show == 6) {
         // Перевод содержит
         $tt = trim(strip_tags($tt));
         if ($tt == "") {
             $filter->show = 0;
         } else {
             $crit->mergeWith(array("condition" => "trs.body ILIKE :like", "params" => array(":like" => "%" . addcslashes($tt, "%_") . "%")));
             $f->together();
         }
     }
     $orig_dp = new CActiveDataProvider($f, array("criteria" => $crit, "pagination" => array("pageSize" => 50)));
     if ($filter->show == 0) {
         $orig_dp->totalItemCount = $chap->n_verses;
     }
     $chap->book->registerJS();
     $chap->registerJS();
     $view = "index-" . intval(Yii::app()->user->ini["t.iface"]);
     $this->render($view, array("chap" => $chap, "orig_dp" => $orig_dp, "filter" => $filter, "show" => $show, "show_user" => $show_user, "to" => $to, "tt" => $tt));
 }