Skip to content

Instantly share code, notes, and snippets.

@sevein
Created October 13, 2011 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevein/1285753 to your computer and use it in GitHub Desktop.
Save sevein/1285753 to your computer and use it in GitHub Desktop.
search module changes
Index: apps/qubit/modules/search/actions/indexAction.class.php
===================================================================
--- apps/qubit/modules/search/actions/indexAction.class.php (revision 10078)
+++ apps/qubit/modules/search/actions/indexAction.class.php (working copy)
@@ -29,18 +29,20 @@
$request->limit = sfConfig::get('app_hits_per_page');
}
- // limit search to current culture and info. objects
+ // Limit search to current culture and info. objects
$this->prefix .= ' +culture:' . $this->context->user->getCulture() . ' ';
$this->prefix .= ' +className:QubitInformationObject ';
- // simple search
- if (empty($this->querystring) && !empty($request->query)) {
+ // Simple search
+ if (empty($this->querystring) && !empty($request->query))
+ {
$this->title = $this->context->i18n->__('Search for [%1%]', array('%1%' => $request->query));
$this->querystring = $request->query;
- // limit to a repository if in context
- if (isset($this->getRoute()->resource) && $this->getRoute()->resource instanceof QubitRepository) {
+ // Limit to a repository if in context
+ if (isset($this->getRoute()->resource) && $this->getRoute()->resource instanceof QubitRepository)
+ {
$this->prefix .= ' +repositoryId:' . $this->getRoute()->resource->id;
$this->title .= $this->context->i18n->__(' in %1%', array('%1%' => $this->getRoute()->resource->authorizedFormOfName));
}
@@ -48,16 +50,23 @@
$this->response->setTitle("{$this->title} - {$this->response->getTitle()}");
}
- if (empty($this->querystring)) $this->prefix = '';
+ if (empty($this->querystring))
+ {
+ $this->prefix = '';
+ }
+
$hits = $this->executeQuery();
- if (!empty($hits)) {
+ if (!empty($hits))
+ {
$this->pager = new QubitArrayPager;
$this->pager->hits = $hits;
$this->pager->setMaxPerPage($request->limit);
$this->pager->setPage($request->page);
- } elseif (empty($this->error)) {
+ }
+ else if (empty($this->error))
+ {
// no error, must be empty result set
$this->error = $this->context->i18n->__('No results found.');
}
@@ -93,4 +102,4 @@
return $hits;
}
-}
\ No newline at end of file
+}
Index: apps/qubit/modules/search/actions/globalReplaceAction.class.php
===================================================================
--- apps/qubit/modules/search/actions/globalReplaceAction.class.php (revision 10078)
+++ apps/qubit/modules/search/actions/globalReplaceAction.class.php (working copy)
@@ -21,14 +21,15 @@
{
public function execute($request)
{
- // execute the search request
parent::execute($request);
$this->addFields();
- if ($request->isMethod('post')) {
- // make sure we have required information for search/replace
- if (empty($request->pattern) || empty($request->replacement)) {
+ if ($request->isMethod('post'))
+ {
+ // Make sure we have required information for search/replace
+ if (empty($request->pattern) || empty($request->replacement))
+ {
$this->error = $this->context->i18n->__('Both source and replacement fields are required.');
return;
@@ -37,18 +38,20 @@
// TODO
// process replacement action
- // when complete, redirect to GSR home
+ // When complete, redirect to GSR home
$this->redirect(array('module' => 'search', 'action' => 'globalReplace'));
}
}
public function addFields()
{
- // information object attribute (db column) to perform s/r on
+ // Information object attribute (db column) to perform s/r on
$map = new InformationObjectI18nTableMap;
- foreach ($map->getColumns() as $col) {
- if (!$col->isPrimaryKey() && !$col->isForeignKey()) {
+ foreach ($map->getColumns() as $col)
+ {
+ if (!$col->isPrimaryKey() && !$col->isForeignKey())
+ {
$col_name = $col->getPhpName();
$choices[$col_name] = sfInflector::humanize(sfInflector::underscore($col_name));
}
@@ -57,11 +60,11 @@
$this->form->setValidator('column', new sfValidatorString);
$this->form->setWidget('column', new sfWidgetFormSelect(array('choices' => $choices), array('style' => 'width: auto')));
- // search-replace values
+ // Search-replace values
$this->form->setValidator('pattern', new sfValidatorString);
- $this->form->setWidget('pattern', new sfWidgetFormInput(array()));
+ $this->form->setWidget('pattern', new sfWidgetFormInput);
$this->form->setValidator('replacement', new sfValidatorString);
- $this->form->setWidget('replacement', new sfWidgetFormInput(array()));
+ $this->form->setWidget('replacement', new sfWidgetFormInput);
}
}
Index: apps/qubit/modules/search/templates/_advancedSearch.php
===================================================================
--- apps/qubit/modules/search/templates/_advancedSearch.php (revision 10078)
+++ apps/qubit/modules/search/templates/_advancedSearch.php (working copy)
@@ -1,5 +1,5 @@
<div class="form-item form-item-identifier">
- <table class="multiRow" style="white-space:nowrap;">
+ <table class="multiRow" style="white-space: nowrap;">
<tbody>
<?php echo get_partial('search/searchFields') ?>
</tbody>
@@ -22,4 +22,4 @@
->label(__('Digital object available'))
->renderRow() ?>
-</fieldset>
\ No newline at end of file
+</fieldset>
Index: apps/qubit/modules/search/templates/_searchFields.php
===================================================================
--- apps/qubit/modules/search/templates/_searchFields.php (revision 10078)
+++ apps/qubit/modules/search/templates/_searchFields.php (working copy)
@@ -1,3 +1,5 @@
+<?php use_helper('Text') ?>
+
<?php if (isset($sf_request->searchFields)): ?>
<?php foreach ($sf_request->searchFields as $key => $item): ?>
@@ -6,13 +8,13 @@
<tr>
<td>
<select name="searchFields[<?php echo $key ?>][operator]">
- <option value="and"<?php echo $item['operator'] == 'and' ? ' selected="selected"' : '' ?>>and</option>
- <option value="or"<?php echo $item['operator'] == 'or' ? ' selected="selected"' : '' ?>>or</option>
- <option value="not"<?php echo $item['operator'] == 'not' ? ' selected="selected"' : '' ?>>not</option>
+ <option value="and"<?php echo $item['operator'] == 'and' ? ' selected="selected"' : '' ?>><?php echo __('and') ?></option>
+ <option value="or"<?php echo $item['operator'] == 'or' ? ' selected="selected"' : '' ?>><?php echo __('or') ?></option>
+ <option value="not"<?php echo $item['operator'] == 'not' ? ' selected="selected"' : '' ?>><?php echo __('not') ?></option>
</select>
</td><td>
- <input type="text" name="searchFields[<?php echo $key ?>][query]" value="<?php echo $item['query'] ?>"/>
- </td><td>in&nbsp;
+ <input type="text" name="searchFields[<?php echo $key ?>][query]" value="<?php echo esc_entities($item['query']) ?>"/>
+ </td><td><?php echo __('in') ?>&nbsp;
<select style="width: 90%;" 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>
@@ -24,29 +26,31 @@
<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>
- </td><td>using&nbsp;
+ </td><td><?php echo __('using') ?>&nbsp;
<select name="searchFields[<?php echo $key ?>][match]" style="width: 100px;">
- <option value="keyword"<?php echo $item['match'] == 'keyword' ? ' selected="selected"' : '' ?>>keyword</option>
- <option value="phrase"<?php echo $item['match'] == 'phrase' ? ' selected="selected"' : '' ?>>phrase</option>
+ <option value="keyword"<?php echo $item['match'] == 'keyword' ? ' selected="selected"' : '' ?>><?php echo __('keyword') ?></option>
+ <option value="phrase"<?php echo $item['match'] == 'phrase' ? ' selected="selected"' : '' ?>><?php echo __('phrase') ?></option>
</select>
</td>
</tr>
<?php endforeach; ?>
- <?php else: ?>
- <?php $count = 0 ?>
- <?php endif; ?>
+<?php else: ?>
+
+ <?php $count = 0 ?>
+
+<?php endif; ?>
<tr>
<td>
<select name="searchFields[<?php echo $count ?>][operator]">
- <option value="and">and</option>
- <option value="or">or</option>
- <option value="not">not</option>
+ <option value="and"><?php echo __('and') ?></option>
+ <option value="or"><?php echo __('or') ?></option>
+ <option value="not"><?php echo __('not') ?></option>
</select>
</td><td>
<input type="text" name="searchFields[<?php echo $count ?>][query]"/>
- </td><td>in&nbsp;
+ </td><td><?php echo __('in') ?>&nbsp;
<select style="width: 90%;" name="searchFields[<?php echo $count ?>][field]">
<option value=""><?php echo __('Any field') ?></option>
<option value="title"><?php echo __('Title') ?></option>
@@ -58,10 +62,10 @@
<option value="place"><?php echo __('Place access points') ?></option>
<option value="identifier"><?php echo __('Identifier') ?></option>
</select>
- </td><td>using&nbsp;
+ </td><td><?php echo __('using') ?>&nbsp;
<select name="searchFields[<?php echo $count ?>][match]" style="width: 100px;">
- <option value="keyword">keyword</option>
- <option value="phrase">phrase</option>
+ <option value="keyword"><?php echo __('keyword') ?></option>
+ <option value="phrase"><?php echo __('phrase') ?></option>
</select>
</td>
</tr>
Index: apps/qubit/modules/search/templates/advancedSuccess.php
===================================================================
--- apps/qubit/modules/search/templates/advancedSuccess.php (revision 10078)
+++ apps/qubit/modules/search/templates/advancedSuccess.php (working copy)
@@ -1,8 +1,6 @@
-<?php use_helper('Text') ?>
-
<h1><?php echo __('Advanced search') ?></h1>
-<form action="<?php echo url_for(array('module' => 'search', 'action' => 'advanced')) ?>" method="get">
+<?php echo $form->renderFormTag(url_for(array('module' => 'search', 'action' => 'advanced')), array('method' => 'get')) ?>
<?php echo get_partial('search/advancedSearch', array('form' => $form)) ?>
@@ -29,9 +27,11 @@
<?php else: ?>
- <?php if(isset($pager)): ?>
- <?php echo get_partial('search/searchResults', array('pager' => $pager)) ?>
- <?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+ <?php if (isset($pager)): ?>
+
+ <?php echo get_partial('search/searchResults', array('pager' => $pager)) ?>
+ <?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+
<?php endif; ?>
<?php endif; ?>
Index: apps/qubit/modules/search/templates/indexSuccess.php
===================================================================
--- apps/qubit/modules/search/templates/indexSuccess.php (revision 10078)
+++ apps/qubit/modules/search/templates/indexSuccess.php (working copy)
@@ -1,6 +1,6 @@
<?php use_helper('Text') ?>
-<h1><?php echo esc_entities($title, ENT_COMPAT, 'UTF-8') ?></h1>
+<h1><?php echo esc_entities($title) ?></h1>
<?php if (isset($error)): ?>
@@ -12,9 +12,11 @@
<?php else: ?>
- <?php if(isset($pager)) {
- echo get_partial('search/searchResults', array('pager' => $pager));
- echo get_partial('default/pager', array('pager' => $pager));
- } ?>
+ <?php if (isset($pager)): ?>
+
+ <?php echo get_partial('search/searchResults', array('pager' => $pager)) ?>
+ <?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+
+ <?php endif; ?>
<?php endif; ?>
Index: apps/qubit/modules/search/templates/globalReplaceSuccess.php
===================================================================
--- apps/qubit/modules/search/templates/globalReplaceSuccess.php (revision 10078)
+++ apps/qubit/modules/search/templates/globalReplaceSuccess.php (working copy)
@@ -1,38 +1,41 @@
-<?php use_helper('Text') ?>
-
<h1><?php echo __('Global search/replace') ?></h1>
-<form action="<?php echo url_for(array('module' => 'search', 'action' => 'globalReplace')) ?>" name="form" method="get">
+<?php echo $form->renderFormTag(url_for(array('module' => 'search', 'action' => 'globalReplace')), array('name' => 'form', 'method' => 'get')) ?>
<?php echo get_partial('search/advancedSearch', array('form' => $form)) ?>
- <?php if(isset($pager)): ?>
+ <?php if (isset($pager)): ?>
- <div class="form-item form-item-identifier">
- <table>
- <tbody>
- <tr>
- <td>Replace:</td>
- <td style="padding: 0px;"><?php echo $form->pattern->render() ?></td>
- <td>With:</td>
- <td style="padding: 0px;"><?php echo $form->replacement->render() ?></td>
- <td style="white-space:nowrap;">in:
- <?php echo $form->column->render() ?>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
+ <div class="form-item form-item-identifier">
+ <table>
+ <tbody>
+ <tr>
+ <td>
+ <?php echo __('Replace') ?>:
+ </td><td style="padding: 0px;">
+ <?php echo $form->pattern->render() ?>
+ </td><td>
+ <?php echo __('With') ?>:
+ </td><td style="padding: 0px;">
+ <?php echo $form->replacement->render() ?>
+ </td><td style="white-space: nowrap;"><?php echo __('in') ?>:
+ <?php echo $form->column->render() ?>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
<?php endif; ?>
<div class="actions">
<div class="content">
<ul class="clearfix links">
- <input type="submit" name="Submit" class="form-submit" value="Search" />
- <?php if(isset($pager)): ?>
- <li><a class="delete" href="#" title="Replace" onclick="document.form.method = 'post'; document.form.submit();">Replace</a></li>
+ <input type="submit" name="Submit" class="form-submit" value="<?php echo __('Search') ?>" />
+
+ <?php if (isset($pager)): ?>
+ <li><a class="delete" href="#" title="<?php echo __('Replace') ?>" onclick="document.form.method = 'post'; document.form.submit();"><?php echo __('Replace') ?></a></li>
<?php endif; ?>
</ul>
@@ -51,7 +54,9 @@
<?php endif; ?>
-<?php if(isset($pager)): ?>
+<?php if (isset($pager)): ?>
+
<?php echo get_partial('search/searchResults', array('pager' => $pager)) ?>
<?php echo get_partial('default/pager', array('pager' => $pager)) ?>
+
<?php endif; ?>
Index: apps/qubit/modules/search/templates/_searchResults.php
===================================================================
--- apps/qubit/modules/search/templates/_searchResults.php (revision 10078)
+++ apps/qubit/modules/search/templates/_searchResults.php (working copy)
@@ -1,6 +1,8 @@
+<?php use_helper('Text') ?>
+
<div class="section">
<?php foreach ($pager->getResults() as $hit): ?>
- <?php $doc =& $hit->getDocument(); ?>
+ <?php $doc = $hit->getDocument(); ?>
<div class="clearfix search-results <?php echo 0 == @++$row % 2 ? 'even' : 'odd' ?>">
<?php if ('true' == $doc->hasDigitalObject): ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment