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