[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/things/ -> validator-permission.php (source)

   1  <?php
   2  /**
   3   * Things: GP_Validator_Permission class
   4   *
   5   * @package GlotPress
   6   * @subpackage Things
   7   * @since 1.0.0
   8   */
   9  
  10  /**
  11   * Core class used to implement the validator permissions.
  12   *
  13   * @since 1.0.0
  14   */
  15  class GP_Validator_Permission extends GP_Permission {
  16  
  17      var $table_basename           = 'gp_permissions';
  18      var $field_names              = array( 'id', 'user_id', 'action', 'object_type', 'object_id' );
  19      var $non_db_field_names       = array( 'project_id', 'locale_slug', 'set_slug' );
  20      var $non_updatable_attributes = array( 'id' );
  21  
  22      public $object_type;
  23      public $project_id;
  24      public $locale_slug;
  25      public $set_slug;
  26  
  27      /**
  28       * Sets restriction rules for fields.
  29       *
  30       * @since 1.0.0
  31       *
  32       * @param GP_Validation_Rules $rules The validation rules instance.
  33       */
  34  	public function restrict_fields( $rules ) {
  35          $rules->project_id_should_not_be( 'empty' );
  36          $rules->locale_slug_should_not_be( 'empty' );
  37          $rules->user_id_should_not_be( 'empty' );
  38          $rules->action_should_not_be( 'empty' );
  39          $rules->set_slug_should_not_be( 'empty' );
  40      }
  41  
  42      /**
  43       * Sets fields of the current GP_Thing object.
  44       *
  45       * @param array $fields Fields for a GP_Thing object.
  46       */
  47  	public function set_fields( $fields ) {
  48          parent::set_fields( $fields );
  49          if ( $this->object_id ) {
  50              list( $this->project_id, $this->locale_slug, $this->set_slug ) = $this->project_id_locale_slug_set_slug( $this->object_id );
  51          }
  52          $this->object_type        = 'project|locale|set-slug';
  53          $this->default_conditions = "object_type = '" . $this->object_type . "'";
  54      }
  55  
  56  	public function prepare_fields_for_save( $args ) {
  57          $args                = (array) $args;
  58          $args['object_type'] = $this->object_type;
  59          if ( gp_array_get( $args, 'project_id' ) && gp_array_get( $args, 'locale_slug' )
  60                  && gp_array_get( $args, 'set_slug' ) && ! gp_array_get( $args, 'object_id' ) ) {
  61              $args['object_id'] = $this->object_id( $args['project_id'], $args['locale_slug'], $args['set_slug'] );
  62          }
  63          $args = parent::prepare_fields_for_save( $args );
  64          return $args;
  65      }
  66  
  67  	public function project_id_locale_slug_set_slug( $object_id ) {
  68          return explode( '|', $object_id );
  69      }
  70  
  71  	public function object_id( $project_id, $locale_slug, $set_slug = 'default' ) {
  72          return implode( '|', array( $project_id, $locale_slug, $set_slug ) );
  73      }
  74  
  75  	public function by_project_id( $project_id ) {
  76          $project_id = (int) $project_id;
  77          return $this->find_many( "object_id LIKE '$project_id|%'" );
  78      }
  79  }
  80  GP::$validator_permission = new GP_Validator_Permission();


Generated: Thu Sep 24 01:04:02 2020 Cross-referenced by PHPXref 0.7.1