Source for file timeinfo.php

Documentation is available at timeinfo.php

  1. <?php
  2. /**
  3. * Class helpDeskTimeInfo
  4. * @package helpdesk
  5. * Copyright OSI 2005. All rights reserved.
  6. * It is expected that version 1.0 will be GPLed, but this interim work
  7. * is kept closed until 1.0 is ready.
  8. */
  9. // echo "<p>Start of " . __FILE__ . "</p>" ;
  10. $_timeinfo_saved_er = error_reporting (E_ALL | E_STRICT) ;
  11.  
  12. /**
  13. * import ancillary functions
  14. */
  15. require_once("misc.php") ;
  16.  
  17. /**
  18. * import HD core
  19. */
  20. require_once("core.php");
  21.  
  22. /**
  23. * VIEW: Time value, drupal style
  24. * @subpackage helpdesk_time
  25. */
  26. class helpdeskTimeValue
  27. {
  28. /**
  29. * POSIX timestamp
  30. * @var integer
  31. */
  32. public $ts ;
  33. /**
  34. * is it to be displayed in views/forms
  35. * @var boolean
  36. */
  37. public $isShown ;
  38. /**
  39. * is it to be enabled in forms
  40. * @var boolean
  41. */
  42. public $isEnabled;
  43. /**
  44. * HTML render size in forms
  45. * @var integer
  46. */
  47. public $size;
  48. /**
  49. * HTML max length in forms
  50. * @var integer
  51. */
  52. public $maxLength;
  53. /**
  54. * format code for drupal's format_date
  55. * @var string
  56. * @see http://drupaldocs.org/api/4.6/function/format_date API
  57. */
  58. public $format;
  59. /**
  60. * HTML name attribute in forms
  61. * @var string
  62. */
  63. public $name ;
  64.  
  65. /**
  66. * Init default value: beware, they are mutually dependent
  67. * @return void
  68. */
  69. function __construct()
  70. {
  71. $this->size = 16 ;
  72. $this->maxLength = 16 ;
  73. $this->format = 'small' ; // do not localize
  74. }
  75.  
  76. /**
  77. * formats a time value for the use of a form
  78. * 0 or empty displayed as empty
  79. * @return string HTML for form field
  80. */
  81. function form_field ()
  82. {
  83. $disabled = array ('disabled' => 'disabled') ; // Do not localize !
  84. if (isset($this->ts) && ($this->ts > 0))
  85. $ret = format_date($this->ts, $this->format) ;
  86. else
  87. $ret = '' ;
  88. $ret = form_textfield(
  89. '',
  90. $this->name,
  91. $ret,
  92. $this->size,
  93. $this->maxLength,
  94. NULL,
  95. ($this->isEnabled ? NULL : $disabled),
  96. TRUE) ;
  97.  
  98. return $ret;
  99. }
  100. }
  101.  
  102. //===========================================================================================
  103.  
  104. /**
  105. * TimeInfo class implementing S.A.M.E. properties
  106. * @subpackage helpdesk_time
  107. */
  108. class helpdeskTimeInfo extends helpdeskObject
  109. {
  110. /**
  111. * Indexed array of S.A.M.E. helpdeskTimeValues
  112. * @var array
  113. */
  114. public $values ;
  115. /**
  116. * Title when TI is displayed in a form
  117. * @var string plain text
  118. */
  119. public $title ;
  120. /**
  121. * description for forms
  122. * @var string
  123. */
  124. public $description;
  125.  
  126. /**
  127. * Enumerate S.A.M.E. properties.
  128. * Defining the array as a global doesn't work (why?) so
  129. * I return this from a method. It belongs in the class anyway
  130. * @return array
  131. */
  132. function enumKeys ()
  133. {
  134. return array('S', 'A', 'M', 'E') ;
  135. }
  136.  
  137. /**
  138. * Enumerate the titles of the S.A.M.E. properties
  139. * @return array
  140. */
  141. function enumKeyTitles ()
  142. {
  143. return array('S' => t('Start'), 'A' => t('Access'), 'M' => t('Modify'), 'E' => t('End'));
  144. }
  145. /**
  146. * constructor MUST run to initialize SAME array
  147. * @return void
  148. */
  149. function __construct()
  150. {
  151. $this->values = array();
  152. foreach ($this->enumKeys() as $key)
  153. $this->values[$key] = new helpdeskTimeValue();
  154. }
  155. /**
  156. * initialize fields in existing timeinfo from param array
  157. * @param array $ar S.A.M.E. timestamps. Cheating: it should be an object
  158. * @param boolean $fromDB
  159. * @return void
  160. */
  161. function init($ar, $fromDB)
  162. {
  163. foreach ($this->enumKeys() as $key)
  164. {
  165. $this->values[$key]->ts = $ar[ $key ];
  166. $this->values[$key]->isShown = $ar[ "show$key"];
  167. $this->values[$key]->isEnabled = $ar["enabled$key"];
  168. }
  169. }
  170. /**
  171. * Builds the form representation of a helpdesk_timeinfo
  172. * @param boolean $enabledS If function show the S column, is it enabled ?
  173. * @return string HTML form code
  174. */
  175. function form()
  176. {
  177. $ret = '' ;
  178. $header = array () ;
  179. $row = array () ;
  180. foreach ($this->enumKeyTitles() as $key => $value)
  181. {
  182. if ($this->values[$key]->isShown)
  183. {
  184. array_push ($header, $value) ;
  185. array_push ($row, $this->values[$key]->form_field()) ;
  186. }
  187. }
  188. $items = theme_table ($header, array ($row));
  189.  
  190. $ret .= form_group
  191. (
  192. $this->title,
  193. $items,
  194. $this->description,
  195. NULL) ;
  196. unset ($items) ;
  197. return $ret ;
  198. }
  199. /**
  200. * display a timeinfo, typically for hook_view
  201. * @return string HTML
  202. */
  203. function view()
  204. {
  205. $header = array();
  206. foreach ($this->enumKeys() as $key)
  207. {
  208. if ($this->values[$key]->isShown)
  209. { $header[] = $this->values[$key] ; }
  210. }
  211. $output = theme_table($header, NULL);
  212. return $output;
  213. }
  214. }
  215. error_reporting($_timeinfo_saved_er) ;
  216. unset ($_timeinfo_saved_er) ;
  217.  
  218. // echo "<p>End of " . __FILE__ . "</p>" ;
  219. ?>

Documentation generated on Tue, 01 Nov 2005 23:15:03 +0100 by phpDocumentor 1.3.0RC3