diff --git a/README.md b/README.md index 118d8bf..228974f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/controllers/EndpointController.php b/controllers/EndpointController.php index ae8342b..0ae7307 100644 --- a/controllers/EndpointController.php +++ b/controllers/EndpointController.php @@ -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; } /** diff --git a/controllers/IndexController.php b/controllers/IndexController.php index ae7b20f..7947880 100644 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -1,59 +1,59 @@ 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:
'; - 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 .= ' *'; @@ -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() @@ -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); @@ -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; } - } diff --git a/controllers/SuggestController.php b/controllers/SuggestController.php index 0c0c0c6..f1e352c 100644 --- a/controllers/SuggestController.php +++ b/controllers/SuggestController.php @@ -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 @@ -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) { @@ -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); } - - -} \ No newline at end of file +} diff --git a/controllers/VocabularyController.php b/controllers/VocabularyController.php index 37c41df..acdcb8a 100644 --- a/controllers/VocabularyController.php +++ b/controllers/VocabularyController.php @@ -1,147 +1,146 @@ _validatePost(); - - $name = $_REQUEST['nv-name']; - if($_REQUEST['nv-local']=='local') { - $text = $_REQUEST['nv-definetext']; - $vocab = $this->_helper->db->getTable('SvpVocab')->createVocab($name,'local'); - - $success = $this->_helper->db->getTable('SvpTerm')->addFromText($vocab->id,$text); - - } else if($_REQUEST['nv-local']=='remote') { - $url = $_REQUEST['nv-url']; - $vocab = $this->_helper->db->getTable('SvpVocab')->createVocab($name,$url); - $vocab->updateNow(); - } - $flash = $this->_helper->FlashMessenger; - $flash->addMessage('Your vocabulary has been created successfully. You may now assign it to metadata elements.','success'); - - $this->_helper->redirector('index','index'); - - + public function addAction() + { + $this->_validatePost(); + + $name = $_REQUEST['nv-name']; + // Local. + if ($_REQUEST['nv-local'] == 'local') { + $text = $_REQUEST['nv-definetext']; + $vocab = $this->_helper->db->getTable('SvpVocab')->createVocab($name, 'local'); + $success = $this->_helper->db->getTable('SvpTerm')->addFromText($vocab->id, $text); + } + // Remote.. + elseif ($_REQUEST['nv-local'] == 'remote') { + $url = $_REQUEST['nv-url']; + $vocab = $this->_helper->db->getTable('SvpVocab')->createVocab($name,$url); + $vocab->updateNow(); + } + $flash = $this->_helper->FlashMessenger; + $flash->addMessage(__('Your vocabulary has been created successfully. You may now assign it to metadata elements.'), 'success'); + $this->_helper->redirector('index', 'index'); } - - public function editAction() { - - $this->_validatePost(); - - if(isset($_REQUEST['vocab']) && $_REQUEST['vocab'] !='') - $vocab_id=$_REQUEST['vocab']; - else - $this->_helper->flashMessenger(__('There was a problem editing your vocabulary.'), 'error'); - //throw new Exception('no vocab chosen'); - - if(isset($_REQUEST['ev-url']) && ($url=$_REQUEST['ev-url']) !='local') { - - $vocab = $this->_helper->db->getTable('SvpVocab')->find($vocab_id); - $vocab->url = $url; - $vocab->save(); - - } else if(isset($_REQUEST['ev-edittext'])) { - - $text = $_REQUEST['ev-edittext']; - - $possibleUpdates = $this->_helper->db->getTable('SvpTerm')->updateFromText($vocab_id,$text); - - if($possibleUpdates) { - //prompt about updates - $updates = $this->_promptUpdates($possibleUpdates); - //if there are updates - //update terms for all assigned records - $this->_updateRecords($vocab_id,$updates); - } - } - $this->_helper->flashMessenger(__('Vocabulary edited successfully'), 'success'); - $this->_helper->redirector('index','index'); + public function editAction() + { + $this->_validatePost(); + + if (isset($_REQUEST['vocab']) && $_REQUEST['vocab'] != '') { + $vocab_id = $_REQUEST['vocab']; + } + else { + //throw new Exception('no vocab chosen'); + $this->_helper->flashMessenger(__('There was a problem editing your vocabulary.'), 'error'); + $this->_helper->redirector('index', 'index'); + } + + if (isset($_REQUEST['ev-url']) && $_REQUEST['ev-url'] !=' local') { + $url = $_REQUEST['ev-url']; + $vocab = $this->_helper->db->getTable('SvpVocab')->find($vocab_id); + $vocab->url = $url; + $vocab->save(); + } + // Edit text. + elseif (isset($_REQUEST['ev-edittext'])) { + $text = $_REQUEST['ev-edittext']; + $possibleUpdates = $this->_helper->db->getTable('SvpTerm')->updateFromText($vocab_id, $text); + if ($possibleUpdates) { + //prompt about updates + $updates = $this->_promptUpdates($possibleUpdates); + //if there are updates + //update terms for all assigned records + $this->_updateRecords($vocab_id, $updates); + } + } + $this->_helper->flashMessenger(__('Vocabulary edited successfully'), 'success'); + $this->_helper->redirector('index', 'index'); } public function getAction() { + $db = $this->_helper->db; + $vocabId = $this->getParam('vocab'); + $vocab = $db->getTable('SvpVocab')->find($vocabId); + $terms = $db->getTable('SvpTerm')->findBy(array('vocab_id' => $vocabId)); + $return = array('url' => $vocab->url, 'terms' => array()); + foreach ($terms as $term) { + $return['terms'][] = $term->term; + } $this->_helper->viewRenderer->setNoRender(); - $vocabId = $this->getParam('vocab'); - $vocab = $this->_helper->db->getTable('SvpVocab')->find($vocabId); - $termTable = $this->_helper->db->getTable('SvpTerm'); - $select = $termTable->getSelect()->where('vocab_id = ?',$vocabId); - $terms = $termTable->fetchObjects($select); - //$terms = $termTable->fetchObjects('select * from omeka_svp_terms where vocab_id = '.$vocabId); - $return = array('url'=>$vocab->url,'terms'=>array()); - foreach($terms as $term) { - $return['terms'][]=$term->term; - } - echo(json_encode($return)); + echo json_encode($return); } - - private function _promptUpdates($possibleUpdates) { - //this is only a test function. - //it'll work ok as long as there - //are the same number of deleted and added - //terms and they're all intended as - //updates. This code will have to be - //reorganized, since we will probably need an interactive - //dialog here - - $length = (count($possibleUpdates['add']) > count($possibleUpdates['delete'])) ? count($possibleUpdates['delete']) : count($possibleUpdates['add']); - - for($i=0;$i<$length;$i++) { - $updates[$possibleUpdates['delete'][$i]] = $possibleUpdates['add'][$i]; - } - return($updates); + private function _promptUpdates($possibleUpdates) + { + // this is only a test function. + // it'll work ok as long as there + // are the same number of deleted and added + // terms and they're all intended as + // updates. This code will have to be + // reorganized, since we will probably need an interactive + // dialog here + + $length = count($possibleUpdates['add']) > count($possibleUpdates['delete']) + ? count($possibleUpdates['delete']) + : count($possibleUpdates['add']); + + for ($i=0; $i < $length; $i++) { + $updates[$possibleUpdates['delete'][$i]] = $possibleUpdates['add'][$i]; + } + return $updates; } - private function _updateRecords($vocab_id,$updates) { - //find all assignments for this vocab - //run a sql query to update the element texts table - //for these elements when the old term is matched - //should be able to get it in a single query. - foreach($updates as $old=>$new) { - $sql = 'update omeka_element_texts as et left join omeka_svp_assigns as sa on (et.element_id = sa.element_id) set et.text=REPLACE(et.text,"'.$old.'","'.$new.'") where sa.vocab_id='.$vocab_id; - get_db()->query($sql); - } - + private function _updateRecords($vocab_id, $updates) + { + // find all assignments for this vocab + // run a sql query to update the element texts table + // for these elements when the old term is matched + // should be able to get it in a single query. + $db = $this->_helper->db; + foreach ($updates as $old => $new) { + $sql = "UPDATE `{$db->ElementText}` AS et + LEFT JOIN `{$db->SvpAssign}` AS sa + ON et.element_id = sa.element_id + SET et.text = REPLACE(et.text, ?, ?) + WHERE sa.vocab_id = ? + "; + $bind = array($old, $new, (integer) $vocab_id); + $db->query($sql, $bind); + } } /** * Check if the specified vocabulary exists. - * + * * @param string $vocab * @return bool */ private function _vocabExists($vocab) { - $vocab = $this->_helper->db->getTable('SvpVocab')->find($vocab); - - if ($vocab) { - return true; - } - return false; + $vocab = $this->_helper->db->getTable('SvpVocab')->find($vocab); + return !empty($vocab); } - private function _validatePost(){ - $csrf = new Omeka_Form_SessionCsrf; - if(!$csrf->isValid($_POST)){ - $flash->addMessage('There was an error processing your request.','error'); - $this->_helper->redirector('index','index'); - } + private function _validatePost() + { + $csrf = new Omeka_Form_SessionCsrf; + if (!$csrf->isValid($_POST)) { + $flash->addMessage(__('There was an error processing your request.'), 'error'); + $this->_helper->redirector('index', 'index'); + } } - - } diff --git a/libraries/SimpleVocabPlus/Controller/Plugin/Autosuggest.php b/libraries/SimpleVocabPlus/Controller/Plugin/Autosuggest.php index e3ad7e8..a12af05 100644 --- a/libraries/SimpleVocabPlus/Controller/Plugin/Autosuggest.php +++ b/libraries/SimpleVocabPlus/Controller/Plugin/Autosuggest.php @@ -1,26 +1,26 @@ getModuleName(); if (is_null($module)) { @@ -28,49 +28,50 @@ public function preDispatch($request) } $controller = $request->getControllerName(); $action = $request->getActionName(); - - // Include all routes (route + controller + actions) that render an + + // Include all routes (route + controller + actions) that render an // element form, including actions requested via AJAX. $routes = array( - array('module' => 'default', - 'controller' => 'items', - 'actions' => array('add', 'edit', 'element-form', 'change-type')) + array( + 'module' => 'default', + 'controller' => 'items', + 'actions' => array('add', 'edit', 'element-form', 'change-type'), + ), ); - - // Allow plugins to add routes that contain form inputs rendered by + + // Allow plugins to add routes that contain form inputs rendered by // Omeka_View_Helper_ElementForm::_displayFormInput(). $routes = apply_filters('sv_suggest_routes', $routes); - + // Iterate the defined routes. foreach ($routes as $route) { - // Set the autosuggest if the current action matches a defined route. - if ($route['module'] === $module && $route['controller'] === $controller - && in_array($action, $route['actions'])) { - + if ($route['module'] === $module + && $route['controller'] === $controller + && in_array($action, $route['actions']) + ) { // Iterate the elements that are assigned to a suggest endpoint. $svSuggests = $db->getTable('SvpAssign')->findAll(); foreach ($svSuggests as $svSuggest) { - $element = $db->getTable('Element')->find($svSuggest->element_id); $elementSet = $db->getTable('ElementSet')->find($element->element_set_id); - + // Add the autosuggest JavaScript to the JS queue. $view = Zend_Registry::get('view'); $view->headScript()->captureStart(); ?> - // Add autosuggest to name . ':' . $element->name; ?>. Used by the Simple Vocab Plus plugin. - jQuery(document).bind('omeka:elementformload', function(event) { - jQuery('#element-id; ?> textarea').autocomplete({ - minLength: 2, - source: url('simple-vocab-plus/endpoint/suggest-proxy/element-id/' . $element->id)); ?> - }); +// Add autosuggest to name . ':' . $element->name; ?>. Used by the Simple Vocab Plus plugin. +jQuery(document).bind('omeka:elementformload', function(event) { + jQuery('#element-id; ?> textarea').autocomplete({ + minLength: 2, + source: url('simple-vocab-plus/endpoint/suggest-proxy/element-id/' . $element->id)); ?> }); +}); headScript()->captureEnd(); } - - // Once the JavaScript is applied there is no need to continue + + // Once the JavaScript is applied there is no need to continue // looping the defined routes. break; } diff --git a/models/SvpAssign.php b/models/SvpAssign.php index 9b06b6b..5342ebf 100644 --- a/models/SvpAssign.php +++ b/models/SvpAssign.php @@ -1,14 +1,14 @@ \ No newline at end of file diff --git a/models/SvpVocab.php b/models/SvpVocab.php index 43b3a25..32b275c 100644 --- a/models/SvpVocab.php +++ b/models/SvpVocab.php @@ -1,7 +1,7 @@ id; $url = $this->url; - if($url == "local") - return; + if ($url == "local") { + return; + } //$newText = $this->_streamFetch($url); $newText = $this->_curlFetch($url); //die($newText); $newTerms = get_db()->getTable('SvpTerm')->updateFromText($id,$newText); } - - private function _streamFetch($Url) { + private function _streamFetch($Url) + { ob_start(); $context_options = array( 'http' => array( - 'method'=>'GET', - 'header'=>'Accept-language: en\r\n' + 'method '=> 'GET', + 'header' => 'Accept-language: en\r\n' ) ); $context = stream_context_create($context_options); - $contents = file_get_contents($Url,NULL,$context); + $contents = file_get_contents($Url, NULL, $context); ob_end_clean(); //$contents = file_get_contents($Url); return $contents; } - private function _curlFetch($url) { + private function _curlFetch($url) + { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); - curl_close($ch); - return($output); + curl_close($ch); + return($output); } } - -?> \ No newline at end of file diff --git a/models/Table/SvpAssign.php b/models/Table/SvpAssign.php index c527328..910c0c6 100644 --- a/models/Table/SvpAssign.php +++ b/models/Table/SvpAssign.php @@ -1,37 +1,37 @@ getSelect()->where('element_id = ?', $elementId); return $this->fetchObjects($select); } - } diff --git a/models/Table/SvpTerm.php b/models/Table/SvpTerm.php index 4550b38..5735a0f 100644 --- a/models/Table/SvpTerm.php +++ b/models/Table/SvpTerm.php @@ -1,68 +1,70 @@ _parseText($text); - foreach($terms as $term) { - $term = trim($term); - $svpTerm = new SvpTerm(); - $svpTerm->vocab_id = $vocab_id; - $svpTerm->term = $term; - $svpTerm->save(); + public function addFromText($vocab_id, $text) + { + $terms = $this->_parseText($text); + foreach($terms as $term) { + $term = trim($term); + $svpTerm = new SvpTerm(); + $svpTerm->vocab_id = $vocab_id; + $svpTerm->term = $term; + $svpTerm->save(); + } + return true; } - return true; - } - - public function updateFromText($vocab_id,$text) { - //set this to all rows - $deleted = array(); - $added = array(); - $termObjs = $this->fetchObjects("Select `term` from omeka_svp_terms where vocab_id = ".$vocab_id); - foreach($termObjs as $termObj) { - $deleted[]=trim($termObj['term']); - } - - $terms = $this->_parseText($text); + public function updateFromText($vocab_id, $text) + { + // set this to all rows + $deleted = array(); + $added = array(); + $termObjs = $this->findBy(array('vocab_id' => $vocab_id)); + $terms = $this->_parseText($text); + foreach ($termObjs as $termObj) { + $deleted[] = trim($termObj->term); + } - foreach($terms as $term) { - $i=array_search(trim($term),$deleted); - if($i!==false) { - unset($deleted[$i]); - } else { - $added[]=$term; - } - } + foreach ($terms as $term) { + $i = array_search(trim($term), $deleted); + if ($i !== false) { + unset($deleted[$i]); + } else { + $added[] = $term; + } + } - foreach($deleted as $delete) { - $sql = 'delete from omeka_svp_terms where vocab_id = "'.$vocab_id.'" and term = "'.trim($delete).'"'; - //die($sql); - get_db()->query($sql); - } + $db = $this->_db; + foreach ($deleted as $delete) { + $sql = "DELETE FROM `{$db->SvpTerm}` WHERE vocab_id = ? AND term = ?"; + $bind = array($vocab_id, trim($delete)); + get_db()->query($sql, $bind); + } - foreach($added as $add) { - $term = trim($term); - $svpTerm = new SvpTerm(); - $svpTerm->vocab_id = $vocab_id; - $svpTerm->term = $add; - $svpTerm->save(); - } - - if ( !empty($added) && !empty($deleted) ) { - return(array('add'=>array_values($added),'delete'=>array_values($deleted))); + foreach ($added as $add) { + $term = trim($term); + $svpTerm = new SvpTerm(); + $svpTerm->vocab_id = $vocab_id; + $svpTerm->term = $add; + $svpTerm->save(); + } + + if (!empty($added) && !empty($deleted)) { + return array( + 'add' => array_values($added), + 'delete' => array_values($deleted), + ); + } + + return false; } - - return false; - } - - private function _parseText($text) { - $text = str_replace("\n\r","\n",$text); - $text = str_replace("\r","",$text); - $terms = explode("\n",$text); - $terms = array_map('trim',$terms); - return($terms); - } + private function _parseText($text) + { + $text = str_replace("\n\r", "\n", $text); + $text = str_replace("\r", '', $text); + $terms = explode("\n", $text); + $terms = array_map('trim', $terms); + return $terms; + } } - -?> \ No newline at end of file diff --git a/models/Table/SvpVocab.php b/models/Table/SvpVocab.php index 7ba1047..f30f398 100644 --- a/models/Table/SvpVocab.php +++ b/models/Table/SvpVocab.php @@ -1,21 +1,18 @@ name = $name; - $vocab->url = $url; - $save = $vocab->save(); - return($vocab); - } - - - public function updateAll() { - foreach($this->findAll() as $vocab) { - $vocab->update(); +class Table_SvpVocab extends Omeka_Db_Table +{ + public function createVocab($name, $url) { + $vocab = new SvpVocab(); + $vocab->name = $name; + $vocab->url = $url; + $save = $vocab->save(); + return $vocab; } - } + public function updateAll() + { + foreach($this->findAll() as $vocab) { + $vocab->update(); + } + } } - -?> \ No newline at end of file diff --git a/plugin.ini b/plugin.ini index 63defb1..c663a5f 100644 --- a/plugin.ini +++ b/plugin.ini @@ -3,8 +3,8 @@ name="Simple Vocab Plus" author="UC Santa Cruz University Library" description="Allows for cloud based vocabulary definition and autosuggest features for Omeka elements" license="GPLv3" -link="" -support_link="https://github.com/UCSCLibrary/SimpleVocabPlus" +link="https://github.com/UCSCLibrary/SimpleVocabPlus" +support_link="https://github.com/UCSCLibrary/SimpleVocabPlus/issues" omeka_minimum_version="2.1" -omeka_target_version="2.1" -version="1.3" +omeka_target_version="2.4.1" +version="2.4" diff --git a/views/admin/index/index.php b/views/admin/index/index.php index a5af842..d255202 100644 --- a/views/admin/index/index.php +++ b/views/admin/index/index.php @@ -1,263 +1,237 @@ 'Simple Vocabulary Plus')); ?> - - - -
- -
+
- -
-
- -

