/** * Checks is the concept valid and saves it if it is. * * @see Api_Models_Concept::save() * @param array $extraData * @param bool $commit, optional To do a solr commit or not. Default: true. * @param bool $ignoreValidation, optional, Default: false If set to true the validation on save will not be performed. * @return bool True if the save is successfull. False otherwise. You can see errors by calling getErrors(); */ public function save($extraData = null, $commit = true, $ignoreValidation = false) { if ($ignoreValidation || $this->_validateSave($extraData)) { parent::save($extraData, $commit); return true; } else { return false; } }
/** * 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()); }
/** * @param array $data * @param Api_Models_Concepts $model * @return Editor_Models_ConceptScheme */ public static function factory($data = array(), Api_Models_Concepts $model = null) { return new Editor_Models_ConceptScheme(parent::factory($data, $model)); }
/** * Rollback a concept to a previous state. If no previous state - purge the concept. * @param Api_Models_Concept $concept * @param null|Api_Models_Concept $oldState */ protected function rollbackConcept(Api_Models_Concept $concept, $previousState) { if ($previousState !== null) { // Save the previous state with all its extra data. (new Editor_Models_Concept($previousState))->update([], [], true, true); } else { $concept->purge(true); } }