Exemplo n.º 1
0
 public function __construct($vars)
 {
     parent::__construct($vars, $vars->get('edit') ? _("Edit Text Criterion") : _("Add Text Criterion"), 'Whups_Form_Query_TextCriterion');
     $this->addHidden('', 'edit', 'boolean', false);
     $this->addVariable(_("Text"), 'text', 'text', true);
     $this->addVariable(_("Match Operator"), 'operator', 'enum', true, false, null, array(Whups_Query::textOperators()));
     $this->addVariable(_("Search Summary"), 'summary', 'boolean', false);
     $this->addVariable(_("Search Comments"), 'comments', 'boolean', false);
 }
Exemplo n.º 2
0
 public function __construct($vars)
 {
     parent::__construct($vars, $vars->get('edit') ? _("Edit User Criterion") : _("Add User Criterion"), 'Whups_Form_Query_UserCriterion');
     $this->addHidden('', 'edit', 'boolean', false);
     $this->addVariable(_("User ID"), 'user', 'text', true);
     $this->addVariable(_("Match Operator"), 'operator', 'enum', true, false, null, array(Whups_Query::textOperators()));
     $this->addVariable(_("Search Owners"), 'owners', 'boolean', false);
     $this->addVariable(_("Search Requester"), 'requester', 'boolean', false);
     $this->addVariable(_("Search Comments"), 'comments', 'boolean', false);
 }
Exemplo n.º 3
0
 public function __construct(&$vars)
 {
     global $whups_driver;
     parent::__construct($vars, $vars->get('edit') ? _("Edit Attribute Criterion") : _("Add Attribute Criterion"), 'Whups_Form_Query_AttributeCriterion');
     $this->addHidden('', 'edit', 'boolean', false);
     try {
         $this->attribs = $whups_driver->getAttributesForType();
         if ($this->attribs) {
             $this->addVariable(_("Match"), 'text', 'text', true);
             $this->addVariable(_("Match Operator"), 'operator', 'enum', true, false, null, array(Whups_Query::textOperators()));
             foreach ($this->attribs as $id => $attribute) {
                 $this->addVariable(sprintf(_("Search %s Attribute"), $attribute['human_name']), "a{$id}", 'boolean', false);
             }
         } else {
             $this->addVariable(_("Search Attribute"), 'attribute', 'invalid', true, false, null, array(_("There are no attributes defined.")));
         }
     } catch (Whups_Exception $e) {
         $this->addVariable(_("Search Attribute"), 'attribute', 'invalid', true, false, null, array($e->getMessage()));
     }
 }
