Copyright 2001-2016 Horde LLC (http://www.horde.org/) See the enclosed file LICENSE for license information (BSD). If you did not did not receive this file, see http://www.horde.org/licenses/bsdl.php.
Автор: Michael J Rubinsky (mrubinsk@horde.org)
Наследование: implements Serializable
Пример #1
0
 /**
  * Performs a Task search. self::_tasks is populated with the results.
  *
  * @throws Nag_Exception
  */
 protected function _doSearch()
 {
     // Clear the tag browser in case we have an active browse set.
     $this->_browser->clearSearch();
     // Don't show the tag browser.
     $this->_showTagBrowser = false;
     $form = new Nag_Form_Search($this->_vars);
     if ($form->validate($this->_vars, true)) {
         $form->getInfo($this->_vars, $info);
     } else {
         throw new Nag_Exception(current($form->getErrors()));
     }
     // Text filter
     $search_pattern = $this->_vars->search_pattern;
     $search_in = empty($this->_vars->search_in) ? array() : $this->_vars->search_in;
     $search_name = in_array('search_name', $search_in) ? Nag_Search::MASK_NAME : 0;
     $search_desc = in_array('search_desc', $search_in) ? Nag_Search::MASK_DESC : 0;
     $search_tags = !empty($this->_vars->search_tags) ? Nag_Search::MASK_TAGS : 0;
     $search_completed = $this->_vars->search_completed;
     $this->_vars->set('show_completed', $search_completed);
     $mask = $search_name | $search_desc | $search_tags;
     // Date filter
     $date = $info['due_date'];
     if (empty($date)) {
         $date = array();
     }
     // Prepare the search
     $search = new Nag_Search($search_pattern, $mask, array('completed' => $search_completed, 'due' => $date, 'tags' => empty($this->_vars->search_tags) ? array() : $GLOBALS['injector']->getInstance('Nag_Tagger')->split($this->_vars->search_tags)));
     try {
         $tasks = $search->getSlice();
     } catch (Nag_Exception $e) {
         $GLOBALS['notification']->push($tasks, 'horde.error');
         $tasks = new Nag_Task();
     }
     // Save as a smart list?
     if ($id = $this->_vars->get('smart_id')) {
         // Existing list.
         $smartlist = $GLOBALS['nag_shares']->getShare($id);
         Nag::updateTasklist($smartlist, array('name' => $this->_vars->get('smartlist_name'), 'search' => serialize($search)));
         $this->_title = $smartlist->get('name');
         $this->_smartShare = $smartlist;
     } elseif ($this->_vars->get('save_smartlist')) {
         $this->_smartShare = Nag::addTasklist(array('name' => $this->_vars->get('smartlist_name'), 'search' => serialize($search)), false);
         $this->_title = $this->_vars->get('smartlist_name');
     } else {
         // Build a page title based on criteria.
         $this->_title = sprintf(_("Search: Results for"));
         $have_title = false;
         if (!empty($search_pattern)) {
             $have_title = true;
             $this->_title .= ' "' . $search_pattern . '" ';
         } else {
             $this->_title .= ' ' . _("tasks") . ' ';
         }
         if (!empty($date)) {
             if ($have_title) {
                 $this->_title .= _("and") . ' ';
             } else {
                 $this->_title .= _("with") . ' ';
                 $have_title = true;
             }
             $this->_title .= sprintf(_("due date within %d days of %s"), $date[0], $date[1]) . ' ';
         }
         if (!empty($search_tags)) {
             if ($have_title) {
                 $this->_title .= _("and") . ' ';
             } else {
                 $this->_title .= _("with") . ' ';
             }
             $this->_title .= sprintf(_("and tagged with %s"), $this->_vars->search_tags);
         }
     }
     $GLOBALS['session']->set('nag', 'search', $search, Horde_Session::TYPE_OBJECT);
     $this->_haveSearch = true;
     $this->_tasks = $tasks;
 }
Пример #2
0
 /**
  * Override the default tag search in order to filter by the 'completed'
  * filter.
  *
  * @return array  An array of task UIDs.
  */
 protected function _runSearch()
 {
     $search = new Nag_Search(null, Nag_Search::MASK_TAGS, array('completed' => $this->_completed, 'tags' => $this->_tags));
     $tasks = $search->getSlice();
     $tasks->reset();
     // Save the resulting task list.
     $this->_tasks = $tasks;
     // Must return the UID array since the parent class requires them.
     $ids = array();
     while ($task = $tasks->each()) {
         $ids[] = $task->uid;
     }
     return $ids;
 }