diff --git a/README.md b/README.md index be6aa99..bb7c10c 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Copyright * Copyright Center for History and New Media, 2011-2015 * Copyright GerZah, 2015 -* Copyright Daniel Berthereau, 2015 +* Copyright Daniel Berthereau, 2015-2016 [Item Relations]: https://github.com/omeka/plugin-ItemRelations diff --git a/controllers/LookupController.php b/controllers/LookupController.php index f6a6613..aa0fec9 100644 --- a/controllers/LookupController.php +++ b/controllers/LookupController.php @@ -15,12 +15,18 @@ public function indexAction() { $db = get_db(); + if (!$this->_hasParam('subject_id')) { + $this->_setParam('subject_id', -1); + } if (!$this->_hasParam('partial')) { $this->_setParam('partial', ''); } if (!$this->_hasParam('item_type')) { $this->_setParam('item_type', -1); } + if (!$this->_hasParam('collection')) { + $this->_setParam('collection', -1); + } if (!$this->_hasParam('sort')) { $this->_setParam('sort', 'mod_desc'); } @@ -31,6 +37,12 @@ public function indexAction() $this->_setParam('per_page', 15); } + $subject_id = intval($this->_getParam('subject_id')); + $where_subject_id = ''; + if ($subject_id > 0) { + $where_subject_id = "AND items.id != $subject_id"; + } + $partial = preg_replace('/[^ \.,\!\?\p{L}\p{N}\p{Mc}]/ui', '', $this->_getParam('partial')); $where_text = ''; if (strlen($partial) > 0) { @@ -43,6 +55,12 @@ public function indexAction() $where_item_type = "AND items.item_type_id = $item_type"; } + $collection = intval($this->_getParam('collection')); + $where_collection = ''; + if ($collection > 0) { + $where_collection = "AND items.collection_id = $collection"; + } + $per_page = intval($this->_getParam('per_page')); $page = intval($this->_getParam('page')); $offset = $page * $per_page; @@ -71,9 +89,11 @@ public function indexAction() SELECT count(*) AS count FROM {$db->Item} items LEFT JOIN {$db->Element_Texts} elementtexts -ON (items.id = elementtexts.record_id) +ON (items.id = elementtexts.record_id) AND (elementtexts.record_type = 'Item') WHERE elementtexts.element_id = $titleId +$where_subject_id $where_item_type +$where_collection $where_text GROUP BY elementtexts.record_id QCOUNT; @@ -89,9 +109,11 @@ public function indexAction() SELECT items.id AS id, text FROM {$db->Item} items LEFT JOIN {$db->Element_Texts} elementtexts -ON (items.id = elementtexts.record_id) +ON (items.id = elementtexts.record_id) AND (elementtexts.record_type = 'Item') WHERE elementtexts.element_id = $titleId +$where_subject_id $where_item_type +$where_collection $where_text GROUP BY elementtexts.record_id $order_clause diff --git a/plugin.ini b/plugin.ini index ed9d7ec..6c80805 100644 --- a/plugin.ini +++ b/plugin.ini @@ -2,10 +2,10 @@ name="Item Relations" author="Roy Rosenzweig Center for History and New Media" description="Allows administrators to define relations between items." -link="http://omeka.org/codex/Plugins/ItemRelations" -support_link="http://omeka.org/forums/forum/plugins" +link="https://omeka.org/codex/Plugins/ItemRelations" +support_link="https://omeka.org/forums/forum/plugins" license="GPLv3" omeka_minimum_version="2.0" -omeka_target_version="2.0" -version="2.0.2.1" +omeka_target_version="2.4" +version="2.0.2.2" tags="item,relation,rdf" diff --git a/views/admin/plugins/item-relations-config-form.php b/views/admin/plugins/item-relations-config-form.php index 24cfd42..b849ff3 100644 --- a/views/admin/plugins/item-relations-config-form.php +++ b/views/admin/plugins/item-relations-config-form.php @@ -3,7 +3,6 @@
formLabel('item_relations_allow_vocabularies', __('Limit Relations to Vocabularies')); ?> -

