Api

Version

mediamosa-30

Class

mediamosa_rest_call_asset_supplement_get

Code

File: /sites/all/modules/mediamosa/modules/asset/supplement/mediamosa_asset_supplement.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 calls of asset supplement.
  */

/**
 * URI: /asset/$asset_id/supplement
 * Method: GET
 *
 * Get the asset supplement.
 *
 * 1.x media_management_get_asset_supplement
 */
class mediamosa_rest_call_asset_supplement_get extends mediamosa_rest_call {
  
// ------------------------------------------------------------------ Consts.
  // Rest vars;
  
const ASSET_ID 'asset_id';

  
// ------------------------------------------------------------------ Get Var Setup.
  
public function get_var_setup() {
    
$var_setup = array();

    
$var_setup = array(
      
self::VARS => array(
        
self::ASSET_ID => array(
          
self::VAR_TYPE => mediamosa_sdk::TYPE_ASSET_ID,
          
self::VAR_DESCRIPTION => 'The asset ID.',
          
self::VAR_IS_REQUIRED => self::VAR_IS_REQUIRED_YES,
        ),
      )
    );

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

  
// ------------------------------------------------------------------ Do Call.
  
public function do_call() {
    
$mediamosa mediamosa::get();

    
$app_ids $this->get_param_value_app();
    
$app_id reset($app_ids);

    
// Asset ID.
    
$asset_id $this->get_param_value(self::ASSET_ID);

    
// Asset must exist.
    
mediamosa_db::db_must_exists(mediamosa_asset_db::TABLE_NAME, array(mediamosa_asset_db::ID => $asset_id));

    
// Test webservice.
    
mediamosa_webservice_app::webservice_must_be_active(mediamosa_webservice_app::HANDLE_MEDIA_MANAGEMENT$app_ids);

    
// FIXME: No APP check, can get any supplement, just by suppling an asset id...

    // Get the supplements.
    
$supplements mediamosa_asset_supplement::get_all_with_assetid($asset_id);

    
// Add to response.
    
foreach ($supplements as $supplement) {
      
$supplement['supplement_base64'] = base64_encode($supplement[mediamosa_asset_supplement_db::SUPPLEMENT]);
      unset(
$supplement[mediamosa_asset_supplement_db::SUPPLEMENT]);

      
// Convert times.
      
$supplement[mediamosa_asset_supplement_db::CHANGED] = mediamosa::utcdate2appdate($supplement[mediamosa_asset_supplement_db::CHANGED]);
      
$supplement[mediamosa_asset_supplement_db::CREATED] = mediamosa::utcdate2appdate($supplement[mediamosa_asset_supplement_db::CREATED]);

      
$mediamosa->add_item($supplement);
    }
  }
}