Author: sevein
Date: Mon Jun 4 20:14:33 2012
New Revision: 11729
Log:
Advanced search filters plus compatibility with mobile, it was not required for
AC but it was pretty easy to do
Modified:
branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php
branches/2.0/apps/qubit/modules/search/templates/_advancedSearch.php
branches/2.0/apps/qubit/modules/search/templates/_printAdvancedSearchTerms.php
branches/2.0/apps/qubit/modules/search/templates/_searchFields.php
branches/2.0/apps/qubit/modules/search/templates/_searchResults.php
branches/2.0/plugins/qtDominionPlugin/css/less/advancedSearch.less
Modified:
branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php
==============================================================================
--- branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php
Mon Jun 4 20:13:10 2012 (r11728)
+++ branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php
Mon Jun 4 20:14:33 2012 (r11729)
@@ -19,133 +19,316 @@
class SearchAdvancedAction extends sfAction
{
- public function execute($request)
+ public static
+ $NAMES = array(
+ 'copyrightStatus',
+ 'hasDigitalObject',
+ 'levelOfDescription',
+ 'materialType',
+ 'mediaType',
+ 'repository',
+ 'searchFields'
+ );
+
+ protected function addField($name)
{
- if ('print' == $request->getGetParameter('media'))
+ switch ($name)
{
- $this->getResponse()->addStylesheet('print-preview', 'last');
- }
+ case 'copyrightStatus':
+ $this->form->setValidator('copyrightStatus', new sfValidatorString);
- if (!isset($request->limit))
- {
- $request->limit = sfConfig::get('app_hits_per_page');
- }
+ $choices = array();
+ $choices[null] = null;
+ foreach
(QubitTaxonomy::getTaxonomyTerms(QubitTaxonomy::COPYRIGHT_STATUS_ID) as $item)
+ {
+ $choices[$item->id] = $item->__toString();
+ }
- $this->form = new sfForm;
- $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
+ $this->form->setValidator('copyrightStatus', new sfValidatorString);
+ $this->form->setWidget('copyrightStatus', new
sfWidgetFormSelect(array('choices' => $choices)));
- $this->form->bind($request->getRequestParameters() +
$request->getGetParameters() + $request->getPostParameters());
+ break;
- // Check that we have at least a query
- $exist = false;
- if (isset($this->request->searchFields))
- {
- foreach ($this->request->searchFields as $item)
- {
- if (!empty($item['query']))
- {
- $exist = true;
+ case 'hasDigitalObject':
+ $choices = array(
+ '' => '',
+ 'true' => $this->context->i18n->__('Yes'),
+ 'false' => $this->context->i18n->__('No')
+ );
+
+ $this->form->setValidator($name, new sfValidatorChoice(array('choices'
=> array_keys($choices))));
+ $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
+
+ break;
- break;
+ case 'levelOfDescription':
+ $this->form->setValidator('levelOfDescription', new sfValidatorString);
+
+ $choices = array();
+ $choices[null] = null;
+ foreach
(QubitTaxonomy::getTaxonomyTerms(QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID) as
$item)
+ {
+ $choices[$item->id] = $item->__toString();
}
- }
- }
- if ($exist && $this->form->isValid())
- {
- $query = new Elastica_Query;
- $queryBool = new Elastica_Query_Bool();
+ $this->form->setValidator('levelOfDescription', new sfValidatorString);
+ $this->form->setWidget('levelOfDescription', new
sfWidgetFormSelect(array('choices' => $choices)));
- foreach ($this->request->searchFields as $key => $item)
- {
- if (empty($item['query']))
+ break;
+
+ case 'materialType':
+ $criteria = new Criteria;
+ $criteria->add(QubitTerm::TAXONOMY_ID,
QubitTaxonomy::MATERIAL_TYPE_ID);
+
+ // Do source culture fallback
+ $criteria = QubitCultureFallback::addFallbackCriteria($criteria,
'QubitTerm');
+ $criteria->addAscendingOrderByColumn('name');
+
+ $choices = array();
+ $choices[null] = null;
+ foreach (QubitTerm::get($criteria) as $item)
{
- continue;
+ $choices[$item->id] = $item->__toString();
}
- $queryText = new Elastica_Query_Text();
+ $this->form->setValidator($name, new sfValidatorChoice(array('choices'
=> array_keys($choices))));
+ $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
+
+ break;
- switch ($item['field'])
+ case 'mediaType':
+ // Get list of media types
+ $criteria = new Criteria;
+ $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MEDIA_TYPE_ID);
+
+ // Do source culture fallback
+ $criteria = QubitCultureFallback::addFallbackCriteria($criteria,
'QubitTerm');
+ $criteria->addAscendingOrderByColumn('name');
+
+ $choices = array();
+ $choices[null] = null;
+ foreach (QubitTerm::get($criteria) as $item)
{
- case 'identifier':
- $queryText->setFieldQuery('identifier', $item['query']);
+ $choices[$item->id] = $item->__toString();
+ }
- break;
+ $this->form->setValidator($name, new sfValidatorChoice(array('choices'
=> array_keys($choices))));
+ $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
- case 'title':
- $queryText->setFieldQuery('i18n.title', $item['query']);
+ break;
- break;
+ case 'repository':
+ // Get list of repositories
+ $criteria = new Criteria;
- case 'scopeAndContent':
- $queryText->setFieldQuery('i18n.scopeAndContet', $item['query']);
+ // Do source culture fallback
+ $criteria = QubitCultureFallback::addFallbackCriteria($criteria,
'QubitActor');
- break;
+ $criteria->addAscendingOrderByColumn('authorized_form_of_name');
- case 'archivalHistory':
- $queryText->setFieldQuery('i18n.archivalHistory', $item['query']);
+ $choices = array();
+ $choices[null] = null;
+ foreach (QubitRepository::get($criteria) as $repository)
+ {
+ $choices[$repository->id] = $repository->__toString();
+ }
- break;
+ $this->form->setValidator($name, new sfValidatorChoice(array('choices'
=> array_keys($choices))));
+ $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
- case 'extentAndMedium':
- $queryText->setFieldQuery('i18n.extentAndMedium', $item['query']);
+ break;
- break;
+ case 'searchFields':
+ $this->form->setValidator($name, new sfValidatorPass);
+ $this->form->setWidget($name, new sfWidgetFormInputHidden);
- case 'creatorHistory':
- $queryText->setFieldQuery('', $item['query']);
+ break;
+ }
+ }
- break;
+ protected function processField($field, $queryBool)
+ {
+ if (null === $value = $this->form->getValue($field->getName()))
+ {
+ return;
+ }
- case 'subject':
- $queryText->setFieldQuery('', $item['query']);
+ switch ($field->getName())
+ {
+ case 'copyrightStatus':
+ $query = new Elastica_Query_Term;
+ $query->setTerm('copyrightStatusId', $value);
+ $queryBool->addMust($query);
+ break;
- break;
+ case 'hasDigitalObject':
+ $query = new Elastica_Query_Term;
+ $query->setTerm('hasDigitalObject', $value);
+ $queryBool->addMust($query);
- case 'name':
- $queryText->setFieldQuery('', $item['query']);
+ break;
- break;
+ case 'levelOfDescription':
+ $query = new Elastica_Query_Term;
+ $query->setTerm('levelOfDescriptionId', $value);
+ $queryBool->addMust($query);
- case 'place':
- $queryText->setFieldQuery('', $item['query']);
+ break;
- break;
+ case 'materialType':
+ $query = new Elastica_Query_Term;
+ $query->setTerm('materialTypeId', $value);
+ $queryBool->addMust($query);
- default:
- $queryText->setFieldQuery('_all', $item['query']);
+ break;
- break;
- }
+ case 'mediaType':
+ $query = new Elastica_Query_Term;
+ $query->setTerm('digitalObject.mediaTypeId', $value);
+ $queryBool->addMust($query);
+
+ break;
+
+ case 'repository':
+ $query = new Elastica_Query_Term;
+ $query->setTerm('repositoryId', $value);
+ $queryBool->addMust($query);
+
+ break;
- if (0 == $key)
+ case 'searchFields':
+ foreach ($value as $key => $item)
{
- $item['operator'] == 'add';
+ if (empty($item['query']))
+ {
+ continue;
+ }
+
+ $queryText = new Elastica_Query_Text();
+
+ switch ($item['field'])
+ {
+ case 'identifier':
+ $queryText->setFieldQuery('identifier', $item['query']);
+
+ break;
+
+ case 'title':
+ $queryText->setFieldQuery('i18n.title', $item['query']);
+
+ break;
+
+ case 'scopeAndContent':
+ $queryText->setFieldQuery('i18n.scopeAndContet', $item['query']);
+
+ break;
+
+ case 'archivalHistory':
+ $queryText->setFieldQuery('i18n.archivalHistory',
$item['query']);
+
+ break;
+
+ case 'extentAndMedium':
+ $queryText->setFieldQuery('i18n.extentAndMedium',
$item['query']);
+
+ break;
+
+ case 'creatorHistory':
+ $queryText->setFieldQuery('', $item['query']);
+
+ break;
+
+ case 'subject':
+ $queryText->setFieldQuery('', $item['query']);
+
+ break;
+
+ case 'name':
+ $queryText->setFieldQuery('', $item['query']);
+
+ break;
+
+ case 'place':
+ $queryText->setFieldQuery('', $item['query']);
+
+ break;
+
+ default:
+ $queryText->setFieldQuery('_all', $item['query']);
+
+ break;
+ }
+
+ if (0 == $key)
+ {
+ $item['operator'] == 'add';
+ }
+
+ switch ($item['operator'])
+ {
+ case 'not':
+ $queryBool->addMustNot($queryText);
+
+ break;
+
+ case 'or':
+ $queryBool->addShould($queryText);
+
+ break;
+
+ case 'add':
+ default:
+ $queryBool->addMust($queryText);
+
+ break;
+ }
}
- switch ($item['operator'])
- {
- case 'not':
- $queryBool->addMustNot($queryText);
+ break;
- break;
+ }
+ }
- case 'or':
- $queryBool->addShould($queryText);
+ public function execute($request)
+ {
+ if ('print' == $request->getGetParameter('media'))
+ {
+ $this->getResponse()->addStylesheet('print-preview', 'last');
+ }
- break;
+ if (!isset($request->limit))
+ {
+ $request->limit = sfConfig::get('app_hits_per_page');
+ }
+
+ $this->form = new sfForm;
+ $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
+
+ foreach ($this::$NAMES as $name)
+ {
+ $this->addField($name);
+ }
- case 'add':
- default:
- $queryBool->addMust($queryText);
+ $this->form->bind($request->getRequestParameters() +
$request->getGetParameters() + $request->getPostParameters());
- break;
+ if ($this->form->isValid())
+ {
+ $query = new Elastica_Query;
+ $queryBool = new Elastica_Query_Bool();
+
+ // Process filters passing $queryBool
+ foreach ($this->form as $field)
+ {
+ if (isset($this->request[$field->getName()]))
+ {
+ $this->processField($field, $queryBool);
}
}
$query->setQuery($queryBool);
// Add facets to list related items
+ /*
foreach (array('repository.id', 'digitalObject.mediaTypeId') as $field)
{
$facet = new Elastica_Facet_Terms($field);
@@ -153,6 +336,7 @@
$facet->setSize(50);
$query->addFacet($facet);
}
+ */
$resultSet =
QubitSearch::getInstance()->index->getType('QubitInformationObject')->search($query);
Modified: branches/2.0/apps/qubit/modules/search/templates/_advancedSearch.php
==============================================================================
--- branches/2.0/apps/qubit/modules/search/templates/_advancedSearch.php
Mon Jun 4 20:13:10 2012 (r11728)
+++ branches/2.0/apps/qubit/modules/search/templates/_advancedSearch.php
Mon Jun 4 20:14:33 2012 (r11729)
@@ -4,4 +4,62 @@
<?php echo get_partial('search/searchFields') ?>
+ <div id="filters" class="row-fluid">
+
+ <p class="headline"><?php echo __('Filter/Limit') ?>:</p>
+
+ <div class="row-fluid">
+
+ <div class="span6 left">
+ <?php if (sfConfig::get('app_multi_repository')): ?>
+ <?php echo $form->repository
+ ->label(__('Repository'))
+ ->renderRow() ?>
+ <?php endif; ?>
+ </div>
+
+ <div class="span6 right">
+ <?php echo $form->materialType
+ ->label(__('General material designation'))
+ ->renderRow() ?>
+ </div>
+
+ </div>
+
+ <div class="row-fluid">
+
+ <div class="span6 left">
+ <?php echo $form->mediaType
+ ->label(__('Media type'))
+ ->renderRow() ?>
+ </div>
+
+ <div class="span6 right">
+ <?php echo $form->hasDigitalObject
+ ->label(__('Digital object available'))
+ ->renderRow() ?>
+ </div>
+
+ </div>
+
+ <div class="row-fluid">
+
+ <div class="span6 left">
+ <?php echo $form->levelOfDescription->renderRow() ?>
+ </div>
+
+ <div class="span6 right">
+ <?php echo $form->copyrightStatus
+ ->label(__('Copyright status'))
+ ->renderRow() ?>
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="actions">
+ <button type="submit" class="gray btn-large"><?php echo __('Search')
?></button>
+ </div>
+
</form>
Modified:
branches/2.0/apps/qubit/modules/search/templates/_printAdvancedSearchTerms.php
==============================================================================
---
branches/2.0/apps/qubit/modules/search/templates/_printAdvancedSearchTerms.php
Mon Jun 4 20:13:10 2012 (r11728)
+++
branches/2.0/apps/qubit/modules/search/templates/_printAdvancedSearchTerms.php
Mon Jun 4 20:14:33 2012 (r11729)
@@ -2,11 +2,12 @@
<div class="section search-terms">
<ul>
- <?php $i = 0; foreach ($queryTerms as $item): ?>
- <li>
- <?php echo (0 < $i++) ?
'<strong>'.strtoupper($item['operator'])."</strong>\n" : '' ?>
- <?php echo $item['term'] ?>
- </li>
- <?php endforeach; ?>
+ <?php $i = 0 ?>
+ <?php foreach ($queryTerms as $item): ?>
+ <li>
+ <?php echo (0 < $i++) ?
'<strong>'.strtoupper($item['operator'])."</strong>\n" : '' ?>
+ <?php echo $item['term'] ?>
+ </li>
+ <?php endforeach; ?>
</ul>
</div>
Modified: branches/2.0/apps/qubit/modules/search/templates/_searchFields.php
==============================================================================
--- branches/2.0/apps/qubit/modules/search/templates/_searchFields.php Mon Jun
4 20:13:10 2012 (r11728)
+++ branches/2.0/apps/qubit/modules/search/templates/_searchFields.php Mon Jun
4 20:14:33 2012 (r11729)
@@ -24,20 +24,24 @@
<input type="text" class="span6" placeholder="<?php echo __('Search')
?>" name="searchFields[<?php echo $key ?>][query]" value="<?php echo
esc_entities($item['query']) ?>"/>
- <span><?php echo __('in') ?></span>
+ <div class="in">
- <select name="searchFields[<?php echo $key ?>][field]">
- <option value=""<?php echo $item['field'] == '' ? '
selected="selected"' : '' ?>><?php echo __('Any field') ?></option>
- <option value="title"<?php echo $item['field'] == 'title' ? '
selected="selected"' : '' ?>><?php echo __('Title') ?></option>
- <option value="creatorHistory"<?php echo $item['field'] ==
'creatorHistory' ? ' selected="selected"' : '' ?>><?php echo
__('Admin/biographical history') ?></option>
- <option value="archivalHistory"<?php echo $item['field'] ==
'archivalHistory' ? ' selected="selected"' : '' ?>><?php echo __('Archival
history') ?></option>
- <option value="scopeAndContent"<?php echo $item['field'] ==
'scopeAndContent' ? ' selected="selected"' : '' ?>><?php echo __('Scope and
content') ?></option>
- <option value="extentAndMedium"<?php echo $item['field'] ==
'extentAndMedium' ? ' selected="selected"' : '' ?>><?php echo __('Extent and
medium') ?></option>
- <option value="subject"<?php echo $item['field'] == 'subject' ? '
selected="selected"' : '' ?>><?php echo __('Subject access points') ?></option>
- <option value="name"<?php echo $item['field'] == 'name' ? '
selected="selected"' : '' ?>><?php echo __('Name access points') ?></option>
- <option value="place"<?php echo $item['field'] == 'place' ? '
selected="selected"' : '' ?>><?php echo __('Place access points') ?></option>
- <option value="identifier"<?php echo $item['field'] == 'identifier'
? ' selected="selected"' : '' ?>><?php echo __('Identifier') ?></option>
- </select>
+ <span><?php echo __('in') ?></span>
+
+ <select name="searchFields[<?php echo $key ?>][field]">
+ <option value=""<?php echo $item['field'] == '' ? '
selected="selected"' : '' ?>><?php echo __('Any field') ?></option>
+ <option value="title"<?php echo $item['field'] == 'title' ? '
selected="selected"' : '' ?>><?php echo __('Title') ?></option>
+ <option value="creatorHistory"<?php echo $item['field'] ==
'creatorHistory' ? ' selected="selected"' : '' ?>><?php echo
__('Admin/biographical history') ?></option>
+ <option value="archivalHistory"<?php echo $item['field'] ==
'archivalHistory' ? ' selected="selected"' : '' ?>><?php echo __('Archival
history') ?></option>
+ <option value="scopeAndContent"<?php echo $item['field'] ==
'scopeAndContent' ? ' selected="selected"' : '' ?>><?php echo __('Scope and
content') ?></option>
+ <option value="extentAndMedium"<?php echo $item['field'] ==
'extentAndMedium' ? ' selected="selected"' : '' ?>><?php echo __('Extent and
medium') ?></option>
+ <option value="subject"<?php echo $item['field'] == 'subject' ? '
selected="selected"' : '' ?>><?php echo __('Subject access points') ?></option>
+ <option value="name"<?php echo $item['field'] == 'name' ? '
selected="selected"' : '' ?>><?php echo __('Name access points') ?></option>
+ <option value="place"<?php echo $item['field'] == 'place' ? '
selected="selected"' : '' ?>><?php echo __('Place access points') ?></option>
+ <option value="identifier"<?php echo $item['field'] ==
'identifier' ? ' selected="selected"' : '' ?>><?php echo __('Identifier')
?></option>
+ </select>
+
+ </div>
</div>
@@ -65,20 +69,24 @@
<input type="text" class="span6" placeholder="<?php echo __('Search') ?>"
name="searchFields[<?php echo $count?>][query]"/>
- <span><?php echo __('in') ?></span>
+ <div class="in">
- <select name="searchFields[<?php echo $count ?>][field]">
- <option value=""><?php echo __('Any field') ?></option>
- <option value="title"><?php echo __('Title') ?></option>
- <option value="creatorHistory"><?php echo __('Admin/biographical
history') ?></option>
- <option value="archivalHistory"><?php echo __('Archival history')
?></option>
- <option value="scopeAndContent"><?php echo __('Scope and content')
?></option>
- <option value="extentAndMedium"><?php echo __('Extent and medium')
?></option>
- <option value="subject"><?php echo __('Subject access points')
?></option>
- <option value="name"><?php echo __('Name access points') ?></option>
- <option value="place"><?php echo __('Place access points') ?></option>
- <option value="identifier"><?php echo __('Identifier') ?></option>
- </select>
+ <span><?php echo __('in') ?></span>
+
+ <select name="searchFields[<?php echo $count ?>][field]">
+ <option value=""><?php echo __('Any field') ?></option>
+ <option value="title"><?php echo __('Title') ?></option>
+ <option value="creatorHistory"><?php echo __('Admin/biographical
history') ?></option>
+ <option value="archivalHistory"><?php echo __('Archival history')
?></option>
+ <option value="scopeAndContent"><?php echo __('Scope and content')
?></option>
+ <option value="extentAndMedium"><?php echo __('Extent and medium')
?></option>
+ <option value="subject"><?php echo __('Subject access points')
?></option>
+ <option value="name"><?php echo __('Name access points') ?></option>
+ <option value="place"><?php echo __('Place access points') ?></option>
+ <option value="identifier"><?php echo __('Identifier') ?></option>
+ </select>
+
+ </div>
</div>
@@ -97,7 +105,3 @@
</ul>
</div>
</div>
-
-<div class="actions">
- <button type="submit" class="gray btn-large"><?php echo __('Search')
?></button>
-</div>
Modified: branches/2.0/apps/qubit/modules/search/templates/_searchResults.php
==============================================================================
--- branches/2.0/apps/qubit/modules/search/templates/_searchResults.php Mon Jun
4 20:13:10 2012 (r11728)
+++ branches/2.0/apps/qubit/modules/search/templates/_searchResults.php Mon Jun
4 20:14:33 2012 (r11729)
@@ -27,33 +27,11 @@
<h2 class="visible-phone widebtn btn-huge" data-toggle="collapse"
data-target="#institutions"><?php echo __('Institutions') ?></h2>
- <div class="section well clearfix" id="institutions">
-
- <div class="institution mini">
- <h2 class="active"><?php echo link_to(__('All Institutions'),
array('repository_id' => null, 'page' => null) +
$sf_request->getParameterHolder()->getAll()) ?></h2>
- </div>
-
- <?php $numNav = 7; $i = 0; // NB: numNav could be hardcoded but
might change ?>
- <?php foreach ($pager->facets['repository_id']['terms'] as $id =>
$term): ?>
- <?php $i++; ?>
-
- <div class="institution mini">
- <h2><?php echo link_to(__($term['term']), array('repository_id'
=> $id, 'page' => null) + $sf_request->getParameterHolder()->getAll()) ?></h2>
- </div>
-
- <?php if ($i >= $numNav) break ?>
- <?php endforeach; ?>
-
- </div>
-
- <div id="more-institutions" class="clearfix pull-right">
+ <div id="more-institutions" class="pull-right">
<select>
- <option value="" selected="selected"><?php echo __('%1% more
institutions with results', array('%1%' =>
count($pager->facets['repository_id']['terms']) - $numNav)) ?></option>
- <?php $i = 0; ?>
- <?php foreach($pager->facets['repository_id']['terms'] as $id =>
$term): ?>
- <?php $i++; ?>
- <?php if ($i <= $numNav) continue; ?>
+ <option value=""><?php echo __('All institutions') ?></option>
+ <?php foreach ($pager->facets['repository_id']['terms'] as $id =>
$term): ?>
<option value="<?php echo $id; ?>"><?php echo __($term['term'])
?></option>
<?php endforeach; ?>
</select>
Modified: branches/2.0/plugins/qtDominionPlugin/css/less/advancedSearch.less
==============================================================================
--- branches/2.0/plugins/qtDominionPlugin/css/less/advancedSearch.less Mon Jun
4 20:13:10 2012 (r11728)
+++ branches/2.0/plugins/qtDominionPlugin/css/less/advancedSearch.less Mon Jun
4 20:14:33 2012 (r11729)
@@ -51,6 +51,12 @@
}
+ .in {
+
+ display: inline;
+
+ }
+
}
.boolean {
@@ -73,4 +79,49 @@
}
+ #filters {
+
+ .row-fluid {
+
+ .left {
+
+ padding: 10px 10px 0 20px;
+
+ }
+
+ .right {
+
+ padding: 10px 20px 0 0;
+
+ }
+
+ }
+
+ select {
+
+ width: 100%;
+ .box-sizing(border-box);
+
+ }
+
+ }
+
+}
+
+@media (max-width: 767px) {
+
+ .in {
+
+ display: block !important;
+ margin-top: 1em;
+
+ }
+
+ .row-fluid .left,
+ .row-fluid .right {
+
+ padding: 0 20px !important;
+
+ }
+
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.