Overview

Packages

  • Horde
    • Form
    • MIME
      • Viewer
    • Scheduler
  • None
  • Whups
    • UnitTests

Classes

  • Whups_Application
  • Whups_Block_Myqueries
  • Whups_Block_Myrequests
  • Whups_Block_Mytickets
  • Whups_Block_Query
  • Whups_Block_Queuecontents
  • Whups_Block_Queuesummary
  • Whups_Block_Unassigned
  • Whups_Driver_sql
  • Whups_Exception
  • Whups_Factory_Driver
  • Whups_Form_AddListener
  • Whups_Form_DeleteListener
  • Whups_Form_Queue_StepOne
  • Whups_Form_Queue_StepThree
  • Whups_Form_Queue_StepTwo
  • Whups_Form_Renderer_Query
  • Whups_Form_SetTypeStepOne
  • Whups_Form_SetTypeStepTwo
  • Whups_Form_Ticket_Delete
  • Whups_Test_Perms
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * A Horde_Form_Renderer for rendering Whups queries.
  4:  *
  5:  * Copyright 2001-2002 Robert E. Coyle <robertecoyle@hotmail.com>
  6:  * Copyright 2001-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file LICENSE for license information (BSD). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 10:  *
 11:  * @package Whups
 12:  */
 13: 
 14: /*class Horde_Form_Renderer_QuerySetCurrentType extends Horde_Form_Renderer {
 15: 
 16:     function _renderForm(&$form, &$vars, $isActive)
 17:     {
 18:         global $whups_driver;
 19: 
 20:         $droptext = Horde_Core_Ui_VarRenderer_html::selectOptions($whups_driver->getAllTypes());
 21:         include WHUPS_TEMPLATES . '/renderer/querysetcurrenttype.inc';
 22:     }
 23: 
 24:     function submit()
 25:     {
 26:         // noop
 27:     }
 28: }*/
 29: 
 30: class Whups_Form_Renderer_Query extends Horde_Form_Renderer
 31: {
 32:     public $ticketTypes = null;
 33: 
 34:     public $attributes = null;
 35: 
 36:     function __construct()
 37:     {
 38:         $this->ticketTypes = $GLOBALS['whups_driver']->getAllTypes();
 39:         $this->attributes = $GLOBALS['whups_driver']->getAllAttributes();
 40:     }
 41: 
 42:     protected function _renderBegin()
 43:     {
 44:         echo '<table class="item">';
 45:     }
 46: 
 47:     /**
 48:      * @TODO: this is public becuase the parent:: method is public
 49:      */
 50:     public function _renderForm(&$query, &$vars, $active)
 51:     {
 52:         $this->currentRow = 1;
 53:         $this->isActive = $active;
 54:         $this->currentPath = $vars->get('path');
 55: 
 56:         $this->_renderBegin();
 57:         $query->walk($this, '_renderRow');
 58:         $this->_renderEnd();
 59:     }
 60: 
 61:     public function edit(&$operations, $formname, $id)
 62:     {
 63:         include WHUPS_TEMPLATES . '/renderer/query/edit.inc';
 64:     }
 65: 
 66:     /**
 67:      * @TODO: This must be public, but method name has underscore.
 68:      */
 69:     public function _renderRow(&$more, &$path, $type, $criterion, $cvalue, $operator, $value)
 70:     {
 71:         global $whups_driver, $registry;
 72: 
 73:         $this->currentRow++;
 74: 
 75:         $pathstring = Whups_Query::pathToString($path);
 76: 
 77:         $depth = count($path);
 78:         $class = "item" . ($this->currentRow % 2);
 79: 
 80:         switch ($type) {
 81:         case Whups_Query::TYPE_AND: $text = _("And"); break;
 82:         case Whups_Query::TYPE_OR:  $text = _("Or");  break;
 83:         case Whups_Query::TYPE_NOT: $text = _("Not"); break;
 84:         case Whups_Query::TYPE_CRITERION:
 85: 
 86:             switch ($criterion) {
 87:             case Whups_Query::CRITERION_ID:             $text = _("Id"); break;
 88:             case Whups_Query::CRITERION_OWNERS:         $text = _("Owners"); break;
 89:             case Whups_Query::CRITERION_GROUPS:         $text = _("Groups"); break;
 90:             case Whups_Query::CRITERION_REQUESTER:      $text = _("Requester"); break;
 91:             case Whups_Query::CRITERION_ADDED_COMMENT:  $text = _("Commentor"); break;
 92:             case Whups_Query::CRITERION_COMMENT:        $text = _("Comment"); break;
 93:             case Whups_Query::CRITERION_SUMMARY:        $text = _("Summary"); break;
 94: 
 95:             case Whups_Query::CRITERION_QUEUE:
 96:                 $queue = $whups_driver->getQueue($value);
 97:                 if ($queue) {
 98:                     $text = _("Queue");
 99:                     $value = $queue['name'];
100:                 }
101:                 break;
102: 
103:             case Whups_Query::CRITERION_VERSION:
104:                 $version = $whups_driver->getVersion($value);
105:                 if ($version) {
106:                     $text = _("Version");
107:                     $value = $version['name'];
108:                 }
109:                 break;
110: 
111:             case Whups_Query::CRITERION_TYPE:
112:                 $text = _("Type");
113:                 $value = $whups_driver->getTypeName($value);
114:                 break;
115: 
116:             case Whups_Query::CRITERION_STATE:
117:                 // The value of the following depends on the type.
118:                 $state = $whups_driver->getState($value);
119:                 if ($state && isset($this->ticketTypes[$state['type']])) {
120:                     $text = '[' . $this->ticketTypes[$state['type']] . '] ' .
121:                         _("State");
122:                     $value = $state['name'];
123:                 }
124:                 break;
125: 
126:             case Whups_Query::CRITERION_PRIORITY:
127:                 $state = $whups_driver->getPriority($value);
128:                 $text = '[' . $this->ticketTypes[$state['type']] . '] ' .
129:                     _("Priority");
130:                 $value = $state['name'];
131:                 break;
132: 
133:             case Whups_Query::CRITERION_ATTRIBUTE:
134:                 // The value of the following depends on the type.
135:                 $aname = $whups_driver->getAttributeName($cvalue);
136:                 foreach ($this->attributes as $attribute) {
137:                     if ($attribute['attribute_id'] == $cvalue) {
138:                         $type = $attribute['type_id'];
139:                         break;
140:                     }
141:                 }
142:                 if (isset($this->ticketTypes[$type])) {
143:                     $aname .= ' (' . $this->ticketTypes[$type] . ')';
144:                 }
145:                 $text = sprintf("Attribute \"%s\"", $aname);
146:                 break;
147: 
148:             case Whups_Query::CRITERION_TIMESTAMP:
149:                 $text = _("Created");
150:                 $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
151:                 break;
152: 
153:             case Whups_Query::CRITERION_UPDATED:
154:                 $text = _("Updated");
155:                 $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
156:                 break;
157: 
158:             case Whups_Query::CRITERION_RESOLVED:
159:                 $text = _("Resolved");
160:                 $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
161:                 break;
162: 
163:             case Whups_Query::CRITERION_ASSIGNED:
164:                 $text = _("Assigned");
165:                 $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
166:                 break;
167: 
168:             case Whups_Query::CRITERION_DUE:
169:                 $text = _("Due");
170:                 $value = strftime($GLOBALS['prefs']->getValue('report_time_format'), $value);
171:                 break;
172:             }
173: 
174:             if (!isset($text)) {
175:                 $text = sprintf(_("Unknown node type %s"), $type);
176:                 break;
177:             }
178: 
179:             $text .= ' ';
180: 
181:             switch ($operator) {
182:             case Whups_Query::OPERATOR_GREATER:
183:                 $text .= _("is greater than");
184:                 break;
185: 
186:             case Whups_Query::OPERATOR_LESS:
187:                 $text .= _("is less than");
188:                 break;
189: 
190:             case Whups_Query::OPERATOR_EQUAL:
191:                 $text .= _("is");
192:                 break;
193: 
194:             case Whups_Query::OPERATOR_CI_SUBSTRING:
195:                 $text .= _("contains (case insensitive) substring");
196:                 break;
197: 
198:             case Whups_Query::OPERATOR_CS_SUBSTRING:
199:                 $text .= _("contains (case sensitive) substring");
200:                 break;
201: 
202:             case Whups_Query::OPERATOR_WORD:
203:                 $text .= _("contains the word");
204:                 break;
205: 
206:             case Whups_Query::OPERATOR_PATTERN:
207:                 $text .= _("matches the pattern");
208:                 break;
209:             }
210: 
211:             $text .= " $value";
212:             break;
213: 
214:         default:
215:             $text = sprintf(_("Unknown node type %s"), $type);
216:             break;
217:         }
218: 
219:         // Stick vertical-align: middle; on everything to make it look a
220:         // little nicer.
221:         $fimgattrs = 'height="20" width="0" style="vertical-align: middle;"';
222:         $imgattrs = 'height="20" width="20" style="vertical-align: middle;"';
223: 
224:         $space = '';
225:         $count = count($more);
226: 
227:         if ($count == 0) {
228:             // Always have at least one image to make sure all rows are the
229:             // same height.
230:             $space = Horde::img('tree/blank.png', '', $fimgattrs) . "\n";
231:         } else {
232:             for ($i = 0; $i < $count - 1; $i++) {
233:                 if ($more[$i] == 1) {
234:                     $space .= Horde::img('tree/line.png', '|', $imgattrs) . "\n";
235:                 } else {
236:                     $space .= Horde::img('tree/blank.png', '', $imgattrs) . "\n";
237:                 }
238:             }
239:         }
240: 
241:         if ($count > 0) {
242:             if ($more[$count - 1] == 1) {
243:                 $space .= Horde::img('tree/join.png', '+', $imgattrs) . "\n";
244:             } else {
245:                 $space .= Horde::img('tree/joinbottom.png', '-', $imgattrs) . "\n";
246:             }
247:         }
248: 
249:         $extra  = ($this->isActive ? '' : ' disabled="disabled"');
250:         $extra .= ($pathstring == $this->currentPath ? ' checked="checked"' : '');
251:         include WHUPS_TEMPLATES . '/renderer/query/render.inc';
252:     }
253: 
254:     /**
255:      * @TODO: This needs to stay public for now since Horde_Form_Renderer::
256:      *        has it as public.
257:      */
258:     public function _renderEnd()
259:     {
260:         echo '</table>';
261:     }
262: 
263: }
264: 
API documentation generated by ApiGen