[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/action/admin/ -> adminaddarticlecategoryaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/emptyvalidator.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );    
   9      lt_include( PLOG_CLASS_PATH."class/view/admin/adminarticlecategorieslistview.class.php" );
  10  
  11      /**
  12       * \ingroup Action
  13       * @private
  14       *
  15       * Action that adds a new article category to the database.
  16       */
  17      class AdminAddArticleCategoryAction extends AdminAction 
  18      {
  19  
  20          var $_categoryName;
  21          var $_categoryUrl;
  22          var $_properties;
  23          var $_categoryDescription;
  24  
  25          /**
  26           * Constructor. If nothing else, it also has to call the constructor of the parent
  27           * class, BlogAction with the same parameters
  28           */
  29          function AdminAddArticleCategoryAction( $actionInfo, $request )
  30          {
  31              $this->AdminAction( $actionInfo, $request );
  32              
  33              // register two validators
  34              $this->registerFieldValidator( "categoryName", new StringValidator());
  35              $this->registerFieldValidator( "categoryDescription", new StringValidator());
  36              $this->registerFieldValidator( "categoryInMainPage", new EmptyValidator());
  37              // and the view we should show in case there is a validation error
  38              $errorView = new AdminTemplatedView( $this->_blogInfo, "newpostcategory" );
  39              $errorView->setErrorMessage( $this->_locale->tr("error_adding_article_category" ));            
  40              $this->setValidationErrorView( $errorView );
  41              
  42              $this->requirePermission( "add_category" );
  43  
  44          }
  45  
  46          /**
  47           * Carries out the specified action
  48           */
  49          function perform()
  50          {
  51              // fetch the data, we already know it's valid and that we can trust it!
  52              $this->_categoryName     = Textfilter::filterAllHTML($this->_request->getValue( "categoryName" ));
  53              $this->_categoryUrl      = $this->_request->getValue( "categoryUrl" );
  54              $this->_categoryInMainPage = Textfilter::checkboxToBoolean($this->_request->getValue( "categoryInMainPage" ));
  55              $this->_categoryDescription = Textfilter::filterAllHTML($this->_request->getValue( "categoryDescription" ));
  56              $this->_properties = $this->_request->getValue( "properties" );        
  57          
  58              // create the object...
  59              $categories = new ArticleCategories();
  60              $category   = new ArticleCategory( $this->_categoryName,
  61                                                 $this->_categoryUrl,
  62                                                 $this->_blogInfo->getId(),
  63                                                 $this->_categoryInMainPage,
  64                                                 $this->_categoryDescription,
  65                                                 0,
  66                                                 $this->_properties );
  67                                                 
  68              // fire the pre event...
  69              $this->notifyEvent( EVENT_PRE_CATEGORY_ADD, Array( "category" => &$category ));
  70  
  71              // once we have built the object, we can add it to the database!
  72              if( $categories->addArticleCategory( $category )) {
  73                  // if everything went fine, transfer the execution flow to the action that
  74                  // lists all the article categories... without forgetting that we should let the
  75                  // next class know that we actually added a category alongside a message
  76                  // and the category that we just added!
  77                  if( $this->userHasPermission( "view_categories" )) 
  78                      $this->_view = new AdminArticleCategoriesListView( $this->_blogInfo );
  79                  else
  80                      $this->_view = new AdminTemplatedView( $this->_blogInfo, "newpostcategory" );
  81                      
  82                  $this->_view->setSuccess( true );
  83                  $this->_view->setSuccessMessage( $this->_locale->pr("category_added_ok", $category->getName()));
  84                  
  85                  // fire the post event
  86                  $this->notifyEvent( EVENT_POST_CATEGORY_ADD, Array( "category" => &$category ));
  87                  
  88                  // clear the cache if everything went fine
  89                  CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );                                                        
  90                  
  91                  $this->setCommonData();                
  92              }
  93              else {
  94                  // if there was an error, we should say so... as well as not changing the view since
  95                  // we're going back to the original view where we can add the category
  96                  $this->_view->setError( true );
  97                  $this->_view->setErrorMessage( $this->_locale->tr("error_adding_article_category" ));
  98                  $this->setCommonData( true );
  99              }
 100  
 101              // better to return true if everything fine
 102              return true;
 103          }
 104      }
 105  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics