Skip to content

Commit

Permalink
Merge branch 'doana-add-file-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsafley committed Jan 10, 2017
2 parents b9b70ab + e0ce32f commit fb76296
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
33 changes: 32 additions & 1 deletion SimpleVocabPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ class SimpleVocabPlugin extends Omeka_Plugin_AbstractPlugin
/**
* @var array This plugin's hooks.
*/
protected $_hooks = array('install', 'uninstall', 'initialize', 'define_acl');
protected $_hooks = array(
'install', 'uninstall', 'initialize', 'upgrade',
'define_acl', 'config_form', 'config',
);

/**
* @var array This plugin's filters.
*/
protected $_filters = array('admin_navigation_main');

protected $_options = array(
'simple_vocab_files' => 0,
);

/**
* Install this plugin.
*/
Expand All @@ -38,6 +45,7 @@ public function hookInstall()
UNIQUE KEY `element_id` (`element_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$db->query($sql);
$this->_installOptions();
}

/**
Expand All @@ -48,6 +56,14 @@ public function hookUninstall()
$db = get_db();
$sql = "DROP TABLE IF EXISTS `{$db->SimpleVocabTerm}`;";
$db->query($sql);
$this->_uninstallOptions();
}

public function hookUpgrade($args)
{
if (version_compare($args['old_version'], '2.0.1', '<=')) {
set_option('simple_vocab_files', $this->_options['simple_vocab_files']);
}
}

/**
Expand All @@ -63,6 +79,21 @@ public function hookInitialize()
add_translation_source(dirname(__FILE__) . '/languages');
}

public function hookConfigForm()
{
$view = get_view();
include 'config_form.php';
}

public function hookConfig($args)
{
$files = 0;
if (isset($args['post']['simple_vocab_files'])) {
$files = (int) $args['post']['simple_vocab_files'];
}
set_option('simple_vocab_files', $files);
}

/**
* Define this plugin's ACL.
*/
Expand Down
20 changes: 20 additions & 0 deletions config_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<section class="seven columns alpha">
<div class="field">
<div class="two column alpha">
<label for="simple_vocab_files">Apply to Files</label>
</div>
<div class="inputs five columns omega">
<?php echo $view->formCheckbox(
'simple_vocab_files',
null,
array(
'id' => 'simple_vocab_files',
'checked' => (bool) get_option('simple_vocab_files'),
)
); ?>
<p class="explanation">By default, your simple vocabularies will only
apply to item metadata. Check the above box if you want to apply your
vocabularies to file metadata as well.</p>
</div>
</div>
</section>
19 changes: 17 additions & 2 deletions libraries/SimpleVocab/Controller/Plugin/SelectFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class SimpleVocab_Controller_Plugin_SelectFilter extends Zend_Controller_Plugin_
protected $_defaultRoutes = array(
array('module' => 'default', 'controller' => 'items',
'actions' => array('add', 'edit', 'change-type')),
array('module' => 'default', 'controller' => 'elements',
'actions' => array('element-form')),
array('module' => 'default', 'controller' => 'elements',
'actions' => array('element-form')),
);

/**
Expand All @@ -44,6 +44,16 @@ public function preDispatch(Zend_Controller_Request_Abstract $request)
$currentModule = is_null($request->getModuleName()) ? 'default' : $request->getModuleName();
$currentController = $request->getControllerName();
$currentAction = $request->getActionName();

$filterFiles = get_option('simple_vocab_files');
if ($filterFiles) {
// Add the file add/edit route if configured to.
$this->_defaultRoutes[] = array(
'module' => 'default',
'controller' => 'files',
'actions' => array('add', 'edit')
);
}

// Allow plugins to register routes that contain form inputs rendered by
// Omeka_View_Helper_ElementForm::_displayFormInput().
Expand Down Expand Up @@ -71,6 +81,11 @@ public function preDispatch(Zend_Controller_Request_Abstract $request)
$elementSet = $db->getTable('ElementSet')->find($element->element_set_id);
add_filter(array('ElementInput', 'Item', $elementSet->name, $element->name),
array($this, 'filterElementInput'));
if ($filterFiles) {
// Add the file filter if configured to.
add_filter(array('ElementInput', 'File', $elementSet->name, $element->name),
array($this, 'filterElementInput'));
}
}
// Once the filter is applied for one route there is no need to
// continue looping the routes.
Expand Down
2 changes: 1 addition & 1 deletion plugin.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description="A simple way to create controlled vocabularies."
license="GPLv3"
link="http://omeka.org/codex/Plugins/SimpleVocab_2.0"
support_link="http://omeka.org/forums/forum/plugins"
version="2.0.1"
version="2.1"
omeka_minimum_version="2.0"
omeka_target_version="2.0"
tags="controlled vocabulary, vocabulary"

0 comments on commit fb76296

Please sign in to comment.