NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype/branches/lifetype-1.0.6/class/action/commentaction.class.php

Go to the documentation of this file.
00001 <?php
00002 
00003         include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/view/blogview.class.php" );
00005         include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00008     include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00009     include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00010     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00011 
00018         class CommentAction extends BlogAction 
00019         {
00020 
00021         var $_articleId;
00022         var $_parentId;
00023 
00024                 function ViewArticleAction( $actionInfo, $request )
00025         {
00026                         $this->BlogAction( $actionInfo, $request );
00027                         
00028                         // data validation
00029                         $this->registerFieldValidator( "articleId", new IntegerValidator());
00030                         $this->registerFieldValidator( "parentId", new IntegerValidator());                     
00031             $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_incorrect_article_id" ));
00032         }
00033 
00034         function perform()
00035         {
00036                         // fetch the data and make some arrangements if needed
00037                 $this->_parentId  = $this->_request->getValue( "parentId" );
00038             $this->_articleId = $this->_request->getValue( "articleId" );       
00039                                         
00040             if( $this->_parentId < 0 || $this->_parentId == "" )
00041                 $this->_parentId = 0;
00042                                 
00043             // check if comments are enabled
00044             $blogSettings = $this->_blogInfo->getSettings();
00045             if( !$blogSettings->getValue( "comments_enabled" )) {
00046                 $this->_view = new ErrorView( $this->_blogInfo, "error_comments_not_enabled" );
00047                 $this->setCommonData();
00048 
00049                 return false;
00050             }                                                                   
00051 
00052             // fetch the article
00053             $blogs    = new Blogs();
00054             $articles = new Articles();
00055             $article  = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
00056                         
00057             // if there was a problem fetching the article, we give an error and quit
00058             if( $article == false ) {
00059                 $this->_view = new ErrorView( $this->_blogInfo );
00060                 $this->_view->setValue( "message", "error_fetching_article" );
00061                 $this->setCommonData();
00062                 return false;
00063             }                   
00064 
00065                 $this->_view = new BlogView( $this->_blogInfo, "commentarticle", SMARTY_VIEW_CACHE_CHECK, 
00066                                                                                            Array( "articleId" => $this->_articleId, "parentId" => $this->_parentId ));
00067                         // do nothing if the view was already cached
00068                         if( $this->_view->isCached()) 
00069                                 return true;
00070 
00071                         // fetch the comments so far
00072                         $comments = new ArticleComments();
00073                         $postComments = $comments->getPostComments( $article->getId());
00074                         if( $this->_parentId > 0 ) {
00075                                 // get a pre-set string for the subject field, for those users interested
00076                                 $comment = $comments->getPostComment( $article->getId(), $this->_parentId );
00077                                 // create the string
00078                                 if( $comment ) {
00079                                         $replyString = $this->_locale->tr("reply_string").$comment->getTopic();
00080                                         $this->_view->setValue( "comment", $comment );
00081                                 }
00082                         }                       
00083 
00084             // if everything's fine, we set up the article object for the view
00085             $this->_view->setValue( "post", $article );
00086             $this->_view->setValue( "parentId", $this->_parentId );
00087                         $this->_view->setValue( "comments", $postComments );
00088                         $this->_view->setValue( "postcomments", $postComments );
00089                         $this->_view->setValue( "topic", $replyString );                        
00090             
00091             $this->setCommonData();
00092 
00093             // and return everything normal
00094             return true;
00095         }
00096     }
00097 ?>