Copyright 2003-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Jason M. Felice (jason.m.felice@gmail.com)
Inheritance: extends Horde_Core_Ui_VarRenderer
Example #1
0
 /**
  * Fetch ticket history
  *
  * @param integer $ticket_id  The ticket to fetch history for.
  *
  * @return array
  */
 public function getHistory($ticket_id, Horde_Form $form = null)
 {
     $rows = $this->_getHistory($ticket_id);
     $attributes = $attributeDetails = array();
     foreach ($rows as $row) {
         if ($row['log_type'] == 'attribute' && strpos($row['log_value'], ':')) {
             $attributes[(int) $row['log_value']] = $row['attribute_name'];
         }
         if ($row['log_type'] == 'type') {
             $attributeDetails += $this->getAttributesForType($row['log_value']);
         }
     }
     $renderer = new Horde_Core_Ui_VarRenderer_Html();
     $history = array();
     foreach ($rows as $row) {
         $label = null;
         $human = $value = $row['log_value'];
         $type = $row['log_type'];
         $transaction = $row['transaction_id'];
         $history[$transaction]['timestamp'] = $row['timestamp'];
         $history[$transaction]['user_id'] = $row['user_id'];
         $history[$transaction]['ticket_id'] = $row['ticket_id'];
         switch ($type) {
             case 'comment':
                 $history[$transaction]['comment'] = $row['comment_text'];
                 $history[$transaction]['changes'][] = array('type' => 'comment', 'value' => $row['log_value'], 'comment' => $row['comment_text']);
                 continue 2;
             case 'queue':
                 $label = $row['queue_name'];
                 break;
             case 'version':
                 $label = $row['version_name'];
                 break;
             case 'type':
                 $label = $row['type_name'];
                 break;
             case 'state':
                 $label = $row['state_name'];
                 break;
             case 'priority':
                 $label = $row['priority_name'];
                 break;
             case 'attribute':
                 continue 2;
             case 'due':
                 $label = $row['log_value_num'];
                 break;
             default:
                 if (strpos($type, 'attribute_') === 0) {
                     try {
                         $value = Horde_Serialize::unserialize($value, Horde_Serialize::JSON);
                     } catch (Horde_Serialize_Exception $e) {
                     }
                     $attribute = substr($type, 10);
                     if (isset($attributes[$attribute])) {
                         $label = $attributes[$attribute];
                         if ($form) {
                             if (isset($form->attributes[$attribute])) {
                                 /* Attribute is part of the current type, so we
                                  * have the form field in the current form. */
                                 $field = $form->attributes[$attribute];
                             } else {
                                 /* Attribute is from a different type, create
                                  * the form field manually. */
                                 $detail = $attributeDetails[$attribute];
                                 $field = new Horde_Form_Variable($detail['human_name'], $type, $form->getType($detail['type'], $detail['params']), $detail['required'], $detail['readonly'], $detail['desc']);
                             }
                             $human = $renderer->render($form, $field, new Horde_Variables(array($type => $value)));
                         }
                         $type = 'attribute';
                     } else {
                         $label = sprintf(_("Attribute %d"), $attribute);
                     }
                 }
                 break;
         }
         $history[$transaction]['changes'][] = array('type' => $type, 'value' => $value, 'human' => $human, 'label' => $label);
     }
     return $history;
 }
Example #2
0
 /**
  * Render the table.
  *
  * @param array $data  The data to render (unused).
  *
  * @return mixed The HTML needed to render the table or false if failed.
  */
 public function render($data = null)
 {
     global $notification;
     try {
         $result = $this->getMetaData();
     } catch (Hermes_Exception $e) {
         $notification->push($e->getMessage(), 'horde.error');
         return false;
     }
     $varRenderer = new Horde_Core_Ui_VarRenderer_Html();
     $html = '<h1 class="header">';
     // Table title.
     if (isset($this->_config['title'])) {
         $html .= $this->_config['title'];
     } else {
         $html .= _("Table");
     }
     // Hook for icons and things
     if (isset($this->_config['title_extra'])) {
         $html .= $this->_config['title_extra'];
     }
     $html .= '</h1>';
     // Column titles.
     $html .= '<table class="time striped" id="hermes_time" cellspacing="0"><thead><tr class="item">';
     foreach ($this->_metaData['sections']['data']['columns'] as $col) {
         $html .= '<th' . (isset($col['colspan']) ? ' colspan="' . $col['colspan'] . '"' : '') . '>' . $col['title'] . '</th>';
     }
     $html .= '</tr></thead>';
     // Display data.
     try {
         $data = $this->_getData();
     } catch (Hermes_Exception $e) {
         $notification->push($e, 'horde.error');
         $data = array();
     }
     foreach ($this->_metaData['sections'] as $secname => $section) {
         if (empty($data[$secname])) {
             continue;
         }
         /* Open the table section, either a tbody or the tfoot. */
         $html .= $secname == 'footer' ? '<tfoot>' : '<tbody>';
         // This Horde_Variables object is populated for each table row
         // so that we can use the Horde_Core_Ui_VarRenderer.
         $vars = new Horde_Variables();
         $form = null;
         foreach ($data[$secname] as $row) {
             $html .= '<tr>';
             foreach ($row as $key => $value) {
                 $vars->set($key, $value);
             }
             foreach ($section['columns'] as $col) {
                 $value = null;
                 if (isset($row[$col['name']])) {
                     $value = $row[$col['name']];
                 }
                 $align = '';
                 if (isset($col['align'])) {
                     $align = ' align="' . htmlspecialchars($col['align']) . '"';
                 }
                 $colspan = '';
                 if (isset($col['colspan'])) {
                     $colspan = ' colspan="' . htmlspecialchars($col['colspan']) . '"';
                 }
                 $html .= "<td{$align}{$colspan}";
                 if (!empty($col['nobr'])) {
                     $html .= ' class="nowrap"';
                 }
                 $html .= '>';
                 // XXX: Should probably be done at the <tr> with a class.
                 if (!empty($row['strong'])) {
                     $html .= '<strong>';
                 }
                 if (isset($col['type']) && substr($col['type'], 0, 1) == '%') {
                     switch ($col['type']) {
                         case '%html':
                             if (!empty($row[$col['name']])) {
                                 $html .= $row[$col['name']];
                             }
                             break;
                     }
                 } else {
                     $html .= $varRenderer->render($form, $this->_formVars[$secname][$col['name']], $vars);
                 }
                 if (!empty($row['strong'])) {
                     $html .= '</strong>';
                 }
                 $html .= '</td>';
             }
             $html .= '</tr>';
         }
         // Close the table section.
         $html .= $secname == 'footer' ? '</tfoot>' : '</tbody>';
     }
     $GLOBALS['page_output']->addScriptFile('stripe.js', 'horde');
     return $html . '</table>';
 }
Example #3
0
 public function __construct($params = array())
 {
     parent::__construct($params);
     // This will autoload the class.
     class_exists('Ingo_Form_Type_Longemail');
 }