Source for file UIUtil.php

Documentation is available at UIUtil.php

  1. <?php
  2.     /**
  3.      * User Interface Util Class
  4.      *
  5.      * @copyright Copyright (c) 2003, 2007 Mirchev Ideas Ltd. All rights reserved.
  6.      * @package MIPHPF
  7.      */
  8.  
  9.     /**
  10.      * Offer same often used user interface functions
  11.      *
  12.      * @copyright Copyright (c) 2003-2007 Mirchev Ideas Ltd. All rights reserved.
  13.      * @package MIPHPF
  14.      */
  15.     class miUIUtil {
  16.         
  17.         /**
  18.          * Returns HTML code for a dropdown menu ("select" element) from the specified array
  19.          * 
  20.          * @access public
  21.          * @param string $name name of the select element
  22.          * @param int $selected which key is selected
  23.          * @param array $optionsArray array whit the dropdown menu elements values
  24.          */
  25.         public static function &getConstDropdown($name, $selected, $optionsArray)
  26.         {
  27.             $html = '<select name="' . $name . '" id="' . $name . '">' . "\n";
  28.             $selected = (string)$selected;
  29.             foreach ($optionsArray as $key => $value)
  30.                 $html .= '<option value="' . miI18N::htmlEscape($key) . '"' . ((string)$key === $selected?' selected="selected"':'') . '>' . miI18N::htmlEscape($value) . '</option>' . "\n";
  31.             $html .= '</select>' . "\n";
  32.             return $html;
  33.         }
  34.         
  35.         /**
  36.          * Creates drop-down filter
  37.          * The filter is applied to the $table
  38.          * 
  39.          * @access public
  40.          * @param miView $view 
  41.          * @param miTable $table the table to apply the filter to
  42.          * @param string $field the field name
  43.          * @param array $values associative array with the values of the filter
  44.          * @param string $condition the filter condition
  45.          */
  46.         public static function createDropdownFilter(miView $view, miTable $table, $field, $values, $condition)
  47.         {
  48.             $filterObj = $view->getTableFilterObj();
  49.             $filterValues = $filterObj->getFilterValues();
  50.             $defaultValue = isset($filterValues[$field]) ? $filterValues[$field] : '';
  51.             
  52.             // Make sure that the filter is applied
  53.             if (!isset($_REQUEST[$field . 'Filter']))
  54.                 $filterObj->addAdditionalFilter($field, $defaultValue, $condition);
  55.             
  56.             $dropdown = miUIUtil::getConstDropdown($field . 'Filter', $defaultValue, $values);
  57.             $condition = '<input type="hidden" name="' . miI18N::htmlEscape($field) . 'Condition" value="' . miI18N::htmlEscape($condition) . '"/>';
  58.             $table->assign('%%HTML_' . strtoupper($field) . '_FILTER%%', $dropdown . $condition);
  59.         }
  60.         
  61.         /**
  62.          * Transposes the $rows array from array of hashes into a hash of
  63.          * arrays. All values will have the &, ", < and > escaped, except
  64.          * the values for keys starting with HTML_
  65.          * 
  66.          * @access public
  67.          * @param array $rows readed rows from the database
  68.          * @return array array with the new transposed rows
  69.          */
  70.         public static function transposeRows($rows)
  71.         {
  72.             $newArray = array();
  73.             
  74.             $count = count($rows);
  75.             if ($count == 0)
  76.                 return $newArray;
  77.             
  78.             foreach ($rows[0] as $key => $row) {
  79.                     if (strncmp($key, 'HTML_', 5)) {
  80.                         for ($i=0; $i < $count; $i++)
  81.                             $newArray[$key][] = $rows[$i][$key];
  82.                         $newArray[$key] = miI18N::htmlEscape($newArray[$key]);
  83.                     } else {
  84.                         for ($i=0; $i < $count; $i++)
  85.                             $newArray[$key][] = $rows[$i][$key];
  86.                     }
  87.             }
  88.             return $newArray;
  89.         }
  90.         
  91.         /**
  92.          * Makes the hash of arrays $rows suitable for the miTemplateParserSectionInfo values
  93.          * 
  94.          * @access public
  95.          * @param array $rows transposed rows read from the database
  96.          * @return array 
  97.          */
  98.         public static function templetizeRows($rows)
  99.         {
  100.             $newRows = array();
  101.             foreach ($rows as $key => $row) {
  102.                 $newRows['%%' . strtoupper($key) . '%%'] = $row;
  103.             }
  104.             return $newRows;
  105.         }
  106.         
  107.         /**
  108.          * Makes the hash of arrays $rows suitable for the miTemplateParserSectionInfo values
  109.          * 
  110.          * @access public
  111.          * @param array $rows transposed rows read from the database
  112.          * @return array 
  113.          */
  114.         public static function templetizeAndEscapeRows($rows)
  115.         {
  116.             $newRows = array();
  117.             foreach ($rows as $key => $row) {
  118.                 if (strncmp($key, 'HTML_', 5))
  119.                     $newRows['%%' . strtoupper($key) . '%%'] = miI18N::htmlEscape($row);
  120.                 else
  121.                     $newRows['%%' . strtoupper($key) . '%%'] = $row;
  122.             }
  123.             return $newRows;
  124.         }
  125.     }
  126. ?>

Documentation generated on Thu, 08 May 2008 16:57:51 +0300 by phpDocumentor 1.4.1