[pLog-svn] r2905 - in plog/trunk: class/action/admin class/controller class/view/admin templates/admin

mark at devel.lifetype.net mark at devel.lifetype.net
Sun Feb 5 16:54:18 GMT 2006


Author: mark
Date: 2006-02-05 16:54:18 +0000 (Sun, 05 Feb 2006)
New Revision: 2905

Added:
   plog/trunk/class/action/admin/adminchangepostscategoryaction.class.php
   plog/trunk/class/action/admin/adminchangepostsstatusaction.class.php
Modified:
   plog/trunk/class/controller/admincontrollermap.properties.php
   plog/trunk/class/view/admin/adminpostslistview.class.php
   plog/trunk/templates/admin/editposts.template
Log:
Massive changes of postsList done, now we can massive change:
1. Post Status
2. Post Category (only single-category-selection allowed)

This is only a proof of concept implementation, so here comes the to do list:

1. change locale messages for massive change function
2. Add a "Show Massive Option" icon, after user click the option, then show the related form input.
3. Change the UI of postCategory from combo box to list box. Becasue we have to allow user to select  multiple category.


Added: plog/trunk/class/action/admin/adminchangepostscategoryaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangepostscategoryaction.class.php	2006-02-05 13:38:43 UTC (rev 2904)
+++ plog/trunk/class/action/admin/adminchangepostscategoryaction.class.php	2006-02-05 16:54:18 UTC (rev 2905)
@@ -0,0 +1,101 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.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/template/cachecontrol.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Massive changes posts category
+     */
+    class AdminChangePostsCategoryAction extends AdminAction 
+	{
+
+        var $_postIds;
+        var $_postCategory;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminChangePostsCategoryAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+			$this->registerFieldValidator( "postIds", new ArrayValidator());
+			$this->registerFieldValidator( "postCategory", new IntegerValidator() );
+			$view = new AdminPostsListView( $this->_blogInfo );
+			$view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id"));
+			$this->setValidationErrorView( $view );		
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function _changePostsCategory()
+        {
+        	// Chanages the post category field by selection
+            $articles = new Articles();
+            $errorMessage = "";
+			$successMessage = "";
+			$totalOk = 0;
+			
+            foreach( $this->_postIds as $postId ) {
+            	// get the post
+                $post = $articles->getBlogArticle( $postId, $this->_blogInfo->getId());
+				
+				if( $post ) {
+					// fire the event
+					$this->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$post ));
+					
+					// update the post category
+					$post->setCategoryIds( array( $this->_postCategory ) );
+					$result = $articles->updateArticle( $post );
+					
+					if( !$result ) {
+						$errorMessage .= $this->_locale->pr("error_update_article", $post->getTopic())."<br/>";
+					}
+					else {
+						$totalOk++;
+						if( $totalOk < 2 ) 
+							$successMessage .= $this->_locale->pr("article_updated_ok", $post->getTopic())."<br/>";
+						else
+							$successMessage = $this->_locale->pr("articles_updated_ok", $totalOk );
+						// fire the post event
+						$this->notifyEvent( EVENT_POST_POST_UPDATE, Array( "article" => &$post ));					
+					}
+				}
+				else {
+					$errorMessage .= $this->_locale->pr( "error_updating_article2", $postId )."<br/>";
+				}
+            }
+			
+			// clean up the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());
+
+			$this->_view = new AdminPostsListView( $this->_blogInfo );
+			if( $errorMessage != "" ) 
+				$this->_view->setErrorMessage( $errorMessage );
+			if( $successMessage != "" )
+				$this->_view->setSuccessMessage( $successMessage );
+				
+			$this->setCommonData();
+			
+            return true;
+        }
+		
+		function perform()
+		{
+			// prepare the parameters.. If there's only one category id, then add it to
+			// an array.
+			$this->_postIds = $this->_request->getValue( "postIds" );
+			$this->_postCategory = $this->_request->getValue( "postCategory" );
+				
+			$this->_changePostsCategory();
+		}
+    }
+?>
\ No newline at end of file

