NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype-1.1.6/class/action/admin/adminaddblogcategoryaction.class.php

Go to the documentation of this file.
00001 <?php
00002 
00003         include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" );
00005     include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );   
00006         include_once( PLOG_CLASS_PATH."class/view/admin/adminblogcategorieslistview.class.php" );
00007 
00014     class AdminAddBlogCategoryAction extends SiteAdminAction 
00015         {
00016 
00017         var $_categoryName;
00018                 var $_categoryDescription;
00019 
00024         function AdminAddBlogCategoryAction( $actionInfo, $request )
00025         {
00026                 $this->SiteAdminAction( $actionInfo, $request );
00027                         
00028                         // register two validators
00029                         $this->registerFieldValidator( "categoryName", new StringValidator());
00030                         $this->registerFieldValidator( "categoryDescription", new StringValidator());
00031                         // and the view we should show in case there is a validation error
00032                         $errorView = new AdminTemplatedView( $this->_blogInfo, "newblogcategory" );
00033                         $errorView->setErrorMessage( $this->_locale->tr("error_adding_blog_category" ));                        
00034                         $this->setValidationErrorView( $errorView );
00035         }
00036 
00040         function perform()
00041         {
00042                         // fetch the data, we already know it's valid and that we can trust it!
00043                 $this->_categoryName     = $this->_request->getValue( "categoryName" );
00044                         $this->_categoryDescription = $this->_request->getValue( "categoryDescription" );
00045                 
00046                         // create the object...
00047             $categories = new BlogCategories();
00048             $category   = new BlogCategory( $this->_categoryName, $this->_categoryDescription );
00049                                                                                            
00050                         // fire the pre event...
00051                         $this->notifyEvent( EVENT_PRE_ADD_BLOG_CATEGORY, Array( "category" => &$category ));
00052 
00053             // once we have built the object, we can add it to the database!
00054             if( $categories->addBlogCategory( $category )) {
00055                                 $this->_view = new AdminBlogCategoriesListView( $this->_blogInfo );
00056                                 $this->_view->setSuccess( true );
00057                                 $this->_view->setSuccessMessage( $this->_locale->pr("blog_category_added_ok", $category->getName()));
00058                                 
00059                                 // fire the post event
00060                                 $this->notifyEvent( EVENT_POST_ADD_BLOG_CATEGORY, Array( "category" => &$category ));
00061                                 
00062                                 // clear the cache if everything went fine
00063                                 CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );                                                                                                               
00064                                 
00065                                 $this->setCommonData();
00066             }
00067             else {
00068                                 // if there was an error, we should say so... as well as not changing the view since
00069                                 // we're going back to the original view where we can add the category
00070                                 $this->_view->setError( true );
00071                                 $this->_view->setErrorMessage( $this->_locale->tr("error_adding_category" ));
00072                                 $this->setCommonData( true );
00073             }
00074 
00075             // better to return true if everything fine
00076             return true;
00077         }
00078     }
00079 ?>