Пример #1
0
 /**
  * Retrieve a resource by lom_id (its an internal identification) from the database
  *
  * @return  String  json returned by remote service
  */
 public function &fetch_resource()
 {
     try {
         $resource = Lom::with(array('Technical.TechnicalsLocation', 'General.GeneralsTitle', 'General.GeneralsDescription', 'General.GeneralsLanguage', 'General.GeneralsKeyword.generalskeywordtext', 'Educational.educationalsuserrole', 'Educational.EducationalsTypicalagerange', 'Educational.EducationalsContext', 'Metametadata', 'Educational.EducationalsType'))->where('loms.lom_id', '=', $this->_params['id'])->first();
         if ($resource) {
             $results = array('success' => true, 'message' => 'Resource metadata retrieved.', 'data' => $this->_make_resource($resource));
         } else {
             $results = array('success' => false, 'errcode' => 10, 'message' => 'API resource not found.');
         }
     } catch (\Exception $e) {
         die($e->getMessage());
     }
     return $results;
 }
Пример #2
0
 /**
  *
  */
 private function retrieve_resource($id)
 {
     $l = Lom::find($id);
     if (!is_object($l)) {
         return;
     }
     /*------------------------------------------------------------------------------------------------
      * GENERAL
      *------------------------------------------------------------------------------------------------*/
     // general identifiers
     if (is_object($l->general)) {
     }
     foreach ($l->general->identifier as $identifier) {
         $r['general']['identifier'][] = array('catalog' => $identifier->identifier_catalog, 'entry' => $identifier->identifier_entry);
     }
     // general title
     foreach ($l->general->generalstitle as $text) {
         $r['general']['title']['string'][] = array('@attributes' => array('language' => $text['generals_title_lang']), '@value' => $text['generals_title_string']);
     }
     // general language
     foreach ($l->general->generalslanguage as $text) {
         $r['general']['language'][] = array('@value' => $text->generals_language_lang);
     }
     // general description
     foreach ($l->general->generalsdescription as $text) {
         $r['general']['description']['string'][] = array('@attributes' => array('language' => $text['generals_description_lang']), '@value' => $text['generals_description_string']);
     }
     // general keyword
     foreach ($l->general->generalskeyword as $keyword) {
         $k = array();
         foreach ($keyword->generalskeywordtext as $text) {
             $k['string'][] = array('@attributes' => array('language' => $text['generals_keywords_text_lang']), '@value' => $text['generals_keywords_text_string']);
         }
         $r['general']['keyword'][] = $k;
     }
     // general coverage
     foreach ($l->general->generalscoverage as $coverage) {
         $k = array();
         foreach ($coverage->generalscoveragestext as $text) {
             $k['string'][] = array('@attributes' => array('language' => $text['generals_coverages_text_lang']), '@value' => $text['generals_coverages_text_string']);
         }
         $r['general']['coverage'][] = $k;
     }
     // general structure
     $r['general']['structure'] = array('value' => $l->general->general_structure, 'source' => $l->general->general_structure_source);
     // general aggregation level
     $r['general']['aggregationLevel'] = array('value' => $l->general->general_aggregation_level, 'source' => $l->general->general_aggregation_level_source);
     /*------------------------------------------------------------------------------------------------
      * LIFECYCLE
      *------------------------------------------------------------------------------------------------*/
     // lifecycle version
     if (isset($l->lifecycle->lifecycle_version_lang)) {
         $k['string'] = array('@attributes' => array('language' => $l->lifecycle->lifecycle_version_lang), '@value' => $l->lifecycle->lifecycle_version);
         $r['lifeCycle']['version'][] = @$k;
     }
     // lifecycle status
     if (isset($l->lifecycle->lifecycle_status)) {
         $r['lifeCycle']['status'] = @array('value' => $l->lifecycle->lifecycle_status, 'source' => $l->lifecycle->lifecycle_status_source);
     }
     // lifecycle contributes
     foreach ($l->lifecycle->contribute as $contribute) {
         $k = array();
         $k['role'] = array('source' => $contribute->contribute_role_source, 'value' => $contribute->contribute_role);
         $k['date'] = array('dateTime' => $contribute->contribute_date);
         foreach ($contribute->contributesentity as $text) {
             $k['entity'][] = array('@cdata' => $text['contributes_entity_string']);
         }
         $r['lifeCycle']['contribute'][] = $k;
     }
     /*------------------------------------------------------------------------------------------------
      * METAMETADATA
      *------------------------------------------------------------------------------------------------*/
     // Metadata language
     if (isset($l->metametadata->metametadata_lang)) {
         $r['metaMetadata']['language'] = $l->metametadata->metametadata_lang;
     }
     // metametadata identifiers
     foreach ($l->metametadata->identifier as $identifier) {
         $r['metaMetadata']['identifier'][] = array('catalog' => $identifier->identifier_catalog, 'entry' => $identifier->identifier_entry);
     }
     // metametadata contributes
     foreach ($l->metametadata->contribute as $contribute) {
         $k = array();
         $k['role'] = array('source' => $contribute->contribute_role_source, 'value' => $contribute->contribute_role);
         $k['date'] = array('dateTime' => $contribute->contribute_date);
         foreach ($contribute->contributesentity as $text) {
             $k['entity'][] = array('@cdata' => $text['contributes_entity_string']);
         }
         $r['metaMetadata']['contribute'][] = $k;
     }
     // metametadata schemas
     foreach ($l->metametadata->metametadatasschema as $schema) {
         $r['metaMetadata']['metadataSchema'][] = $schema->metametadatas_schema_text;
     }
     /*------------------------------------------------------------------------------------------------
      * TECHNICAL
      *------------------------------------------------------------------------------------------------*/
     foreach ($l->technical->technicalsformat as $format) {
         $r['technical']['format'][] = array('@value' => $format->technicals_format_text);
     }
     foreach ($l->technical->technicalslocation as $location) {
         $r['technical']['location'][] = array('@value' => $location->technicals_location_text);
     }
     if (isset($l->technical->technical_duration)) {
         $r['technical']['duration']['duration'] = $l->technical->technical_duration;
     }
     if (isset($l->technical->technical_size)) {
         $r['technical']['size'] = $l->technical->technical_size;
     }
     foreach ($l->technical->technicalsotherplatformrequirement as $requirement) {
         $k = array();
         $k['string'][] = array('@attributes' => array('language' => $requirement->technicals_otherplatformrequirement_lang), '@value' => $requirement->technicals_otherplatformrequirement_string);
         $r['technical']['otherPlatformRequirements'][] = $k;
     }
     foreach ($l->technical->technicalsinstallationremark as $installation) {
         $k = array();
         $k['string'] = array('@attributes' => array('language' => $installation->technicals_installationremark_lang), '@value' => $installation->technicals_installationremark_string);
         $r['technical']['installationRemark'][] = $k;
     }
     foreach ($l->technical->requirement as $requirement) {
         $k = array();
         foreach ($requirement->orcomposite as $or) {
             $k['type'] = array('source' => $or['orcomposite_type_source'], 'value' => $or['orcomposite_type']);
             $k['name'] = array('source' => $or['orcomposite_name_source'], 'value' => $or['orcomposite_name']);
             $k['minimumVersion'] = $or['orcomposite_minimumversion'];
             $k['maximumVersion'] = $or['orcomposite_maximumversion'];
             $r['technical']['requirement']['orComposite'][] = $k;
         }
     }
     /*------------------------------------------------------------------------------------------------
      * EDUCATIONAL
      *------------------------------------------------------------------------------------------------*/
     foreach ($l->educational as $educational) {
         $k = array();
         if ($educational->educational_interactivitytype) {
             $k['interactivityType']['source'] = $educational->educational_interactivitytype_source;
             $k['interactivityType']['value'] = $educational->educational_interactivitytype;
         }
         if ($educational->educational_interactivitylevel) {
             $k['interactivityLevel']['source'] = $educational->educational_interactivitylevel_source;
             $k['interactivityLevel']['value'] = $educational->educational_interactivitylevel;
         }
         if ($educational->educational_difficulty) {
             $k['difficulty']['source'] = $educational->educational_difficulty_source;
             $k['difficulty']['value'] = $educational->educational_difficulty;
         }
         if ($educational->educational_semanticdensity) {
             $k['semanticDensity']['source'] = $educational->educational_semanticdensity_source;
             $k['semanticDensity']['value'] = $educational->educational_semanticdensity;
         }
         if ($educational->educational_typicallearningtime) {
             $k['typicalLearningTime']['duration'] = $educational->educational_typicallearningtime;
         }
         foreach ($educational->educationalsuserrole as $e) {
             $edu = array();
             $edu['source'] = $e->educationals_userrole_source;
             $edu['value'] = $e->educationals_userrole_string;
             $k['intendedEndUserRole'][] = $edu;
         }
         foreach ($educational->educationalslanguage as $e) {
             $edu = array();
             $edu['@value'] = $e->educationals_language_string;
             $k['language'][] = $edu;
         }
         foreach ($educational->educationalstype as $e) {
             $edu = array();
             $edu['source'] = $e->educationals_type_source;
             $edu['value'] = $e->educationals_type_string;
             $k['learningResourceType'][] = $edu;
         }
         foreach ($educational->educationalscontext as $e) {
             $edu = array();
             $edu['source'] = $e->educationals_context_source;
             $edu['value'] = $e->educationals_context_string;
             $k['context'][] = $edu;
         }
         foreach ($educational->educationalstypicalagerange as $e) {
             $edu = array();
             $edu['string']['@value'] = $e->educationals_typicalagerange_string;
             $edu['string']['@attributes']['language'] = $e->educationals_typicalagerange_lang;
             $k['typicalAgeRange'][] = $edu;
         }
         foreach ($educational->educationalsdescription as $e) {
             $edu = array();
             $edu['string']['@value'] = $e->educationals_description_string;
             $edu['string']['@attributes']['language'] = $e->educationals_description_lang;
             $k['description'][] = $edu;
         }
         $r['educational'][] = $k;
     }
     /*------------------------------------------------------------------------------------------------
      * RIGHTS
      *------------------------------------------------------------------------------------------------*/
     if ($l->right->right_copyright) {
         $r['rights']['copyrightAndOtherRestrictions'] = @array('source' => $l->right->right_copyright_source, 'value' => $l->right->right_copyright);
     }
     if ($l->right->right_cost) {
         $r['rights']['cost'] = @array('source' => $l->right->right_cost_source, 'value' => $l->right->right_cost);
     }
     if ($l->right->right_description) {
         $r['rights']['description']['string'][] = @array('@attributes' => array('language' => $l->right->right_description_lang), '@value' => $l->right->right_description);
     }
     /*------------------------------------------------------------------------------------------------
      * RELATIONS
      *------------------------------------------------------------------------------------------------*/
     foreach ($l->relation as $relation) {
         $k = array();
         // Kind
         $k['kind']['source'] = $relation->relation_kind_source;
         $k['kind']['value'] = $relation->relation_kind;
         // Description if exists
         if (@$relation->resource->resource_description) {
             $k['resource']['description']['string']['@value'] = @$relation->resource->resource_description;
             $k['resource']['description']['string']['@attributes']['language'] = @$relation->resource->resource_description_lang;
         }
         // Identifiers
         if (is_object($relation->resource)) {
             foreach (@$relation->resource->identifier as $identifier) {
                 $k['resource']['identifier'][] = array('catalog' => $identifier->identifier_catalog, 'entry' => $identifier->identifier_entry);
             }
         }
         $r['relation'][] = $k;
     }
     /*------------------------------------------------------------------------------------------------
      * ANNOTATIONS
      *------------------------------------------------------------------------------------------------*/
     foreach ($l->annotation as $annotation) {
         $k = array();
         if ($annotation->annotation_entity) {
             $k['entity']['@cdata'] = $annotation->annotation_entity;
         }
         if ($annotation->annotation_date) {
             $k['date']['dateTime'] = $annotation->annotation_date;
         }
         $k['description']['string']['@value'] = $annotation->annotation_description;
         $k['description']['string']['@attributes']['language'] = $annotation->annotation_description_lang;
         $r['annotation'][] = $k;
     }
     /*------------------------------------------------------------------------------------------------
      * CLASSIFICATION
      *------------------------------------------------------------------------------------------------*/
     foreach ($l->classification as $class) {
         $k = array();
         if ($class->classification_purpose) {
             $k['purpose']['value'] = $class->classification_purpose;
             if ($class->classification_purpose_source) {
                 $k['purpose']['source'] = $class->classification_purpose_source;
             }
         }
         foreach ($class->taxonpath as $taxonp) {
             $tp = array();
             $tp['source']['string']['@value'] = @$taxonp->taxonpath_source;
             if ($taxonp->taxonpath_source_lang) {
                 $tp['source']['string']['@attributes']['language'] = @$taxonp->taxonpath_source_lang;
             }
             foreach ($taxonp->taxon as $t) {
                 $tx = array();
                 $tp['taxon']['id'] = $t->taxon_id_string;
                 if ($t->taxon_entry) {
                     $tp['taxon']['entry']['string']['@value'] = @$t->taxon_entry;
                     if ($t->taxon_entry_lang) {
                         $tp['taxon']['entry']['string']['@attributes']['language'] = @$t->taxon_entry_lang;
                     }
                 }
             }
             $k['taxonPath'][] = $tp;
         }
         $r['classification'][] = $k;
     }
     /*------------------------------------------------------------------------------------------------
      * PRINT XML
      *------------------------------------------------------------------------------------------------*/
     $xml = Array2XML::createXML('lom', $r);
     echo $xml->saveXML();
     //return $r;
 }