/** * Install the plugin. */ public function hookInstall() { // Create tables. $db = $this->_db; $sql = "\n CREATE TABLE IF NOT EXISTS `{$db->ItemRelationsVocabulary}` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `name` varchar(100) NOT NULL,\n `description` text,\n `namespace_prefix` varchar(100) NOT NULL,\n `namespace_uri` varchar(200) DEFAULT NULL,\n `custom` BOOLEAN NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $db->query($sql); $sql = "\n CREATE TABLE IF NOT EXISTS `{$db->ItemRelationsProperty}` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `vocabulary_id` int(10) unsigned NOT NULL,\n `local_part` varchar(100) NOT NULL,\n `label` varchar(100) DEFAULT NULL,\n `description` text,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $db->query($sql); $sql = "\n CREATE TABLE IF NOT EXISTS `{$db->ItemRelationsRelation}` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `subject_item_id` int(10) unsigned NOT NULL,\n `property_id` int(10) unsigned NOT NULL,\n `object_item_id` int(10) unsigned NOT NULL,\n `relation_comment` varchar(60) NOT NULL DEFAULT '',\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $db->query($sql); // Install the formal vocabularies and their properties. self::hookInitialize(); // Make sure that the i18n file is already loaded $formalVocabularies = (include 'formal_vocabularies.php'); foreach ($formalVocabularies as $formalVocabulary) { $vocabulary = new ItemRelationsVocabulary(); $vocabulary->name = $formalVocabulary['name']; $vocabulary->description = $formalVocabulary['description']; $vocabulary->namespace_prefix = $formalVocabulary['namespace_prefix']; $vocabulary->namespace_uri = $formalVocabulary['namespace_uri']; $vocabulary->custom = 0; $vocabulary->save(); $vocabularyId = $vocabulary->id; foreach ($formalVocabulary['properties'] as $formalProperty) { $property = new ItemRelationsProperty(); $property->vocabulary_id = $vocabularyId; $property->local_part = $formalProperty['local_part']; $property->label = $formalProperty['label']; $property->description = $formalProperty['description']; $property->save(); } } // Install a custom vocabulary. $customVocabulary = new ItemRelationsVocabulary(); $customVocabulary->name = __('Custom'); $customVocabulary->description = __('Custom vocabulary containing relations defined for this Omeka instance.'); $customVocabulary->namespace_prefix = ''; // cannot be NULL $customVocabulary->namespace_uri = null; $customVocabulary->custom = 1; $customVocabulary->save(); $this->_installOptions(); }
/** * Actually alter and save the vocabulary with the request data. * * @param int $vocabularyId */ protected function _handleEditVocabularyForm($vocabularyId) { // Edit existing properties. $propertyDescriptions = $this->_getParam('property_description'); foreach ($propertyDescriptions as $propertyId => $propertyDescription) { $property = $this->_helper->db->getTable('ItemRelationsProperty')->find($propertyId); $property->description = $propertyDescription; $property->save(); } // Add new properties. $newPropertyLabels = $this->_getParam('new_property_label'); $newPropertyDescriptions = $this->_getParam('new_property_description'); foreach ($newPropertyLabels as $key => $newPropertyLabel) { $newPropertyLabel = trim($newPropertyLabel); $newPropertyDescription = trim($newPropertyDescriptions[$key]); // Labels are required. if (!$newPropertyLabel) { continue; } // Labels must be unique. if ($this->_helper->db->getTable('ItemRelationsProperty')->findByLabel($newPropertyLabel)) { continue; } $newProperty = new ItemRelationsProperty(); $newProperty->vocabulary_id = $vocabularyId; $newProperty->local_part = ''; // cannot be NULL $newProperty->label = $newPropertyLabel; $newProperty->description = $newPropertyDescription; $newProperty->save(); } // Delete existing properties. $propertyDeletes = $this->_getParam('property_delete'); foreach ($propertyDeletes as $propertyId => $propertyDelete) { if ($propertyDelete) { $this->_helper->db->getTable('ItemRelationsProperty')->find($propertyId)->delete(); } } }