コード例 #1
0
 /**
  * Edit resource's settings
  *
  * @param integer $connectionId
  * @param integer $resourceId
  * @param integer $roleId
  * @param array $settings
  *      integer actions_limit
  *      integer actions_reset
  *      integer date_start
  *      integer date_end
  * @param integer $userId
  * @param boolean $cleanActionCounter
  * @return integer|string
  */
 public function editResourceSettings($connectionId, $resourceId, $roleId, array $settings = [], $userId = 0, $cleanActionCounter = false)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         // delete old settings
         $delete = $this->delete()->from('acl_resource_connection_setting')->where(['connection_id' => $connectionId]);
         if (!$userId) {
             $delete->where->IsNull('user_id');
             // global settings
         } else {
             $delete->where(['user_id' => $userId]);
         }
         $statement = $this->prepareStatementForSqlObject($delete);
         $statement->execute();
         // check settings
         $processedSettings = [];
         foreach ($settings as $name => $value) {
             if ((int) $value) {
                 // skip empty values
                 $processedSettings[$name] = $value;
             }
         }
         if ($processedSettings) {
             $extraValues = $userId ? ['user_id' => $userId, 'connection_id' => $connectionId] : ['connection_id' => $connectionId];
             $insert = $this->insert()->into('acl_resource_connection_setting')->values(array_merge($processedSettings, $extraValues));
             $statement = $this->prepareStatementForSqlObject($insert);
             $statement->execute();
         }
         // clean the action counter
         if ($cleanActionCounter && $userId) {
             $delete = $this->delete()->from('acl_resource_action_track')->where(['connection_id' => $connectionId, 'user_id' => $userId]);
             $statement = $this->prepareStatementForSqlObject($delete);
             $statement->execute();
         }
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the edit acl resource settings event
     AclEvent::fireEditAclResourceSettingsEvent($connectionId, $resourceId, $roleId, $userId);
     return true;
 }