diff --git a/FacetsPlugin.php b/FacetsPlugin.php
index 9deef16..3c72de2 100644
--- a/FacetsPlugin.php
+++ b/FacetsPlugin.php
@@ -1,125 +1,364 @@
-addHelperPath(dirname(__FILE__) . '/views/helpers', 'Facets_View_Helper_');
- }
-
- public function hookPublicHead($args)
- {
- queue_css_file('facets');
- }
-
- public function hookDefineRoutes($args)
- {
- if (is_admin_theme()) {
- return;
- }
-
- //Itemtypes browse
- $router = $args['router'];
- $router->addRoute(
- 'facets',
- new Zend_Controller_Router_Route(
- "facets",
- array(
- 'module' => 'facets',
- 'controller' => 'facets',
- 'action' => 'browse'
- )
- )
- );
-
- }
-
- /**
- * Deal with search terms (advanced search).
- *
- * Allows to get refinements when a base Dublin Core is used.
- *
- * @internal This hook is used twice, first to prepare select for the
- * current page, second to get the total count.
- *
- * @internal This should be used, because the filter is not enough for
- * requests with a refinable element that should contains something.
- *
- * @internal MySql 5.5 has a limit: group by is done before order by, and it
- * is complex to skirt.
- *
- * @see DublinCoreExtendedPlugin::filterItemsBrowseParams()
- *
- * @param Omeka_Db_Select $select
- * @param array $params
- */
- public function hookItemsBrowseSql($args)
- {
- $db = $this->_db;
- $select = $args['select'];
- $params = $args['params'];
-
- }
-
- public function hookPublicItemsBrowse($args)
- {
- $view = $args['view'];
- $items = $args['items'];
-
- // $params = $args['params'];
- $itemsArray = array();
- $allItems = get_db()->getTable('Item')->findAll();
- // $allItems = $this->_helper->db->findBy($params);
- foreach($allItems as $item){
- $itemsArray[] = $item->id;
- }
-
- // echo get_view()->partial('facets/browse.php',array(
- // 'itemsArray' => $itemsArray,
- // 'items' => $items
- // ));
-
- echo get_view()->partial('facets/browse.php',array(
- 'itemsArray' => $itemsArray
- ));
- }
-}
+ __('show all'),
+ 'ShowLess' => __('show less')
+));
+
+require_once FACETS_PLUGIN_DIR . '/helpers/FacetsFunctions.php';
+
+class FacetsPlugin extends Omeka_Plugin_AbstractPlugin
+{
+ protected $_hooks = array(
+ 'install',
+ 'uninstall',
+ 'upgrade',
+ 'initialize',
+ 'config_form',
+ 'config',
+ 'collections_browse_sql',
+ 'public_head',
+ 'public_items_browse',
+ 'public_collections_browse',
+ 'public_facets'
+ );
+
+ /**
+ * Installs the plugin.
+ */
+ public function hookInstall()
+ {
+ set_option('facets_public_hook', 'default');
+ set_option('facets_description', 0);
+ set_option('facets_direction', 'vertical');
+ set_option('facets_collapsible', 0);
+ set_option('facets_count', 0);
+
+ $defaults = array(
+ 'elements' => array('item', 'collection', 'style', 'sort', 'popularity'),
+ 'item_types' => array('item', 'style', 'sort', 'popularity'),
+ 'collections' => array('item', 'style', 'sort', 'popularity'),
+ 'tags' => array('item', 'style', 'sort', 'popularity'),
+ 'users' => array('item', 'collection', 'style', 'sort', 'popularity'),
+ 'public' => array('item', 'collection', 'style', 'sort', 'popularity'),
+ 'featured' => array('item', 'collection', 'style', 'sort', 'popularity')
+ );
+ set_option('facets_parameters', json_encode($defaults));
+ }
+
+ /**
+ * Uninstalls the plugin.
+ */
+ public function hookUninstall()
+ {
+ delete_option('facets_public_hook');
+ delete_option('facets_description');
+ delete_option('facets_direction');
+ delete_option('facets_collapsible');
+ delete_option('facets_count');
+ delete_option('facets_parameters');
+ }
+
+ public function hookUpgrade($args)
+ {
+ $oldVersion = $args['old_version'];
+ $newVersion = $args['new_version'];
+
+ if (version_compare($oldVersion, '2.5', '<')) {
+ $parameters = json_decode(str_replace('type', 'style', get_option('facets_elements')), true);
+
+ $parameters['item_types']['item'] = get_option('facets_item_types_active');
+ $parameters['item_types']['style'] = get_option('facets_item_types_style');
+ $parameters['item_types']['sort'] = get_option('facets_item_types_sort');
+ $parameters['item_types']['popularity'] = get_option('facets_item_types_popularity');
+ $parameters['collections']['item'] = get_option('facets_collections_active');
+ $parameters['collections']['style'] = get_option('facets_collections_style');
+ $parameters['collections']['sort'] = get_option('facets_collections_sort');
+ $parameters['collections']['popularity'] = get_option('facets_collections_popularity');
+ $parameters['tags']['item'] = get_option('facets_tags_active');
+ $parameters['tags']['style'] = get_option('facets_tags_style');
+ $parameters['tags']['sort'] = get_option('facets_tags_sort');
+ $parameters['tags']['popularity'] = get_option('facets_tags_popularity');
+ $parameters['users'] = array('item', 'collection', 'style', 'sort', 'popularity');
+ $parameters['public'] = array('item', 'collection', 'style', 'sort', 'popularity');
+ $parameters['featured'] = array('item', 'collection', 'style', 'sort', 'popularity');
+ set_option('facets_parameters', json_encode($parameters));
+
+ delete_option('facets_elements');
+ delete_option('facets_item_types_active');
+ delete_option('facets_item_types_style');
+ delete_option('facets_item_types_sort');
+ delete_option('facets_item_types_popularity');
+ delete_option('facets_collections_active');
+ delete_option('facets_collections_style');
+ delete_option('facets_collections_sort');
+ delete_option('facets_collections_popularity');
+ delete_option('facets_tags_active');
+ delete_option('facets_tags_style');
+ delete_option('facets_tags_sort');
+ delete_option('facets_tags_popularity');
+ } elseif (version_compare($oldVersion, '2.9', '<')) {
+ set_option('facets_description', (get_option('facets_description') != '' ? 1 : 0));
+ set_option('facets_count', 0);
+ delete_option('facets_checkbox_minimum_amount');
+ delete_option('facets_hide_single_entries');
+ }
+ }
+
+ /**
+ * Initialize this plugin.
+ */
+ public function hookInitialize()
+ {
+ add_translation_source(dirname(__FILE__) . '/languages');
+
+ get_view()->addHelperPath(dirname(__FILE__) . '/views/helpers', 'Facets_View_Helper_');
+
+ $settings = json_decode(get_option('facets_parameters'), true);
+ $this->_settings = $settings;
+ }
+
+ /**
+ * Shows plugin configuration page.
+ */
+ public function hookConfigForm($args)
+ {
+ $settings = $this->_settings;
+
+ $table = get_db()->getTable('Element');
+ $select = $table->getSelect()
+ ->order('elements.element_set_id')
+ ->order('ISNULL(elements.order)')
+ ->order('elements.order');
+ $elements = $table->fetchObjects($select);
+
+ include 'config_form.php';
+ }
+
+ /**
+ * Handle the config form.
+ */
+ public function hookConfig($args)
+ {
+ $post = $args['post'];
+
+ set_option('facets_public_hook', $post['facets_public_hook']);
+ set_option('facets_description', $post['facets_description']);
+ set_option('facets_hide_single_entries', $post['facets_hide_single_entries']);
+ set_option('facets_direction', $post['facets_direction']);
+ set_option('facets_collapsible', $post['facets_collapsible']);
+ set_option('facets_count', $post['facets_count']);
+
+ $settings = array(
+ 'elements' => isset($post['elements']) ? $post['elements'] : array(),
+ 'item_types' => isset($post['item_types']) ? $post['item_types'] : array(),
+ 'collections' => isset($post['collections']) ? $post['collections'] : array(),
+ 'tags' => isset($post['tags']) ? $post['tags'] : array(),
+ 'users' => isset($post['users']) ? $post['users'] : array(),
+ 'public' => isset($post['public']) ? $post['public'] : array(),
+ 'featured' => isset($post['featured']) ? $post['featured'] : array()
+ );
+ set_option('facets_parameters', json_encode($settings));
+ }
+
+ /**
+ * Hook into collections_browse_sql
+ *
+ * @select array $args
+ * @params array $args
+ */
+ public function hookCollectionsBrowseSql($args)
+ {
+ $db = $this->_db;
+ $select = $args['select'];
+ $params = $args['params'];
+
+ // if (array_key_exists('_advanced_0', $select->getPart('from')) return;
+
+ if (strpos($select, '_advanced_') !== false) return;
+
+ if ($advancedTerms = @$params['advanced']) {
+ $where = '';
+ $advancedIndex = 0;
+ foreach ($advancedTerms as $v) {
+ // Do not search on blank rows.
+ if (empty($v['element_id']) || empty($v['type'])) {
+ continue;
+ }
+
+ $value = isset($v['terms']) ? $v['terms'] : null;
+ $type = $v['type'];
+ $elementId = (int) $v['element_id'];
+ $alias = "_advanced_{$advancedIndex}";
+
+ $joiner = isset($v['joiner']) && $advancedIndex > 0 ? $v['joiner'] : null;
+
+ $negate = false;
+ // Determine what the WHERE clause should look like.
+ switch ($type) {
+ case 'does not contain':
+ $negate = true;
+ case 'contains':
+ $predicate = "LIKE " . $db->quote('%'.$value .'%');
+ break;
+
+ case 'is not exactly':
+ $negate = true;
+ case 'is exactly':
+ $predicate = ' = ' . $db->quote($value);
+ break;
+
+ case 'is empty':
+ $negate = true;
+ case 'is not empty':
+ $predicate = 'IS NOT NULL';
+ break;
+
+ case 'starts with':
+ $predicate = "LIKE " . $db->quote($value.'%');
+ break;
+
+ case 'ends with':
+ $predicate = "LIKE " . $db->quote('%'.$value);
+ break;
+
+ case 'does not match':
+ $negate = true;
+ case 'matches':
+ if (!strlen($value)) {
+ continue 2;
+ }
+ $predicate = 'REGEXP ' . $db->quote($value);
+ break;
+
+ default:
+ throw new Omeka_Record_Exception(__('Invalid search type given!'));
+ }
+
+ $predicateClause = "{$alias}.text {$predicate}";
+
+ // Note that $elementId was earlier forced to int, so manual quoting
+ // is unnecessary here
+ $joinCondition = "{$alias}.record_id = collections.id AND {$alias}.record_type = 'Collection' AND {$alias}.element_id = $elementId";
+
+ if ($negate) {
+ $joinCondition .= " AND {$predicateClause}";
+ $whereClause = "{$alias}.text IS NULL";
+ } else {
+ $whereClause = $predicateClause;
+ }
+
+ $select->joinLeft(array($alias => $db->ElementText), $joinCondition, array());
+ if ($where == '') {
+ $where = $whereClause;
+ } elseif ($joiner == 'or') {
+ $where .= " OR $whereClause";
+ } else {
+ $where .= " AND $whereClause";
+ }
+
+ $advancedIndex++;
+ }
+
+ if ($where) {
+ $select->where($where);
+ }
+ }
+ }
+
+ public function hookPublicHead($args)
+ {
+ $request = Zend_Controller_Front::getInstance()->getRequest();
+ $controller = $request->getControllerName();
+ $action = $request->getActionName();
+
+ if (($action == 'browse' && ($controller == 'items' || $controller == 'collections')) || ($controller == 'search' && $action == 'index')) {
+ $language = json_encode(FACETS_LANGUAGE);
+ queue_js_string("facetsLanguage = {language: $language};");
+ queue_js_file('facets');
+ queue_css_file('facets');
+ }
+ }
+
+ public function hookPublicItemsBrowse($args)
+ {
+ $settings = $this->_settings;
+ if (get_option('facets_public_hook') == 'default') {
+ self::showFacets($args);
+ }
+ }
+
+ public function hookPublicCollectionsBrowse($args)
+ {
+ $settings = $this->_settings;
+ if (get_option('facets_public_hook') == 'default') {
+ self::showFacets($args);
+ }
+ }
+
+ public function hookPublicFacets($args)
+ {
+ if (get_option('facets_public_hook') == 'custom') {
+ self::showFacets($args);
+ }
+ }
+
+ public function showFacets($args)
+ {
+ $settings = $this->_settings;
+ $request = Zend_Controller_Front::getInstance()->getRequest();
+ $controller = $request->getControllerName();
+ $action = $request->getActionName();
+ $params = array();
+
+ if ($controller == 'items' && $action == 'browse') {
+ if (isset($_GET['advanced'])) $params['advanced'] = $_GET['advanced'];
+ if (isset($_GET['collection'])) $params['collection'] = $_GET['collection'];
+ if (isset($_GET['type'])) $params['type'] = $_GET['type'];
+ if (isset($_GET['tags'])) $params['tags'] = $_GET['tags'];
+ if (isset($_GET['user'])) $params['user'] = $_GET['user'];
+ if (isset($_GET['public'])) $params['public'] = $_GET['public'];
+ if (isset($_GET['featured'])) $params['featured'] = $_GET['featured'];
+ if (isset($_GET['search'])) $params['search'] = $_GET['search'];
+ if (recordTypeActive('item', $settings['elements']) && count(get_records('item', $params, null)) > 0) {
+ echo get_view()->partial('facets/browse.php', array(
+ 'params' => $params,
+ 'recordType' => 'item'
+ ));
+ }
+ } elseif ($controller == 'collections' && $action == 'browse') {
+ if (isset($_GET['advanced'])) $params['advanced'] = $_GET['advanced'];
+ if (isset($_GET['user'])) $params['user'] = $_GET['user'];
+ if (isset($_GET['public'])) $params['public'] = $_GET['public'];
+ if (isset($_GET['featured'])) $params['featured'] = $_GET['featured'];
+ if (recordTypeActive('collection', $settings['elements']) && count(get_records('collection', $params, null)) > 0) {
+ echo get_view()->partial('facets/browse.php', array(
+ 'params' => $params,
+ 'recordType' => 'collection'
+ ));
+ }
+ } elseif ($controller == 'search' && $action == 'index') {
+ // this would be for the site-wide simple search;
+ // main problem is that, differently from advanced search,
+ // it uses its own "search_texts" table, so results from that
+ // would have to be crossjoined with the "advanced" ones used
+ // by the facets;
+ // besides, advanced search works only for Items, so one might
+ // want to check whether the site-wide search has been performed
+ // just on Items.
+ if ($recordTypes = $_GET['record_types']) {
+ if (count($recordTypes) == 1 && in_array('Item', $recordTypes)) {
+ // site-wide search was performed just on Items
+ }
+ }
+ }
+ }
+}
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6beefc8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,63 @@
+# Facets
+
+## Description
+
+Plugin for Omeka Classic. Once installed and active, allows to insert a Faceted search refining block containing available metadata values extracted from browsing context. Works for both Items and Collections.
+
+Settings allow to choose the hook to be used, which criteria to use for search refinement, whether to ignore single entries, sorting order for values, whether to show values popularity, whether to use an horizontal or vertical layout, whether to make the block collapsible, etc.
+
+## Credits
+
+Original development is part of the [Armarium](https://www.armarium-hautsdefrance.fr/) Project, managed by the french association [AR2L Hauts de France](http://www.ar2l-hdf.fr/).
+
+Fixed and improved version by [DBinaghi](https://github.com/DBinaghi).
+
+## Installation
+Uncompress files and rename plugin folder "Facets".
+
+Then install it like any other Omeka plugin.
+
+## (optional) Theme customization
+
+Facets will appear by default in the **Items browse** and **Collections browse** pages, where the `public_items_browse` and `public_collections_browse` hooks are set. It is possible to use instead a custom `public_facets` hook, that can be positioned wherever needed (`YOUR_THEME/items/browse.php` or `YOUR_THEME/common/header.php`, f.i.) according to the theme used; in such a case, the use of [get_specific_plugin_hook_output](http://omeka.readthedocs.io/en/latest/Reference/libraries/globals/get_specific_plugin_hook_output.html) function is suggested.
+
+For **Thanks, Roy** theme, for example, best way is to change `common/header.php` code using the custom hook, while unchecking **Block collapsible** option and setting **Vertical** as **Block layout**:
+```php
+
+
+ true)); ?>
+
+
+
+
+ $this)); ?>
+```
+For **Berlin** theme, instead, check **Block collapsible** option, set **Horizontal** as **Block layout** and then add the custom hook in `items/browse.php` and `collections/browse.php`:
+```php
+
+
+ $this)); ?>
+
+
+```
+
+Background and foreground colors, as well as other parameters, can be customized in `facets.css` file (`views/public/css` folder).
+
+## Plugin configuration
+
+The elements used for search refinement can be selected in the configuration page; best practice suggestion is to activate only elements that are displayed in the browse page, and that are offering some kind of data aggregation (a unique id would not offer any really useful refinement).
+
+Similarly, one can choose to also include **Item Types**, **Collections** and **Tags** to the facets block.
+
+**Single values** can be exluded as not really significant, although they will be listed anyway if less than 5 values are available.
+
+Facets block can be set up for **vertical** or **horizontal** layout, according to the theme layout; and it can be made **collapsible**, to use less vertical space (recommended for horizontal layout).
+
+Style for facets can be either **dropdown selectbox**, or **checkbox**; this last one allows to choose more values, while with the first one one value excludes other. For checkbox style, a **minimum amount of values** can be set too.
+
+Sorting order can be **alphabetical**, or **first by popularity and then alphabetical**. Popularity count can be shown, if needed.
+
+**Date** element filter's behaviour is a bit different: dates are ordered decrescently, and only year is displayed; consequently, the matching will be with the beginning of the date (assuming the format is '_yyyy-mm-dd_'). By default, the following are considered date fields: '**Date**', '**Date Available**', '**Date Created**', '**Date Accepted**', '**Date Copyrighted**', '**Date Submitted**', '**Date Issued**', '**Date Modified**', '**Date Valid**' (the list can be changed in browse.php file).
+
+## Licence
+MIT Licence, please credit AR2L [AR2L Hauts de France](http://www.ar2l-hdf.fr/) and [Daniele Binaghi](https://github.com/DBinaghi).
diff --git a/Readme.md b/Readme.md
deleted file mode 100644
index 1657f7d..0000000
--- a/Readme.md
+++ /dev/null
@@ -1,35 +0,0 @@
-# Omeka Facets Plugin
-
-This is a plugin, for the [Omeka Classic](https://omeka.org/classic/) Publishing platform.
-
-Allows you to insert a Facets block made of Option blocks containing available metadata values extracted from browsing context.
-
-
-
-## Credits
-
-This Development is part of the [Armarium](https://www.armarium-hautsdefrance.fr/) Project, managed by the french association [AR2L Hauts de France](http://www.ar2l-hdf.fr/).
-
-## How to Use
-
-## Install the FacetsPlugin
-
-Copy to your Omeka plugins Folder, should be :
-```
-/plugins/Facets
-```
-
-Then Install the plugin from the Admin/extensions page.
-
-## (Eventually) Customize your Theme
-
-Facets will appear in the Items browse page, where you have set the public_items_browse Hook.
-
-You can Edit your Theme (should be in YOUR_THEME/items/browse) & place the plugin hook where you need to display the facets.
-
-```php
- $items, 'view' => $this)); ?>
-```
-
-## Licence
-MIT Licence, please credit AR2L [AR2L Hauts de France](http://www.ar2l-hdf.fr/)
diff --git a/config_form.php b/config_form.php
new file mode 100644
index 0000000..c678327
--- /dev/null
+++ b/config_form.php
@@ -0,0 +1,289 @@
+
+
+
+
+
+
+
+ formLabel('facets_public_hook', __('Public Hooks')); ?>
+
+
+
+
+
+
+
+
+ formLabel('facets_description', __('Description')); ?>
+
+
+
+
+
+
+ formLabel('facets_count', __('Facet Count')); ?>
+
+
+
+
+
+
+ formLabel('facets_direction', __('Block Layout')); ?>
+
+
+
+
+
+
+ formLabel('facets_collapsible', __('Collapsible Block')); ?>
+
+
+
+
+
+
+
diff --git a/facets.jpg b/facets.jpg
deleted file mode 100644
index 23c948d..0000000
Binary files a/facets.jpg and /dev/null differ
diff --git a/helpers/FacetsFunctions.php b/helpers/FacetsFunctions.php
index dddc256..45a9c49 100644
--- a/helpers/FacetsFunctions.php
+++ b/helpers/FacetsFunctions.php
@@ -1,310 +1,1125 @@
-getTable('Tag');
- // Build the select query.
- $select = $table->getSelectForFindBy();
- /**
- * If there is a Collection, we'll join to the Item table where the
- * collection_id is equal to the ID of our Collection.
- */
- if (count($itemsArray) > 0) {
- $table->filterByTagType($select, 'Item');
- $select->where('items.id IN ('. implode(', ', $itemsArray) . ')');
- }
- // Fetch some tags with our select.
- $tags = $table->fetchObjects($select);
- return $tags;
- }
-
- /**
- * Return Item Types associated with Array of Items Ids.
- *
- * @param itemsArray
- * @return array ItemType.
- */
- function get_item_types_for_items_array($itemsArray = array()) {
-
- // Get the database.
- $db = get_db();
- // Get the Tag table.
- $table = $db->getTable('ItemType');
- // Build the select query.
- $select = $table->getSelect();
- /**
- * If there is a Collection, we'll join to the Item table where the
- * collection_id is equal to the ID of our Collection.
- */
- if (count($itemsArray) > 0) {
- $select->joinInner(array('items' => $db->Items),
- 'item_types.id = items.item_type_id', array());
- $select->where('items.id IN ('. implode(', ', $itemsArray) . ')');
- }
- // Fetch some tags with our select.
- $item_types = $table->fetchObjects($select);
- return $item_types;
- }
-
- /**
- * Return Item Types associated with Array of Items Ids.
- *
- * @return array ItemType.
- */
- function get_item_types() {
-
- // Get the database.
- $db = get_db();
- // Get the Tag table.
- $table = $db->getTable('ItemType');
- // Build the select query.
- $select = $table->getSelect();
-
- // Fetch some tags with our select.
- $item_types = $table->fetchObjects($select);
- return $item_types;
- }
-
- /**
- * Return Collections associated with Array of Items Ids.
- *
- * @param itemsArray
- * @return array Collections.
- */
- function get_collections_for_items_array($itemsArray = array()) {
-
- // Get the database.
- $db = get_db();
- // Get the Tag table.
- $table = $db->getTable('Collection');
- // Build the select query.
- $select = $table->getSelect();
- /**
- * If there is a Collection, we'll join to the Item table where the
- * collection_id is equal to the ID of our Collection.
- */
- if (count($itemsArray) > 0) {
- $select->joinInner(array('items' => $db->Items),
- 'collections.id = items.collection_id', array());
- // $table->filterByTagType($select, 'Item');
- $select->where('items.id IN ('. implode(', ', $itemsArray) . ')');
- }
- // Fetch some tags with our select.
- $collections = $table->fetchObjects($select);
- return $collections;
- }
-
- /**
- * Return Tags associated with Array of Items Ids.
- *
- * @param itemsArray
- * @return array Tags.
- */
- function get_dc_for_items_array($itemsArray = array(), $dcElementName = null) {
-
- // Get the database.
- $db = get_db();
- // Get the Tag table.
- $table = $db->getTable('ElementText');
- // Build the select query.
- $select = $table->getSelect();
- $select->joinInner(array('elements' => $db->Elements),
- 'element_texts.element_id = elements.id', array());
- $select->joinInner(array('element_sets' => $db->ElementSet),
- 'element_sets.id = elements.element_set_id', array());
- $select->joinInner(array('items' => $db->Item),
- 'items.id = element_texts.record_id', array());
- $select->where('element_sets.name = '. $db->quote('Dublin Core'));
- $select->where('elements.name = '. $db->quote($dcElementName));
- $select->where('items.id IN ('. implode(', ', $itemsArray) . ')');
-
- //debug($select->query();
-
- /**
- * If there is a Collection, we'll join to the Item table where the
- * collection_id is equal to the ID of our Collection.
- */
- // Fetch some tags with our select.
- if(!empty($itemsArray)){
- $elements = $table->fetchObjects($select);
- }
- return $elements;
- }
-
- /**
- * Return HTML Select associated with Array of facets values.
- *
- * @param itemsArray
- * @return array Tags.
- */
- function get_dc_facet_select($itemsArray = array(), $dcElementName = null) {
-
- if(is_null($dcElementName)) {
- $dcElementName = "Title";
- }
- if(empty($itemsArray)){
- return "";
- }
- // Get the database.
- $db = get_db();
- // Get the Tag table.
- $table = $db->getTable('ElementText');
- // Build the select query.
- $select = $table->getSelect();
- $select->joinInner(array('elements' => $db->Elements),
- 'element_texts.element_id = elements.id', array());
- $select->joinInner(array('element_sets' => $db->ElementSet),
- 'element_sets.id = elements.element_set_id', array());
- $select->joinInner(array('items' => $db->Item),
- 'items.id = element_texts.record_id', array());
- $select->where('element_sets.name = '. $db->quote('Dublin Core'));
- $select->where('elements.name = '. $db->quote($dcElementName));
- $select->where('items.id IN ('. implode(', ', $itemsArray) . ')');
-
- // Fetch values
- if(!empty($itemsArray)){
- $elements = $table->fetchObjects($select);
- // print_r($elements);
- }
- // build table
- if(!empty($elements)){
- $facet = array();
- foreach ($elements as $element) {
- $facet[] = $element->text;
- }
- $element_id = $element->element_id;
- // make it unique
- // $facet = array_unique($facet);
- $facet = array_count_values($facet);
- arsort($facet);
- // print_r($facet);
-
- // get current parameters to check if one is selected
- // Get the current facets.
- if (!empty($_GET['advanced'])) {
- $search = $_GET['advanced'];
- foreach($search as $Searchindex => $SearchArray){
- if(isset($SearchArray['element_id']) && $SearchArray['element_id'] == $element_id){
- $term = $SearchArray['terms'];
- break;
- }
- }
- }
-
- if(isset($term)){
- $html = "";
- $url = getElementFieldUrl($element_id);
- $html .= " " . html_escape(__('Remove')) . "... ";
- $html .= "$term ";
- } else {
- $html = "";
- $html .= "" . html_escape(__('Select')) . "... ";
- }
-
- foreach($facet as $name => $count){
- $url = getElementFieldUrl($element_id, $name);
- $html .= "".$name." (".$count.") ";
- }
- // foreach($facet as $name){
- // $html .= "".$name." ";
- // }
- $html .= "
";
- } else {
- $html = false;
- }
-
- return $html;
- }
-
- /**
- * Add an Element Field to Search to the current URL.
- *
- * @param string $field The Element id.
- * @param string $value The Element value.
- * @return string The new URL.
- */
- function getElementFieldUrl($field_id, $value = null)
- {
- // Get the current facets.
- if (!empty($_GET['advanced'])) {
- $search = $_GET['advanced'];
- // unset current element filter if already set
- foreach($search as $Searchindex => $SearchArray){
- if(isset($SearchArray['element_id']) && $SearchArray['element_id'] == $field_id){
- unset($search[$Searchindex]);
- }
- }
- } else {
- $search = array();
- }
- if(!is_null($value)){
- $search[] = array('element_id'=>$field_id,'type'=>'is exactly','terms'=>$value);
- }
- $params['advanced'] = $search;
- if(isset($_GET['origin'])) $params['origin'] = $_GET['origin'];
- if(isset($_GET['origin-title'])) $params['origin-title'] = $_GET['origin-title'];
- if(isset($_GET['type'])) $params['type'] = $_GET['type'];
- if(isset($_GET['collection'])) $params['collection'] = $_GET['collection'];
- if(isset($_GET['tag_id'])) $params['tag_id'] = $_GET['tag_id'];
- if(isset($_GET['tag'])) $params['tag'] = $_GET['tag'];
- if(isset($_GET['tags'])) $params['tags'] = $_GET['tags'];
- if(isset($_GET['search'])) $params['search'] = $_GET['search'];
-
- // Rebuild the route.
- // return $_SERVER['HTTP_HOST'] . "?" . http_build_query($params);
- return 'browse?' . http_build_query($params);
- }
-
- /**
- * Add an Element Field to Search to the current URL.
- *
- * @param string $filter The filter field name (tags|tag_id|type|collection).
- * @param string $value The Element value.
- * @return string The new URL.
- */
- function getFieldUrl($filter, $value = null)
- {
- // Get the current facets.
- if (!empty($_GET['advanced'])) {
- $search = $_GET['advanced'];
- } else {
- $search = array();
- }
- // set previous parameters
- $params['advanced'] = $search;
- if(isset($_GET['origin'])) $params['origin'] = $_GET['origin'];
- if(isset($_GET['origin-title'])) $params['origin-title'] = $_GET['origin-title'];
- if(isset($_GET['type'])) $params['type'] = $_GET['type'];
- if(isset($_GET['collection'])) $params['collection'] = $_GET['collection'];
- if(isset($_GET['tag_id'])) $params['tag_id'] = $_GET['tag_id'];
- if(isset($_GET['tag'])) $params['tag'] = $_GET['tag'];
- if(isset($_GET['tags'])) $params['tags'] = $_GET['tags'];
- if(isset($_GET['search'])) $params['search'] = $_GET['search'];
-
- // set(unset) current
- if(!is_null($value)){
- $params[$filter] = $value;
- } else {
- unset($params[$filter]);
- }
-
- // Rebuild the route.
- // return $_SERVER['HTTP_HOST'] . "?" . http_build_query($params);
- return 'browse?' . http_build_query($params);
- }
-// }
-?>
+getTable($recordType);
+ // Build the select query.
+ $subQuery = $table->getSelect();
+ $subQuery->where($whereSubset);
+
+ $select = "SELECT `" . $extraType . "`, COUNT(id) AS count FROM (" . $subQuery . ") foo GROUP BY `" . $extraType . "` ORDER BY " . $orderBy;
+
+ return $table->fetchObjects($select);
+ }
+
+ /**
+ * Return HTML Select associated with Array of facets extra parameter values.
+ *
+ * @param recordType
+ * @param subsetSQL
+ * @param extraType
+ * @param sortOrder
+ * @param showPopularity
+ * @return html.
+ */
+ function getFacetSelectForExtra($recordType, $subsetSQL, $extraType, $sortOrder = 'count_alpha', $showPopularity = false) {
+ if ($extras = getObjectsForExtra($recordType, $subsetSQL, $extraType, $sortOrder)) {
+ // Build array
+ $facetExtras = buildExtrasArray($extras, $extraType);
+
+ // Stores data for selected extra, if any
+ $selectedExtra = getSelectedExtra($facetExtras, $extraType);
+
+ $addOptions = false;
+ // Build first part of the select tag
+ if (isset($selectedExtra)) {
+ $url = getFieldUrl($recordType, $extraType, null);
+ $html = "";
+ $html .= " " . html_escape(__('Remove filter')) . "... ";
+ $html .= "" . __(getExtraName($extraType, $selectedExtra)) . " ";
+ } elseif (count($facetExtras) > 0) {
+ $html = "";
+ $html .= "" . html_escape(__('Select')) . "... ";
+ $addOptions = true;
+ }
+
+ // Build additional part of the select tag (if needed)
+ if ($addOptions) {
+ foreach ($facetExtras as $value => $count) {
+ $url = getFieldUrl($recordType, $extraType, $value);
+ $html .= "" . __(getExtraName($extraType, $value)) . ($showPopularity ? " (" . $count . ")" : "") . " ";
+ }
+ }
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return HTML Checkboxes associated with Array of facets extra parametervalues.
+ *
+ * @param recordType
+ * @param subsetSQL
+ * @param extraType
+ * @param sortOrder
+ * @param showPopularity
+ * @param facetsMaxCount
+ * @return html
+ */
+ function getFacetCheckboxesForExtra($recordType, $subsetSQL, $extraType, $sortOrder = 'count_alpha', $showPopularity = false, $facetsMaxCount = 0) {
+ if ($extras = getObjectsForExtra($recordType, $subsetSQL, $extraType, $sortOrder)) {
+ // Build array
+ $facetExtras = buildExtrasArray($extras, $extraType);
+
+ // Stores data for selected extra, if any
+ $selectedExtra = getSelectedExtra($facetExtras, $extraType);
+
+ $countCheckboxes = 0;
+ $html = '';
+ // Build first part of the checkboxes tag
+ if (isset($selectedExtra)) {
+ $url = getFieldUrl($recordType, $extraType, null, $selectedExtra);
+ $html .= "
" . html_escape(__(getExtraName($extraType, $selectedExtra))) . "
";
+ $countCheckboxes++;
+ }
+
+ $hidingSeparator = false;
+ // Build additional part of the select tag (if needed)
+ foreach ($facetExtras as $value => $count) {
+ if (!isset($selectedExtra) || $value <> $selectedExtra) {
+ if ($facetsMaxCount != 0 && $countCheckboxes >= $facetsMaxCount && !$hidingSeparator) {
+ // Add link to show other values
+ $html .= "";
+ $html .= "";
+ }
+
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return list of objects associated to extra parameters (user, public, featured).
+ *
+ * @param subsetSQL
+ * @return objects
+ */
+ function getObjectsForUser($recordType, $subsetSQL, $sortOrder) {
+ // Create Where clause
+ $whereSubset = createWhereSubsetClause($recordType, $subsetSQL);
+
+ // Define Order By clause
+ if ($sortOrder == 'count_alpha') {
+ $orderBy = array('count DESC', 'name ASC');
+ } else {
+ $orderBy = array('name ASC');
+ }
+
+ // Get the database.
+ $db = get_db();
+ // Get the table.
+ $table = $db->getTable('User');
+ // Build the select query.
+ $select = $table->getSelect();
+ $select->columns('COUNT(users.id) AS count');
+ if ($recordType == 'item') {
+ $select->joinInner(array('items' => $db->Item), 'users.id = items.owner_id', array());
+ } else {
+ $select->joinInner(array('collections' => $db->Collection), 'users.id = collections.owner_id', array());
+ }
+ $select->where($whereSubset);
+ $select->group('users.id');
+ $select->order($orderBy);
+
+ return $table->fetchObjects($select);
+ }
+
+ /**
+ * Return HTML Select associated with Array of facets extra parameter values.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @param showPopularity
+ * @return html.
+ */
+ function getFacetSelectForUser($recordType, $subsetSQL, $sortOrder = 'count_alpha', $showPopularity = false) {
+ if ($users = getObjectsForUser($recordType, $subsetSQL, $sortOrder)) {
+ // Build array
+ $facetUsers = buildUsersArray($users);
+
+ // Stores data for selected user, if any
+ $selectedUser = getSelectedUser($facetUsers);
+
+ $addOptions = false;
+ // Build first part of the select tag
+ if (isset($selectedUser)) {
+ $url = getFieldUrl($recordType, 'user', null);
+ $html = "";
+ $html .= " " . html_escape(__('Remove filter')) . "... ";
+ $html .= "" . trim($selectedUser['name']) . " ";
+ } elseif (count($facetUsers) > 0) {
+ $html = "";
+ $html .= "" . html_escape(__('Select')) . "... ";
+ $addOptions = true;
+ }
+
+ // Build additional part of the select tag (if needed)
+ if ($addOptions) {
+ foreach ($facetUsers as $user) {
+ $url = getFieldUrl($recordType, 'user', $user['id']);
+ $html .= "" . trim($user['name']) . ($showPopularity ? " (" . $user['count'] . ")" : "") . " ";
+ }
+ }
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return HTML Checkboxes associated with Array of facets values.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @param showPopularity
+ * @param facetsMaxCount
+ * @return html
+ */
+ function getFacetCheckboxesForUser($recordType, $subsetSQL, $sortOrder = 'count_alpha', $showPopularity = false, $facetsMaxCount = 0) {
+ if ($users = getObjectsForUser($recordType, $subsetSQL, $sortOrder)) {
+ // Build array
+ $facetUsers = buildUsersArray($users);
+
+ // Store data for selected user, if any
+ $selectedUser = getSelectedUser($facetUsers);
+
+ $countCheckboxes = 0;
+ $html = '';
+ // Build first part of the checkboxes tag
+ if (isset($selectedUser)) {
+ $url = getFieldUrl($recordType, 'user', null, $selectedUser);
+ $html .= "
" . trim(html_escape($selectedUser['name'])) . "
";
+ $countCheckboxes++;
+ }
+
+ $hidingSeparator = false;
+ // Build additional part of the select tag (if needed)
+ foreach ($facetUsers as $user) {
+ if ($user != $selectedUser) {
+ if ($facetsMaxCount != 0 && $countCheckboxes >= $facetsMaxCount && !$hidingSeparator) {
+ // Add link to show other values
+ $html .= "";
+ $html .= "";
+ }
+
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return list of objects associated to tag.
+ *
+ * @param subsetSQL
+ * @return objects
+ */
+ function getObjectsForTag($subsetSQL, $sortOrder) {
+ // Create Where clause
+ $whereSubset = createWhereSubsetClause('item', $subsetSQL);
+
+ // Define Order By clause
+ if ($sortOrder == 'count_alpha') {
+ $orderBy = array('tagCount DESC', 'name ASC');
+ } else {
+ $orderBy = array('name ASC');
+ }
+
+ // Get the database.
+ $db = get_db();
+ // Get the table.
+ $table = $db->getTable('Tag');
+ // Build the select query.
+ $select = $table->getSelectForFindBy();
+ $table->filterByTagType($select, 'Item');
+ $select->where($whereSubset);
+ $select->order($orderBy);
+
+ return $table->fetchObjects($select);
+ }
+
+ /**
+ * Return HTML Select associated with Array of facets tag values.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @param showPopularity
+ * @return html.
+ */
+ function getFacetSelectForTag($subsetSQL, $sortOrder = 'count_alpha', $showPopularity = false) {
+ if ($tags = getObjectsForTag($subsetSQL, $sortOrder)) {
+ // Build array
+ $facetTags = buildTagsArray($tags);
+
+ // Stores data for selected tag, if any
+ $selectedTagName = (isset($_GET['tags']) ? $_GET['tags'] : '');
+
+ $addOptions = false;
+ // Build first part of the select tag
+ if ($selectedTagName != '') {
+ $url = getFieldUrl('item', 'tags', null);
+ $html = "";
+ $html .= " " . html_escape(__('Remove filter')) . "... ";
+ $html .= "" . $selectedTagName . " ";
+ } elseif (count($facetTags) > 0) {
+ $html = "";
+ $html .= "" . html_escape(__('Select')) . "... ";
+ $addOptions = true;
+ }
+
+ // Build additional part of the select tag (if needed)
+ if ($addOptions) {
+ foreach ($facetTags as $tag) {
+ $url = getFieldUrl('item', 'tags', $tag['name']);
+ $html .= "" . trim($tag['name']) . ($showPopularity ? " (" . $tag['count'] . ")" : "") . " ";
+ }
+ }
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return HTML Checkboxes associated with Array of facets tag values.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @param showPopularity
+ * @return html.
+ */
+ function getFacetCheckboxesForTag($subsetSQL, $sortOrder = 'count_alpha', $showPopularity = false, $facetsMaxCount = 0) {
+ if ($tags = getObjectsForTag($subsetSQL, $sortOrder)) {
+ // Build array
+ $facetTags = buildTagsArray($tags);
+
+ // Stores data for selected tags, if any
+ $selectedTags = (isset($_GET['tags']) ? $_GET['tags'] : '');
+ $selectedTagNames = explode(option('tag_delimiter'), $selectedTags);
+
+ $countCheckboxes = 0;
+ $html = '';
+ // Build first part of the checkboxes tag
+ if ($selectedTags != '') {
+ $selectedTagNames = explode(option('tag_delimiter'), $selectedTags);
+ foreach ($selectedTagNames as $selectedTagName) {
+ $url = getFieldUrl('item', 'tags', null, $selectedTagName);
+ $html .= "
" . trim(html_escape($selectedTagName)) . "
";
+ $countCheckboxes++;
+ }
+ }
+
+ $hidingSeparator = false;
+ // Build additional part of the select tag (if needed)
+ foreach ($facetTags as $tag) {
+ if (!in_array($tag['name'], $selectedTagNames)) {
+ if ($facetsMaxCount != 0 && $countCheckboxes >= $facetsMaxCount && !$hidingSeparator) {
+ // Add link to show other values
+ $html .= "";
+ $html .= "";
+ }
+
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return list of objects associated to collection.
+ *
+ * @param subsetSQL
+ * @return objects
+ */
+ function getObjectsForCollection($subsetSQL) {
+ // Create Where clause
+ $whereSubset = createWhereSubsetClause('item', $subsetSQL);
+
+ // Get the database.
+ $db = get_db();
+ // Get the table.
+ $table = $db->getTable('Collection');
+ // Build the select query.
+ $select = $table->getSelect()
+ ->columns('COUNT(collections.id) AS count')
+ ->joinInner(array('items' => $db->Items), 'collections.id = items.collection_id', array())
+ ->where($whereSubset)
+ ->group('collections.id');
+
+ return $table->fetchObjects($select);
+ }
+
+ /**
+ * Return HTML Select associated with Array of facets collection values.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @param showPopularity
+ * @return html.
+ */
+ function getFacetSelectForCollection($subsetSQL, $sortOrder = 'count_alpha', $showPopularity = false) {
+ if ($collections = getObjectsForCollection($subsetSQL, $sortOrder)) {
+ // Build array
+ $facetCollections = buildCollectionsArray($collections);
+
+ // Store data for selected collection, if any
+ $selectedCollection = getSelectedCollection($facetCollections);
+
+ // Sort array (have to do it now instead than in select because of the way we get the Collection name)
+ $facetCollections = sortCollections($facetCollections, $sortOrder);
+
+ $addOptions = false;
+ // Build first part of the select tag
+ if (isset($selectedCollection)) {
+ $url = getFieldUrl('item', 'collection', null);
+ $html = "";
+ $html .= " " . html_escape(__('Remove filter')) . "... ";
+ $html .= "" . trim($selectedCollection['name']) . " ";
+ } elseif (count($facetCollections) > 0) {
+ $html = "";
+ $html .= "" . html_escape(__('Select')) . "... ";
+ $addOptions = true;
+ }
+
+ // Build additional part of the select tag (if needed)
+ if ($addOptions) {
+ foreach ($facetCollections as $collection) {
+ $url = getFieldUrl('item', 'collection', $collection['id']);
+ $html .= "" . trim($collection['name']) . ($showPopularity ? " (" . $collection['count'] . ")" : "") . " ";
+ }
+ }
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return HTML Checkboxes associated with Array of facets values.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @param showPopularity
+ * @param facetsMaxCount
+ * @return html
+ */
+ function getFacetCheckboxesForCollection($subsetSQL, $sortOrder = 'count_alpha', $showPopularity = false, $facetsMaxCount = 0) {
+ if ($collections = getObjectsForCollection($subsetSQL, $sortOrder)) {
+ // Build array
+ $facetCollections = buildCollectionsArray($collections);
+
+ // Store data for selected collection, if any
+ $selectedCollection = getSelectedCollection($facetCollections);
+
+ // Sort array (have to do it now instead than in select because of the way we get the Collection's name)
+ $facetCollections = sortCollections($facetCollections, $sortOrder);
+
+ $countCheckboxes = 0;
+ $html = '';
+ // Build first part of the checkboxes tag
+ if (isset($selectedCollection)) {
+ $url = getFieldUrl('item', 'collection', null);
+ $html .= "
" . trim(html_escape($selectedCollection['name'])) . "
";
+ $countCheckboxes++;
+ }
+
+ $hidingSeparator = false;
+ // Build additional part of the select tag (if needed)
+ foreach ($facetCollections as $collection) {
+ if ($collection != $selectedCollection) {
+ if ($facetsMaxCount != 0 && $countCheckboxes >= $facetsMaxCount && !$hidingSeparator) {
+ // Add link to show other values
+ $html .= "";
+ $html .= "";
+ }
+
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return list of objects associated to collection.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @return objects
+ */
+ function getObjectsForItemType($subsetSQL, $sortOrder) {
+ // Create Where Subset clause
+ $whereSubset = createWhereSubsetClause('item', $subsetSQL);
+
+ // Define Order by clause
+ if ($sortOrder == 'count_alpha') {
+ $orderBy = array('count DESC', 'name ASC');
+ } else {
+ $orderBy = array('name ASC');
+ }
+
+ // Get the database.
+ $db = get_db();
+ // Get the table.
+ $table = $db->getTable('ItemType');
+ // Build the select query.
+ $select = $table->getSelect()
+ ->columns('COUNT(item_types.id) AS count')
+ ->joinInner(array('items' => $db->Items), 'item_types.id = items.item_type_id', array())
+ ->where($whereSubset)
+ ->group('item_types.id')
+ ->order($orderBy);
+
+ return $table->fetchObjects($select);
+ }
+
+ /**
+ * Return HTML Select associated with Array of facets item type values.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @param showPopularity
+ * @return html.
+ */
+ function getFacetSelectForItemType($subsetSQL, $sortOrder = 'count_alpha', $showPopularity = false) {
+ if ($itemTypes = getObjectsForItemType($subsetSQL, $sortOrder)) {
+ // Build array
+ $facetItemTypes = buildItemTypesArray($itemTypes);
+
+ // Store data for selected item type, if any
+ $selectedItemType = getSelectedItemType($facetItemTypes);
+
+ $addOptions = false;
+ // Build first part of the select tag
+ if (!empty($selectedItemType)) {
+ $url = getFieldUrl('item', 'type', null);
+ $html = "";
+ $html .= " " . html_escape(__('Remove filter')) . "... ";
+ $html .= "" . trim($selectedItemType['name']) . " ";
+ } elseif (count($facetItemTypes) > 0) {
+ $html = "";
+ $html .= "" . html_escape(__('Select')) . "... ";
+ $addOptions = true;
+ }
+
+ // Build additional part of the select tag (if needed)
+ if ($addOptions) {
+ foreach ($facetItemTypes as $itemType) {
+ $url = getFieldUrl('item', 'type', $itemType['id']);
+ $html .= "" . trim($itemType['name']) . ($showPopularity ? " (" . $itemType['count'] . ")" : "") . " ";
+ }
+ }
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return HTML Checkboxes associated with Array of facets item type values.
+ *
+ * @param subsetSQL
+ * @param sortOrder
+ * @param showPopularity
+ * @return html.
+ */
+ function getFacetCheckboxesForItemType($subsetSQL, $sortOrder = 'count_alpha', $showPopularity = false, $facetsMaxCount = 0) {
+ if ($itemTypes = getObjectsForItemType($subsetSQL, $sortOrder)) {
+ // Build array
+ $facetItemTypes = buildItemTypesArray($itemTypes);
+
+ // Store data for selected item type, if any
+ $selectedItemType = getSelectedItemType($facetItemTypes);
+
+ $countCheckboxes = 0;
+ $html = '';
+ // Build first part of the checkboxes tag
+ if (isset($selectedItemType)) {
+ $url = getFieldUrl('item', 'type', null);
+ $html .= "
" . trim(html_escape($selectedItemType['name'])) . "
";
+ $countCheckboxes++;
+ }
+
+ $hidingSeparator = false;
+ // Build additional part of the select tag (if needed)
+ foreach ($facetItemTypes as $itemType) {
+ if ($itemType != $selectedItemType) {
+ if ($facetsMaxCount != 0 && $countCheckboxes >= $facetsMaxCount && !$hidingSeparator) {
+ // Add link to show other values
+ $html .= "";
+ $html .= "";
+ }
+
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return list of objects associated to element.
+ *
+ * @param recordType
+ * @param subsetSQL
+ * @param elementId
+ * @param isDate
+ * @param sortOrder
+ * @return objects
+ */
+ function getObjectsForElement($recordType, $subsetSQL, $elementId, $isDate, $sortOrder) {
+ // Create Where clauses
+ $whereRecordType = createWhereRecordTypeClause($recordType);
+ $whereSubset = createWhereSubsetClause($recordType, $subsetSQL);
+
+ // Create the columns, groupBy and orderBy clauses
+ if ($isDate) {
+ $columns1 = array('SUBSTR(element_texts.text, 1, 4) AS year');
+ $columns2 = 'COUNT(year) AS count';
+ $groupBy = array('year', 'record_id');
+ if ($sortOrder == 'count_alpha') {
+ $orderBy = 'count DESC, year DESC';
+ } else {
+ $orderBy = 'year DESC';
+ }
+ } else {
+ $columns1 = '';
+ $columns2 = 'COUNT(text) AS count';
+ $groupBy = array('text', 'record_id');
+ if ($sortOrder == 'count_alpha') {
+ $orderBy = 'count DESC, text ASC';
+ } else {
+ $orderBy = 'text ASC';
+ }
+ }
+
+ // Get the database.
+ $db = get_db();
+ // Get the table.
+ $table = $db->getTable('ElementText');
+ // Build the select query.
+ $subQuery = $table->getSelect();
+ $subQuery->columns($columns1);
+ $subQuery->joinInner(array('elements' => $db->Elements), 'element_texts.element_id = elements.id', array());
+ $subQuery->joinInner(array('element_sets' => $db->ElementSet), 'element_sets.id = elements.element_set_id', array());
+ if ($recordType == 'item') {
+ $subQuery->joinInner(array('items' => $db->Item), 'items.id = element_texts.record_id', array());
+ } else {
+ $subQuery->joinInner(array('collections' => $db->Collection), 'collections.id = element_texts.record_id', array());
+ }
+ $subQuery->where('elements.id = '. $elementId);
+ $subQuery->where($whereRecordType);
+ $subQuery->where($whereSubset);
+ $subQuery->group($groupBy);
+
+ $select = "SELECT *, " . $columns2 . " FROM (" . $subQuery . ") foo GROUP BY `text` ORDER BY " . $orderBy;
+
+ return $table->fetchObjects($select);
+ }
+
+ /**
+ * Return HTML Select associated with Array of facets values.
+ *
+ * @param recordType
+ * @param subsetSQL
+ * @param elementId
+ * @param isDate
+ * @param sortOrder
+ * @param showPopularity
+ * @return html
+ */
+ function getFacetSelectForElement($recordType, $subsetSQL, $elementId = 50, $isDate = false, $sortOrder = 'count_alpha', $showPopularity = false) {
+ // Build array
+ if ($elements = getObjectsForElement($recordType, $subsetSQL, $elementId, $isDate, $sortOrder)) {
+ $facetElement = array();
+ foreach ($elements as $element) {
+ if ($isDate) {
+ $facetElement[$element->year] = $element->count;
+ } else {
+ $facetElement[$element->text] = $element->count;
+ }
+ }
+ $element_id = $element->element_id;
+
+ // Get current parameters to check if one is selected
+ if (!empty($_GET['advanced'])) {
+ $search = $_GET['advanced'];
+ foreach ($search as $searchIndex => $searchArray){
+ if (isset($searchArray['element_id']) && $searchArray['element_id'] == $element_id) {
+ $term = $searchArray['terms'];
+ break;
+ }
+ }
+ }
+
+ $addOptions = false;
+ // Build first part of the select tag
+ if (isset($term)){
+ $html = "";
+ $url = getElementFieldUrl($recordType, $element_id, null, $isDate);
+ $html .= " " . html_escape(__('Remove filter')) . "... ";
+ $html .= "" . trim($term) . " ";
+ } elseif (count($facetElement) > 0) {
+ $html = "";
+ $html .= "" . html_escape(__('Select')) . "... ";
+ $addOptions = true;
+ }
+
+ // Build additional part of the select tag (if needed)
+ if ($addOptions) {
+ foreach ($facetElement as $name => $count) {
+ $url = getElementFieldUrl($recordType, $element_id, $name, $isDate);
+ $html .= "" . trim($name) . ($showPopularity ? " (" . $count . ")" : "") . " ";
+ }
+ }
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Return HTML Checkboxes associated with Array of facets values.
+ *
+ * @param recordType
+ * @param subsetSQL
+ * @param elementId
+ * @param isDate
+ * @param sortOrder
+ * @param showPopularity
+ * @param facetsMaxCount
+ * @return html
+ */
+ function getFacetCheckboxesForElement($recordType, $subsetSQL, $elementId = 50, $isDate = false, $sortOrder = 'count_alpha', $showPopularity = false, $facetsMaxCount = 0) {
+ // Build array
+ if ($elements = getObjectsForElement($recordType, $subsetSQL, $elementId, $isDate, $sortOrder)) {
+ $facetElement = array();
+ foreach ($elements as $element) {
+ if ($isDate) {
+ $facetElement[$element->year] = $element->count;
+ } else {
+ $facetElement[$element->text] = $element->count;
+ }
+ }
+ $element_id = $element->element_id;
+
+ $selectedTerms = array();
+ // Get current parameters to check if one or more are selected
+ if (!empty($_GET['advanced'])) {
+ $search = $_GET['advanced'];
+ foreach ($search as $searchIndex => $searchArray){
+ if (isset($searchArray['element_id']) && $searchArray['element_id'] == $element_id) {
+ $selectedTerms[] = $searchArray['terms'];
+ }
+ }
+ }
+
+ $countCheckboxes = 0;
+ $html = '';
+ // Build first part of the checkboxes tag
+ if (!empty($selectedTerms)) {
+ foreach ($selectedTerms as $term){
+ $url = getElementFieldUrl($recordType, $element_id, null, $isDate, $term);
+ $html .= "
" . trim(html_escape($term)) . "
";
+ $countCheckboxes++;
+ }
+ }
+
+ $hidingSeparator = false;
+ // Build additional part of the select tag (if needed)
+ foreach ($facetElement as $name => $count) {
+ if (!in_array($name, $selectedTerms)) {
+ if ($facetsMaxCount != 0 && $countCheckboxes >= $facetsMaxCount && !$hidingSeparator) {
+ // Add link to show other values
+ $html .= "";
+ $html .= "";
+ }
+
+ $html .= "
";
+ } else {
+ $html = false;
+ }
+
+ return $html;
+ }
+
+ /**
+ * Add an Element Field to Search to the current URL.
+ *
+ * @param string $field_id The Element id.
+ * @param string $value The Element value.
+ * @param string $isDate
+ * @param string $oldValue The Element old value.
+ * @return string The new URL.
+ */
+ function getElementFieldUrl($recordType, $field_id, $value = null, $isDate = false, $oldValue = null)
+ {
+ // Get the current facets.
+ if (!empty($_GET['advanced'])) {
+ $search = $_GET['advanced'];
+ if ($value == '') {
+ if ($oldValue == '') {
+ // unset current element filter(s) if already set
+ foreach ($search as $searchIndex => $searchArray){
+ if (isset($searchArray['element_id']) && $searchArray['element_id'] == $field_id){
+ unset ($search[$searchIndex]);
+ }
+ }
+ } else {
+ // unset current element filter with specific value if already set
+ foreach ($search as $searchIndex => $searchArray){
+ if (isset($searchArray['element_id']) && $searchArray['element_id'] == $field_id && $searchArray['terms'] == $oldValue){
+ unset ($search[$searchIndex]);
+ break;
+ }
+ }
+ }
+ }
+ } else {
+ $search = array();
+ }
+ if (!is_null($value)) {
+ if ($isDate) {
+ $search[] = array('element_id'=>$field_id, 'type'=>'starts with', 'terms'=>$value);
+ } else {
+ $search[] = array('element_id'=>$field_id, 'type'=>'is exactly', 'terms'=>$value);
+ }
+ }
+
+ // set previous parameters
+ $params['advanced'] = $search;
+ $params = setPreviousParameters($params);
+
+ // return rebuilt route
+ return getRebuiltUrl($recordType, $params);
+ }
+
+ /**
+ * Add an Element Field to Search to the current URL.
+ *
+ * @param string $filter The filter field name (tags|tag_id|type|collection).
+ * @param string $value The Element value.
+ * @param string $oldValue The Element old value.
+ * @return string The new URL.
+ */
+ function getFieldUrl($recordType, $filter, $value = null, $oldValue = null)
+ {
+ // Get the current facets.
+ if (!empty($_GET['advanced'])) {
+ $search = $_GET['advanced'];
+ } else {
+ $search = array();
+ }
+
+ // set previous parameters
+ $params['advanced'] = $search;
+ $params = setPreviousParameters($params);
+
+ // set(unset) current
+ if (!is_null($value)){
+ if ($filter != 'tags' || empty($params[$filter])) {
+ $params[$filter] = $value;
+ } else {
+ $tags = explode(option('tag_delimiter'), $params[$filter]);
+ array_push($tags, $value);
+ $params[$filter] = implode(option('tag_delimiter'), $tags);
+ }
+ } else {
+ if ($filter == 'tags' && $oldValue != '') {
+ if (!empty($params[$filter])) {
+ $tags = explode(option('tag_delimiter'), $params[$filter]);
+ $tags = array_diff($tags, array($oldValue));
+ $params[$filter] = implode(option('tag_delimiter'), $tags);
+ }
+ if (empty($params[$filter])) unset($params[$filter]);
+ } else {
+ unset($params[$filter]);
+ }
+ }
+
+ // return rebuilt route
+ return getRebuiltUrl($recordType, $params);
+ }
+
+ function isFacetActive($recordType, $element_name, $settings, $extra_name = null) {
+ if ($extra_name != '') {
+ if (isset($settings[$extra_name][$recordType])) {
+ return ((bool)$settings[$extra_name][$recordType]);
+ }
+ } elseif (isset($settings['elements'][$element_name][$recordType])) {
+ return ((bool)$settings['elements'][$element_name][$recordType]);
+ }
+ return false;
+ }
+
+ function createWhereRecordTypeClause($recordType) {
+ return 'element_texts.record_type = \'' . ucfirst($recordType) . '\'';
+ }
+
+ function createWhereSubsetClause($recordType, $sql) {
+ if ($sql != '') {
+ return $recordType . 's.id IN (' . $sql . ')';
+ } else {
+ return '1=1';
+ }
+ }
+
+ function recordTypeActive($recordType, $elements) {
+ if (isset($elements)) {
+ foreach ($elements as $element) {
+ if (array_key_exists($recordType, $element)) return true;
+ }
+ }
+
+ return false;
+ }
+
+ function buildCollectionsArray($collections) {
+ $facetCollections = array();
+ foreach ($collections as $collection) {
+ $facetCollections[$collection->id]['id'] = $collection->id;
+ $facetCollections[$collection->id]['name'] = $collection->getDisplayTitle();
+ $facetCollections[$collection->id]['count'] = $collection->count;
+ }
+ return $facetCollections;
+ }
+
+ function getSelectedCollection($collections) {
+ if (isset($_GET['collection'])) {
+ $collection_id = $_GET['collection'];
+ if (array_key_exists($collection_id, $collections)) {
+ return $collections[$collection_id];
+ }
+ }
+ }
+
+ function sortCollections($collections, $sortOrder = 'count_alpha') {
+ if ($sortOrder == 'count_alpha') {
+ array_multisort(array_column($collections, 'count'), SORT_DESC, array_column($collections, 'name'), SORT_ASC, $collections);
+ } else {
+ array_multisort(array_column($collections, 'name'), SORT_ASC, $collections);
+ }
+ return $collections;
+ }
+
+ function buildItemTypesArray($itemTypes) {
+ $facetItemTypes = array();
+ foreach ($itemTypes as $itemType) {
+ $facetItemTypes[$itemType->id]['id'] = $itemType->id;
+ $facetItemTypes[$itemType->id]['name'] = $itemType->name;
+ $facetItemTypes[$itemType->id]['count'] = $itemType->count;
+ }
+ return $facetItemTypes;
+ }
+
+ function getSelectedItemType($itemTypes) {
+ if (isset($_GET['type'])) {
+ $itemType_id = $_GET['type'];
+ if (array_key_exists($itemType_id, $itemTypes)) {
+ return $itemTypes[$itemType_id];
+ }
+ }
+ }
+
+ function buildTagsArray($tags) {
+ $facetTags = array();
+ foreach ($tags as $tag) {
+ $facetTags[$tag->id]['id'] = $tag->id;
+ $facetTags[$tag->id]['name'] = $tag->name;
+ $facetTags[$tag->id]['count'] = $tag->tagCount;
+ }
+ return $facetTags;
+ }
+
+ function buildUsersArray($users) {
+ $facetUsers = array();
+ foreach ($users as $user) {
+ $facetUsers[$user->id]['id'] = $user->id;
+ $facetUsers[$user->id]['name'] = $user->name;
+ $facetUsers[$user->id]['count'] = $user->count;
+ }
+ return $facetUsers;
+ }
+
+ function getSelectedUser($users) {
+ if (isset($_GET['user'])) {
+ $user_id = $_GET['user'];
+ if (array_key_exists($user_id, $users)) {
+ return $users[$user_id];
+ }
+ }
+ }
+
+ function buildExtrasArray($extras, $extraType) {
+ $facetExtras = array();
+ foreach ($extras as $extra) {
+ if ($extra->{$extraType}) {
+ $facetExtras[1] = $extra->count;
+ } else {
+ $facetExtras[0] = $extra->count;
+ }
+ }
+ return $facetExtras;
+ }
+
+ function getSelectedExtra($extras, $extraType) {
+ if (isset($_GET[$extraType])) {
+ $extra = $_GET[$extraType];
+ if (array_key_exists($extra, $extras)) {
+ return $extra;
+ }
+ }
+ }
+
+ function getExtraName($extraType, $value) {
+ if ($value == 0) {
+ return "Not " . ucfirst($extraType);
+ } else {
+ return ucfirst($extraType);
+ }
+ }
+
+ function printHtml($html, $key, $facetsDirection, $label) {
+ if ($html != '') {
+ echo "\n";
+ echo "" . html_escape(__($label)) . " \n";
+ echo $html . "\n";
+ echo "
\n";
+ }
+ }
+
+ function getRebuiltUrl($recordType, $params) {
+ return url($recordType . 's/browse', $params);
+ }
+
+ function setPreviousParameters($params) {
+ if (isset($_GET['collection'])) $params['collection'] = $_GET['collection'];
+ if (isset($_GET['type'])) $params['type'] = $_GET['type'];
+ if (isset($_GET['tags'])) $params['tags'] = $_GET['tags'];
+ if (isset($_GET['user'])) $params['user'] = $_GET['user'];
+ if (isset($_GET['public'])) $params['public'] = $_GET['public'];
+ if (isset($_GET['featured'])) $params['featured'] = $_GET['featured'];
+ if (isset($_GET['search'])) $params['search'] = $_GET['search'];
+
+ return $params;
+ }
+?>
diff --git a/languages/eo.mo b/languages/eo.mo
new file mode 100644
index 0000000..1f4c4f0
Binary files /dev/null and b/languages/eo.mo differ
diff --git a/languages/eo.po b/languages/eo.po
new file mode 100644
index 0000000..5e51c00
--- /dev/null
+++ b/languages/eo.po
@@ -0,0 +1,191 @@
+# Translation for the Facets plugin for Omeka.
+# This file is distributed under the same license as the Omeka plugin.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: Facets\n"
+"Report-Msgid-Bugs-To: https://github.com/DBinaghi/plugin-Facets/issues\n"
+"POT-Creation-Date: 2021-06-08 13:56-0001\n"
+"PO-Revision-Date: 2021-06-13 15:39-0001\n"
+"PO-Revision-Date: 2021-07-05 15:17-0001\n"
+"PO-Revision-Date: 2021-07-18 17:16-0001\n"
+"PO-Revision-Date: 2022-08-04 10:41-0001\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: Esperanto\n"
+"Language: eo\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: FacetsPlugin.php:280
+msgid "show all"
+msgstr "montri pli"
+
+#: FacetsPlugin.php:281
+msgid "show less"
+msgstr "montri malpli"
+
+#: browse.php:23
+msgid "Refine search"
+msgstr "Rafini serĉon"
+
+#: browse.php:27
+msgid "Select values for one or more Elements to narrow down your search."
+msgstr ""
+
+#: FacetsFunctions.php:62
+#: FacetsFunctions.php:201
+#: FacetsFunctions.php:346
+#: FacetsFunctions.php:534
+msgid "Remove filter"
+msgstr ""
+
+#: FacetsFunctions.php:66
+#: FacetsFunctions.php:205
+#: FacetsFunctions.php:350
+#: FacetsFunctions.php:538
+msgid "Select"
+msgstr "Elektu"
+
+#: config_form.php:16
+msgid "Use"
+msgstr "Uzo"
+
+#: config_form.php:20
+msgid "Public Hooks"
+msgstr ""
+
+#: config_form.php:24
+msgid ""
+"The hooks you want to use: Omeka's default public_items_browse and public_collections_browse, "
+"already coded into every page (so no changes are needed), normally showing up at the end of the page; or the plugin's "
+"own public_facets, that has to be coded into relevant theme pages but can be used wherever deemed right."
+msgstr ""
+
+#: config_form.php:37
+msgid "Aspect"
+msgstr ""
+
+#: config_form.php:41
+msgid "Description"
+msgstr "Priskribo"
+
+#: config_form.php:45
+msgid "If checked, a short description will be shown above all values."
+msgstr ""
+
+#: config_form.php:53
+msgid "Facet Count"
+msgstr ""
+
+#: config_form.php:57
+msgid "For all checkbox style fields, the maximum amount of values to be displayed (0 means all values will be displayed)."
+msgstr ""
+
+#: config_form.php:65
+msgid "Block Layout"
+msgstr ""
+
+#: config_form.php:69
+msgid "The layout direction of the facets block."
+msgstr ""
+
+#: config_form.php:76
+msgid "Horizontal (useful for themes with top main navigation menu)"
+msgstr ""
+
+#: config_form.php:77
+msgid "Vertical (useful for themes with side main navigation menu)"
+msgstr ""
+
+#: config_form.php:85
+msgid "Collapsible Block"
+msgstr ""
+
+#: config_form.php:89
+msgid "If checked, facets block will be collapsible (tip: as it saves space, it's particularly useful with horizontal theme layouts)."
+msgstr ""
+
+#: config_form.php:95
+msgid "Elements"
+msgstr ""
+
+#: config_form.php:100
+msgid
+"The elements that can be used for search refinement. Item and Collection columns to (de)activate, Style column to "
+"choose the facet style, Sort order column to choose sorting order, Popularity column to show counters near names."
+msgstr ""
+
+#: config_form.php:105
+msgid "Element Name"
+msgstr ""
+
+#: config_form.php:106
+msgid "Item"
+msgstr ""
+
+#: config_form.php:107
+msgid "Collection"
+msgstr ""
+
+#: config_form.php:108
+msgid "Style"
+msgstr ""
+
+#: config_form.php:109
+msgid "Sort Order"
+msgstr ""
+
+#: config_form.php:110
+msgid "Popularity"
+msgstr ""
+
+#: config_form.php:164
+#: config_form.php:252
+msgid "Dropdown"
+msgstr ""
+
+#: config_form.php:165
+#: config_form.php:253
+msgid "Checkbox"
+msgstr ""
+
+#: config_form.php:178
+#: config_form.php:266
+msgid "Alphabetical"
+msgstr ""
+
+#: config_form.php:179
+#: config_form.php:267
+msgid "Popularity first, then alphabetical"
+msgstr ""
+
+#: config_form.php:200
+msgid "Extra parameters"
+msgstr ""
+
+#: config_form.php:215
+msgid "Item Types"
+msgstr ""
+
+#: config_form.php:215
+msgid "Collections"
+msgstr ""
+
+#: config_form.php:215
+msgid "Tags"
+msgstr ""
+
+#: config_form.php:215
+msgid "Owners"
+msgstr ""
+
+#: config_form.php:215
+msgid "Public"
+msgstr ""
+
+#: config_form.php:215
+msgid "Featured"
+msgstr ""
\ No newline at end of file
diff --git a/languages/it.mo b/languages/it.mo
new file mode 100644
index 0000000..6178947
Binary files /dev/null and b/languages/it.mo differ
diff --git a/languages/it.po b/languages/it.po
new file mode 100644
index 0000000..6cc833e
--- /dev/null
+++ b/languages/it.po
@@ -0,0 +1,201 @@
+# Translation for the Facets plugin for Omeka.
+# This file is distributed under the same license as the Omeka plugin.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: Facets\n"
+"Report-Msgid-Bugs-To: https://github.com/DBinaghi/plugin-Facets/issues\n"
+"POT-Creation-Date: 2021-06-08 13:56-0001\n"
+"PO-Revision-Date: 2021-06-13 15:39-0001\n"
+"PO-Revision-Date: 2021-07-05 15:17-0001\n"
+"PO-Revision-Date: 2022-08-04 10:41-0001\n"
+"Last-Translator: Daniele Binaghi \n"
+"Language-Team: Italian\n"
+"Language: it\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: FacetsPlugin.php:280
+msgid "show all"
+msgstr "mostra tutto"
+
+#: FacetsPlugin.php:281
+msgid "show less"
+msgstr "mostra meno"
+
+#: browse.php:23
+msgid "Refine search"
+msgstr "Raffina la ricerca"
+
+#: browse.php:27
+msgid "Select values for one or more Elements to narrow down your search."
+msgstr ""
+
+#: FacetsFunctions.php:62
+#: FacetsFunctions.php:201
+#: FacetsFunctions.php:346
+#: FacetsFunctions.php:534
+msgid "Remove filter"
+msgstr "Rimuovi filtro"
+
+#: FacetsFunctions.php:66
+#: FacetsFunctions.php:205
+#: FacetsFunctions.php:350
+#: FacetsFunctions.php:538
+msgid "Select"
+msgstr "Seleziona"
+
+#: config_form.php:16
+msgid "Use"
+msgstr "Utilizzo"
+
+#: config_form.php:20
+msgid "Public Hooks"
+msgstr "Hook pubblici"
+
+#: config_form.php:24
+msgid ""
+"The hooks you want to use: Omeka's default public_items_browse and public_collections_browse, "
+"already coded into every page (so no changes are needed), normally showing up at the end of the page; or the plugin's "
+"own public_facets, that has to be coded into relevant theme pages but can be used wherever deemed right."
+msgstr ""
+"Gli hook che si vogliono usare: quelli di default di Omeka (public_items_browse e public_collections_browse), "
+"già codificati in ogni pagina (così nessuna modifica è necessaria), solitamente mostrati alla fine della pagina; oppure, "
+"quello proprio del plugin (public_facets), che deve essere codificato nelle giuste pagine del tema "
+"ma può essere usato ovunque lo si ritenga opportuno."
+
+#: config_form.php:37
+msgid "Aspect"
+msgstr "Aspetto"
+
+#: config_form.php:41
+msgid "Description"
+msgstr "Descrizione"
+
+#: config_form.php:45
+msgid "If checked, a short description will be shown above all values."
+msgstr "Se selezionata, una breve descrizione verrà mostrata sopra a tutti i valori."
+
+#: config_form.php:53
+msgid "Facet Count"
+msgstr "Massimo numero caselle"
+
+#: config_form.php:57
+msgid "For all checkbox style fields, the maximum amount of values to be displayed (0 means all values will be displayed)."
+msgstr
+"Per tutti i campi che usano lo stile casella di controllo, numero massimo di valori da mostrare (0 significa "
+"che tutti i valori verranno mostrati)."
+
+#: config_form.php:65
+msgid "Block layout"
+msgstr "Layout blocco"
+
+#: config_form.php:69
+msgid "The layout direction of the facets block."
+msgstr "La direzione del layout del blocco filtri."
+
+#: config_form.php:76
+msgid "Horizontal (useful for themes with top main navigation menu)"
+msgstr "Orizzontale (utile per i temi con un menu di navigazione principale superiore)"
+
+#: config_form.php:77
+msgid "Vertical (useful for themes with side main navigation menu)"
+msgstr "Verticale (utile per i temi con un menu di navigazione principale laterale)"
+
+#: config_form.php:85
+msgid "Collapsible Block"
+msgstr "Blocco contraibile"
+
+#: config_form.php:89
+msgid "If checked, facets block will be collapsible (tip: as it saves space, it's particularly useful with horizontal theme layouts)."
+msgstr ""
+"Se selezionata, il blocco filtri sarà contraibile (consiglio: dal momento che utilizza meno spazio, è particolarmente "
+"utile con i temi a layout orizzontale)."
+
+#: config_form.php:95
+msgid "Elements"
+msgstr "Elementi"
+
+#: config_form.php:100
+msgid
+"The elements that can be used for search refinement. Item and Collection columns to (de)activate, Style column to "
+"choose the facet style, Sort order column to choose sorting order, Popularity column to show counters near names."
+msgstr
+"Gli elementi che possono essere usati per il raffinamento della ricerca. Colonne Documento e Collezione "
+"per (dis)attivare, Stile per scegliere lo stile del campo, Ordinamento per scegliere il criterio di ordinamento, "
+"Popolarità per mostrare i contatori vicino ai nomi."
+
+#: config_form.php:105
+msgid "Element Name"
+msgstr "Nome elemento"
+
+#: config_form.php:106
+msgid "Item"
+msgstr "Documento"
+
+#: config_form.php:107
+msgid "Collection"
+msgstr "Collezione"
+
+#: config_form.php:108
+msgid "Style"
+msgstr "Stile"
+
+#: config_form.php:109
+msgid "Sort Order"
+msgstr "Ordinamento"
+
+#: config_form.php:110
+msgid "Popularity"
+msgstr "Popolarità"
+
+#: config_form.php:164
+#: config_form.php:252
+msgid "Dropdown"
+msgstr "Discesa (casella a)"
+
+#: config_form.php:165
+#: config_form.php:253
+msgid "Checkbox"
+msgstr "Controllo (casella di)"
+
+#: config_form.php:178
+#: config_form.php:266
+msgid "Alphabetical"
+msgstr "Alfabetico"
+
+#: config_form.php:179
+#: config_form.php:267
+msgid "Popularity first, then alphabetical"
+msgstr "Popolarità prima, poi alfabetico"
+
+#: config_form.php:200
+msgid "Extra parameters"
+msgstr "Parametri addizionali"
+
+#: config_form.php:215
+msgid "Item Types"
+msgstr "Tipologie documento"
+
+#: config_form.php:215
+msgid "Collections"
+msgstr "Collezioni"
+
+#: config_form.php:215
+msgid "Tags"
+msgstr "Etichette"
+
+#: config_form.php:215
+msgid "Owners"
+msgstr "Proprietari"
+
+#: config_form.php:215
+msgid "Public"
+msgstr "Pubblico"
+
+#: config_form.php:215
+msgid "Featured"
+msgstr "In Evidenza"
\ No newline at end of file
diff --git a/languages/template.base.pot b/languages/template.base.pot
new file mode 100644
index 0000000..09f46d6
--- /dev/null
+++ b/languages/template.base.pot
@@ -0,0 +1,17 @@
+# Translation for the Facets plugin for Omeka.
+# This file is distributed under the same license as the Omeka plugin.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: Reference\n"
+"Report-Msgid-Bugs-To: http://github.com/Daniel-KM/Reference/issues\n"
+"POT-Creation-Date: 2021-06-08 13:56-0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: LANGUAGE \n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
\ No newline at end of file
diff --git a/languages/template.pot b/languages/template.pot
new file mode 100644
index 0000000..c91e972
--- /dev/null
+++ b/languages/template.pot
@@ -0,0 +1,191 @@
+# Translation for the Facets plugin for Omeka.
+# This file is distributed under the same license as the Omeka plugin.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: Facets\n"
+"Report-Msgid-Bugs-To: https://github.com/DBinaghi/plugin-Facets/issues\n"
+"POT-Creation-Date: 2021-06-08 13:56-0001\n"
+"PO-Revision-Date: 2021-06-13 15:39-0001\n"
+"PO-Revision-Date: 2021-07-05 15:17-0001\n"
+"PO-Revision-Date: 2021-07-18 17:16-0001\n"
+"PO-Revision-Date: 2022-08-04 10:41-0001\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: LANGUAGE \n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: FacetsPlugin.php:280
+msgid "show all"
+msgstr ""
+
+#: FacetsPlugin.php:281
+msgid "show less"
+msgstr ""
+
+#: browse.php:23
+msgid "Refine search"
+msgstr ""
+
+#: browse.php:27
+msgid "Select values for one or more Elements to narrow down your search."
+msgstr ""
+
+#: FacetsFunctions.php:62
+#: FacetsFunctions.php:201
+#: FacetsFunctions.php:346
+#: FacetsFunctions.php:534
+msgid "Remove filter"
+msgstr ""
+
+#: FacetsFunctions.php:66
+#: FacetsFunctions.php:205
+#: FacetsFunctions.php:350
+#: FacetsFunctions.php:538
+msgid "Select"
+msgstr ""
+
+#: config_form.php:16
+msgid "Use"
+msgstr ""
+
+#: config_form.php:20
+msgid "Public Hooks"
+msgstr ""
+
+#: config_form.php:24
+msgid ""
+"The hooks you want to use: Omeka's default public_items_browse and public_collections_browse, "
+"already coded into every page (so no changes are needed), normally showing up at the end of the page; or the plugin's "
+"own public_facets, that has to be coded into relevant theme pages but can be used wherever deemed right."
+msgstr ""
+
+#: config_form.php:37
+msgid "Aspect"
+msgstr ""
+
+#: config_form.php:41
+msgid "Description"
+msgstr ""
+
+#: config_form.php:45
+msgid "If checked, a short description will be shown above all values."
+msgstr ""
+
+#: config_form.php:53
+msgid "Facet Count"
+msgstr ""
+
+#: config_form.php:57
+msgid "For all checkbox style fields, the maximum amount of values to be displayed (0 means all values will be displayed)."
+msgstr ""
+
+#: config_form.php:65
+msgid "Block Layout"
+msgstr ""
+
+#: config_form.php:69
+msgid "The layout direction of the facets block."
+msgstr ""
+
+#: config_form.php:76
+msgid "Horizontal (useful for themes with top main navigation menu)"
+msgstr ""
+
+#: config_form.php:77
+msgid "Vertical (useful for themes with side main navigation menu)"
+msgstr ""
+
+#: config_form.php:85
+msgid "Collapsible Block"
+msgstr ""
+
+#: config_form.php:89
+msgid "If checked, facets block will be collapsible (tip: as it saves space, it's particularly useful with horizontal theme layouts)."
+msgstr ""
+
+#: config_form.php:95
+msgid "Elements"
+msgstr ""
+
+#: config_form.php:100
+msgid
+"The elements that can be used for search refinement. Item and Collection columns to (de)activate, Style column to "
+"choose the facet style, Sort order column to choose sorting order, Popularity column to show counters near names."
+msgstr ""
+
+#: config_form.php:105
+msgid "Element Name"
+msgstr ""
+
+#: config_form.php:106
+msgid "Item"
+msgstr ""
+
+#: config_form.php:107
+msgid "Collection"
+msgstr ""
+
+#: config_form.php:108
+msgid "Style"
+msgstr ""
+
+#: config_form.php:109
+msgid "Sort Order"
+msgstr ""
+
+#: config_form.php:110
+msgid "Popularity"
+msgstr ""
+
+#: config_form.php:164
+#: config_form.php:252
+msgid "Dropdown"
+msgstr ""
+
+#: config_form.php:165
+#: config_form.php:253
+msgid "Checkbox"
+msgstr ""
+
+#: config_form.php:178
+#: config_form.php:266
+msgid "Alphabetical"
+msgstr ""
+
+#: config_form.php:179
+#: config_form.php:267
+msgid "Popularity first, then alphabetical"
+msgstr ""
+
+#: config_form.php:200
+msgid "Extra parameters"
+msgstr ""
+
+#: config_form.php:215
+msgid "Item Types"
+msgstr ""
+
+#: config_form.php:215
+msgid "Collections"
+msgstr ""
+
+#: config_form.php:215
+msgid "Tags"
+msgstr ""
+
+#: config_form.php:215
+msgid "Owners"
+msgstr ""
+
+#: config_form.php:215
+msgid "Public"
+msgstr ""
+
+#: config_form.php:215
+msgid "Featured"
+msgstr ""
\ No newline at end of file
diff --git a/plugin.ini b/plugin.ini
index 8a6412b..df2ea7d 100644
--- a/plugin.ini
+++ b/plugin.ini
@@ -1,10 +1,10 @@
[info]
name = "Facets"
-author = "Jean-Baptiste HEREN"
-description="Filter search using facets"
+author = "Jean-Baptiste Heren and Daniele Binaghi"
+description="Adds a faceted navigation block to narrow down Items and Collections search results by applying multiple filters"
license="GPLv3"
-link=""
-support_link=""
-version="1.0"
+link="https://github.com/DBinaghi/plugin-Facets"
+support_link="https://github.com/DBinaghi/plugin-Facets/issues"
+version="2.9"
omeka_minimum_version="2.6.1"
omeka_target_version="2.6.1"
diff --git a/views/public/css/facets.css b/views/public/css/facets.css
index d836305..dac6cba 100644
--- a/views/public/css/facets.css
+++ b/views/public/css/facets.css
@@ -1,110 +1,162 @@
-.container-fluid {
- display: flex;
-}
-
-.search-container h4 {
- font-family: 'montserrat-light';
- text-align: center;
- width: 80%;
- color: #56575a;
- font-size: 16px;
-}
-
-.search-container {
- width: 350px;
-}
-
-.search-container .container {
- width: 100%;
-}
-
-.search-container form {
- padding-bottom: 25px;
- background-color: #F1F1F1;
- width: 80%;
-}
-
-.search-container .container .container-fluid {
- padding-top: 20px;
-}
-
-.search-container form label {
- /* font-family: 'montserrat-regular'; */
- margin-left: auto;
- margin-right: auto;
- /* font-size: 15px; */
- margin-bottom: 8px;
- color: #545759;
-}
-
-.search-container form select {
- font-family: 'open-italic';
- width: 100%;
- border-radius: 0;
- border: 0;
- padding: 2px;
- -webkit-appearance: none;
- -moz-appearance: none;
- appearance: none;
- background-color: #FFF;
- text-align: center;
-}
-
-.facet-selected {
- color: #FFF;
- background-color: #545759!important;
-}
-
-.search-container .select-arrow, .search-container .select-cross {
- position: relative;
- font-family: "open-italic";
- width: 73%;
- margin-left: auto;
- margin-right: auto;
-}
-
-.search-container .select-arrow select::-ms-expand, .search-container .select-cross select::-ms-expand {
- display: none;
-}
-
-.search-container .select-cross:after {
- pointer-events: none;
- position: absolute;
- content: '';
- top: 9px;
- right: 10px;
- height: 10px;
- width: 10px;
- background-size: cover!important;
- background: url('../images/cross.svg');
-}
-
-.search-container .select-arrow:after {
- width: 0;
- pointer-events: none;
- position: absolute;
- content: '';
- top: 8px;
- right: 10px;
- border-top: 8px solid #3D3D3D;
- border-bottom: 8px solid transparent;
- border-left: 8px solid transparent;
- border-right: 8px solid transparent;
-}
-
-.search-container .select-arrow span, .container-fluid .search-container .select-cross span {
- padding-right:5%;
-}
-
-.search-container button {
- width: 73%;
- font-family: 'open-bold';
- margin-left: auto;
- margin-right: auto;
- padding-top: 7px;
- padding-bottom: 7px;
- border-radius: 0;
- border: 0;
- background-color: #FF5E4D;
- color: white;
-}
+#facets-container {
+ margin-bottom: 20px;
+}
+
+.facets-layout-vertical {
+ margin-left: 5.26316%;
+ margin-right: 5.26316%;
+}
+
+@media screen and (min-width: 768px) {
+ .facets-layout-vertical {
+ margin-left: 0;
+ margin-right: 0;
+ }
+}
+
+.facets-layout-horizontal {
+ margin-top: 20px;
+ width: 100%;
+}
+
+#facets-container button {
+ width: 100%;
+ text-align: center;
+ font-weight: bold;
+ color: white;
+ margin-bottom: 0;
+ padding: 10px;
+}
+
+.facets-collapsed:after {
+ font-size: larger;
+ content: '\002B';
+ float: right;
+ margin-left: 5px;
+}
+
+.facets-collapsible:after {
+ font-size: larger;
+ content: "\2212";
+ float: right;
+ margin-left: 5px;
+}
+
+.facets-container-vertical {
+ /* max-width: 350px; */
+ clear: both;
+}
+
+.facets-container-vertical, .facets-container-horizontal:not(:last-child) {
+ margin-bottom: 10px;
+}
+
+.facets-container-horizontal {
+ max-width: 350px;
+ clear: both;
+ display: inline-block;
+}
+
+.facets-container-vertical label, .facets-container-horizontal label {
+ font-weight: bold;
+}
+
+.flex {
+ /* We first create a flex layout context */
+ display: flex;
+
+ /* Then we define the flow direction
+ and if we allow the items to wrap
+ */
+ flex-flow: row wrap;
+
+ /* Then we define how is distributed the remaining space */
+ justify-content: space-between;
+}
+
+#facets-container p.description {
+ text-align: left;
+ color: #545759;
+ font-size: 90%;
+ margin: 0;
+ border-bottom: 1px solid #545759;
+ font-style: italic;
+ line-height: 140%;
+ padding: 10px;
+}
+
+#facets-body {
+ width: 100%;
+ background-color: #F1F1F1;
+}
+
+#facets-container .hidden {
+ display: none;
+}
+
+#facets-container form {
+ padding: 10px 10px 20px 10px;
+}
+
+#facets-container form label {
+ color: #545759;
+}
+
+#facets-container form select {
+ width: 100%;
+ border: 0;
+ background-color: #FFF;
+ text-align: left;
+ font-size: 80%;
+}
+
+.facet-selected {
+ color: #FFF;
+ background-color: #545759!important;
+}
+
+.facet-checkbox, .facet-checkbox-all, .facet-visibility-toggle {
+ display: block;
+ font-size: 90%;
+}
+
+.facet-checkbox {
+ clear: both;
+}
+
+.facet-visibility-toggle {
+ float: left;
+ cursor: pointer;
+ font-size: 80%;
+ line-height: 100%;
+ margin-bottom: 20px;
+}
+
+.facet-visibility-toggle:hover {
+ font-weight: normal!important;
+}
+
+.facet-checkbox label {
+ font-weight: normal;
+ vertical-align: middle;
+}
+
+.facet-checkbox input[type=checkbox] {
+ margin-right: .2em;
+ vertical-align: middle;
+ position: inherit;
+}
+
+.facet-checkbox-count {
+ float: right;
+ color: #545759;
+ margin-left: .5em;
+}
+
+.hidden {
+ display: none;
+}
+
+.unhidden {
+ display: block;
+}
diff --git a/views/public/facets/browse.php b/views/public/facets/browse.php
index 8ba531d..f9521df 100644
--- a/views/public/facets/browse.php
+++ b/views/public/facets/browse.php
@@ -1,139 +1,124 @@
-
-
-
-
-
- getCollection()): ?>
-
- id; ?>
-
-
-
-
- getItemType()): ?>
- name; ?>
- id; ?>
-
-
-
-
-
-
-
-name] = $tag->id;
- $facetTag[$tag->name] = $tag->name;
- }
-
- $facetTag = array_unique($facetTag);
-
- // collections
- $collections = get_collections_for_items_array($itemsArray);
- foreach ($collections as $collection) {
- $facetCollection[$collection->id] = $collection->getDisplayTitle();
- }
-
- $facetCollection = array_unique($facetCollection);
-
- // item types
- $itemTypes = get_item_types_for_items_array($itemsArray);
- foreach ($itemTypes as $itemType) {
- $facetItemType[$itemType->id] = $itemType->name;
- }
-
- $facetItemType = array_unique($facetItemType);
- ?>
-
-
+getTable('Element');
+ $select = $table->getSelect()
+ ->order('elements.element_set_id')
+ ->order('ISNULL(elements.order)')
+ ->order('elements.order');
+ $elements = $table->fetchObjects($select);
+
+ if ($recordType == 'item') {
+ $subsetSQL = str_replace('`items`.*', '`items`.`id`', (string)get_db()->getTable('Item')->getSelectForFindBy($params));
+ } else {
+ $subsetSQL = str_replace('`collections`.*', '`collections`.`id`', (string)get_db()->getTable('Collection')->getSelectForFindBy($params));
+ }
+?>
+
+">
+
>
+
+ " . __("Select values for one or more Elements to narrow down your search.") . "\n";
+ }
+ ?>
+
+
+
+
diff --git a/views/public/images/cross.svg b/views/public/images/cross.svg
deleted file mode 100755
index e4226af..0000000
--- a/views/public/images/cross.svg
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-cross
-
-
diff --git a/views/public/javascripts/facets.js b/views/public/javascripts/facets.js
new file mode 100644
index 0000000..4e23fb2
--- /dev/null
+++ b/views/public/javascripts/facets.js
@@ -0,0 +1,56 @@
+jQuery(document).ready(function () {
+ // loads language variables
+ var language = facetsLanguage.language;
+
+ // submits results of refining search to reload the page
+ window.jQuery('#facets-body select').change(function() {
+ var option = window.jQuery(this).find('option:selected');
+ if (typeof(option.data('url')) !== 'undefined') window.location.href = option.data('url');
+ });
+
+ // submits results of refining search to reload the page
+ window.jQuery('#facets-body input:checkbox').change(function() {
+ var checkbox = window.jQuery(this);
+ if (typeof(checkbox.data('url')) !== 'undefined') window.location.href = checkbox.data('url');
+ });
+
+ // toggles extra values visibility
+ jQuery('.facet-visibility-toggle').click(function () {
+ var id = jQuery(this).data('element-id');
+ var div = jQuery('#facet-extra-values-' + id);
+ var link = jQuery('#facet-extra-link-' + id);
+ div.toggleClass("hidden unhidden");
+ if (div.hasClass('hidden')) {
+ link.text(language.ShowMore);
+ } else {
+ link.text(language.ShowLess);
+ }
+ });
+
+ // collapses/expands facets block
+ jQuery('#facets-title').click(function () {
+ var header = jQuery(this);
+ if (!header.hasClass('facets-collapsible') && !header.hasClass('facets-collapsed')) return;
+ //getting the next element
+ var content = header.next();
+ //open up the content needed - toggle the slide- if visible, slide up, if not slidedown.
+ content.slideToggle(300, function () {
+ //execute this after slideToggle is done
+ //change icon of header based on visibility of content div
+ header.toggleClass('facets-collapsible facets-collapsed');
+ });
+ });
+});
+
+// forces block collapsible if screen size small
+jQuery(window).on('load', function() {
+ if (jQuery(window).width() < 768) {
+ jQuery('#facets-title').addClass('facets-collapsed');
+ jQuery('#facets-body').addClass('hidden');
+ }
+
+ // hides facets block (but for title) on load
+ if (jQuery('#facets-title').hasClass('facets-collapsed')) {
+ jQuery('#facets-body').addClass('hidden');
+ }
+});