- -
-
- -
-
-

- formSelect('element_id', null, array('id' => 'element-id'), $this->form_element_options) ?> -
+
+ +
+

+
+
+ +
+
+

+

+ formSelect('element_id', null, array('id' => 'element-id'), $this->form_element_options) ?> +
+
+
+
+ +
+
+

'); + ?>

+ formSelect('vocab_id', null, array('id' => 'assign-vocab'), $this->form_vocab_options); ?> +
+
+
+
+
+ formSubmit('edit-element-suggest', __('Assign Vocabulary'), array('class' => 'submit big green button')); ?> +
+
+ csrf; ?> +
+
+

+ assignments): ?> + + + + + + + + + + + assignments as $assignment): ?> + + + + + + + + +
+ +

+ +
+
+
-
-
- -
-
-

'); ?>

- formSelect('vocab_id', null, array('id' => 'assign-vocab'), $this->form_vocab_options); ?> -
+
+
+

+
+
+
+ +
+
+

+ +
+
+
+
+ +
+
+

+ + +
+ + +
+
+
+
+ +
+
+

+ +
+
+
+
+ +
+
+

+ +
+
+
+ formSubmit('new-vocabulary', __('Create Vocabulary'), array('class' => 'submit green button', 'id'=>'createbutton')); ?> +
+ csrf;?> +
+
- -
-
-
- formSubmit('edit-element-suggest', __('Assign Vocabulary'), array('class' => 'submit big green button')); ?> +
+
+

