[ 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/ -> admindeletepermissionsaction.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/permissions.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/adminpermissionslistview.class.php" );
   9  
  10      /**
  11       * \ingroup Action
  12       * @private
  13       *
  14       * Deletes an permission
  15       */
  16      class AdminDeletePermissionsAction extends AdminAction 
  17      {
  18  
  19          var $_permId;
  20          var $_permIds;
  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 AdminDeletePermissionsAction( $actionInfo, $request )
  27          {
  28              $this->AdminAction( $actionInfo, $request );
  29              $this->_mode = $actionInfo->getActionParamValue();
  30              
  31              if( $this->_mode == "deletePermission" ) 
  32                      $this->registerFieldValidator( "permId", new IntegerValidator());
  33              else 
  34                      $this->registerFieldValidator( "permIds", new ArrayValidator());
  35                  
  36              $view = new AdminPermissionsListView( $this->_blogInfo );
  37              $view->setErrorMessage( $this->_locale->tr("error_incorrect_permission_id"));
  38              $this->setValidationErrorView( $view );        
  39              
  40              $this->requireAdminPermission( "update_permission" );
  41          }
  42  
  43          /**
  44           * @private
  45           */
  46  		function _deletePermissions()
  47          {
  48              $perms = new Permissions();
  49              
  50              $errorMessage = "";
  51              $successMessage = "";
  52              $totalOk = 0;
  53              
  54              foreach( $this->_permIds as $permId ) {
  55                  // get the permission
  56                  $perm = $perms->getPermission( $permId );
  57                  
  58                  if( $perm ) {
  59                      // get how many articles it has
  60                      $numUsers = $perm->getNumUsersWithPermission();
  61                                          
  62                      // if everything correct, we can proceed and delete it
  63                      if( $numUsers > 0 || $perm->isCorePermission()) {
  64                          $errorMessage .= $this->_locale->pr( "error_permission_cannot_be_deleted", $perm->getName())."<br/>";
  65                      }
  66                      else {                                    
  67                          // fire the pre-event
  68                          $this->notifyEvent( EVENT_PRE_DELETE_PERMISSION, Array( "permission" => &$perm ));
  69                          
  70                          if( !$perms->deletePermission( $permId ))
  71                              $errorMessage .= $this->_locale->pr("error_deleting_permission", $perm->getName())."<br/>";
  72                          else {
  73                              if( $totalOk < 2 )
  74                                  $successMessage .= $this->_locale->pr( "permission_deleted_ok", $perm->getName())."<br/>";
  75                              else
  76                                  $successMessage = $this->_locale->pr( "permissions_deleted_ok", $totalOk );
  77                                  
  78                              // fire the pre-event
  79                              $this->notifyEvent( EVENT_POST_DELETE_PERMISSION, Array( "permission" => &$perm ));
  80                          }
  81                      }
  82                  }
  83                  else {
  84                      $errorMessage .= $this->_locale->pr("error_deleting_permission2", $permId)."<br/>";
  85                  }
  86              }
  87                          
  88              // prepare the view and all the information it needs to know
  89              $this->_view = new AdminPermissionsListView( $this->_blogInfo );
  90              if( $errorMessage != "" ) 
  91                  $this->_view->setErrorMessage( $errorMessage );
  92              if( $successMessage != "" ) {
  93                  // and clear the cache to avoid outdated information
  94                  CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );            
  95                  $this->_view->setSuccessMessage( $successMessage );
  96              }
  97                  
  98              $this->setCommonData();
  99              
 100              return true;
 101          }
 102  
 103          /**
 104           * Carries out the specified action
 105           */
 106          function perform()
 107          {
 108              if( $this->_mode == "deletePermission" ) {
 109                  $this->_permIds = Array();
 110                  $this->_permIds[] = $this->_request->getValue( "permId" );
 111              }
 112              else
 113                  $this->_permIds = $this->_request->getValue( "permIds" );
 114              
 115              return $this->_deletePermissions();
 116          }
 117      }
 118  ?>


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