Example #1
0
 public function addComment($parent_id, $article_id, $text)
 {
     $comment = new CommentDB();
     if (!$this->auth_user) {
         return false;
     }
     $comment->article_id = $article_id;
     $comment->user_id = $this->auth_user->id;
     $comment->parent_id = $parent_id;
     $comment->text = $text;
     try {
         $comment->save();
         /*не верно*/
         $comment_parent = new CommentDB();
         $comment_parent->load($parent_id);
         if ($comment_parent->isSaved() && $comment_parent->user_id != $this->auth_user->id) {
             $user = new UserDB();
             $user->load($comment_parent->user_id);
             $this->mail->send($user->email, array("user" => $user, "link" => $comment_parent->link), "comment_subscribe");
         }
         return json_encode(array("id" => $comment->id, "parent_id" => $comment->parent_id, "user_id" => $this->auth_user->id, "name" => $this->auth_user->name, "avatar" => $this->auth_user->avatar, "text" => $comment->text, "date" => $comment->date));
     } catch (Exception $e) {
         return false;
     }
 }
 protected function preDelete()
 {
     $comments = CommentDB::getAllOnParentID($this->id);
     foreach ($comments as $comment) {
         try {
             $comment->delete();
         } catch (Exception $e) {
             return false;
         }
     }
     return true;
 }
 public function actionArticle()
 {
     $article_db = new ArticleDB();
     $article_db->load($this->request->id);
     //загружаем id для выгрузки нужной статьи из базы
     if (!$article_db->isSaved()) {
         $this->notFound();
     } else {
         $this->title = $article_db->title;
         $this->meta_desc = $article_db->meta_desc;
         $this->meta_key = $article_db->meta_key;
         $hornav = $this->getHornav();
         //горизонтальная навигация
         if ($article_db->section) {
             $this->section_id = $article_db->section->id;
             $hornav->addData($article_db->section->title, $article_db->section->link);
             $this->url_active = URL::get("section", "", array("id" => $article_db->section->id));
         }
         if ($article_db->category) {
             $hornav->addData($article_db->category->title, $article_db->category->link);
             $this->url_active = URL::get("category", "", array("id" => $article_db->category->id));
         }
         $hornav->addData($article_db->title);
         $prev_article_db = new ArticleDB();
         $prev_article_db->loadPrevArticle($article_db);
         $next_article_db = new ArticleDB();
         $next_article_db->loadNextArticle($article_db);
         $article = new Article();
         $article->hornav = $hornav;
         $article->auth_user = $this->auth_user;
         $article->article = $article_db;
         if ($prev_article_db->isSaved()) {
             $article->prev_article = $prev_article_db;
         }
         if ($next_article_db->isSaved()) {
             $article->next_article = $next_article_db;
         }
         $article->link_register = URL::get("register");
         $comments = CommentDB::getAllOnArticleID($article_db->id);
         $article->comments = $comments;
         $this->render($article);
     }
 }
Example #4
0
 private function postHandling()
 {
     $this->setSectionAndCategory();
     //подгружаем разделы и категории
     $this->count_comments = CommentDB::getCountOnArticleID($this->id);
     //кол-во коментариев
     $this->day_show = ObjectDB::getDay($this->date);
     $this->month_show = ObjectDB::getMonth($this->date);
 }
 private function postHandling()
 {
     $this->setSectionAndCategory();
     $this->count_comments = CommentDB::getCountOnArticleID($this->id);
     $this->day_show = ObjectDB::getDay($this->date);
     $this->month_show = ObjectDB::getMonth($this->date);
 }