NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype-1.1.6/class/action/admin/adminaddarticlecategoryajaxaction.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/data/textfilter.class.php" );      
00006         include_once( PLOG_CLASS_PATH."class/view/admin/adminxmlview.class.php" );
00007 
00014     class AdminAddArticleCategoryAjaxAction extends AdminAction 
00015         {
00016 
00017         var $_categoryName;
00018         var $_categoryUrl;
00019                 var $_properties;
00020                 var $_categoryDescription;
00021 
00026         function AdminAddArticleCategoryAjaxAction( $actionInfo, $request )
00027         {
00028                 $this->AdminAction( $actionInfo, $request );
00029         }
00030         function validate()
00031         {
00032                         // fetch the data, we already know it's valid and that we can trust it!
00033                 $this->_categoryName     = Textfilter::filterAllHTML($this->_request->getValue( "categoryName" ));
00034             $this->_categoryUrl      = "";
00035             $this->_categoryInMainPage = 1;
00036                         $this->_categoryDescription = $this->_categoryName;
00037                         $this->_properties = "";               
00038 
00039             // check if there's any file to upload
00040             if( empty($this->_categoryName) || $this->_categoryName == "" ) {
00041                     $this->_view = new AdminXmlView( $this->_blogInfo, "response" );                            
00042                     $this->_view->setValue( "method", "addCategoryAjax" );
00043                 $this->_view->setValue( "success", "0" );
00044                 $this->_view->setValue( "message", $this->_locale->tr("error_adding_article_category") );                   
00045                 return false;
00046             }               
00047             return true;
00048         }
00049 
00053         function perform()
00054         {
00055                         // create the object...
00056             $categories = new ArticleCategories();
00057             $category   = new ArticleCategory( $this->_categoryName,
00058                                                $this->_categoryUrl,
00059                                                $this->_blogInfo->getId(),
00060                                                $this->_categoryInMainPage,
00061                                                                                            $this->_categoryDescription,
00062                                                                                            0,
00063                                                                                            $this->_properties );
00064                                                                                            
00065                         // fire the pre event...
00066                         $this->notifyEvent( EVENT_PRE_CATEGORY_ADD, Array( "category" => &$category ));
00067 
00068                         $this->_view = new AdminXmlView( $this->_blogInfo, "response" );                                
00069                         $this->_view->setValue( "method", "addCategoryAjax" );  
00070             
00071             // once we have built the object, we can add it to the database!
00072             $catId = $categories->addArticleCategory( $category );
00073 
00074             // once we have built the object, we can add it to the database
00075             $this->_view = new AdminXmlView( $this->_blogInfo, "response" );                            
00076             $this->_view->setValue( "method", "addCategoryAjax" );
00077             if( $catId )
00078             {
00079                 $this->_view->setValue( "success", "1" );
00080                 $this->_view->setValue( "message", $this->_locale->pr("category_added_ok", $this->_categoryName) );             
00081                 
00082                 $result = '<id>'.$catId.'</id>';
00083                 $result .= '<name>'.$this->_categoryName.'</name>';
00084                 $this->_view->setValue( "result", $result );
00085                                 
00086                                 // fire the post event
00087                                 $this->notifyEvent( EVENT_POST_CATEGORY_ADD, Array( "category" => &$category ));
00088                                 
00089                                 // clear the cache if everything went fine
00090                                 CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );                                                       
00091                         }             
00092             else
00093             {
00094                 $this->_view->setValue( "success", "0" );
00095                 $this->_view->setValue( "message", $this->_locale->tr("error_adding_article_category") );                
00096             }
00097                 
00098             return true;        
00099         }
00100     }
00101 ?>