Skip to content

Commit

Permalink
Merge pull request #7 from Daniel-KM/various_fix
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
NedHenry committed Nov 14, 2016
2 parents f2647e3 + 4169f20 commit 0365b08
Show file tree
Hide file tree
Showing 15 changed files with 609 additions and 586 deletions.
72 changes: 69 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,70 @@
# SimpleVocabPlus
This Omeka 2.1+ plugin allows administrators to create, edit, and update controlled vocabularies either defined in Omeka or in the cloud
Simple Vocab Plus (plugin for Omeka)
====================================

If you use this plugin, please take a moment to submit feedback about your experience, so we can keep making Omeka better: [User Survey] (https://docs.google.com/forms/d/17kHFdT-cx7K7ihrpGsSkCNytoHPDP7bc6OmavLbFe0w/viewform?usp=send_form "User Survey")
This [Omeka] 2.1+ plugin allows administrators to create, edit, and update
controlled vocabularies either defined in Omeka or in the cloud.

[Simple Vocab Plus] is an improved fork of the official [Simple Vocab].
The user interface is optimized too.

If you use this plugin, please take a moment to submit feedback about your
experience, so we can keep making Omeka better: [User Survey].


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

Uncompress files and rename plugin folder "SimpleVocabPlus".

Then install it like any other Omeka plugin.


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 issues on the [plugin issues] page on GitHub.


License
-------

This plugin is published under [GNU/GPL v3].

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.


Copyright
---------

* Copyright UCSC Library Digital Initiatives, 2014-2016
* Copyright Daniel Berthereau, 2016 (see [Daniel-KM] on GitHub)


[Simple Vocab Plus]: https://github.com/UCSCLibrary/SimpleVocabPlus
[Simple Vocab]: https://github.com/omeka/plugin-SimpleVocab
[Omeka]: https://omeka.org
[User Survey]: https://docs.google.com/forms/d/17kHFdT-cx7K7ihrpGsSkCNytoHPDP7bc6OmavLbFe0w/viewform?usp=send_form
[plugin issues]: https://github.com/UCSCLibrary/SimpleVocabPlus/issues
[GNU/GPL v3]: https://www.gnu.org/licenses/gpl-3.0.html
[Daniel-KM]: https://github.com/Daniel-KM
2 changes: 1 addition & 1 deletion controllers/EndpointController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function vocabAction()
$elementId = $this->getRequest()->getParam('element_id');
$svAssign = $this->_helper->db->getTable('SvpAssign')->findByElementId($elementId);
$vocab = $this->_helper->db->getTable('SvpAssign')->find($svAssign->vocab_id);
echo $vocab->url;
echo $vocab ? $vocab->url : null;
}

/**
Expand Down
83 changes: 41 additions & 42 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
<?php
/**
* Simple Vocab Plus
*
*
* @copyright Copyright 2014 UCSC Library Digital Initiatives
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* The Simple Vocab Plus controller.
*
* @package SvPlus
*
* @package SimpleVocabPlus
*/
class SimpleVocabPlus_IndexController extends Omeka_Controller_AbstractActionController
{
public function indexAction()
{
$this->view->form_element_options = $this->_getFormElementOptions();
$this->view->form_vocab_options = $this->_getFormSuggestOptions();
$this->view->assignments = $this->_getAssignments();

$csrf = new Omeka_Form_SessionCsrf;
$this->view->csrf = $csrf;
$this->view->form_element_options = $this->_getFormElementOptions();
$this->view->form_vocab_options = $this->_getFormSuggestOptions();
$this->view->assignments = $this->_getAssignments();

//echo 'updating:<br>';
foreach(get_db()->getTable('SvpVocab')->findAll() as $vocab) {
$vocab->updateNow();
}
//die();
}
$csrf = new Omeka_Form_SessionCsrf;
$this->view->csrf = $csrf;

foreach(get_db()->getTable('SvpVocab')->findAll() as $vocab) {
$vocab->updateNow();
}
}