Added: plog/trunk/class/action/admin/adminchangepostsstatusaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminchangepostsstatusaction.class.php	2006-02-05 13:38:43 UTC (rev 2904)
+++ plog/trunk/class/action/admin/adminchangepostsstatusaction.class.php	2006-02-05 16:54:18 UTC (rev 2905)
@@ -0,0 +1,101 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.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/template/cachecontrol.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Massive changes posts status
+     */
+    class AdminChangePostsStatusAction extends AdminAction 
+	{
+
+        var $_postIds;
+        var $_postStatus;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminChangePostsStatusAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+			$this->registerFieldValidator( "postIds", new ArrayValidator());
+			$this->registerFieldValidator( "postStatus", new IntegerValidator() );
+			$view = new AdminPostsListView( $this->_blogInfo );
+			$view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id"));
+			$this->setValidationErrorView( $view );		
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function _changePostsStatus()
+        {
+        	// Chanages the post status field by selection
+            $articles = new Articles();
+            $errorMessage = "";
+			$successMessage = "";
+			$totalOk = 0;
+			
+            foreach( $this->_postIds as $postId ) {
+            	// get the post
+                $post = $articles->getBlogArticle( $postId, $this->_blogInfo->getId());
+				
+				if( $post ) {
+					// fire the event
+					$this->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$post ));
+					
+					// update the post status
+					$post->setStatus( $this->_postStatus );
+					$result = $articles->updateArticle( $post );
+					
+					if( !$result ) {
+						$errorMessage .= $this->_locale->pr("error_update_article", $post->getTopic())."<br/>";
+					}
+					else {
+						$totalOk++;
+						if( $totalOk < 2 ) 
+							$successMessage .= $this->_locale->pr("article_updated_ok", $post->getTopic())."<br/>";
+						else
+							$successMessage = $this->_locale->pr("articles_updated_ok", $totalOk );
+						// fire the post event
+						$this->notifyEvent( EVENT_POST_POST_UPDATE, Array( "article" => &$post ));					
+					}
+				}
+				else {
+					$errorMessage .= $this->_locale->pr( "error_updating_article2", $postId )."<br/>";
+				}
+            }
+			
+			// clean up the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());
+
+			$this->_view = new AdminPostsListView( $this->_blogInfo );
+			if( $errorMessage != "" ) 
+				$this->_view->setErrorMessage( $errorMessage );
+			if( $successMessage != "" )
+				$this->_view->setSuccessMessage( $successMessage );
+				
+			$this->setCommonData();
+			
+            return true;
+        }
+		
+		function perform()
+		{
+			// prepare the parameters.. If there's only one category id, then add it to
+			// an array.
+			$this->_postIds = $this->_request->getValue( "postIds" );
+			$this->_postStatus = $this->_request->getValue( "postStatus" );
+				
+			$this->_changePostsStatus();
+		}
+    }
+?>
\ No newline at end of file

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2006-02-05 13:38:43 UTC (rev 2904)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2006-02-05 16:54:18 UTC (rev 2905)
@@ -37,6 +37,9 @@
     // removes a post from the database
     $actions["deletePost"] = "AdminDeletePostAction";
 	$actions["deletePosts"] = "AdminDeletePostAction";
+	// massive change post status & category
+	$actions["changePostsStatus"] = "AdminChangePostsStatusAction";
+	$actions["changePostsCategory"] = "AdminChangePostsCategoryAction";
     // log out
     $actions["Logout"] = "AdminLogoutAction";
     // shows form to add a new link category

Modified: plog/trunk/class/view/admin/adminpostslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminpostslistview.class.php	2006-02-05 13:38:43 UTC (rev 2904)
+++ plog/trunk/class/view/admin/adminpostslistview.class.php	2006-02-05 16:54:18 UTC (rev 2905)
@@ -175,6 +175,7 @@
 			
 			// and all the post status available
 			$postStatusList = ArticleStatus::getStatusList( true );
+			$postStatusListWithoutAll = ArticleStatus::getStatusList( false );
 
             $this->setValue( "categories", $blogCategories );
 			// values for the session, so that we can recover the status
@@ -191,6 +192,7 @@
             $this->setValue( "users", $blogUsers );
             $this->setValue( "months", $this->_getMonths());			
 			$this->setValue( "poststatus", $postStatusList );
+			$this->setValue( "poststatusWithoutAll", $postStatusListWithoutAll );
 			$this->setValue( "searchTerms", $this->_searchTerms );
 			$this->setValue( "pager", $pager );
 			

