Beispiel #1
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id, $replyId = null, $latest = null)
 {
     $page = null;
     $model = $this->loadModel($id);
     if (!is_null($latest) && !Yii::app()->request->isAjaxRequest) {
         $replyId = $model->lastPost->id;
     }
     if (!is_null($replyId) && !Yii::app()->request->isAjaxRequest) {
         $post = TopicReplies::model()->findByPk($replyId);
         if (!is_null($post)) {
             $page = $post->getTopicPage();
         } else {
             $replyId = null;
         }
     }
     $this->noBackdrop = true;
     $topicReply = new TopicReplies();
     if (!isset($_GET['ajax'])) {
         $log = new ViewLog();
         $log->user = Yii::app()->user->getName();
         $log->recordType = get_class($model);
         $log->recordId = $model->id;
         $log->timestamp = time();
         $log->save();
         X2Flow::trigger('RecordViewTrigger', array('model' => $model));
     }
     $dataProvider = new CArrayDataProvider($model->replies, array('id' => 'topic-replies', 'pagination' => array('pageSize' => Topics::PAGE_SIZE)));
     $dataProvider->getPagination()->setItemCount($dataProvider->getTotalItemCount());
     if (!Yii::app()->request->isAjaxRequest && !is_null($page)) {
         $dataProvider->getPagination()->setCurrentPage($page);
     }
     $this->render('view', array('model' => $model, 'replyId' => $replyId, 'dataProvider' => $dataProvider, 'topicReply' => $topicReply, 'page' => is_null($page) ? $dataProvider->getPagination()->getCurrentPage() : $page));
 }
 public function run($id)
 {
     parent::beforeRun();
     $model = $this->getModel($id);
     $reply = new TopicReplies();
     if (isset($_POST['TopicReplies'])) {
         if (!$this->controller->checkPermissions($model, 'view')) {
             $this->controller->denied();
         }
         $reply->text = $_POST['TopicReplies']['text'];
         $reply->topicId = $model->id;
         $this->controller->setFileFields($reply, true);
         if ($reply->save()) {
             if (isset($_FILES['TopicReplies'])) {
                 Yii::app()->end();
             }
             $reply = new TopicReplies();
         } else {
             if (isset($_FILES['TopicReplies'])) {
                 throw new CHttpException(400, Yii::t('app', 'Upload failed'));
             }
         }
     }
     $this->controller->pageClass = $this->pageClass;
     $this->controller->dataUrl = $model->getUrl();
     //       AuxLib::debugLogR ('$_GET = ');
     //        AuxLib::debugLogR ($_GET);
     //
     //        if (isset ($_GET['topic-replies_page'])) {
     //            AuxLib::debugLogR ('merging');
     //            $this->controller->dataUrl .= '/topic-replies_page/' . $_GET['topic-replies_page'];
     //           AuxLib::debugLogR ('$this->controller->dataUrl = ');
     //            AuxLib::debugLogR ($this->controller->dataUrl);
     //
     //
     //        }
     $this->controller->pageId .= '-' . $model->id;
     $this->controller->headerTitle = $model->name;
     User::addRecentItem(get_class($model), $id);
     $dataProvider = new CArrayDataProvider($model->replies, array('id' => 'topic-replies', 'pagination' => array('pageSize' => Topics::PAGE_SIZE)));
     $dataProvider->getPagination()->setItemCount($dataProvider->getTotalItemCount());
     $this->controller->render($this->pathAliasBase . 'views.mobile.topicsView', array('model' => $model, 'reply' => $reply, 'dataProvider' => $dataProvider));
 }