Author: mj
Date: Thu Oct 13 15:03:37 2011
New Revision: 10078
Log:
More work on global search/replace, code clean-up
Modified:
trunk/apps/qubit/modules/search/actions/advancedAction.class.php
trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php
trunk/apps/qubit/modules/search/actions/indexAction.class.php
trunk/apps/qubit/modules/search/templates/_searchFields.php
trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php
Modified: trunk/apps/qubit/modules/search/actions/advancedAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/search/actions/advancedAction.class.php Thu Oct
13 13:56:06 2011 (r10077)
+++ trunk/apps/qubit/modules/search/actions/advancedAction.class.php Thu Oct
13 15:03:37 2011 (r10078)
@@ -44,7 +44,7 @@
'hasDigitalObject' => ''
);
- $this->form->bind($request->getRequestParameters() +
$request->getGetParameters() + $defaults);
+ $this->form->bind($request->getRequestParameters() +
$request->getGetParameters() + $request->getPostParameters() + $defaults);
if ($this->form->isValid())
{
@@ -80,8 +80,8 @@
$choices[$repository->id] = $repository;
}
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
+ $this->form->setValidator($name, new sfValidatorChoice(array('choices'
=> array_keys($choices))));
+ $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices), array('style' => 'min-width: 50%; width: auto')));
break;
@@ -100,88 +100,83 @@
$choices[$media->id] = $media;
}
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
+ $this->form->setValidator($name, new sfValidatorChoice(array('choices'
=> array_keys($choices))));
+ $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices), array('style' => 'width: auto')));
break;
case 'hasDigitalObject':
$choices = array(
- '' => 'All',
+ '' => '',
'true' => 'Yes',
'false' => 'No'
);
$this->form->setValidator($name, new sfValidatorChoice(array('choices'
=> array_keys($choices))));
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
+ $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices), array('style' => 'width: auto')));
break;
-
}
}
public function buildAdvancedSearch($request)
{
- foreach ($request->searchFields as $searchField) {
+ foreach ($request->searchFields as $searchField) {
+ // if no terms for this field, skip it
+ if (empty($searchField['query'])) continue;
+
+ // enclose phrase searches in quotes (strip existing ones)
+ if ('phrase' == $searchField['match']) {
+ $terms = array('"'.str_replace(array('"', "'"), '',
$searchField['query']).'"');
+ } else {
+ $terms = explode(' ', $searchField['query']);
+ }
- // if no terms for this field, skip it
- if (empty($searchField['query'])) continue;
+ // select which boolean operator to use
+ if (!isset($searchField['operator'])) $searchField['operator'] = null;
+ switch ($searchField['operator']) {
+ case 'not':
+ $token = '-';
+ break;
+ case 'or':
+ $token = '';
+ break;
+ case 'and':
+ default:
+ $token = '+';
+ break;
+ }
- // enclose phrase searches in quotes (strip existing ones)
- if ('phrase' == $searchField['match']) {
- $terms = array('"'.str_replace(array('"', "'"), '',
$searchField['query']).'"');
- } else {
- $terms = explode(' ', $searchField['query']);
- }
-
- // select which boolean operator to use
- if (!isset($searchField['operator'])) $searchField['operator'] =
null;
- switch ($searchField['operator']) {
- case 'not':
- $token = '-';
- break;
- case 'or':
- $token = '';
- break;
- case 'and':
- default:
- $token = '+';
- }
-
- if (!empty($searchField['field'])) {
- // search on a specific field
- $string = '';
- foreach ($terms as $term) {
- $string .= $searchField['field'].':'.$term.' ';
- }
- $token .= '('.$string.') ';
- } else {
- // search across all fields
- $token .= '('.implode(' ', $terms).') ';
- }
- $this->querystring .= $token;
- }
+ if (!empty($searchField['field'])) {
+ // search on a specific field
+ $string = '';
+ foreach ($terms as $term) {
+ $string .= $searchField['field'].':'.$term.' ';
+ }
+ $token .= '('.$string.') ';
+
+ } else {
+ // search across all fields
+ $token .= '('.implode(' ', $terms).') ';
+ }
- if (!empty($request->hasDigitalObject)) {
- switch ($request->hasDigitalObject) {
- case 'true':
- $this->querystring .= '+hasDigitalObject:true ';
- break;
- case 'false':
- $this->querystring .= '+hasDigitalObject:false ';
- break;
- }
- }
+ $this->querystring .= $token;
+ }
- // limit to a repository if selected
- if (!empty($request->repository)) {
- $this->prefix = ' +repositoryId:' . $request->repository;
- }
+ // limit to a repository if selected
+ if (!empty($request->repository)) {
+ $this->prefix .= ' +repositoryId:' . $request->repository;
+ }
- // digital object filters
- if (!empty($request->media)) {
- $this->querystring .= '+do_mediaTypeId:'.$request->media.' ';
- }
- }
+ // digital object filters
+ if ('true' == $request->hasDigitalObject) {
+ $this->prefix .= ' +hasDigitalObject:true ';
+ } elseif ('false' == $request->hasDigitalObject) {
+ $this->prefix .= ' +hasDigitalObject:false ';
+ }
+ if (!empty($request->media)) {
+ $this->prefix .= '+do_mediaTypeId:'.$request->media.' ';
+ }
+ }
}
Modified: trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php
Thu Oct 13 13:56:06 2011 (r10077)
+++ trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php
Thu Oct 13 15:03:37 2011 (r10078)
@@ -27,18 +27,24 @@
$this->addFields();
if ($request->isMethod('post')) {
- // process replacement action
-
// 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;
}
- }
+ // TODO
+ // process replacement action
+
+ // 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
$map = new InformationObjectI18nTableMap;
foreach ($map->getColumns() as $col) {
@@ -49,6 +55,13 @@
}
$this->form->setValidator('column', new sfValidatorString);
- $this->form->setWidget('column', new sfWidgetFormSelect(array('choices' =>
$choices)));
- }
+ $this->form->setWidget('column', new sfWidgetFormSelect(array('choices' =>
$choices), array('style' => 'width: auto')));
+
+ // search-replace values
+ $this->form->setValidator('pattern', new sfValidatorString);
+ $this->form->setWidget('pattern', new sfWidgetFormInput(array()));
+
+ $this->form->setValidator('replacement', new sfValidatorString);
+ $this->form->setWidget('replacement', new sfWidgetFormInput(array()));
+ }
}
Modified: trunk/apps/qubit/modules/search/actions/indexAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/search/actions/indexAction.class.php Thu Oct
13 13:56:06 2011 (r10077)
+++ trunk/apps/qubit/modules/search/actions/indexAction.class.php Thu Oct
13 15:03:37 2011 (r10078)
@@ -30,8 +30,8 @@
}
// limit search to current culture and info. objects
- $this->prefix .= ' +culture:'.$this->context->user->getCulture();
- $this->prefix .= ' +className:QubitInformationObject';
+ $this->prefix .= ' +culture:' . $this->context->user->getCulture() . ' ';
+ $this->prefix .= ' +className:QubitInformationObject ';
// simple search
if (empty($this->querystring) && !empty($request->query)) {
Modified: trunk/apps/qubit/modules/search/templates/_searchFields.php
==============================================================================
--- trunk/apps/qubit/modules/search/templates/_searchFields.php Thu Oct 13
13:56:06 2011 (r10077)
+++ trunk/apps/qubit/modules/search/templates/_searchFields.php Thu Oct 13
15:03:37 2011 (r10078)
@@ -1,7 +1,7 @@
<?php if (isset($sf_request->searchFields)): ?>
<?php foreach ($sf_request->searchFields as $key => $item): ?>
- <?php if (0 == strlen($item['query'])) continue ?>
+ <?php if (empty($item['query'])) continue ?>
<?php @$count++ ?>
<tr>
<td>
@@ -33,11 +33,9 @@
</tr>
<?php endforeach; ?>
-<?php else: ?>
-
- <?php $count = 0 ?>
-
-<?php endif; ?>
+ <?php else: ?>
+ <?php $count = 0 ?>
+ <?php endif; ?>
<tr>
<td>
Modified: trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php Thu Oct
13 13:56:06 2011 (r10077)
+++ trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php Thu Oct
13 15:03:37 2011 (r10078)
@@ -13,9 +13,9 @@
<tbody>
<tr>
<td>Replace:</td>
- <td style="padding: 0px;"><input type="text" name="pattern"/></td>
+ <td style="padding: 0px;"><?php echo $form->pattern->render() ?></td>
<td>With:</td>
- <td style="padding: 0px;"><input type="text"
name="replacement"/></td>
+ <td style="padding: 0px;"><?php echo $form->replacement->render()
?></td>
<td style="white-space:nowrap;">in:
<?php echo $form->column->render() ?>
</td>
@@ -32,7 +32,7 @@
<input type="submit" name="Submit" class="form-submit" value="Search"
/>
<?php if(isset($pager)): ?>
- <li><a class="delete" href="#" title="Replace"
onclick="document.form.submit();">Replace</a></li>
+ <li><a class="delete" href="#" title="Replace"
onclick="document.form.method = 'post';
document.form.submit();">Replace</a></li>
<?php endif; ?>
</ul>
@@ -49,11 +49,9 @@
</ul>
</div>
-<?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 endif; ?>
+<?php endif; ?>
+<?php if(isset($pager)): ?>
+ <?php echo get_partial('search/searchResults', array('pager' => $pager)) ?>
+ <?php echo get_partial('default/pager', array('pager' => $pager)) ?>
<?php endif; ?>
--
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.