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

@ -2,7 +2,9 @@
class LibraryController extends Zend_Controller_Action
{
protected $pl_sess = null;
protected $search_sess = null;
public function init()
@ -18,6 +20,7 @@ class LibraryController extends Zend_Controller_Action
->addActionContext('upload', 'json')
->addActionContext('delete', 'json')
->addActionContext('context-menu', 'json')
->addActionContext('quick-search', 'json')
->initContext();
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
@ -36,6 +39,7 @@ class LibraryController extends Zend_Controller_Action
unset($this->search_sess->md);
$this->_helper->actionStack('contents', 'library');
$this->_helper->actionStack('quick-search', 'library');
$this->_helper->actionStack('index', 'sideplaylist');
}
@ -94,7 +98,7 @@ class LibraryController extends Zend_Controller_Action
public function deleteAction()
{
$id = $this->_getParam('id');
if (!is_null($id)) {
$file = StoredFile::Recall($id);
@ -121,7 +125,7 @@ class LibraryController extends Zend_Controller_Action
public function contentsAction()
{
$this->view->headScript()->appendFile('/js/campcaster/library/library.js','text/javascript');
$this->_helper->viewRenderer->setResponseSegment('library');
$cat = $this->_getParam('ob', null);
@ -183,7 +187,48 @@ class LibraryController extends Zend_Controller_Action
$this->view->form = $form;
}
public function quickSearchAction()
{
$this->view->headScript()->appendFile('/js/campcaster/library/quicksearch.js','text/javascript');
$this->_helper->viewRenderer->setResponseSegment('quick_search');
$search = $this->_getParam('search', null);
$format = $this->_getParam('format', 'layout');
if($format !== 'json')
return;
$categories = array("dc:title", "dc:creator", "dc:source");
$keywords = explode(" ", $search);
$md = array();
$i = 0;
foreach($keywords as $word) {
foreach($categories as $cat) {
$md["row_".$i]["metadata_".$i] = $cat;
$md["row_".$i]["match_".$i] = 0;
$md["row_".$i]["search_".$i] = $word;
$i = $i + 1;
}
}
$currpage = isset($this->search_sess->page) ? $this->search_sess->page : null;
$order = isset($this->search_sess->order) ? $this->search_sess->order : null;
$count = StoredFile::searchFiles($md, $order, true);
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Null($count));
$paginator->setCurrentPageNumber($currpage);
$this->view->paginator = $paginator;
$this->view->files = StoredFile::searchFiles($md, $order, false, $paginator->getCurrentPageNumber(), $paginator->getItemCountPerPage());
$this->view->html = $this->view->render('library/contents.phtml');
unset($this->view->files);
unset($this->view->paginator);
}
}
@ -200,3 +245,5 @@ class LibraryController extends Zend_Controller_Action

View file

@ -2,29 +2,49 @@
class SearchController extends Zend_Controller_Action
{
protected $search_sess = null;
protected $form;
protected $search_sess = null;
private function addGroup($group_id) {
$form = new Application_Form_AdvancedSearch();
$form->addGroup($group_id, 1);
$group = $form->getSubForm('group_'.$group_id);
return $group->__toString();
}
private function addFieldToGroup($group_id, $row_id) {
$form = new Application_Form_AdvancedSearch();
$form->addGroup($group_id);
$group = $form->getSubForm('group_'.$group_id);
$group->addRow($row_id);
return $group->__toString();
}
public function init()
{
if(!Zend_Auth::getInstance()->hasIdentity())
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('login/index');
}
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('newfield', 'html')
$ajaxContext->addActionContext('newfield', 'json')
->addActionContext('newgroup', 'json')
->initContext();
$this->form = new Application_Form_AdvancedSearch();
$this->search_sess = new Zend_Session_Namespace("search");
}
public function indexAction()
{
$this->_helper->layout->setLayout('search');
$this->_helper->layout->setLayout('search');
$this->view->headScript()->appendFile('/js/campcaster/onready/search.js','text/javascript');
$this->view->headScript()->appendFile('/js/contextmenu/jjmenu.js','text/javascript');
$this->view->headLink()->appendStylesheet('/css/contextmenu.css');
@ -36,28 +56,30 @@ class SearchController extends Zend_Controller_Action
public function displayAction()
{
$this->view->headScript()->appendFile('/js/campcaster/library/advancedsearch.js','text/javascript');
$this->view->headLink()->appendStylesheet('/css/library_search.css');
$this->view->headScript()->appendFile('/js/campcaster/library/advancedsearch.js','text/javascript');
//$this->view->headLink()->appendStylesheet('/css/library_search.css');
$this->_helper->viewRenderer->setResponseSegment('search');
$request = $this->getRequest();
$this->form = new Application_Form_AdvancedSearch();
$form = $this->form;
$form = new Application_Form_AdvancedSearch();
$this->view->form = $form;
// Form has not been submitted - displayed using layouts
if (!$request->isPost()) {
$sub = new Application_Form_AdvancedSearchRow(1);
$form->addSubForm($sub, 'row_1');
$form->getSubForm('row_1')->removeDecorator('DtDdWrapper');
$form->addGroup(1, 1);
$this->search_sess->next_group = 2;
$this->search_sess->next_row[1] = 2;
return;
}
// Form has been submitted - run data through preValidation()
$this->view->md = $request->getPost();
// Form has been submitted
$form->preValidation($request->getPost());
if (!$form->isValid($request->getPost())) {
@ -65,8 +87,8 @@ class SearchController extends Zend_Controller_Action
}
// valid form was submitted set as search criteria.
$info = $form->getValues();
$this->search_sess->md = $info;
$this->view->md = $form->getValues();
$this->search_sess->md = $form->getValues();
//make sure to start on first page of new results.
unset($this->search_sess->page);
@ -74,19 +96,31 @@ class SearchController extends Zend_Controller_Action
public function newfieldAction()
{
$id = $this->_getParam('id', 1);
$group_id = $this->_getParam('group', 1);
$row_id = $this->search_sess->next_row[$group_id];
$this->form->addSubForm(new Application_Form_AdvancedSearchRow($id), 'row_'.$id, $id);
$this->view->html = $this->addFieldToGroup($group_id, $row_id);
$this->view->row = $row_id;
$this->form->getSubForm('row_'.$id)->removeDecorator('DtDdWrapper');
$e = $this->form->getSubForm('row_'.$id);
$this->view->field = $e->__toString();
$this->search_sess->next_row[$group_id] = $row_id + 1;
}
public function newgroupAction()
{
$group_id = $this->search_sess->next_group;
$this->view->html = $this->addGroup($group_id);
$this->search_sess->next_group = $group_id + 1;
$this->search_sess->next_row[$group_id] = 2;
}
}