/**
* Get an array to be used in formSelect() containing all elements.
*
*
* @return array
*/
private function _getFormElementOptions()
{
$db = $this->_helper->db->getDb();
$sql = "
SELECT es.name AS element_set_name, e.id AS element_id, e.name AS element_name,
it.name AS item_type_name, gv.id AS gv_suggest_id
FROM {$db->ElementSet} es
JOIN {$db->Element} e ON es.id = e.element_set_id
LEFT JOIN {$db->ItemTypesElements} ite ON e.id = ite.element_id
LEFT JOIN {$db->ItemType} it ON ite.item_type_id = it.id
LEFT JOIN {$db->SvpAssign} gv ON e.id = gv.element_id
WHERE es.record_type IS NULL OR es.record_type = 'Item'
SELECT es.name AS element_set_name,
e.id AS element_id,
e.name AS element_name,
it.name AS item_type_name,
gv.id AS gv_suggest_id
FROM {$db->ElementSet} es
JOIN {$db->Element} e ON es.id = e.element_set_id
LEFT JOIN {$db->ItemTypesElements} ite ON e.id = ite.element_id
LEFT JOIN {$db->ItemType} it ON ite.item_type_id = it.id
LEFT JOIN {$db->SvpAssign} gv ON e.id = gv.element_id
WHERE es.record_type IS NULL OR es.record_type = 'Item'
ORDER BY es.name, it.name, e.name";
$elements = $db->fetchAll($sql);
$options = array('' => __('Select Below'));
foreach ($elements as $element) {
$optGroup = $element['item_type_name']
? __('Item Type') . ': ' . __($element['item_type_name'])
: __($element['element_set_name']);
$optGroup = $element['item_type_name']
? __('Item Type') . ': ' . __($element['item_type_name'])
: __($element['element_set_name']);
$value = __($element['element_name']);
if ($element['gv_suggest_id']) {
$value .= ' *';
Expand All @@ -62,30 +62,28 @@ private function _getFormElementOptions()
}
return $options;
}

/**
* Get an array to be used in formSelect() containing all sugggest endpoints.
*
*
* @return array
*/
private function _getFormSuggestOptions()
{
//print_r($this->_helper->db->getTable('SimpleVocabPlus'));
//die();
$vocabs = $this->_helper->db->getTable('SvpVocab')->findAll();

$options = array('' => __('Select Below'));
$vocabs = $this->_helper->db->getTable('SvpVocab')->findAll();

$options = array('' => __('Select Below'));

foreach ($vocabs as $vocab) {
$options[$vocab['id']] = $vocab['name'];
$options[$vocab['id']] = $vocab['name'];
}

return $options;
}

/**
* Get all the authority/vocabulary assignments.
*
*
* @return array
*/
private function _getAssignments()
Expand All @@ -96,7 +94,7 @@ private function _getAssignments()
$elementSetTable = $this->_helper->db->getTable('ElementSet');
$itemTypeTable = $this->_helper->db->getTable('ItemType');
$itemTypesElementsTable = $this->_helper->db->getTable('ItemTypesElements');

$assignments = array();
foreach ($svSuggestTable->findAll() as $svSuggest) {
$element = $elementTable->find($svSuggest->element_id);
Expand All @@ -112,13 +110,14 @@ private function _getAssignments()

$assignments[] = array(
'suggest_id' => $svSuggest->id,
'element_set_name' => $elementSetName,
'element_name' => $element->name,
'element_set_name' => $elementSetName,
'element_set_id' => $elementSet->id,
'element_name' => $element->name,
'element_id' => $svSuggest->element_id,
'authority_vocabulary' => __($authorityVocabularyName),
'element_id' => $svSuggest->element_id
'authority_vocabulary_id' => $authorityVocabulary->id,
);
}
return $assignments;
}

}
51 changes: 21 additions & 30 deletions controllers/SuggestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,31 @@ public function deleteAction()
$this->_helper->flashMessenger(__('Successfully disabled the element\'s suggest feature.'), 'success');
$this->_helper->redirector('index','index');
}

public function editAction()
{
$suggestId = $this->getRequest()->getParam('suggest_id');
$elementId = $this->getRequest()->getParam('element_id');
$vocab = $this->getRequest()->getParam('vocab_id');
$vocabId = $this->getRequest()->getParam('vocab_id');
// Don't process empty select options.
if ('' == $elementId) {
$this->_helper->redirector('index','index');
}

// Don't process an invalid suggest endpoint.
if (!$this->_vocabExists($vocab)) {
if (!$this->_vocabExists($vocabId)) {
$this->_helper->flashMessenger(__('Invalid suggest endpoint. No changes have been made.'), 'error');
$this->_helper->redirector('index','index');
}

$svAssign = $this->_helper->db->getTable('SvpAssign')->find($suggestId);
$svAssign->element_id = $vocab;
$svAssign->vocab_id = $vocab;

$svAssign->element_id = $elementId;
$svAssign->vocab_id = $vocabId;
$svAssign->save();
$this->_helper->flashMessenger(__('Successfully edited the element\'s suggest feature.'), 'success');

}

$this->_helper->redirector('index','index');
}

/**
* Adds a connection between an element and a vocabulary
Expand All @@ -57,9 +56,9 @@ public function editAction()
* @return void
*/
public function addAction() {

$elementId = $this->getRequest()->getParam('element_id');
$vocab = $this->getRequest()->getParam('vocab_id');
$vocabId = $this->getRequest()->getParam('vocab_id');

// Don't process empty select options.
if ('' == $elementId) {
Expand All @@ -68,36 +67,28 @@ public function addAction() {
}

// Don't process an invalid suggest endpoint.
if (!$this->_vocabExists($vocab)) {
if (!$this->_vocabExists($vocabId)) {
$this->_helper->flashMessenger(__('Invalid suggest endpoint. No changes have been made.'), 'error');
$this->_helper->redirector('index','index');
}

$svAssign = new SvpAssign;
$svAssign->element_id = $elementId;
$svAssign->vocab_id = $vocab;
$svAssign->vocab_id = $vocabId;
$svAssign->save();
$this->_helper->flashMessenger(__('Successfully enabled the element\'s suggest feature.'), 'success');
$this->_helper->redirector('index','index');
}




/**
* Check if the specified vocabulary exists.
*
* @param string $vocab
*
* @param integer $vocabId
* @return bool
*/
private function _vocabExists($vocab)
private function _vocabExists($vocabId)
{
$vocab = $this->_helper->db->getTable('SvpVocab')->find($vocab);

if ($vocab) {
return true;
}
return false;
$vocab = $this->_helper->db->getTable('SvpVocab')->find($vocabId);
return !empty($vocab);
}


}
}
Loading

0 comments on commit 0365b08

Please sign in to comment.