[ 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/ -> admindeletecustomfieldsaction.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfields.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfieldsvalues.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/view/admin/admincustomfieldslistview.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   9      
  10      /**
  11       * \ingroup Action
  12       * @private
  13       *
  14       * Removes a custom field, and all the values that have been given
  15       * to that field in all posts
  16       */
  17      class AdminDeleteCustomFieldsAction extends AdminAction
  18      {
  19          
  20          var $_fieldIds;
  21          
  22  		function AdminDeleteCustomFieldsAction( $actionInfo, $request )
  23          {
  24              $this->AdminAction( $actionInfo, $request );
  25              
  26              // data validation, which may vary depending on the parameter
  27              $this->_op = $actionInfo->getActionParamValue();
  28              if( $this->_op == "deleteCustomField" )
  29                  $this->registerFieldValidator( "fieldId", new IntegerValidator());
  30              else
  31                  $this->registerFieldValidator( "fieldIds", new ArrayValidator());
  32              $view = new AdminCustomFieldsListView( $this->_blogInfo );
  33              $view->setErrorMessage( $this->_locale->tr("error_incorrect_field_id"));
  34              $this->setValidationErrorView( $view );            
  35              
  36              $this->requirePermission( "update_custom_field" );
  37          }
  38          
  39          /**
  40           * prepares the data for AdminDeleteCustomFieldsAction::_deleteFields
  41           */
  42  		function perform()
  43          {
  44              if( $this->_op == "deleteCustomField" ) {
  45                  $this->_fieldId = $this->_request->getValue( "fieldId" );
  46                  $this->_fieldIds = Array();
  47                  $this->_fieldIds[] = $this->_fieldId;
  48              }
  49              else
  50                  $this->_fieldIds = $this->_request->getValue( "fieldIds" );
  51                  
  52              $this->_deleteFields();
  53          }
  54          
  55          /**
  56           * @private
  57           */
  58  		function _deleteFields()
  59          {
  60              // otherwise, go through all the selected fields and remove them one by one, 
  61              // also removing the rows that contain the values
  62              $customFields = new CustomFields();
  63              $errorMessage = "";
  64              $successMessage = "";
  65              $totalOk = 0;
  66              
  67              $this->_view = new AdminCustomFieldsListView( $this->_blogInfo );
  68              
  69              foreach( $this->_fieldIds as $fieldId ) {
  70                  $field = $customFields->getCustomField( $fieldId );
  71                  
  72                  if( $field ) {
  73                      // fire the pre-event
  74                      $this->notifyEvent( EVENT_PRE_CUSTOM_FIELD_DELETE, Array( "field" => &$field ));
  75                      
  76                      $result = $customFields->removeCustomField( $fieldId );
  77                      if( $result ) {
  78                          $totalOk++;
  79                          if( $totalOk > 1 ) 
  80                              $successMessage = $this->_locale->pr( "fields_deleted_ok", $totalOk );
  81                          else
  82                              $successMessage = $this->_locale->pr( "field_deleted_ok", $field->getName());
  83                              
  84                          // fire the post-event
  85                          $this->notifyEvent( EVENT_POST_CUSTOM_FIELD_DELETE, Array( "field" => &$field ));
  86                      }
  87                      else
  88                          $errorMessage .= $this->_locale->pr( "error_deleting_field", $field->getName())."<br/>";
  89                  }
  90                  else
  91                      $errorMessage .= $this->_locale->pr( "error_deleting_field2", $fieldId )."<br/>";
  92              }
  93              
  94              if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
  95              if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );
  96              $this->setCommonData();
  97              
  98              return true;
  99          }
 100      }
 101  ?>


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