Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions ItemRelationsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ItemRelationsPlugin extends Omeka_Plugin_AbstractPlugin
*/
protected $_options = array(
'item_relations_public_append_to_items_show' => 1,
'item_relations_provide_relation_comments' => 0,
'item_relations_relation_format' => 'prefix_local_part'
);

Expand Down Expand Up @@ -83,11 +84,13 @@ public function hookInstall()
`subject_item_id` int(10) unsigned NOT NULL,
`property_id` int(10) unsigned NOT NULL,
`object_item_id` int(10) unsigned NOT NULL,
`relation_comment` varchar(60) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) 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;
Expand All @@ -112,8 +115,8 @@ public function hookInstall()

// Install a custom vocabulary.
$customVocabulary = new ItemRelationsVocabulary;
$customVocabulary->name = 'Custom';
$customVocabulary->description = 'Custom vocabulary containing relations defined for this Omeka instance.';
$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;
Expand Down Expand Up @@ -150,6 +153,7 @@ public function hookUninstall()
public static function hookConfigForm()
{
$publicAppendToItemsShow = get_option('item_relations_public_append_to_items_show');
$provideRelationComments = get_option('item_relations_provide_relation_comments');
$relationFormat = get_option('item_relations_relation_format');

require dirname(__FILE__) . '/config_form.php';
Expand All @@ -162,6 +166,8 @@ public static function hookConfig()
{
set_option('item_relations_public_append_to_items_show',
(int)(boolean) $_POST['item_relations_public_append_to_items_show']);
set_option('item_relations_provide_relation_comments',
(int)(boolean) $_POST['item_relations_provide_relation_comments']);
set_option('item_relations_relation_format',
$_POST['item_relations_relation_format']);
}
Expand Down Expand Up @@ -218,6 +224,13 @@ public function hookUpgrade($args)
$db->query($sql);
}
}

if ($oldVersion <= '2.21') {
// Insert relation_comment column
$sql = "ALTER TABLE `{$db->prefix}item_relations_relations` ADD `relation_comment` VARCHAR(60) NOT NULL DEFAULT '' AFTER `object_item_id`";
$db->query($sql);
}

}

/**
Expand Down Expand Up @@ -304,7 +317,8 @@ public function hookAfterSaveItem($args)
self::insertItemRelation(
$record,
$propertyId,
$post['item_relations_item_relation_object_item_id'][$key]
$post['item_relations_item_relation_object_item_id'][$key],
$post['item_relations_item_relation_relation_comment'][$key]
);
}
}
Expand Down Expand Up @@ -402,7 +416,8 @@ public function hookItemsBatchEditCustom($args)
self::insertItemRelation(
$item,
$custom['item_relations_property_id'],
$custom['item_relations_item_relation_object_item_id']
$custom['item_relations_item_relation_object_item_id'],
$custom['item_relations_item_relation_relation_comment']
);
}

Expand Down Expand Up @@ -463,6 +478,7 @@ public static function prepareSubjectRelations(Item $item)
$subjectRelations[] = array(
'item_relation_id' => $subject->id,
'object_item_id' => $subject->object_item_id,
'relation_comment' => $subject->relation_comment,
'object_item_title' => self::getItemTitle($item),
'relation_text' => $subject->getPropertyText(),
'relation_description' => $subject->property_description
Expand All @@ -488,6 +504,7 @@ public static function prepareObjectRelations(Item $item)
$objectRelations[] = array(
'item_relation_id' => $object->id,
'subject_item_id' => $object->subject_item_id,
'relation_comment' => $object->relation_comment,
'subject_item_title' => self::getItemTitle($item),
'relation_text' => $object->getPropertyText(),
'relation_description' => $object->property_description
Expand Down Expand Up @@ -519,7 +536,7 @@ public static function getItemTitle($item)
* @param Item|int $objectItem
* @return bool True: success; false: unsuccessful
*/
public static function insertItemRelation($subjectItem, $propertyId, $objectItem)
public static function insertItemRelation($subjectItem, $propertyId, $objectItem, $relationComment)
{
// Only numeric property IDs are valid.
if (!is_numeric($propertyId)) {
Expand All @@ -545,6 +562,7 @@ public static function insertItemRelation($subjectItem, $propertyId, $objectItem
$itemRelation->subject_item_id = $subjectItem->id;
$itemRelation->property_id = $propertyId;
$itemRelation->object_item_id = $objectItem->id;
$itemRelation->relation_comment = ( $relationComment ? $relationComment : "");
$itemRelation->save();

return true;
Expand Down
15 changes: 14 additions & 1 deletion config_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
<?php echo get_view()->formCheckbox('item_relations_public_append_to_items_show', null, array('checked' => $publicAppendToItemsShow)); ?>
</div>
</div>
<div class="field">
<div class="two columns alpha">
<?php echo get_view()->formLabel('item_relations_provide_relation_comments', __('Provide comment field for relations')); ?>
</div>
<div class="inputs five columns omega">
<p class="explanation">
<?php
echo __('Check this if you want to be able to enter a comment to a relation.');
?>
</p>
<?php echo get_view()->formCheckbox('item_relations_provide_relation_comments', null, array('checked' => $provideRelationComments)); ?>
</div>
</div>
<div class="field">
<div class="two columns alpha">
<?php echo get_view()->formLabel('item_relations_relation_format', __('Relation Format')); ?>
Expand All @@ -23,6 +36,6 @@
. 'prefer to show. If one is unavailable the other will be used.');
?>
</p>
<?php echo get_view()->formSelect('item_relations_relation_format', $relationFormat, null, array('prefix_local_part' => 'prefix:localPart', 'label' => 'label')); ?>
<?php echo get_view()->formSelect('item_relations_relation_format', $relationFormat, null, array('prefix_local_part' => __('prefix:localPart'), 'label' => __('label'))); ?>
</div>
</div>
Loading