Exemplo n.º 4
0
 /**
  * @TODO: This must be public, but method name has underscore.
  */
 public function _renderRow(&$more, &$path, $type, $criterion, $cvalue, $operator, $value)
 {
     global $whups_driver, $registry;
     $this->currentRow++;
     $pathstring = Whups_Query::pathToString($path);
     $depth = count($path);
     $class = "item" . $this->currentRow % 2;
     switch ($type) {
         case Whups_Query::TYPE_AND:
             $text = _("And");
             break;
         case Whups_Query::TYPE_OR:
             $text = _("Or");
             break;
         case Whups_Query::TYPE_NOT:
             $text = _("Not");
             break;
         case Whups_Query::TYPE_CRITERION:
             switch ($criterion) {
                 case Whups_Query::CRITERION_ID:
                     $text = _("Id");
                     break;
                 case Whups_Query::CRITERION_OWNERS:
                     $text = _("Owners");
                     break;
                 case Whups_Query::CRITERION_GROUPS:
                     $text = _("Groups");
                     break;
                 case Whups_Query::CRITERION_REQUESTER:
                     $text = _("Requester");
                     break;
                 case Whups_Query::CRITERION_ADDED_COMMENT:
                     $text = _("Commentor");
                     break;
                 case Whups_Query::CRITERION_COMMENT:
                     $text = _("Comment");
                     break;
                 case Whups_Query::CRITERION_SUMMARY:
                     $text = _("Summary");
                     break;
                 case Whups_Query::CRITERION_QUEUE:
                     $queue = $whups_driver->getQueue($value);
                     if ($queue) {
                         $text = _("Queue");
                         $value = $queue['name'];
                     }
                     break;
                 case Whups_Query::CRITERION_VERSION:
                     $version = $whups_driver->getVersion($value);
                     if ($version) {
                         $text = _("Version");
                         $value = $version['name'];
                     }
                     break;
                 case Whups_Query::CRITERION_TYPE:
                     $text = _("Type");
                     $value = $whups_driver->getTypeName($value);
                     break;
                 case Whups_Query::CRITERION_STATE:
                     // The value of the following depends on the type.
                     $state = $whups_driver->getState($value);
                     if ($state && isset($this->ticketTypes[$state['type']])) {
                         $text = '[' . $this->ticketTypes[$state['type']] . '] ' . _("State");
                         $value = $state['name'];
                     }
                     break;
                 case Whups_Query::CRITERION_PRIORITY:
                     $state = $whups_driver->getPriority($value);
                     $text = '[' . $this->ticketTypes[$state['type']] . '] ' . _("Priority");
                     $value = $state['name'];
                     break;
                 case Whups_Query::CRITERION_ATTRIBUTE:
                     // The value of the following depends on the type.
                     $aname = $whups_driver->getAttributeName($cvalue);
                     foreach ($this->attributes as $attribute) {
                         if ($attribute['attribute_id'] == $cvalue) {
                             $type = $attribute['type_id'];
                             break;
                         }
                     }
                     if (isset($this->ticketTypes[$type])) {
                         $aname .= ' (' . $this->ticketTypes[$type] . ')';
                     }
                     $text = sprintf("Attribute \"%s\"", $aname);
                     break;
                 case Whups_Query::CRITERION_TIMESTAMP:
                     $text = _("Created");
                     $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
                     break;
                 case Whups_Query::CRITERION_UPDATED:
                     $text = _("Updated");
                     $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
                     break;
                 case Whups_Query::CRITERION_RESOLVED:
                     $text = _("Resolved");
                     $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
                     break;
                 case Whups_Query::CRITERION_ASSIGNED:
                     $text = _("Assigned");
                     $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
                     break;
                 case Whups_Query::CRITERION_DUE:
                     $text = _("Due");
                     $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
                     break;
             }
             if (!isset($text)) {
                 $text = sprintf(_("Unknown node type %s"), $type);
                 break;
             }
             $text .= ' ';
             switch ($operator) {
                 case Whups_Query::OPERATOR_GREATER:
                     $text .= _("is greater than");
                     break;
                 case Whups_Query::OPERATOR_LESS:
                     $text .= _("is less than");
                     break;
                 case Whups_Query::OPERATOR_EQUAL:
                     $text .= _("is");
                     break;
                 case Whups_Query::OPERATOR_CI_SUBSTRING:
                     $text .= _("contains (case insensitive) substring");
                     break;
                 case Whups_Query::OPERATOR_CS_SUBSTRING:
                     $text .= _("contains (case sensitive) substring");
                     break;
                 case Whups_Query::OPERATOR_WORD:
                     $text .= _("contains the word");
                     break;
                 case Whups_Query::OPERATOR_PATTERN:
                     $text .= _("matches the pattern");
                     break;
             }
             $text .= " {$value}";
             break;
         default:
             $text = sprintf(_("Unknown node type %s"), $type);
             break;
     }
     // Stick vertical-align: middle; on everything to make it look a
     // little nicer.
     $fimgattrs = 'height="20" width="0" style="vertical-align: middle;"';
     $imgattrs = 'height="20" width="20" style="vertical-align: middle;"';
     $space = '';
     $count = count($more);
     if ($count == 0) {
         // Always have at least one image to make sure all rows are the
         // same height.
         $space = Horde::img('tree/blank.png', '', $fimgattrs) . "\n";
     } else {
         for ($i = 0; $i < $count - 1; $i++) {
             if ($more[$i] == 1) {
                 $space .= Horde::img('tree/line.png', '|', $imgattrs) . "\n";
             } else {
                 $space .= Horde::img('tree/blank.png', '', $imgattrs) . "\n";
             }
         }
     }
     if ($count > 0) {
         if ($more[$count - 1] == 1) {
             $space .= Horde::img('tree/join.png', '+', $imgattrs) . "\n";
         } else {
             $space .= Horde::img('tree/joinbottom.png', '-', $imgattrs) . "\n";
         }
     }
     $extra = $this->isActive ? '' : ' disabled="disabled"';
     $extra .= $pathstring == $this->currentPath ? ' checked="checked"' : '';
     include WHUPS_TEMPLATES . '/renderer/query/render.inc';
 }
