Beispiel #1
0
 /**
  * Prepares concept data for exporting in rtf format.
  * 
  * @param Api_Models_Concept $concept
  * @param array $fieldsToExport
  * @return array The result concept data
  */
 protected function _prepareConceptDataForRtf(Api_Models_Concept $concept, $fieldsToExport)
 {
     $conceptData = array();
     $conceptData['previewLabel'] = $this->_constructRtfFieldData('previewLabel', $concept->getPreviewLabel());
     $conceptData['fields'] = array();
     // Prepares concept schemes titles map
     $schemesUris = array();
     $schemesFields = Api_Models_Concept::$classes['ConceptSchemes'];
     foreach ($schemesFields as $schemeField) {
         if (in_array($schemeField, $fieldsToExport) && !empty($concept[$schemeField])) {
             $schemesUris = array_merge($schemesUris, $concept[$schemeField]);
         }
     }
     $schemesUris = array_unique($schemesUris);
     $schemesTitleMap = $this->_getApiClientInstance()->getConceptSchemeMap('uri', array('dcterms_title' => 0), $schemesUris);
     // Prepares related concepts map
     $relatedConceptsUris = array();
     $relationFields = array_merge(Api_Models_Concept::$classes['SemanticRelations'], Api_Models_Concept::$classes['MappingProperties']);
     foreach ($relationFields as $relationField) {
         if (in_array($relationField, $fieldsToExport) && !empty($concept[$relationField])) {
             $relatedConceptsUris = array_merge($relatedConceptsUris, $concept[$relationField]);
         }
     }
     $relatedConceptsUris = array_unique($relatedConceptsUris);
     $relatedConceptsMap = Api_Models_Concepts::factory()->getEnumeratedConceptsMapByUris($relatedConceptsUris);
     // Prepare language dependant fields. Remove the orginal field from fields to export and adds each per language field (field@en for example).
     $allConceptFields = $concept->getFields();
     $fieldsToExportInLanguages = array();
     foreach ($allConceptFields as $currentConceptField) {
         if (preg_match('/^([^@]+)@([^@]+)$/i', $currentConceptField, $matches) && in_array($matches[1], $fieldsToExport)) {
             if (!isset($fieldsToExportInLanguages[$matches[1]])) {
                 $fieldsToExportInLanguages[$matches[1]] = array();
             }
             $fieldsToExportInLanguages[$matches[1]][] = $matches[2];
         }
     }
     // Goes trought each export field
     foreach ($fieldsToExport as $field) {
         if (isset($concept[$field])) {
             if (isset($fieldsToExportInLanguages[$field])) {
                 foreach ($fieldsToExportInLanguages[$field] as $language) {
                     foreach ($concept[$field . '@' . $language] as $value) {
                         $conceptData['fields'][] = $this->_constructRtfFieldData($field, $value, $language);
                     }
                 }
             } else {
                 if (is_array($concept[$field])) {
                     foreach ($concept[$field] as $value) {
                         if (in_array($field, $schemesFields) && isset($schemesTitleMap[$value])) {
                             $value = $schemesTitleMap[$value];
                         } else {
                             if (in_array($field, $relationFields) && isset($relatedConceptsMap[$value])) {
                                 $value = $relatedConceptsMap[$value]->getPreviewLabel();
                             }
                         }
                         $conceptData['fields'][] = $this->_constructRtfFieldData($field, $value);
                     }
                 } else {
                     $conceptData['fields'][] = $this->_constructRtfFieldData($field, $concept[$field]);
                 }
             }
         }
     }
     // Get concept children (narrowers)
     if ($this->get('maxDepth') > 1) {
         $narrowers = $this->_getRtfNarrowers(new Editor_Models_Concept($concept), 1);
         if (!empty($narrowers)) {
             $conceptData['narrowers'] = $narrowers;
         }
     }
     return $conceptData;
 }
 /**
  * Compares two Api_Models_Concept classes by their preview labels.
  *
  * @param Api_Models_Concept $a
  * @param Api_Models_Concept $b
  */
 public static function compareByPreviewLabel(Api_Models_Concept $a, Api_Models_Concept $b)
 {
     return strcasecmp($a->getPreviewLabel(), $b->getPreviewLabel());
 }