[ 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/ -> admindeletearticlecategoryaction.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/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/adminarticlecategorieslistview.class.php" );
   9  
  10      /**
  11       * \ingroup Action
  12       * @private
  13       *
  14       * Deletes an article category from the database
  15       */
  16      class AdminDeleteArticleCategoryAction 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 AdminDeleteArticleCategoryAction( $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 == "deleteArticleCategory" ) 
  33                  $this->registerFieldValidator( "categoryId", new IntegerValidator());
  34              else 
  35                  $this->registerFieldValidator( "categoryIds", new ArrayValidator());
  36                  
  37              $view = new AdminArticleCategoriesListView( $this->_blogInfo );
  38              $view->setErrorMessage( $this->_locale->tr("error_incorrect_category_id"));
  39              $this->setValidationErrorView( $view );        
  40          }
  41  
  42          /**
  43           * @private
  44           * removes categories from the database
  45           */
  46  		function _deleteArticleCategories()
  47          {
  48              $categories = new ArticleCategories();
  49              
  50              $errorMessage = "";
  51              $successMessage = "";
  52              $totalOk = 0;
  53              
  54              foreach( $this->_categoryIds as $categoryId ) {
  55                  // get the category
  56                  $category   = $categories->getCategory( $categoryId, $this->_blogInfo->getId());
  57                  if( $category ) {
  58                      // get how many articles it has
  59                      //$numArticles = $categories->getNumArticlesCategory( $categoryId );
  60                      $numArticles = $category->getNumArticles( POST_STATUS_ALL );
  61                      
  62                      // fire the pre-event
  63                      $this->notifyEvent( EVENT_PRE_CATEGORY_DELETE, Array( "category" => &$category ));
  64  
  65                      // if it has at least one we can't delete it because then it would break the
  66                      // integrity of our data in the database...
  67                      if( $numArticles > 0 ) {
  68                          $errorMessage .= $this->_locale->pr( "error_category_has_articles", $category->getName())."<br/>";
  69                      }
  70                      else {
  71                          // if everything correct, we can proceed and delete it
  72                          if( !$categories->deleteCategory( $categoryId, $this->_blogInfo->getId()))
  73                              $errorMessage .= $this->_locale->pr("error_deleting_category")."<br/>";
  74                          else {
  75                              if( $totalOk < 2 )
  76                                  $successMessage .= $this->_locale->pr("category_deleted_ok", $category->getName())."<br/>";
  77                              else
  78                                  $successMessage = $this->_locale->pr( "categories_deleted_ok", $totalOk );
  79                                  
  80                              // fire the pre-event
  81                              $this->notifyEvent( EVENT_POST_CATEGORY_DELETE, Array( "category" => &$category ));
  82                          }
  83                      }
  84                  }
  85                  else {
  86                      $errorMessage .= $this->_locale->pr("error_deleting_category2", $categoryId)."<br/>";
  87                  }
  88              }
  89              
  90              // prepare the view and all the information it needs to know
  91              $this->_view = new AdminArticleCategoriesListView( $this->_blogInfo );
  92              if( $errorMessage != "" ) 
  93                  $this->_view->setErrorMessage( $errorMessage );
  94              if( $successMessage != "" ) {
  95                  // and clear the cache to avoid outdated information
  96                  CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );            
  97                  $this->_view->setSuccessMessage( $successMessage );
  98              }
  99                  
 100              $this->setCommonData();
 101              
 102              return true;
 103          }
 104  
 105          /**
 106           * Carries out the specified action
 107           */
 108          function perform()
 109          {
 110              // prepare the parameters.. If there's only one category id, then add it to
 111              // an array.
 112              if( $this->_mode == "deleteArticleCategory" ) {
 113                  $this->_categoryIds = Array();
 114                  $this->_categoryIds[] = $this->_request->getValue( "categoryId" );
 115              }
 116              else
 117                  $this->_categoryIds = $this->_request->getValue( "categoryIds" );
 118              
 119              return $this->_deleteArticleCategories();
 120          }
 121      }
 122  ?>


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