[pLog-svn] r2908 - in plog/trunk: class/action/admin class/controller class/plugin class/view/admin js/ui locale templates/admin

mark at devel.lifetype.net mark at devel.lifetype.net
Mon Feb 6 08:35:40 GMT 2006


Author: mark
Date: 2006-02-06 08:35:40 +0000 (Mon, 06 Feb 2006)
New Revision: 2908

Added:
   plog/trunk/class/action/admin/adminchangecommentsstatusaction.class.php
Modified:
   plog/trunk/class/action/admin/admindeletecommentaction.class.php
   plog/trunk/class/controller/admincontrollermap.properties.php
   plog/trunk/class/plugin/eventlist.properties.php
   plog/trunk/class/view/admin/adminarticlecommentslistview.class.php
   plog/trunk/js/ui/plogui.js
   plog/trunk/locale/locale_en_UK.php
   plog/trunk/locale/locale_zh_TW.php
   plog/trunk/templates/admin/editcomments.template
Log:
Massive change of comments available, now.

Added: plog/trunk/class/action/admin/adminchangecommentsstatusaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangecommentsstatusaction.class.php	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/class/action/admin/adminchangecommentsstatusaction.class.php	2006-02-06 08:35:40 UTC (rev 2908)
@@ -0,0 +1,131 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminarticlecommentslistview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	
+    include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Action that shows a list of all the comments for a given post
+     */
+    class AdminChangeCommentsStatusAction extends AdminAction 
+	{
+
+    	var $_articleId;
+        var $_commentIds;
+        var $_commentStatus;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminChangeCommentsStatusAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+			$this->registerFieldValidator( "articleId", new IntegerValidator());
+			$this->registerFieldValidator( "commentIds", new ArrayValidator());
+			$this->registerFieldValidator( "commentStatus", new IntegerValidator());
+			$view = new AdminArticleCommentsListView( $this->_blogInfo );
+			$view->setErrorMessage( $this->_locale->tr("error_updating_comments"));
+			$this->setValidationErrorView( $view );
+        }
+		
+		/**
+		 * sets up the parameters and calls the method below
+		 */
+		function perform()
+		{
+			$this->_articleId = $this->_request->getValue( "articleId" );
+			$this->_commentIds = $this->_request->getValue( "commentIds" );
+			$this->_commentStatus = $this->_request->getValue( "commentStatus" );
+				
+			$this->_changeComments();
+		}
+
+        /**
+         * changes comments status
+		 * @private
+         */
+        function _changeComments()
+        {
+            $comments = new ArticleComments();
+            $errorMessage = "";
+			$successMessage = "";
+			$totalOk = 0;
+			
+			if( $articleId > 0 ) {
+				// if we can't even load the article, then forget it...
+				$articles = new Articles();
+				$article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
+				if( !$article ) {
+					$this->_view = new AdminArticleCommentsListView( $this->_blogInfo );
+					$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));
+					$this->setCommonData();
+					
+					return false;
+				}
+			}
+			else {
+				// there was no article, so this probably was the view that shows all comments...
+				$article = null;
+			}
+			
+			// loop through the comments and remove them
+            foreach( $this->_commentIds as $commentId ) {
+            	// fetch the comment
+				$comment = $comments->getComment( $commentId );
+				
+				if( !$comment ) {
+					$errorMessage .= $this->_locale->pr("error_updating_comment2", $commentId);
+				}
+				else {
+					// fire the pre-event
+					$this->notifyEvent( EVENT_PRE_COMMENT_UPDATE, Array( "comment" => &$comment ));
+					
+					// check if the comment really belongs to this blog...
+					$article = $comment->getArticle();
+					if( $article->getBlogId() != $this->_blogInfo->getId()) {
+						// if not, then we shouldn't be allowed to remove anything!						
+						$errorMessage .= $this->_locale->pr("error_deleting_comment", $comment->getTopic())."<br/>";
+					}
+					else {
+						if( !$comments->updateCommentStatus( $commentId, $this->_commentStatus ))
+							$errorMessage .= $this->_locale->pr("error_updating_comment", $comment->getTopic())."<br/>";
+						else {
+							$totalOk++;
+							if( $totalOk < 2 )
+								$successMessage .= $this->_locale->pr("comment_updating_ok", $comment->getTopic())."<br/>";
+							else
+								$successMessage = $this->_locale->pr("comments_updating_ok", $totalOk );
+							
+							// fire the post-event
+							$this->notifyEvent( EVENT_POST_COMMENT_UPDATE, Array( "comment" => &$comment ));
+						}
+					}
+				}
+            }
+
+			// if everything fine, then display the same view again with the feedback
+			if( $this->_articleId == 0 )
+				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));
+			else
+				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $article ));
+				
+			if( $successMessage != "" ) {
+				$this->_view->setSuccessMessage( $successMessage );
+				// clear the cache
+				CacheControl::resetBlogCache( $this->_blogInfo->getId());
+			}
+			if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
+            $this->setCommonData();
+
+            // better to return true if everything fine
+            return true;
+        }
+    }
+?>

Modified: plog/trunk/class/action/admin/admindeletecommentaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admindeletecommentaction.class.php	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/class/action/admin/admindeletecommentaction.class.php	2006-02-06 08:35:40 UTC (rev 2908)
@@ -2,7 +2,6 @@
 
 	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminarticlecommentslistview.class.php" );
-	include_once( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	
     include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
@@ -35,7 +34,7 @@
 			else
 				$this->registerFieldValidator( "commentIds", new ArrayValidator());
 				
-			$view = new AdminPostsListView( $this->_blogInfo );
+			$view = new AdminArticleCommentsListView( $this->_blogInfo );
 			$view->setErrorMessage( $this->_locale->tr("error_deleting_comments"));
 			$this->setValidationErrorView( $view );
         }
@@ -73,7 +72,7 @@
 				$articles = new Articles();
 				$article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
 				if( !$article ) {
-					$this->_view = new AdminPostsListView( $this->_blogInfo );
+					$this->_view = new AdminArticleCommentsListView( $this->_blogInfo );
 					$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));
 					$this->setCommonData();
 					

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2006-02-06 08:35:40 UTC (rev 2908)
@@ -90,6 +90,8 @@
     // deletes a comment
     $actions["deleteComment"] = "AdminDeleteCommentAction";
 	$actions["deleteComments"] = "AdminDeleteCommentAction";
+	// massive change comments status
+	$actions["changeCommentsStatus"] = "AdminChangeCommentsStatusAction";	
     // show the user settings
     $actions["userSettings"] = "AdminUserSettingsAction";
     // update the user settings

Modified: plog/trunk/class/plugin/eventlist.properties.php
===================================================================
--- plog/trunk/class/plugin/eventlist.properties.php	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/class/plugin/eventlist.properties.php	2006-02-06 08:35:40 UTC (rev 2908)
@@ -37,8 +37,8 @@
 	// before and after a comment is added, updated and deleted
 	define( "EVENT_PRE_COMMENT_ADD", 18 ); 
 	define( "EVENT_POST_COMMENT_ADD", 19 ); 
-	define( "EVENT_PRE_COMMENT_UPDATE", 20 ); // can't be generated!
-	define( "EVENT_POST_COMMENT_UPDATE", 21 ); // can't be generated!
+	define( "EVENT_PRE_COMMENT_UPDATE", 20 );
+	define( "EVENT_POST_COMMENT_UPDATE", 21 );
 	define( "EVENT_PRE_COMMENT_DELETE", 22 ); 
 	define( "EVENT_POST_COMMENT_DELETE", 23 ); 
 	// before and after a comment is marked as spam and no-spam

Modified: plog/trunk/class/view/admin/adminarticlecommentslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminarticlecommentslistview.class.php	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/class/view/admin/adminarticlecommentslistview.class.php	2006-02-06 08:35:40 UTC (rev 2908)
@@ -111,9 +111,12 @@
 														
 			// get a list with all the different comment status
 			$statusList = ArticleCommentStatus::getStatusList( true );
+			$statusListWithoutAll = ArticleCommentStatus::getStatusList( false );
+			
 			// and pass all the information to the templates
 			$this->setValue( "comments", $postComments);
 			$this->setValue( "commentstatus", $statusList );
+			$this->setValue( "commentstatusWithoutAll", $statusListWithoutAll );
 			$this->setValue( "currentstatus", $this->_commentStatus );
 			$this->setValue( "searchTerms", $this->_searchTerms );
 

Modified: plog/trunk/js/ui/plogui.js
===================================================================
--- plog/trunk/js/ui/plogui.js	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/js/ui/plogui.js	2006-02-06 08:35:40 UTC (rev 2908)
@@ -176,6 +176,25 @@
 	}
 }
 