diff --git a/views/shared/common/item-relations-form.php b/views/shared/common/item-relations-form.php index 94617ad..8b689b1 100644 --- a/views/shared/common/item-relations-form.php +++ b/views/shared/common/item-relations-form.php @@ -18,110 +18,218 @@ - id; - $colspan = ($provideRelationComments ? 4 : 3); - $lastVocab = -1; - foreach ($allRelations as $relation) { - if ($lastVocab != $relation["vocabulary_id"]) { - echo "" - ."" - .$relation["vocabulary"] - .""; - $lastVocab = $relation["vocabulary_id"]; - } - $subjectRelation = ( $relation['subject_item_id']==$thisItemId ); - $objectRelation = ( $relation['object_item_id']==$thisItemId ); - echo ""; - echo "" . - ( $subjectRelation ? __('This Item') - : "". - $relation['subject_item_title'] . "" - ) . - ""; - echo ""; + id; + $colspan = ($provideRelationComments ? 4 : 3); + $lastVocab = -1; + foreach ($allRelations as $relation) { + if ($lastVocab != $relation['vocabulary_id']) { + echo "" + . "" + . $relation['vocabulary'] + . ""; + $lastVocab = $relation['vocabulary_id']; + } + $subjectRelation = $relation['subject_item_id'] == $thisItemId; + $objectRelation = $relation['object_item_id'] == $thisItemId; + echo ''; + echo '' + . ($subjectRelation + ? __('This Item') + : '' . $relation['subject_item_title'] . '' + ) + . ''; + echo ''; if ($subjectRelation) { - echo get_view()->formSelect('item_relations_subject_property['.$relation['item_relation_id'].']', - $relation['relation_property'], - array( 'id' => 'item_relations_subject_property_'.$relation['item_relation_id'], - 'multiple' => false, - 'style' => 'width: 150px;'), - array_slice($formSelectProperties,1)); + echo $this->formSelect('item_relations_subject_property[' . $relation['item_relation_id'] . ']', + $relation['relation_property'], + array( + 'id' => 'item_relations_subject_property_' . $relation['item_relation_id'], + 'multiple' => false, + 'style' => 'width: 150px;', + ), + array_slice($formSelectProperties, 1)); + } + else { + echo '' . $relation['relation_text'] . ''; } - else { echo "" . $relation['relation_text'] . ""; } - echo ""; - echo "" . - ( $objectRelation ? __('This Item') - : "". - $relation['object_item_title'] . "" - ). - ""; - if ($provideRelationComments) { - echo ""; - if ($subjectRelation) { ?> - - "; - } - ?> + echo ''; + echo '' + . ($objectRelation + ? __('This Item') + : '' . $relation['object_item_title'] . '' + ) + . ''; + if ($provideRelationComments) { + echo ''; + if ($subjectRelation) { ?> + + '; + } ?> "; - } - /* */ - ?> - + echo ''; + } ?> + + + + + + - + + formSelect('item_relations_subject_property[]', + null, + array( + 'multiple' => false, + 'style' => 'width: 150px;', + ), + array_slice($formSelectProperties, 1)); + ?> + . - - - - + + + + + + + + -

-

- - formSelect('new_relation_property_id', - null, array('multiple' => false), $formSelectProperties); ?>
-

- formSelect('new_relation_object_item_type_id', - null, array('multiple' => false), $itemTypesList); ?>

+
+
+
+ formLabel('new_relation_property_id', __('This Subject')); ?> +
+
+ id) ? '' : 'data-subject-id="' . $item->id . '"'; ?>>id) ? __('[New]') : '#' . $item->id; ?> +
+
+ id) ? '' : metadata('item', array('Dublin Core', 'Title')); ?> +
+
+
+
+ formLabel('new_relation_property_id', __('Is Related By')); ?> +
+
+ formSelect('new_relation_property_id', + null, array('multiple' => false), $formSelectProperties); ?> +
+
+
+
+ formLabel('object_title', __('With Object')); ?> +
+
+ +
+
+ +
+
-

: -

- - - - -
-

+ +
+
+ formLabel('relation_comment', __('Comment')); ?> +
+
+ formText('relation_comment', null); ?> +
+
+ -

:

- - -
-
    -
  • <
  • -
  • >
  • -
