Api

Version

mediamosa-30

Class

mediamosa_rest_call_acl_collection_get_rights

Code

File: /sites/all/modules/mediamosa/modules/acl/mediamosa_acl.rest.class.inc
<?php

/**
 * URI: /collection/$coll_id/acl
 * Method: GET
 */
class mediamosa_rest_call_acl_collection_get_rights extends mediamosa_rest_call {

  
// ------------------------------------------------------------------- Consts.
  // Rest vars;
  
const COLL_ID 'coll_id';
  const 
USER_ID 'user_id';

  
// ------------------------------------------------------- Functions (public).
  
public function get_var_setup() {
    
$var_setup = array();

    
$var_setup[self::VARS][self::COLL_ID] = array(
      
self::VAR_TYPE => mediamosa_sdk::TYPE_COLLECTION_ID,
      
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES,
      
self::VAR_DESCRIPTION => 'The coll id.',
    );

    
$var_setup[self::VARS][self::USER_ID] = array(
      
self::VAR_TYPE => mediamosa_sdk::TYPE_USER_ID,
      
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES,
      
self::VAR_DESCRIPTION => 'The user id.',
    );

    
// Enrich with required REST vars.
    
return self::get_var_setup_default($var_setup);
  }

  public function 
do_call() {
    
$mediamosa mediamosa::get();

    
// Get the app id(s).
    
$app_ids $this->get_param_value_app();
    
$collection_id $this->get_param_value(self::COLL_ID);
    
$user_id $this->get_param_value(self::USER_ID);
    
$is_app_admin $this->get_param_value(self::IS_APP_ADMIN);

    
// First is always the main app.
    
$app_id reset($app_ids);

    
// Make sure the collection exists.
    // Removed the app_id so the collection can be accessed by other app.
    // vpx_acl_rights_get() will check if its in the right app or you have access through slave.
    
$collection mediamosa_db::db_must_exists(mediamosa_collection_db::TABLE_NAME, array(mediamosa_collection_db::ID => $collection_id));

    
// Get the rights.
    
$rights mediamosa_acl::rights_get($app_id$user_idmediamosa_acl::ACL_TYPE_COLLECTION$collection$is_app_admin);

    foreach (
$rights[mediamosa_acl::OBJ_LINK_TYPE_NAME] as $right) {
      
$right['type'] = ($right['type'] == 'acl_user_group' 'acl_group' $right['type']);
      
$mediamosa->add_item(array(fix_vars_acl_2_aut($right['type']) => $right['name']));
    }

    foreach (
$rights[mediamosa_acl::OBJ_LINK_TYPE_GROUP] as $right) {
      
$mediamosa->add_item(array(fix_vars_acl_2_aut($right['type']) => $right['name']));
    }

    foreach (
$rights[mediamosa_acl::OBJ_LINK_TYPE_APP] as $right) {
      
$mediamosa->add_item(array(fix_vars_acl_2_aut($right['type']) => $right['app_id_master']));
    }
  }
}