+
+
+
+ +
+
+

+ formSelect('vocab', null, array('id' => 'edit-vocab'), $this->form_vocab_options); ?> +
+
+
+
+ +
+
+

+ +
+
+
+
+ +
+
+

+ +
+
+
+ formSubmit('edit-vocabulary', __('Edit Vocabulary'), array('class' => 'submit green button', 'id'=>'edit-button')); ?> +
+ csrf;?> +
+
-
- csrf;?> - -
- -
-

- assignments): ?> - - - - - - - - - - - assignments as $assignment): ?> - - - - - - - - -
- -

- -
-
- - -
-
-
-

- -
- -
-
- -
-
-

- -
-
- -
-
- -
-
-

- - - Define vocabulary here and edit it manually here
- - Sync vocabulary with cloud -
-
- -
-
- -
-
-

- -
-
- -
-
- -
-
-

- -
-
- - -
- formSubmit('new-vocabulary', __('Create Vocabulary'), array('class' => 'submit green button', 'id'=>'createbutton')); ?> -
- - csrf;?> - -
- -
- -
- -
-
-

- -
-
-
- -
-
-

- formSelect('vocab', null, array('id' => 'edit-vocab'), $this->form_vocab_options); ?> -
- - -
-
- -
-
-

- -
-
- - -
-
- -
-
-

- -
-
- - -
- formSubmit('edit-vocabulary', __('Edit Vocabulary'), array('class' => 'submit green button', 'id'=>'edit-button')); ?> -
- - csrf;?> - -
- -
-
-
- \ No newline at end of file +