PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/modules/user/components/UHtml.php

https://gitlab.com/Griffolion/Final-Year-Project
PHP | 190 lines | 149 code | 26 blank | 15 comment | 19 complexity | 01538d81eda612fdf4b93c733d91ca2b MD5 | raw file
  1. <?php
  2. class UHtml extends CHtml
  3. {
  4. public static function activeTimeField($model,$attribute,$htmlOptions=array())
  5. {
  6. // SET UP ARRAYS OF OPTIONS FOR DAY, MONTH, YEAR
  7. $x = 0;
  8. $hourOptions = array('0'=>' - ');
  9. while ($x < 24)
  10. {
  11. $hourOptions[$x] = (($x<10)?'0':'').$x;
  12. $x++;
  13. }
  14. $x = 0;
  15. $minuteOptions = array('0'=>' - ');
  16. while ($x < 61)
  17. {
  18. $minuteOptions[$x] = (($x<10)?'0':'').$x;
  19. $x++;
  20. }
  21. $x = 0;
  22. $secondOptions = array('0'=>' - ');
  23. while ($x < 61)
  24. {
  25. $secondOptions[$x] = (($x<10)?'0':'').$x;
  26. $x++;
  27. }
  28. $x = 1;
  29. $dayOptions = array('0'=>' - ');
  30. while ($x < 31)
  31. {
  32. $dayOptions[$x] = $x;
  33. $x++;
  34. }
  35. $monthOptions = array(
  36. '0' => ' - ',
  37. '1'=> UserModule::t('January'),
  38. '2'=> UserModule::t('February'),
  39. '3'=> UserModule::t('March'),
  40. '4'=> UserModule::t('April'),
  41. '5'=> UserModule::t('May'),
  42. '6'=> UserModule::t('June'),
  43. '7'=> UserModule::t('July'),
  44. '8'=> UserModule::t('August'),
  45. '9'=> UserModule::t('September'),
  46. '10'=> UserModule::t('October'),
  47. '11'=> UserModule::t('November'),
  48. '12'=> UserModule::t('December'),
  49. );
  50. $yearOptions = array('0'=>' - ');
  51. $x = 1901;
  52. while ($x < 2030)
  53. {
  54. $yearOptions[$x] = $x;
  55. $x++;
  56. }
  57. parent::resolveNameID($model,$attribute,$htmlOptions);
  58. if (is_array($model->$attribute)) {
  59. $arr = $model->$attribute;
  60. $model->$attribute = mktime($arr['hour'],$arr['minute'],$arr['second'],$arr['month'],$arr['day'],$arr['year']);
  61. }
  62. if ($model->$attribute != '0' && isset($model->$attribute))
  63. {
  64. //echo "<pre>"; print_r(date('Y-m-d',$model->$attribute)); die();
  65. // intval removes leading zero
  66. $day = intval(date('j',$model->$attribute));
  67. $month = intval(date('m',$model->$attribute));
  68. $year = intval(date('Y',$model->$attribute));
  69. $hour = intval(date('H',$model->$attribute));
  70. $minute = intval(date('i',$model->$attribute));
  71. $second = intval(date('s',$model->$attribute));
  72. } else
  73. {
  74. // DEFAULT TO 0 IF THERE IS NO DATE SET
  75. $day = intval(date('j',time()));
  76. $month = intval(date('m',time()));
  77. $year = intval(date('Y',time()));
  78. $hour = intval(date('H',time()));
  79. $minute = intval(date('i',time()));
  80. $second = intval(date('s',time()));
  81. /*
  82. $day = 0;
  83. $month = 0;
  84. $year = 0;
  85. $hour = 0;
  86. $minute = 0;
  87. $second = 0;//*/
  88. }
  89. $return = parent::dropDownList($htmlOptions['name'].'[day]', $day,$dayOptions);
  90. $return .= parent::dropDownList($htmlOptions['name'].'[month]', $month,$monthOptions);
  91. $return .= parent::dropDownList($htmlOptions['name'].'[year]', $year,$yearOptions);
  92. $return .= ' Time:';
  93. $return .= parent::dropDownList($htmlOptions['name'].'[hour]', $hour,$hourOptions);
  94. $return .= parent::dropDownList($htmlOptions['name'].'[minute]', $minute,$minuteOptions);
  95. $return .= parent::dropDownList($htmlOptions['name'].'[second]', $second,$secondOptions);
  96. return $return;
  97. }
  98. public static function activeDateField($model,$attribute,$htmlOptions=array())
  99. {
  100. // SET UP ARRAYS OF OPTIONS FOR DAY, MONTH, YEAR
  101. $x = 1;
  102. $dayOptions = array('00'=>' - ');
  103. while ($x < 31)
  104. {
  105. $dayOptions[(($x<10)?'0':'').$x] = $x;
  106. $x++;
  107. }
  108. $monthOptions = array(
  109. '00' => ' - ',
  110. '01'=> UserModule::t('January'),
  111. '02'=> UserModule::t('February'),
  112. '03'=> UserModule::t('March'),
  113. '04'=> UserModule::t('April'),
  114. '05'=> UserModule::t('May'),
  115. '06'=> UserModule::t('June'),
  116. '07'=> UserModule::t('July'),
  117. '08'=> UserModule::t('August'),
  118. '09'=> UserModule::t('September'),
  119. '10'=> UserModule::t('October'),
  120. '11'=> UserModule::t('November'),
  121. '12'=> UserModule::t('December'),
  122. );
  123. $yearOptions = array('0000'=>' - ');
  124. $x = 1901;
  125. while ($x < 2030)
  126. {
  127. $yearOptions[$x] = $x;
  128. $x++;
  129. }
  130. parent::resolveNameID($model,$attribute,$htmlOptions);
  131. if ($model->$attribute != '0000-00-00' && isset($model->$attribute))
  132. {
  133. if (is_array($model->$attribute)) {
  134. $new = $model->$attribute;
  135. $day = $new['day'];
  136. $month = $new['month'];
  137. $year = $new['year'];
  138. } else {
  139. $new = explode('-',$model->$attribute);
  140. // intval removes leading zero
  141. $day = $new[2];
  142. $month = $new[1];
  143. $year = $new[0];
  144. }
  145. } else {
  146. // DEFAULT TO 0 IF THERE IS NO DATE SET
  147. $day = '00';
  148. $month = '00';
  149. $year = '0000';
  150. }
  151. //echo "<pre>"; print_r(array($day,$month,$year)); die();
  152. $return = parent::dropDownList($htmlOptions['name'].'[day]', $day,$dayOptions);
  153. $return .= parent::dropDownList($htmlOptions['name'].'[month]', $month,$monthOptions);
  154. $return .= parent::dropDownList($htmlOptions['name'].'[year]', $year,$yearOptions);
  155. return $return;
  156. }
  157. public static function markSearch($model,$field,$prefix='<strong>',$sufix='</strong>') {
  158. $className = get_class($model);
  159. if (isset($_GET[$className][$field])&&$_GET[$className][$field])
  160. return str_replace($_GET[$className][$field],$prefix.$_GET[$className][$field].$sufix,$model->getAttribute($field));
  161. else
  162. return $model->getAttribute($field);
  163. }
  164. }