+function submitCommentsList(op)
+{
+	if ( op == 'changeCommentsStatus' )
+	{
+		if ( document.getElementById("postCommentsList").commentStatus.value == -1 )
+	    	window.alert(errorCommentStatusMsg);
+		else
+		{
+			document.getElementById("postCommentsList").op.value = op;
+			document.getElementById("postCommentsList").submit();
+		}
+	}
+	else
+	{
+		document.getElementById("postCommentsList").op.value = op;
+		document.getElementById("postCommentsList").submit();
+	}
+}
+
 function switchMassiveOption()
 {
 	if ( $('massiveChangeOption').style.display == 'none' )

Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/locale/locale_en_UK.php	2006-02-06 08:35:40 UTC (rev 2908)
@@ -986,7 +986,9 @@
 $messages['messave_change_option'] = 'Massive Change Option';
 $messages['show_massive_change_option'] = 'Show Massive Change Options';
 $messages['hide_massive_change_option'] = 'Hide Massive Change Options';
-$messages['error_post_status'] = 'Please select post status.';
 $messages['change_status'] = 'Change Status';
 $messages['change_category'] = 'Change Category';
+
+$messages['error_post_status'] = 'Please select post status.';
+$messages['error_comment_status'] = 'Please select comment status.';
 ?>
\ No newline at end of file

Modified: plog/trunk/locale/locale_zh_TW.php
===================================================================
--- plog/trunk/locale/locale_zh_TW.php	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/locale/locale_zh_TW.php	2006-02-06 08:35:40 UTC (rev 2908)
@@ -986,7 +986,9 @@
 $messages['messave_change_option'] = '大量修改選項';
 $messages['show_massive_change_option'] = '顯示大量修改選項';
 $messages['hide_massive_change_option'] = '隱藏大量修改選項';
-$messages['error_post_status'] = '請選擇文章狀態。';
 $messages['change_status'] = '修改狀態';
 $messages['change_category'] = '修改分類';
+
+$messages['error_post_status'] = '請選擇文章狀態。';
+$messages['error_comment_status'] = '請選擇迴響狀態。';
 ?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/editcomments.template
===================================================================
--- plog/trunk/templates/admin/editcomments.template	2006-02-06 06:12:45 UTC (rev 2907)
+++ plog/trunk/templates/admin/editcomments.template	2006-02-06 08:35:40 UTC (rev 2908)
@@ -1,5 +1,11 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=editComments title=$locale->tr("editComments")}
+	<script type="text/javascript" src="js/ui/plogui.js"></script>
+	<script type="text/javascript">
+		var errorCommentStatusMsg = '{$locale->tr("error_comment_status")}';
+		var showMassiveChangeOption = '{$locale->tr("show_massive_change_option")}';
+		var hideMassiveChangeOption = '{$locale->tr("hide_massive_change_option")}';
+	</script>
         <div id="list_nav_bar">
             <div id="list_nav_select">		
 
@@ -36,6 +42,9 @@
         </div>
 		
         <form id="postCommentsList" action="admin.php" method="post">
+        <div class="optionIcon">
+			<a id="optionIconLink" href="#" title="{$locale->tr("show_massive_change_option")}" onclick="switchMassiveOption()">{$locale->tr("show_massive_change_option")}</a>
+		</div>          
         <div id="list">
   {include file="$admintemplatepath/successmessage.template"}
   {include file="$admintemplatepath/errormessage.template"}
@@ -108,9 +117,22 @@
 
         <div id="list_action_bar">
 	    {include file="$admintemplatepath/adminpager.template" style=list}
-            <input type="submit" name="delete" value="{$locale->tr("delete")}" class="submit" />
 			<input type="hidden" name="articleId" value="{if $post}{$post->getId()}{else}0{/if}" />
-            <input type="hidden" name="op" value="deleteComments" />
+            <input type="button" name="delete" value="{$locale->tr("delete")}" class="submit" onClick="javascript:submitCommentsList('deleteComments');" />
+            <input type="hidden" name="op" value="" />
+            <div id="massiveChangeOption" style="display: none">
+                <fieldset>
+                <legend>{$locale->tr("messave_change_option")}</legend>            
+		            <label for="commentStatus">{$locale->tr("status")}</label>
+		            <select name="commentStatus" id="commentStatus">
+		              <option value="-1">-{$locale->tr("select")}-</option>
+		              {foreach from=$commentstatusWithoutAll key=name item=status}
+		                <option value="{$status}" {if $currentstatus == $status} selected="selected"{/if}>{$locale->tr($name)}</option>
+		              {/foreach}
+		            </select>
+		            <input type="button" name="changeCommentsStatus" value="{$locale->tr("change_status")}" class="submit" onClick="javascript:submitCommentsList('changeCommentsStatus');" /> 
+		        </fieldset>
+			</div>              
         </div>
         </form>
 {include file="$admintemplatepath/footernavigation.template"}



More information about the pLog-svn mailing list