Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual item ID selector / translatable relation texts + German translation #9

Open
wants to merge 80 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
3960883
Additional translatable strings (tiny ones, but relation texts can no…
May 19, 2015
9959c48
Text correction: "Subject" == "Subjekt-Ressource", not "Betreff"
May 20, 2015
940ab06
Visually select relation object in sortable / filterable item list in…
May 28, 2015
a24417a
Runtime memory footprint improval (more PHP preprocessing) / i18n cle…
May 29, 2015
eb5d4e8
Added missing "All" i18n string
May 29, 2015
4ccc168
"Subject" duality (Item Relations vs. Code) resolved: Item Relations …
May 29, 2015
818381b
Bugfix bugfix :-/ – Dublin Core relations actually require "Subject",…
May 29, 2015
4871cd8
Bugfix – fix faulty item titles
Jun 1, 2015
a0fa4c5
(1) Removed current item ID from selection list | (2) added (dormant)…
Jun 2, 2015
33f5e55
Last update broke added new content – fixed
Jun 2, 2015
144f1cd
Merge commit '31e6697b6bfd9f1795008d4005fedab15be82e40'
Jun 5, 2015
52b44fe
Added the ability to add a comment field to relations
Jun 17, 2015
aa682e0
Bugfix, actually for master – find only one title per record (element…
Jun 19, 2015
5d2b832
Display item's relations underneath its metadata, and not in the lowe…
Jul 14, 2015
9236548
Display item's relations underneath its metadata, and not in the lowe…
Jul 14, 2015
ee60667
Re-order relation order in dropdown box
Jul 14, 2015
2fb4513
Merge branch 'relationComments'
Jul 14, 2015
0cb701e
Merge branch 'showRelLeft'
Jul 14, 2015
f09f40c
Item Relations with AJAX selector incorporated from https://github.co…
Oct 9, 2015
9b7df5d
Commit missing latest update (d'oh!)
Oct 9, 2015
ed4f95f
Bugfixes, mostly pertaining to editing relationships / relationship c…
Oct 9, 2015
fc7456c
Search for Item Relations now also in public frontend
Nov 3, 2015
03c7db6
Added a pointer to select items.
Daniel-KM Nov 22, 2015
2256d87
Normalized use of css and javascripts to make them themable.
Daniel-KM Nov 22, 2015
efa5b48
Made the form themable.
Daniel-KM Nov 22, 2015
4a665da
Cleaned whitespace and normalized config form.
Daniel-KM Nov 22, 2015
66160b3
Avoided sql queries in view.
Daniel-KM Nov 22, 2015
7545dc4
Simplified form to display only the used item types.
Daniel-KM Nov 22, 2015
50bb359
Secured an ajax input.
Daniel-KM Nov 22, 2015
a326489
Secured sql used for update.
Daniel-KM Nov 22, 2015
55c00fb
Simplified the send of the json metadata for ajax.
Daniel-KM Nov 22, 2015
8c297e9
Added an option to limit the vocabularies to use.
Daniel-KM Nov 22, 2015
6cb2caa
Improved queries to get relations.
Daniel-KM Nov 22, 2015
5e3f8c2
Added an option to display relations by item type.
Daniel-KM Nov 22, 2015
0290fdd
Added Readme.
Daniel-KM Nov 22, 2015
d88f943
Merge pull request #1 from Daniel-KM/various_improvements
GerZah Nov 23, 2015
f527603
Manual rollback to before pull request merge – new version will be ad…
Nov 23, 2015
87a0a51
Huge update: Support for multiple user-defined vocabularies, includin…
Dec 7, 2015
0bfd5b2
"Backport" of all enhancement that occurred between last fork and now
Dec 7, 2015
28e0ac3
Fixed config form.
Daniel-KM Dec 13, 2015
bb1815b
(Yet unsuccessful) experiments with addSearchText() to be able to sea…
Jan 26, 2016
fb6f443
Add relation comments to search text works now
Feb 2, 2016
47c2024
Relationship titles are now editable as well / + report existing titl…
Feb 10, 2016
af91950
manual merge of "Backport" branch into "master" branch
Feb 11, 2016
f069a4f
Merge branch 'Backport'
Feb 11, 2016
882a6db
Fixed ajax query to limit element texts to items ones.
Daniel-KM Mar 20, 2016
fdf1c28
Simplified the main form.
Daniel-KM Mar 20, 2016
6bd04ef
Added a drop-down to select relations by collection.
Daniel-KM Mar 20, 2016
91fdf31
Added link to selected record.
Daniel-KM Mar 20, 2016
711d50a
Disallowed relation to itself.
Daniel-KM Mar 20, 2016
c514a19
Improved button to add a relation.
Daniel-KM Mar 20, 2016
c5e8d8a
Improved management of newly created relations.
Daniel-KM Mar 20, 2016
841b25e
Added a button to create a new record directly.
Daniel-KM Mar 20, 2016
daf8118
Released version 2.0.2.2.
Daniel-KM Mar 20, 2016
7c5f2c1
Merge pull request #2 from Daniel-KM/new_improvements
GerZah Mar 22, 2016
6dc63cf
Updated i18n / fixed untranslatable string in .js / "Create a new Rel…
Mar 22, 2016
25032f8
Updated i18n / fixed untranslatable string in .js / "Create a new Rel…
Mar 22, 2016
ecbeaa0
Tiny bugfix for "Most Recently" and "Alphabetically" radio button lab…
Mar 22, 2016
9d64508
D'oh! Revert erroneous fix ("Add new Record" vs. "Add new Relation") …
Mar 22, 2016
02ac6fc
Updated list of item types and collections dynamically in the form.
Daniel-KM Mar 22, 2016
5df0268
Merge pull request #3 from Daniel-KM/updated_form
GerZah Mar 23, 2016
0eebac5
Updated README (cokernel contributed at https://github.com/omeka/plug…
Mar 23, 2016
fa945f4
Updated link to cokernel
Mar 23, 2016
38ea4da
Fixed batch edit with a new relation.
Daniel-KM May 1, 2016
af03e20
Merge pull request #4 from Daniel-KM/fix_batch_edit
GerZah May 9, 2016
e88723a
BatchEdit issue – wouldn't honor the "provide_relation_comments" conf…
May 9, 2016
61edffd
Merge branch 'upstream' into various_improvements
Daniel-KM May 15, 2016
ae98e84
Added an ID filter field – to limit results based on item ID (/ranges…
Jul 5, 2016
9ebfb2e
Tiny modification to prevent a race condition when initializing the r…
Jul 5, 2016
23e3a57
Missing initialization for id filter (doesn't seem to have been too i…
Jul 5, 2016
e5f1ffd
Fix broken pagination (would switch URLs) plus a couple of performanc…
Jul 5, 2016
9f0878c
"FrontPort" – i.e. the opposite of a backport from ItemReferences: ad…
Jul 5, 2016
a90bed9
item-relations-show-table.php i.e. the table view of all relations no…
Jul 6, 2016
17499b2
Merge remote-tracking branch 'GerZah/master'
Daniel-KM Jul 10, 2016
786da1d
Reindented code.
Daniel-KM Jul 10, 2016
43e8411
Fixed class of the form.
Daniel-KM Jul 10, 2016
a5b0d76
Merge pull request #5 from Daniel-KM/various_improvements
GerZah Jul 18, 2016
7a98b78
Collapsible tables (when "as table" is selected) are now configurable
Jul 18, 2016
8e29b0e
Fixed display when the subject is public and the object private.
Daniel-KM Oct 30, 2016
67f48c1
Merge pull request #6 from Daniel-KM/fix_private_item
GerZah Dec 6, 2016
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
498 changes: 382 additions & 116 deletions ItemRelationsPlugin.php

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Item Relations (plugin for Omeka)
=================================

[Item Relations] is a plugin for [Omeka] that lets you define relations between
items. For example, you can make one item a part of another item, where
"part of" is the relation. You can also make one item a "reproduction of" or a
"translation of" another item.

We've bundled the plugin with common relations derived from several formal
vocabularies, like Dublin Core and FRBR. You can use these or you could populate
a custom vocabulary with the relations needed in your archive. You could, for
example, define custom relations like "is parent of", "is better than", and
"fits within".

See http://omeka.org/codex/Plugins/ItemRelations for more info.

This fork adds a quick visual selector and made the item relations themable.


Installation
------------

Uncompress files and rename plugin folder "ItemRelations".

Then install it like any other Omeka plugin and follow the config instructions.


Warning
-------

Use it at your own risk.

It's always recommended to backup your files and database regularly so you can
roll back if needed.


Troubleshooting
---------------

See online [plugin issues] and [fork issues].


License
-------

This plugin is published under [GNU/GPL].

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


Contact
-------

Current maintainers:

* [Center for History & New Media]
* Gero Zahn (see [GerZah])
* Michael Slone (see [cokernel](https://github.com/cokernel))
* Daniel Berthereau (see [Daniel-KM])


Copyright
---------

* Copyright Center for History and New Media, 2011-2015
* Copyright Michael Slone, 2015
* Copyright Gero Zahn, 2015-2016
* Copyright Daniel Berthereau, 2015-2016


[Item Relations]: https://github.com/omeka/plugin-ItemRelations
[Omeka]: https://omeka.org
[plugin issues]: https://github.com/omeka/plugin-ItemRelations/issues
[fork issues]: https://github.com/Daniel-KM/ItemRelations/issues
[GNU/GPL]: https://www.gnu.org/licenses/gpl-3.0.html
[Center for History & New Media]: http://chnm.gmu.edu
[GerZah]: https://github.com/GerZah
[Daniel-KM]: https://github.com/Daniel-KM "Daniel Berthereau"
28 changes: 0 additions & 28 deletions config_form.php

This file was deleted.

213 changes: 213 additions & 0 deletions controllers/LookupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<?php
/**
* Item Relations
* LookupController
* @copyright 2015 Michael Slone
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* Lookup controller.
*/
class ItemRelations_LookupController extends Omeka_Controller_AbstractActionController
{
public function indexAction()
{
// error_log(microtime());
$db = get_db();

if (!$this->hasParam('subject_id')) {
$this->setParam('subject_id', -1);
}
if (!$this->hasParam('partial')) {
$this->setParam('partial', '');
}
if (!$this->hasParam('id_limit')) {
$this->setParam('id_limit', '');
}
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');
}
if (!$this->hasParam('page')) {
$this->setParam('page', 0);
}
if (!$this->hasParam('per_page')) {
$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) {
$where_text = 'AND text RLIKE ' . $db->quote($partial);
}

$where_id_limit = '';
if (preg_match('/\s*(\d+)(?:-(\d+))?\s*/', $this->getParam('id_limit'), $matches)) {
$fromId = (integer) $matches[1];
$toId = (integer) @$matches[2];
if (!$toId) {
$toId = $fromId;
}
if ($fromId > $toId) {
$tmpId = $toId;
$toId = $fromId;
$fromId = $tmpId;
}
$where_id_limit = "AND items.id BETWEEN $fromId AND $toId";
}

$item_type = intval($this->_getParam('item_type'));
$where_item_type = '';
if ($item_type > 0) {
$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;

$order_clause = 'ORDER BY items.item_type_id ASC, text ASC';
switch ($this->_getParam('sort')) {
case 'mod_desc':
$order_clause = 'ORDER BY UNIX_TIMESTAMP(modified) DESC, items.item_type_id ASC, text ASC';
break;
case 'mod_asc':
$order_clause = 'ORDER BY UNIX_TIMESTAMP(modified) ASC, items.item_type_id ASC, text ASC';
break;
case 'alpha_desc':
$order_clause = 'ORDER BY items.item_type_id ASC, text DESC';
break;
case 'alpha_asc':
$order_clause = 'ORDER BY items.item_type_id ASC, text ASC';
break;
default:
/* do nothing */
break;
}

$titleId = 50;
$query = <<<QCOUNT
SELECT count(*) AS count
FROM {$db->Item} items
LEFT JOIN {$db->Element_Texts} elementtexts
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
$where_id_limit
GROUP BY elementtexts.record_id
QCOUNT;
$m_count = count($db->fetchAll($query));

$max_page = floor($m_count / $per_page);
if ($page > $max_page) {
$page = $max_page;
$offset = $page * $per_page;
}

$query = <<<QUERY
SELECT items.id AS id, text
FROM {$db->Item} items
LEFT JOIN {$db->Element_Texts} elementtexts
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
$where_id_limit
GROUP BY elementtexts.record_id
$order_clause
LIMIT $per_page
OFFSET $offset
QUERY;
$items = $db->fetchAll($query);
$m_items = array();

foreach ($items as $item) {
$m_items[] = array(
'value' => $item['id'],
'label' => $item['text'],
);
}

$metadata = array(
'count' => $m_count,
'items' => $m_items,
);

$this->_helper->json($metadata);
}

public function listItemTypesAction()
{
$itemTypesList = array(
'' => '- ' . __('All') . ' -',
);
$itemTypesList += $this->_getUsedItemTypes();
// Convert to a pseudo-associative array to keep order of ids.
$json = array(
'id' => array_keys($itemTypesList),
'label' => array_values($itemTypesList),
);
$this->_helper->json($json);
}

public function listCollectionsAction()
{
$collections = get_table_options('Collection');
// Convert to a pseudo-associative array to keep order of ids.
$json = array(
'id' => array_keys($collections),
'label' => array_values($collections),
);
$this->_helper->json($json);
}

/**
* Get the list of used item types for select form.
*
* @return array
*/
protected function _getUsedItemTypes()
{
$db = get_db();

$itemTypesTable = $db->getTable('ItemType');
$itemTypesAlias = $itemTypesTable->getTableAlias();

$select = $itemTypesTable->getSelect()
->reset(Zend_Db_Select::COLUMNS)
->from(array(), array($itemTypesAlias . '.id', $itemTypesAlias . '.name'))
->joinInner(array('items' => $db->Item), "items.item_type_id = $itemTypesAlias.id", array())
->group($itemTypesAlias . '.id')
->order($itemTypesAlias . '.name ASC');

$permissions = new Omeka_Db_Select_PublicPermissions('Items');
$permissions->apply($select, 'items');

$itemTypes = $db->fetchPairs($select);

return $itemTypes;
}
}
Loading