Modified: plog/trunk/templates/admin/editposts.template
===================================================================
--- plog/trunk/templates/admin/editposts.template	2006-02-05 13:38:43 UTC (rev 2904)
+++ plog/trunk/templates/admin/editposts.template	2006-02-05 16:54:18 UTC (rev 2905)
@@ -1,5 +1,39 @@
 {include file="$admintemplatepath/header.template"}
 {include file="$admintemplatepath/navigation.template" showOpt=editPosts title=$locale->tr("editPosts")}
+	<script type="text/javascript">
+	var errorPostStatusMsg = '{$locale->tr("error_post_status")}';
+	var errorPostCategoryMsg = '{$locale->tr("error_post_category")}';
+	{literal}
+	function submitPostsList(op)
+	{
+		if ( op == 'changePostsStatus' )
+		{
+			if ( document.getElementById("postsList").postStatus.value == -1 )
+		    	window.alert(errorPostStatusMsg);
+			else
+			{
+				document.getElementById("postsList").op.value = op;
+				document.getElementById("postsList").submit();
+			}
+		}
+		else if ( op == 'changePostsCategory' )
+		{
+			if ( document.getElementById("postsList").postCategory.value == -1 )
+		    	window.alert(errorPostCategoryMsg);
+			else
+			{
+				document.getElementById("postsList").op.value = op;
+				document.getElementById("postsList").submit();
+			}
+		}
+		else
+		{
+			document.getElementById("postsList").op.value = op;
+			document.getElementById("postsList").submit();
+		}
+	}
+	{/literal}
+	</script>
 		  <div id="list_nav_bar">
             <div id="list_nav_select">
                 <form id="showBy" action="admin.php" method="post">
@@ -94,7 +128,13 @@
                         <td class="col_highlighted">
                             <a href="?op=editPost&amp;postId={$post->getId()}">
                             {$post->getTopic()|strip_tags}
-                            </a>
+                            </a><br />
+                            &nbsp;&raquo;
+                            <span style="font-weight: normal;">
+                            {foreach name=postCategories from=$post->getCategories() item=postCategory}
+                                <a href="?op=editPosts&amp;showCategory={$postCategory->getId()}&amp;showStatus=0">{$postCategory->getName()}</a>{if !$smarty.foreach.postCategories.last}, {/if}
+                            {/foreach}
+                            </span>
                         </td>
                         <td>
                             {assign var=date value=$post->getDateObject()}
@@ -132,6 +172,7 @@
                             <div class="list_action_button">
                             <a href="?op=editPost&amp;postId={$post->getId()}"><img src="imgs/admin/icon_edit-16.png" alt="{$locale->tr("edit")}" /></a>
                             <a href="?op=deletePost&amp;postId={$post->getId()}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" /></a>
+                            <a href="{$url->postPermalink($post)}"><img src="imgs/admin/icon_url-16.png" alt="{$locale->tr("permalink")}" /></a>
                             <a href="?op=postStats&amp;postId={$post->getId()}"><img src="imgs/admin/icon_stats-16.png" alt="{$locale->tr("statistics")}" /></a>
                             </div>
                         </td>
@@ -142,8 +183,24 @@
         </div>
         <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="op" value="deletePosts" />
+            <label for="postStatus">{$locale->tr("status")}</label>
+            <select name="postStatus" id="postStatus">
+              <option value="-1">-{$locale->tr("select")}-</option>
+              {foreach from=$poststatusWithoutAll key=name item=status}
+                <option value="{$status}" {if $currentstatus == $status} selected="selected"{/if}>{$locale->tr($name)}</option>
+              {/foreach}
+            </select>
+            <input type="button" name="changePostsStatus" value="{$locale->tr("change_status")}" class="submit" onClick="javascript:submitPostsList('changePostsStatus');" />
+            <label for="postCategory">{$locale->tr("categories")}</label>
+            <select name="postCategory" id="postCategory">
+              <option value="-1">-{$locale->tr("select")}-</option>
+              {foreach from=$categories item=category}
+                <option value="{$category->getId()}" {if $currentcategory == $category->getId()} selected="selected" {/if}>{$category->getName()}</option>
+              {/foreach}
+            </select>
+            <input type="button" name="changePostsCategory" value="{$locale->tr("change_category")}" class="submit" onClick="javascript:submitPostsList('changePostsCategory');" />
+            <input type="button" name="delete" value="{$locale->tr("delete")}" class="submit" onClick="javascript:submitPostsList('deletePosts');" />
+            <input type="hidden" name="op" value="" />
         </div>
 
         </form>



More information about the pLog-svn mailing list