[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/data/validator/emptyvalidator.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/view/admin/adminblogcategorieslistview.class.php" ); 9 10 /** 11 * \ingroup Action 12 * @private 13 * 14 * Deletes a blog category from the database 15 */ 16 class AdminDeleteBlogCategoryAction extends AdminAction 17 { 18 19 var $_categoryId; 20 var $_categoryIds; 21 22 /** 23 * Constructor. If nothing else, it also has to call the constructor of the parent 24 * class, BlogAction with the same parameters 25 */ 26 function AdminDeleteBlogCategoryAction( $actionInfo, $request ) 27 { 28 $this->AdminAction( $actionInfo, $request ); 29 30 $this->_mode = $actionInfo->getActionParamValue(); 31 // get the array that contains the categories we'd like to delete 32 if( $this->_mode == "deleteBlogCategory" ) 33 $this->registerFieldValidator( "categoryId", new IntegerValidator()); 34 else 35 $this->registerFieldValidator( "categoryIds", new ArrayValidator()); 36 37 $view = new AdminBlogCategoriesListView( $this->_blogInfo ); 38 $view->setErrorMessage( $this->_locale->tr("error_incorrect_blog_category")); 39 $this->setValidationErrorView( $view ); 40 41 $this->requireAdminPermission( "update_blog_category" ); 42 } 43 44 /** 45 * @private 46 * removes categories from the database 47 */ 48 function _deleteBlogCategories() 49 { 50 $categories = new BlogCategories(); 51 52 $errorMessage = ""; 53 $successMessage = ""; 54 $totalOk = 0; 55 56 foreach( $this->_categoryIds as $categoryId ) { 57 // if there's only one blog category left, we can't do this 58 if( $categories->getNumBlogCategories() == 1 ) { 59 $errorMessage .= $this->_locale->tr( "error_cannot_delete_last_blog_category" ); 60 break; 61 } 62 63 // get the category 64 $category = $categories->getBlogCategory( $categoryId ); 65 if( $category ) { 66 // get how many blogs it has 67 $numBlogs = $category->getNumBlogs( BLOG_STATUS_ALL ); 68 69 // fire the pre-event 70 $this->notifyEvent( EVENT_PRE_DELETE_BLOG_CATEGORY, Array( "category" => &$category )); 71 72 // if it has at least one we can't delete it because then it would break the 73 // integrity of our data in the database... 74 if( $numBlogs > 0 ) { 75 $errorMessage .= $this->_locale->pr( "error_blog_category_has_blogs", $category->getName())."<br/>"; 76 } 77 else { 78 // if everything correct, we can proceed and delete it 79 if( !$categories->deleteBlogCategory( $categoryId, $this->_blogInfo->getId())) 80 $errorMessage .= $this->_locale->pr("error_deleting_blog_category")."<br/>"; 81 else { 82 if( $totalOk < 2 ) 83 $successMessage .= $this->_locale->pr("blog_category_deleted_ok", $category->getName())."<br/>"; 84 else 85 $successMessage = $this->_locale->pr( "blog_categories_deleted_ok", $totalOk ); 86 87 // fire the pre-event 88 $this->notifyEvent( EVENT_POST_DELETE_BLOG_CATEGORY, Array( "category" => &$category )); 89 } 90 } 91 } 92 else { 93 $errorMessage .= $this->_locale->pr("error_deleting_blog_category2", $categoryId)."<br/>"; 94 } 95 } 96 97 // prepare the view and all the information it needs to know 98 $this->_view = new AdminBlogCategoriesListView( $this->_blogInfo ); 99 if( $errorMessage != "" ) 100 $this->_view->setErrorMessage( $errorMessage ); 101 if( $successMessage != "" ) { 102 // and clear the cache to avoid outdated information 103 CacheControl::resetBlogCache( $this->_blogInfo->getId(), false ); 104 $this->_view->setSuccessMessage( $successMessage ); 105 } 106 107 $this->setCommonData(); 108 109 return true; 110 } 111 112 /** 113 * Carries out the specified action 114 */ 115 function perform() 116 { 117 // prepare the parameters.. If there's only one category id, then add it to 118 // an array. 119 if( $this->_mode == "deleteBlogCategory" ) { 120 $this->_categoryIds = Array(); 121 $this->_categoryIds[] = $this->_request->getValue( "categoryId" ); 122 } 123 else 124 $this->_categoryIds = $this->_request->getValue( "categoryIds" ); 125 126 return $this->_deleteBlogCategories(); 127 } 128 } 129 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |