NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype/branches/lifetype-1.0.6/class/action/admin/adminaddarticlecategoryaction.class.php

Go to the documentation of this file.
00001 <?php
00002 
00003         include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00005     include_once( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/data/validator/emptyvalidator.class.php" );
00008         include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );      
00009         include_once( PLOG_CLASS_PATH."class/view/admin/adminarticlecategorieslistview.class.php" );
00010 
00017     class AdminAddArticleCategoryAction extends AdminAction 
00018         {
00019 
00020         var $_categoryName;
00021         var $_categoryUrl;
00022                 var $_properties;
00023                 var $_categoryDescription;
00024 
00029         function AdminAddArticleCategoryAction( $actionInfo, $request )
00030         {
00031                 $this->AdminAction( $actionInfo, $request );
00032                         
00033                         // register two validators
00034                         $this->registerFieldValidator( "categoryName", new StringValidator());
00035                         $this->registerFieldValidator( "categoryDescription", new StringValidator());
00036                         $this->registerFieldValidator( "categoryInMainPage", new EmptyValidator());
00037                         // and the view we should show in case there is a validation error
00038                         $errorView = new AdminTemplatedView( $this->_blogInfo, "newpostcategory" );
00039                         $errorView->setErrorMessage( $this->_locale->tr("error_adding_article_category" ));                     
00040                         $this->setValidationErrorView( $errorView );
00041 
00042         }
00043 
00047         function perform()
00048         {
00049                         // fetch the data, we already know it's valid and that we can trust it!
00050                 $this->_categoryName     = Textfilter::filterAllHTML($this->_request->getValue( "categoryName" ));
00051             $this->_categoryUrl      = $this->_request->getValue( "categoryUrl" );
00052             $this->_categoryInMainPage = Textfilter::checkboxToBoolean($this->_request->getValue( "categoryInMainPage" ));
00053                         $this->_categoryDescription = Textfilter::filterAllHTML($this->_request->getValue( "categoryDescription" ));
00054                         $this->_properties = $this->_request->getValue( "properties" );         
00055                 
00056                         // create the object...
00057             $categories = new ArticleCategories();
00058             $category   = new ArticleCategory( $this->_categoryName,
00059                                                $this->_categoryUrl,
00060                                                $this->_blogInfo->getId(),
00061                                                $this->_categoryInMainPage,
00062                                                                                            $this->_categoryDescription,
00063                                                                                            0,
00064                                                                                            $this->_properties );
00065                                                                                            
00066                         // fire the pre event...
00067                         $this->notifyEvent( EVENT_PRE_CATEGORY_ADD, Array( "category" => &$category ));
00068 
00069             // once we have built the object, we can add it to the database!
00070             if( $categories->addArticleCategory( $category )) {
00071                                 // if everything went fine, transfer the execution flow to the action that
00072                                 // lists all the article categories... without forgetting that we should let the
00073                                 // next class know that we actually added a category alongside a message
00074                                 // and the category that we just added!
00075                                 $this->_view = new AdminArticleCategoriesListView( $this->_blogInfo );
00076                                 $this->_view->setSuccess( true );
00077                                 $this->_view->setSuccessMessage( $this->_locale->pr("category_added_ok", $category->getName()));
00078                                 
00079                                 // fire the post event
00080                                 $this->notifyEvent( EVENT_POST_CATEGORY_ADD, Array( "category" => &$category ));
00081                                 
00082                                 // clear the cache if everything went fine
00083                                 CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );                                                                                                               
00084                                 
00085                                 $this->setCommonData();                         
00086             }
00087             else {
00088                                 // if there was an error, we should say so... as well as not changing the view since
00089                                 // we're going back to the original view where we can add the category
00090                                 $this->_view->setError( true );
00091                                 $this->_view->setErrorMessage( $this->_locale->tr("error_adding_article_category" ));
00092                                 $this->setCommonData( true );
00093             }
00094 
00095             // better to return true if everything fine
00096             return true;
00097         }
00098     }
00099 ?>