Exemplo n.º 5
0
 /**
  * Executes a query.
  *
  * @param Whups_Query $query     A query object.
  * @param Horde_Variables $vars  Request variables.
  * @param boolean $get_details   Whether to return all ticket details.
  * @param boolean $munge         @TODO (?)
  *
  * @return array  List of ticket IDs or ticket details that match the query
  *                criteria.
  * @throws Whups_Exception
  */
 public function executeQuery(Whups_Query $query, Horde_Variables $vars, $get_details = true, $munge = true)
 {
     $this->jtables = array();
     $this->joins = array();
     $where = $query->reduce(array($this, 'clauseFromQuery'), $vars);
     if (!$where) {
         $GLOBALS['notification']->push(_("No query to run"), 'horde.message');
         return array();
     }
     if ($this->joins) {
         $joins = implode(' ', $this->joins);
     } else {
         $joins = '';
     }
     try {
         $ids = $this->_db->selectValues("SELECT whups_tickets.ticket_id FROM whups_tickets {$joins} " . "WHERE {$where}");
     } catch (Horde_Db_Exception $e) {
         $GLOBALS['notification']->push($e->getMessage(), 'horde.error');
         return array();
     }
     if (!count($ids)) {
         return array();
     }
     if ($get_details) {
         $ids = $this->getTicketsByProperties(array('id' => $ids), $munge);
     }
     return $ids;
 }
Exemplo n.º 6
0
 public function insertCriterion($pathstring, $criterion, $cvalue, $operator, $value)
 {
     $path = Whups_Query::stringToPath($pathstring);
     $qobj =& $this->query;
     $value = trim($value);
     if ($value[0] == '"') {
         // FIXME: The last character should be '"' as well.
         $value = substr($value, 1, -1);
     } else {
         $pn = $this->_getParameterName($value);
         if ($pn !== null) {
             $this->parameters[] = $pn;
         }
     }
     $newbranch = array('type' => Whups_Query::TYPE_CRITERION, 'criterion' => $criterion, 'cvalue' => $cvalue, 'operator' => $operator, 'value' => $value);
     $count = count($path);
     for ($i = 0; $i < $count; $i++) {
         $qobj =& $qobj['children'][$path[$i]];
     }
     $qobj['children'][] = $newbranch;
 }
Exemplo n.º 7
0
            $session->set('whups', 'query_form', $qf);
            $vars->set('edit', true);
            break;
    }
    $vars->remove('qaction1');
    $vars->remove('qaction2');
} elseif ($vars->get('formname')) {
    // Now check for submitted forms.
    $class = $vars->get('formname');
    $form = new $class($vars);
    if ($form->validate($vars)) {
        if ($vars->get('edit')) {
            $whups_query->deleteNode($vars->get('path'));
            $path = Whups_Query::stringToPath($vars->get('path'));
            array_pop($path);
            $vars->set('path', Whups_Query::pathToString($path));
            $vars->remove('edit');
        }
        $form->execute($vars);
        $vars->remove('action');
    }
} elseif ($vars->get('action') != '') {
    // Last, check for actions from tabs.
    $action = $vars->get('action');
    switch ($action) {
        case 'new':
            $whups_query = $qManager->newQuery();
            break;
        case 'delete':
            $showExtraForm = 'Whups_Form_Query_Delete';
            $showEditQuery = false;