+
+
+ +
+
+
+ +
+
+
-
-
    +
    +

    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    + formLabel('new_relation_object_item_type_id', __('By Item Types')); ?> +
    +
    + formSelect('new_relation_object_item_type_id', + null, array('multiple' => false), $itemTypesList); ?> +
    +
    +
    +
    + formLabel('new_relation_object_collection_id', __('By Collection')); ?> +
    +
    + formSelect('new_relation_object_collection_id', + null, array('multiple' => false), get_table_options('Collection')); ?> +
    +
    - -
    -

    : formText('relation_comment', null, array('size' => 10, 'maxlength' => 60)); ?>

    - +
    +
    + formLabel('partial_object_title', __('By Partial Title')); ?> +
    +
    + formText('partial_object_title', null, array('size' => 10, 'maxlength' => 60)); ?> +
    +
    + +
    +
    + formLabel('new_relation_item_sort', __('Sort By')); ?> +
    +
    +
    + + +
    +
    + + +
    +
    +
    + +
    +
    +
      +
      - +
      +
      +
        +
      • <
      • +
      • >
      • +
      +
      +
      diff --git a/views/shared/css/item-relations.css b/views/shared/css/item-relations.css index 98cc848..525bb27 100644 --- a/views/shared/css/item-relations.css +++ b/views/shared/css/item-relations.css @@ -1,3 +1,10 @@ +.subject-id, +.object-id { + font-style: italic; +} +tr.new { + background-color: #f3f3e7; +} .pg_disabled { visibility: hidden; } diff --git a/views/shared/javascripts/item-relations.js b/views/shared/javascripts/item-relations.js index 0aa677a..12fab58 100644 --- a/views/shared/javascripts/item-relations.js +++ b/views/shared/javascripts/item-relations.js @@ -2,15 +2,31 @@ jQuery(document).ready(function () { var $ = jQuery; var options = {}; + init(); + + function init() { + resetOptions(); + + $('#new_relation_object_item_id').val(''); + $('#object_id').html(''); + $('#object_title').html('' + '[Search and Select Below]' + ''); + $('#new_relation_property_id').val(''); + $('#relation_comment').val(''); + $('#new_relation_object_item_type_id').val(-1); + $('#new_relation_object_collection_id').val(''); + $('#partial_object_title').val(''); + $('input[name=itemsListSort]:checked').val('timestamp'); + + updateChoices(); + updateAddButton(); + } + function resetOptions() { - options['partial'] = ''; - options['item_type'] = -1; - options['sort'] = 'mod_desc'; - options['page'] = 0; - options['per_page'] = 15; options = { + subject_id: $('#subject_id').attr('data-subject-id'), partial: '', item_type: -1, + collection: -1, sort: 'mod_desc', page: 0, per_page: 15, @@ -18,12 +34,10 @@ jQuery(document).ready(function () { }; } - resetOptions(); - updateChoices(); - function updateChoices() { options['partial'] = $('#partial_object_title').val(); options['item_type'] = $('#new_relation_object_item_type_id').val(); + options['collection'] = $('#new_relation_object_collection_id').val(); if ($('input[name=itemsListSort]:checked').val() === 'timestamp') { options['sort'] = 'mod_desc'; } @@ -71,18 +85,93 @@ jQuery(document).ready(function () { }); } + function updateAddButton() { + var addButton = $('#add-relation'); + if ($('#new_relation_property_id').val() && $('#new_relation_object_item_id').val()) { + addButton.removeProp('disabled'); + addButton.removeAttr('disabled'); + } + else { + addButton.prop('disabled', true); + addButton.attr('disabled', true); + } + } + + function updateNewRelationHiddenProperty() { + var entry = $(this).closest('tr.item-relations-entry'); + var hiddenInput = entry.find(".item-relations-hidden input[name='item_relations_property_id[]']"); + hiddenInput.val($(this).val()); + }; + + function updateNewRelationHiddenComment() { + var entry = $(this).closest('tr.item-relations-entry'); + var hiddenInput = entry.find(".item-relations-hidden input[name='item_relations_item_relation_relation_comment[]']"); + hiddenInput.val($(this).val()); + }; + + function deleteNewRelation() { + $(this).closest('tr.item-relations-entry').remove(); + return false; + }; + + /* Edit existing relations. */ + + $("select[id^='item_relations_subject_property_']").change(function(e) { + e.preventDefault(); + var id = this.id; + var suffix = this.id.match(/\d+/); + $("#item_relations_subject_property_" + suffix).siblings('span').remove(); + $("#item_relations_subject_property_" + suffix).parent().append('' + + '' + + ''); + }); + + $("input[id^='item_relations_subject_comment_']").change(function(e) { + e.preventDefault(); + var provideSubjectComments = ($("input[id^='item_relations_subject_comment_']").length > 0); + if (provideSubjectComments) { + var id = $(this).attr('id'); + var suffix = this.id.match(/\d+/); + $("#item_relations_subject_comment_" + suffix).siblings('span').remove(); + $("#item_relations_subject_comment_" + suffix).parent().append('' + + '' + + ''); + } + }); + + /* Add new relations. */ + $('#add-relation').click(function () { + if ($('#add-relation').prop('disabled')) { + return false; + } + + // Set visible row. var oldRow = $('.item-relations-entry').last(); var newRow = oldRow.clone(); - var provideRelationComments = ($('#relation_comment').length > 0); + var provideRelationComments = ($('#relation_comment').length > 0); newRow.toggleClass('hidden'); - newRow.find('.item-relations-property').html($('#new_relation_property_id').find(':selected').html()); + newRow.find("select[name='item_relations_subject_property[]']").val($('#new_relation_property_id').val()); var new_url = newRow.find('.item-relations-object a').attr('href'); newRow.find('.item-relations-object a').attr('href', new_url + $('#new_relation_object_item_id').val()); newRow.find('.item-relations-object a').text($('#object_title').text()); - if (provideRelationComments) { - newRow.find('.item-relations-comment').text($('#relation_comment').val()); - } + if (provideRelationComments) { + newRow.find("input[name='item_relations_subject_comment[]']").val($('#relation_comment').val()); + } + + // Set hidden row for data. + var hidden = _createHiddenNewRelation(); + newRow.find('.item-relations-hidden').html(hidden); + oldRow.before(newRow); + + $(".delete-new-relation").bind('click', deleteNewRelation); + $("select[name='item_relations_subject_property[]'").bind('change', updateNewRelationHiddenProperty); + $("input[name='item_relations_subject_comment[]'").bind('change', updateNewRelationHiddenComment); + + init(); + }); + + function _createHiddenNewRelation() { var hidden = []; hidden.push(''); - if (provideRelationComments) { - hidden.push(''); - } - newRow.find('.item-relations-hidden').html(hidden.join('')); - oldRow.before(newRow); - }); + if ($('#relation_comment').length > 0) { + hidden.push(''); + } + return hidden.join(''); + }; - $('#lookup-results').on('click', 'li', function () { - $('#new_relation_object_item_id').val($(this).attr('data-value')); - $('#object_title').html($(this).html()); - }); + /* Search and select an object to create a new relation. */ - $('#selector-previous-page').click(function () { - if (0 < options['page']) { - options['page']--; - updateChoices(); - } + $('#refresh-results').click(function () { + updateChoices(); }); - $('#selector-next-page').click(function () { - if (options['page'] < options['max_page']) { - options['page']++; - updateChoices(); - } + $('#new_relation_object_item_type_id').change(function () { + updateChoices(); }); - $('#new_relation_object_item_type_id').change(function () { + $('#new_relation_object_collection_id').change(function () { updateChoices(); }); @@ -134,26 +213,28 @@ jQuery(document).ready(function () { updateChoices(); }); - $("input[id^='item_relations_subject_comment_']").change(function(e) { - e.preventDefault(); - var provideSubjectComments = ($("input[id^='item_relations_subject_comment_']").length > 0); - if (provideSubjectComments) { - var id = $(this).attr('id'); - var suffix = this.id.match(/\d+/); - $("#item_relations_subject_comment_"+suffix).siblings('span').remove(); - $("#item_relations_subject_comment_"+suffix).parent().append(''+ - '' - +''); - } + $('#selector-previous-page').click(function () { + if (0 < options['page']) { + options['page']--; + updateChoices(); + } }); - $("select[id^='item_relations_subject_property_']").change(function(e) { - e.preventDefault(); - var id = this.id; - var suffix = this.id.match(/\d+/); - $("#item_relations_subject_property_"+suffix).siblings('span').remove(); - $("#item_relations_subject_property_"+suffix).parent().append(''+ - '' - +''); + $('#selector-next-page').click(function () { + if (options['page'] < options['max_page']) { + options['page']++; + updateChoices(); + } + }); + + $('#lookup-results').on('click', 'li', function () { + $('#new_relation_object_item_id').val($(this).attr('data-value')); + $('#object_id').html('#' + $(this).attr('data-value') + ''); + $('#object_title').html($(this).html()); + updateAddButton(); + }); + + $('#new_relation_property_id').change(function () { + updateAddButton(); }); -} ); +});