Api
Version
mediamosa-30Class
mediamosa_rest_call_asset_mediafile_uploadticket_createCode
File: /sites/all/modules/mediamosa/modules/asset/mediafile/upload/mediamosa_asset_mediafile_upload.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
* REST functions for upload.
*/
/**
* URI: /mediafile/$mediafile_id/uploadticket/create
* /mediafile/$mediafile_id/upload_ticket (deprecated)
*
* Method: GET
*/
class mediamosa_rest_call_asset_mediafile_uploadticket_create extends mediamosa_rest_call {
// ------------------------------------------------------------------ Consts.
// Rest vars;
const MEDIAFILE_ID = 'mediafile_id';
const USER_ID = 'user_id';
const GROUP_ID = 'group_id';
private $a_metadata_definitions_full = NULL;
// ------------------------------------------------------------------ Get Var Setup.
public function get_var_setup() {
$a_var_setup = array();
$a_var_setup = array(
self::VARS => array(
self::MEDIAFILE_ID => array(
self::VAR_TYPE => mediamosa_sdk::TYPE_MEDIAFILE_ID,
self::VAR_DESCRIPTION => 'ID of an original file (then it is without transcode) or empty mediafile.',
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES,
self::VAR_RANGE_END => mediamosa_db::HASH_ID_LENGTH,
),
self::USER_ID => array(
self::VAR_TYPE => mediamosa_sdk::TYPE_USER_ID,
self::VAR_DESCRIPTION => 'User id, determined to check whether the applicant has the rights and quotas to upload the mediafile.',
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES,
self::VAR_RANGE_END => mediamosa_user_db::NAME_LENGTH,
),
self::GROUP_ID => array(
self::VAR_TYPE => mediamosa_sdk::TYPE_GROUP_ID,
self::VAR_DESCRIPTION => 'Group id, used for any quota check..',
self::VAR_RANGE_END => mediamosa_user_group_db::GROUP_ID_LENGTH,
),
)
);
// Enrich with required REST vars.
return self::get_var_setup_default($a_var_setup);
}
// ------------------------------------------------------------------ Do Call.
public function do_call() {
$mediamosa = mediamosa::get();
// Get the app_id.
$app_ids = $this->get_param_value_app();
$app_id = reset($app_ids);
$mediafile_id = $this->get_param_value(self::MEDIAFILE_ID);
$user_id = $this->get_param_value(self::USER_ID);
$group_id = $this->get_param_value(self::GROUP_ID);
// Create.
$ticket_id = mediamosa_ticket::create_for_upload($app_id, $mediafile_id, $user_id, $group_id);
// Get serverupload.
$server_upload = mediamosa_server::get_random_upload();
if (!$server_upload) {
throw new mediamosa_exception_error(mediamosa_error::ERRORCODE_SERVER_UPLOAD_NOT_FOUND);
}
// Generate unique ID.
$uuid = rand(1000000, 9999999);
// Set response.
$mediamosa->add_item(
array(
'action' => strtr(mediamosa_server::get_server_url($server_upload), array('{TICKET}' => $ticket_id, '{PROGRESS_ID}' => $uuid)),
'uploadprogress_url' => strtr($server_upload[mediamosa_server_db::URI_UPLOAD_PROGRESS], array('{PROGRESS_ID}' => $uuid, '{SERVER_ID}' => $server_upload[mediamosa_server_db::NID])),
'ticket_id' => $ticket_id,
'progress_id' => $uuid,
'server_id' => $server_upload[mediamosa_server_db::NID],
)
);
}
}