[pLog-svn] r2334 - in plog/trunk: class/action/admin
class/controller class/dao locale
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Thu Jul 14 21:45:09 GMT 2005
Author: oscar
Date: 2005-07-14 21:45:08 +0000 (Thu, 14 Jul 2005)
New Revision: 2334
Added:
plog/trunk/class/action/admin/admindeleteblogcategoryaction.class.php
Modified:
plog/trunk/class/controller/admincontrollermap.properties.php
plog/trunk/class/dao/blogcategories.class.php
plog/trunk/class/dao/blogcategory.class.php
plog/trunk/locale/locale_en_UK.php
Log:
added support for removing blog categories
Added: plog/trunk/class/action/admin/admindeleteblogcategoryaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admindeleteblogcategoryaction.class.php 2005-07-14 21:44:16 UTC (rev 2333)
+++ plog/trunk/class/action/admin/admindeleteblogcategoryaction.class.php 2005-07-14 21:45:08 UTC (rev 2334)
@@ -0,0 +1,121 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/emptyvalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminblogcategorieslistview.class.php" );
+
+ /**
+ * \ingroup Action
+ * @private
+ *
+ * Deletes a blog category from the database
+ */
+ class AdminDeleteBlogCategoryAction extends SiteAdminAction
+ {
+
+ var $_categoryId;
+ var $_categoryIds;
+
+ /**
+ * Constructor. If nothing else, it also has to call the constructor of the parent
+ * class, BlogAction with the same parameters
+ */
+ function AdminDeleteBlogCategoryAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+
+ $this->_mode = $actionInfo->getActionParamValue();
+ // get the array that contains the categories we'd like to delete
+ if( $this->_mode == "deleteBlogCategory" )
+ $this->registerFieldValidator( "categoryId", new IntegerValidator());
+ else
+ $this->registerFieldValidator( "categoryIds", new ArrayValidator());
+
+ $view = new AdminBlogCategoriesListView( $this->_blogInfo );
+ $view->setErrorMessage( $this->_locale->tr("error_incorrect_blog_category"));
+ $this->setValidationErrorView( $view );
+ }
+
+ /**
+ * @private
+ * removes categories from the database
+ */
+ function _deleteBlogCategories()
+ {
+ $categories = new BlogCategories();
+
+ $errorMessage = "";
+ $successMessage = "";
+ $totalOk = 0;
+
+ foreach( $this->_categoryIds as $categoryId ) {
+ // get the category
+ $category = $categories->getBlogCategory( $categoryId );
+ if( $category ) {
+ // get how many blogs it has
+ $numBlogs = $category->getNumBlogs( BLOG_STATUS_ALL );
+
+ // fire the pre-event
+ $this->notifyEvent( EVENT_PRE_BLOG_CATEGORY_DELETE, Array( "category" => &$category ));
+
+ // if it has at least one we can't delete it because then it would break the
+ // integrity of our data in the database...
+ if( $numBlogs > 0 ) {
+ $errorMessage .= $this->_locale->pr( "error_blog_category_has_blogs", $category->getName())."<br/>";
+ }
+ else {
+ // if everything correct, we can proceed and delete it
+ if( !$categories->deleteBlogCategory( $categoryId, $this->_blogInfo->getId()))
+ $errorMessage .= $this->_locale->pr("error_deleting_blog_category")."<br/>";
+ else {
+ if( $totalOk < 2 )
+ $successMessage .= $this->_locale->pr("blog_category_deleted_ok", $category->getName())."<br/>";
+ else
+ $successMessage = $this->_locale->pr( "blog_categories_deleted_ok", $totalOk );
+
+ // fire the pre-event
+ $this->notifyEvent( EVENT_POST_BLOG_CATEGORY_DELETE, Array( "category" => &$category ));
+ }
+ }
+ }
+ else {
+ $errorMessage .= $this->_locale->pr("error_deleting_blog_category2", $categoryId)."<br/>";
+ }
+ }
+
+ // prepare the view and all the information it needs to know
+ $this->_view = new AdminBlogCategoriesListView( $this->_blogInfo );
+ if( $errorMessage != "" )
+ $this->_view->setErrorMessage( $errorMessage );
+ if( $successMessage != "" ) {
+ // and clear the cache to avoid outdated information
+ CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
+ $this->_view->setSuccessMessage( $successMessage );
+ }
+
+ $this->setCommonData();
+
+ return true;
+ }
+
+ /**
+ * Carries out the specified action
+ */
+ function perform()
+ {
+ // prepare the parameters.. If there's only one category id, then add it to
+ // an array.
+ if( $this->_mode == "deleteBlogCategory" ) {
+ $this->_categoryIds = Array();
+ $this->_categoryIds[] = $this->_request->getValue( "categoryId" );
+ }
+ else
+ $this->_categoryIds = $this->_request->getValue( "categoryIds" );
+
+ return $this->_deleteBlogCategories();
+ }
+ }
+?>
Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php 2005-07-14 21:44:16 UTC (rev 2333)
+++ plog/trunk/class/controller/admincontrollermap.properties.php 2005-07-14 21:45:08 UTC (rev 2334)
@@ -259,4 +259,6 @@
$actions["newBlogCategory"] = "AdminNewBlogCategoryAction";
$actions["addBlogCategory"] = "AdminAddBlogCategoryAction";
$actions["editBlogCategories"] = "AdminBlogCategoriesAction";
+ $actions["deleteBlogCategory"] = "AdminDeleteBlogCategoryAction";
+ $actions["deleteBlogCategories"] = "AdminDeleteBlogCategoryAction";
?>
Modified: plog/trunk/class/dao/blogcategories.class.php
===================================================================
--- plog/trunk/class/dao/blogcategories.class.php 2005-07-14 21:44:16 UTC (rev 2333)
+++ plog/trunk/class/dao/blogcategories.class.php 2005-07-14 21:45:08 UTC (rev 2334)
@@ -141,6 +141,35 @@
}
/**
+ * returns how many blogs have been categorized under this category
+ *
+ * @param categoryId
+ * @param blogStatus
+ * @return an integer
+ */
+ function getNumBlogsCategory( $categoryId, $status = BLOG_STATUS_ALL )
+ {
+ $prefix = $this->getPrefix();
+ $query = "SELECT COUNT(*) AS total
+ FROM {$prefix}blogs b
+ WHERE b.blog_category_id = '".Db::qstr( $categoryId )."'";
+ if( $status != BLOG_STATUS_ALL )
+ $query .= " AND status = '".Db::qstr( $status )."'";
+
+ $result = $this->Execute( $query );
+
+ if( !$result )
+ return 0;
+
+ $row = $result->FetchRow();
+ $total = $row["total"];
+ if( $total == "" ) $total = 0;
+
+ return( $total );
+
+ }
+
+ /**
* @private
*/
function _mapRow( $row )
Modified: plog/trunk/class/dao/blogcategory.class.php
===================================================================
--- plog/trunk/class/dao/blogcategory.class.php 2005-07-14 21:44:16 UTC (rev 2333)
+++ plog/trunk/class/dao/blogcategory.class.php 2005-07-14 21:45:08 UTC (rev 2334)
@@ -78,8 +78,12 @@
* @param status A valid post status
* @return An integer value
*/
- function getNumBlogs( $status = BLOG_STATUS_ACTIVE )
+ function getNumBlogs( $status = BLOG_STATUS_ACTIVE )
{
+ include_once( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
+
+ $categories = new BlogCategories();
+ return( $categories->getNumBlogsCategory( $this->getId(), $status ));
}
/**
Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php 2005-07-14 21:44:16 UTC (rev 2333)
+++ plog/trunk/locale/locale_en_UK.php 2005-07-14 21:45:08 UTC (rev 2334)
@@ -925,4 +925,9 @@
$messages['newBlogCategory'] = 'New Blog Category';
$messages['editBlogCategories'] = 'Blog Categories';
$messages['blog_category_added_ok'] = 'Blog category added successfully';
+$messages['error_blog_category_has_blogs'] = 'The blog category "%s" has some blogs assigned to it. Please edit first the blogs and then try again.';
+$messages['error_deleting_blog_category'] = 'There was an error deleting blog category "%s"';
+$messages['blog_category_deleted_ok'] = 'Blog category "%s" was deleted successfully';
+$messages['blog_categories_deleted_ok'] = '%s blog categories deleted successfully';
+$messages['error_deleting_blog_category2'] = 'There was an error removing the blog category with id %s';
?>
\ No newline at end of file
More information about the pLog-svn
mailing list