searching includes groups for and/or

This commit is contained in:
naomiaro 2011-01-04 19:18:44 -05:00
parent f6a56c01a9
commit 101b6fafa6
16 changed files with 244 additions and 102 deletions

View file

@ -5,18 +5,13 @@ class Application_Form_AdvancedSearch extends Zend_Form
public function init()
{
$this->addElement('hidden', 'search_next_id', array(
'value' => 2
));
$this->getElement('search_next_id')->removeDecorator('Label')->removeDecorator('HtmlTag');
// Add the add button
$this->addElement('button', 'search_add', array(
$this->addElement('button', 'search_add_group', array(
'ignore' => true,
'label' => 'Add',
'order' => '-2'
));
$this->getElement('search_add')->removeDecorator('DtDdWrapper');
$this->getElement('search_add_group')->removeDecorator('DtDdWrapper');
// Add the submit button
$this->addElement('submit', 'search_submit', array(
@ -27,6 +22,17 @@ class Application_Form_AdvancedSearch extends Zend_Form
$this->getElement('search_submit')->removeDecorator('DtDdWrapper');
}
public function addGroup($group_id, $row_id=null) {
$this->addSubForm(new Application_Form_AdvancedSearchGroup(), 'group_'.$group_id, $group_id);
$this->getSubForm('group_'.$group_id)->removeDecorator('DtDdWrapper');
if(!is_null($row_id)) {
$subGroup = $this->getSubForm('group_'.$group_id);
$subGroup->addRow($row_id);
}
}
public function preValidation(array $data) {
function findId($name) {
@ -34,36 +40,26 @@ class Application_Form_AdvancedSearch extends Zend_Form
return $t[1];
}
// array_filter callback
function findFields($field) {
return strpos($field, 'row') !== false;
return strpos($field, 'group') !== false;
}
$fields = array_filter(array_keys($data), 'findFields');
$groups = array_filter(array_keys($data), 'findFields');
foreach ($fields as $field) {
// use id to set new order
$id = findId($field);
$this->addNewField($data, $id);
foreach ($groups as $group) {
$group_id = findId($group);
$this->addGroup($group_id);
$subGroup = $this->getSubForm($group);
foreach (array_keys($data[$group]) as $row) {
$row_id = findId($row);
$subGroup->addRow($row_id, $data[$group][$row]);
}
}
}
public function addNewField($data, $id) {
$sub = new Application_Form_AdvancedSearchRow($id);
$values = array("metadata_".$id => $data["row_".$id]["metadata_".$id],
"match_".$id => $data["row_".$id]["match_".$id],
"search_".$id => $data["row_".$id]["search_".$id]);
$sub->setDefaults($values);
$this->addSubForm($sub, 'row_'.$id, $id);
$this->getSubForm('row_'.$id)->removeDecorator('DtDdWrapper');
}
}

View file

@ -0,0 +1,29 @@
<?php
class Application_Form_AdvancedSearchGroup extends Zend_Form_SubForm
{
public function init()
{
// Add the add button
$this->addElement('button', 'search_add_row', array(
'ignore' => true,
'label' => 'Add',
'order' => '-2'
));
$this->getElement('search_add_row')->removeDecorator('DtDdWrapper');
}
public function addRow($row_id, $data=null) {
$this->addSubForm(new Application_Form_AdvancedSearchRow(), 'row_'.$row_id, $row_id);
$row = $this->getSubForm('row_'.$row_id);
$row->removeDecorator('DtDdWrapper');
if(!is_null($data)) {
$row->setDefaults($data);
}
}
}

View file

@ -2,22 +2,11 @@
class Application_Form_AdvancedSearchRow extends Zend_Form_SubForm
{
protected $_rowid;
public function __construct($id = null)
{
$this->_rowid = $id;
parent::__construct();
}
public function init()
{
$id = $this->_rowid;
$this->addElement(
'select',
'metadata_'.$id,
'metadata',
array(
'required' => true,
'multiOptions' => array(
@ -50,11 +39,11 @@ class Application_Form_AdvancedSearchRow extends Zend_Form_SubForm
),
)
);
$this->getElement('metadata_'.$id)->removeDecorator('Label')->removeDecorator('HtmlTag');
$this->getElement('metadata')->removeDecorator('Label')->removeDecorator('HtmlTag');
$this->addElement(
'select',
'match_'.$id,
'match',
array(
'required' => true,
'multiOptions' => array(
@ -68,12 +57,12 @@ class Application_Form_AdvancedSearchRow extends Zend_Form_SubForm
),
)
);
$this->getElement('match_'.$id)->removeDecorator('Label')->removeDecorator('HtmlTag');
$this->getElement('match')->removeDecorator('Label')->removeDecorator('HtmlTag');
$this->addElement('text', 'search_'.$id, array(
$this->addElement('text', 'search', array(
'required' => true,
));
$this->getElement('search_'.$id)->removeDecorator('Label')->removeDecorator('HtmlTag');
$this->getElement('search')->removeDecorator('Label')->removeDecorator('HtmlTag');
}