[ 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  	public function set_fields( $db_object ) {
  43          parent::set_fields( $db_object );
  44          if ( $this->object_id ) {
  45              list( $this->project_id, $this->locale_slug, $this->set_slug ) = $this->project_id_locale_slug_set_slug( $this->object_id );
  46          }
  47          $this->object_type = 'project|locale|set-slug';
  48          $this->default_conditions = "object_type = '".$this->object_type."'";
  49      }
  50  
  51  	public function prepare_fields_for_save( $args ) {
  52          $args = (array)$args;
  53          $args['object_type'] = $this->object_type;
  54          if ( gp_array_get( $args, 'project_id' ) && gp_array_get( $args, 'locale_slug' )
  55                   && gp_array_get( $args, 'set_slug' ) && !gp_array_get( $args, 'object_id' ) ) {
  56              $args['object_id'] = $this->object_id( $args['project_id'], $args['locale_slug'], $args['set_slug'] );
  57          }
  58          $args = parent::prepare_fields_for_save( $args );
  59          return $args;
  60      }
  61  
  62  	public function project_id_locale_slug_set_slug( $object_id ) {
  63          return explode( '|', $object_id );
  64      }
  65  
  66  	public function object_id( $project_id, $locale_slug, $set_slug = 'default' ) {
  67          return implode( '|', array( $project_id, $locale_slug, $set_slug ) );
  68      }
  69  
  70  	public function by_project_id( $project_id ) {
  71          $project_id = (int)$project_id;
  72          return $this->find_many( "object_id LIKE '$project_id|%'" );
  73      }
  74  }
  75  GP::$validator_permission = new GP_Validator_Permission();


Generated: Mon Nov 18 01:01:56 2019 Cross-referenced by PHPXref 0.7.1