Api
Version
mediamosa-30Class
mediamosa_rest_call_asset_collection_createCode
File: /sites/all/modules/mediamosa/modules/asset/collection/mediamosa_asset_collection.rest.class.inc
<?php?php
// $Id$
/**
* MediaMosa is Open Source Software to build a Full Featured, Webservice
* Oriented Media Management and Distribution platform (http://mediamosa.org)
*
* Copyright (C) 2011 SURFnet BV (http://www.surfnet.nl) and Kennisnet
* (http://www.kennisnet.nl)
*
* MediaMosa is based on the open source Drupal platform and
* was originally developed by Madcap BV (http://www.madcap.nl)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, you can find it at:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/**
* @file
* Asset <-> Collection REST calls.
*/
/**
* URI: /collection/$coll_id/asset_relation
* Method: POST
*
* Create a link between collection and asset.
*
* 1.x media_management_create_collection_relation
*/
class mediamosa_rest_call_asset_collection_create extends mediamosa_rest_call {
// ------------------------------------------------------------------ Consts.
// Rest vars;
const COLL_ID = 'coll_id';
const ASSET_ID = 'asset_id';
const USER_ID = 'user_id';
// ------------------------------------------------------------------ Get Var Setup.
public function get_var_setup() {
$a_var_setup = array();
$a_var_setup = array(
self::VARS => array(
self::COLL_ID => array(
self::VAR_TYPE => mediamosa_sdk::TYPE_COLLECTION_ID,
self::VAR_DESCRIPTION => 'The collection ID.',
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES
),
self::ASSET_ID => array(
self::VAR_TYPE => mediamosa_sdk::TYPE_ASSET_ID,
self::VAR_DESCRIPTION => 'The asset ID to add to the collection. Multiple assets may be given here with asset_id[].',
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES,
self::VAR_IS_ARRAY => self::VAR_IS_ARRAY_YES,
),
self::USER_ID => array(
self::VAR_TYPE => mediamosa_sdk::TYPE_USER_ID,
self::VAR_DESCRIPTION => 'The user ID, must be owner of the collection.',
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES
),
)
);
// Enrich with required REST vars.
return self::get_var_setup_default($a_var_setup);
}
// ------------------------------------------------------------------ Do Call.
public function do_call() {
$o_mediamosa = mediamosa::get();
$a_app_ids = $this->get_param_value_app();
// Get the 1st app.
$app_id = reset($a_app_ids);
// App admin.
$is_app_admin = $this->get_param_value(self::IS_APP_ADMIN);
// Get params.
$coll_id = $this->get_param_value(self::COLL_ID);
$a_asset_ids = $this->get_param_value(self::ASSET_ID);
$user_id = $this->get_param_value(self::USER_ID);
// Test webservice.
mediamosa_webservice_app::webservice_must_be_active(mediamosa_webservice_app::HANDLE_MEDIA_MANAGEMENT, $a_app_ids);
// Collection must exist.
mediamosa_db::db_must_exists(mediamosa_collection_db::TABLE_NAME, array(mediamosa_collection_db::ID => $coll_id));
foreach ($a_asset_ids as $asset_id) {
try {
// Create the link.
mediamosa_asset_collection::create($app_id, $user_id, $is_app_admin, $asset_id, $coll_id);
$o_mediamosa->add_item(
array(
'coll_id' => $coll_id,
'asset_id' => $asset_id,
'result' => mediamosa_response::SUCCESS,
'result_id' => mediamosa_error::ERRORCODE_OKAY,
'result_description' => mediamosa_error::error_code_find_description(mediamosa_error::ERRORCODE_OKAY)
)
);
}
catch (mediamosa_exception_error $e) {
$o_mediamosa->add_item(
array(
'coll_id' => $coll_id,
'asset_id' => $asset_id,
'result' => mediamosa_response::ERROR,
'result_id' => $e->getCode(),
'result_description' => $e->getMessage()
)
);
}
}
}
}