Tabs
1 year ago
DSTemplate.php
1 year ago
DailyTimetablePrinter.php
1 year ago
DptApiDoc.php
2 years ago
HelpsAndTips.php
3 years ago
MonthlyTimetablePrinter.php
1 year ago
TimetablePrinter.php
1 year ago
dptWidgetForm.php
4 years ago
horizontal-div.php
1 year ago
widget-admin.php
1 year ago
DailyTimetablePrinter.php
421 lines
| 1 | <?php |
| 2 | require_once( 'TimetablePrinter.php' ); |
| 3 | require_once(__DIR__ . '/../Models/DPTHelper.php'); |
| 4 | |
| 5 | class DailyTimetablePrinter extends TimetablePrinter |
| 6 | { |
| 7 | /** @var DPTHelper */ |
| 8 | protected $dptHelper; |
| 9 | |
| 10 | public function __construct() |
| 11 | { |
| 12 | parent::__construct(); |
| 13 | $this->localPrayerNames = $this->getLocalPrayerNames(false, true); |
| 14 | $this->dptHelper = new DPTHelper(); |
| 15 | } |
| 16 | |
| 17 | public function horizontalTimeDiv($row) |
| 18 | { |
| 19 | ob_start(); |
| 20 | include 'horizontal-div.php'; |
| 21 | return ob_get_clean(); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @param $row |
| 26 | * @return string |
| 27 | */ |
| 28 | public function printHorizontalTime($row) |
| 29 | { |
| 30 | $table = $this->printHorizontalTableTop( $row ); |
| 31 | |
| 32 | $table .= ' |
| 33 | <tr> |
| 34 | <th class="tableHeading prayerName">' . $this->localHeaders['prayer'] . '</th>' |
| 35 | . $this->printTableHeading($row) . |
| 36 | '</tr> |
| 37 | <tr> |
| 38 | <th class="tableHeading">' .$this->localHeaders['begins']. '</th>' |
| 39 | .$this->printAzanTime($row). |
| 40 | '</tr> |
| 41 | <tr><th class="tableHeading">' .$this->localHeaders['iqamah']. '</th>' |
| 42 | .$this->printJamahTime($row, false). |
| 43 | '</tr>'; |
| 44 | |
| 45 | if ( get_option('jumuah1') && ! $this->todayIsFriday() ) { |
| 46 | $table .= '<tr> |
| 47 | <th class="tableHeading">' . stripslashes($this->getLocalHeaders()['jumuah']) . '</th> |
| 48 | <td colspan="6" class="jamah">' . $this->getJumuahTimesArray() . '</td> |
| 49 | </tr>'; |
| 50 | } |
| 51 | |
| 52 | $table .= '</table>'; |
| 53 | |
| 54 | return $table; |
| 55 | } |
| 56 | |
| 57 | public function horizontalTimeJamahOnly($row) |
| 58 | { |
| 59 | $table = $this->printHorizontalTableTop( $row ); |
| 60 | |
| 61 | $table .= ' |
| 62 | <tr><th>' .$this->localHeaders['prayer']. '</th>' |
| 63 | . $this->printTableHeading($row) . |
| 64 | '</tr> |
| 65 | <tr> |
| 66 | <th>'.$this->localHeaders['iqamah'].'</th>' |
| 67 | .$this->printJamahTime($row). |
| 68 | '</tr> |
| 69 | </table>'; |
| 70 | |
| 71 | return $table; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param $row |
| 76 | * |
| 77 | * @return string |
| 78 | */ |
| 79 | public function horizontalTimeAzanOnly($row) |
| 80 | { |
| 81 | $table = $this->printHorizontalTableTop( $row, true ); |
| 82 | |
| 83 | $table .= ' |
| 84 | <tr><th>' .$this->localHeaders['prayer']. '</th>' |
| 85 | . $this->printTableHeading($row) . |
| 86 | '</tr> |
| 87 | <tr> |
| 88 | <th>'.$this->localHeaders['begins'].'</th>' |
| 89 | .$this->printAzanTime($row). |
| 90 | '</tr> |
| 91 | </table>'; |
| 92 | |
| 93 | return $table; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @param $row |
| 98 | * @return string |
| 99 | */ |
| 100 | public function printVerticalTime($row) |
| 101 | { |
| 102 | $table = $this->printVerticalTableTop( $row , true); |
| 103 | |
| 104 | $table .= |
| 105 | '<tr> |
| 106 | <th class="tableHeading">' .$this->localHeaders['prayer']. '</th> |
| 107 | <th class="tableHeading">' .$this->localHeaders['begins']. '</th> |
| 108 | <th class="tableHeading">' .$this->localHeaders['iqamah']. '</th> |
| 109 | </tr>' |
| 110 | . $this->printVerticalRow( $row, 'both' ) . |
| 111 | '</table>'; |
| 112 | |
| 113 | return $table; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @param array $row |
| 118 | * @return string |
| 119 | */ |
| 120 | public function verticalTimeJamahOnly($row) |
| 121 | { |
| 122 | $table = $this->printVerticalTableTop( $row ); |
| 123 | |
| 124 | $table .= |
| 125 | '<tr> |
| 126 | <th class="tableHeading">' .$this->localHeaders['prayer']. '</th> |
| 127 | <th class="tableHeading">' .$this->localHeaders['iqamah']. '</th> |
| 128 | </tr>' |
| 129 | .$this->printVerticalRow( $row, 'iqamah' ) . |
| 130 | '</table>'; |
| 131 | |
| 132 | return $table; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @param array $row |
| 137 | * @return string |
| 138 | */ |
| 139 | public function verticalTimeAzanOnly($row) |
| 140 | { |
| 141 | $table = $this->printVerticalTableTop( $row, false, true ); |
| 142 | |
| 143 | $table .= |
| 144 | '<tr> |
| 145 | <th class="tableHeading">' .$this->localHeaders['prayer']. '</th> |
| 146 | <th class="tableHeading">' .$this->localHeaders['begins']. '</th> |
| 147 | </tr>' |
| 148 | .$this->printVerticalRow( $row, 'azan' ) . |
| 149 | '</table>'; |
| 150 | |
| 151 | return $table; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * @param $row |
| 156 | * |
| 157 | * @param bool $isAzanOnly |
| 158 | * |
| 159 | * @return string |
| 160 | */ |
| 161 | private function printHorizontalTableTop($row, $isAzanOnly=false) |
| 162 | { |
| 163 | $announcement = ''; |
| 164 | if (! $row['hideTimeRemaining']) { |
| 165 | $nextIqamah = $isAzanOnly == true ? '' : $this->getNextIqamahTime($row); |
| 166 | } |
| 167 | $colspan = 7; |
| 168 | $ramadanTds = '<td></td>'; |
| 169 | |
| 170 | $ramadan = ''; |
| 171 | if ($this->isRamadan() && ! $row['hideRamadan']) { |
| 172 | $ramadan = ' |
| 173 | <tr class=""> |
| 174 | <td colspan="3" class="highlight">'. $this->localHeaders['fast_begins'].': '.$this->formatDateForPrayer($row['fajr_begins'], true).'</td> |
| 175 | '. $ramadanTds . ' |
| 176 | <td colspan="3" class="highlight">'. $this->localHeaders['fast_ends'].': '.$this->formatDateForPrayer($row['maghrib_begins']).'</td> |
| 177 | </tr>'; |
| 178 | } |
| 179 | |
| 180 | if(isset($row['announcement']) && ! empty( $row['announcement'] )) { |
| 181 | $announcement = "<tr><th colspan='".$colspan."' style='text-align:center' class='notificationBackground notificationFont'>".$row['announcement']. "</th></tr>"; |
| 182 | } |
| 183 | |
| 184 | $table = ""; |
| 185 | $table .= |
| 186 | '<table class="customStyles dptUserStyles dptTimetable ' .$this->getTableClass().'"> '.$announcement.' |
| 187 | <tr> |
| 188 | <th colspan="'. $colspan .'" style="text-align:center">' |
| 189 | .$row['widgetTitle']. ' ' . date_i18n( get_option( 'date_format' ) ) .' '. $this->getHijriDate(date("d"), date("m"), date("Y"),$row) .' ' . $nextIqamah .' |
| 190 | </th> |
| 191 | </tr>'. $ramadan; |
| 192 | |
| 193 | return $table; |
| 194 | } |
| 195 | |
| 196 | public function displayRamadanTime($row) |
| 197 | { |
| 198 | return ' <table class="customStyles dptUserStyles"> |
| 199 | <tr style="text-align:center"> |
| 200 | <td colspan="3" class="fasting highlight">'. $this->localHeaders['fast_begins'].': '.$this->formatDateForPrayer($row['fajr_begins'], true).'</td> |
| 201 | <td style="border:0px;"></td> |
| 202 | <td colspan="3" class="fasting highlight">'. $this->localHeaders['fast_ends'].': '.$this->formatDateForPrayer($row['maghrib_begins']).'</td> |
| 203 | </tr></table>'; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * @param $row |
| 208 | * |
| 209 | * @return string |
| 210 | */ |
| 211 | private function printTableHeading($row) |
| 212 | { |
| 213 | $ths = ''; |
| 214 | $nextPrayer = $this->getNextPrayer( $row ); |
| 215 | |
| 216 | $localPrayerNames = $this->localPrayerNames; |
| 217 | |
| 218 | if (get_option('zawal')) { |
| 219 | $localPrayerNames = $this->toggleSunriseZawal($row, $localPrayerNames); |
| 220 | } |
| 221 | foreach ($localPrayerNames as $key=>$prayerName) { |
| 222 | $class = $nextPrayer == $key ? 'highlight' : ''; |
| 223 | $ths .= "<th class='tableHeading prayerName" . $this->tableClass . " ". $class."'>".$prayerName."</th>"; |
| 224 | } |
| 225 | |
| 226 | return $ths; |
| 227 | } |
| 228 | |
| 229 | private function toggleSunriseZawal($row, $prayerNames) |
| 230 | { |
| 231 | if ($this->dptHelper->isZawalTimeNext($row)) { |
| 232 | $prayerNames['sunrise'] = $prayerNames['zawal']; |
| 233 | unset($prayerNames['zawal']); |
| 234 | } |
| 235 | |
| 236 | unset($prayerNames['zawal']); |
| 237 | |
| 238 | return $prayerNames; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * @param $row |
| 243 | * |
| 244 | * @return string |
| 245 | */ |
| 246 | private function printAzanTime($row) |
| 247 | { |
| 248 | $tds = ''; |
| 249 | $nextPrayer = $this->getNextPrayer( $row ); |
| 250 | $azanTimings = $this->getAzanTime( $row ); |
| 251 | |
| 252 | |
| 253 | if (get_option('zawal')) { |
| 254 | if ($this->dptHelper->isZawalTimeNext($row)) { |
| 255 | $azanTimings['sunrise'] = $this->dptHelper->getZawalTime($azanTimings['zuhr']); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | foreach ($azanTimings as $key => $azan) { |
| 260 | |
| 261 | $class = $nextPrayer == $key ? 'class=highlight' : ''; |
| 262 | $rowspan = ''; |
| 263 | if ($key == 'sunrise') |
| 264 | { |
| 265 | $rowspan = "rowspan='2'"; |
| 266 | } |
| 267 | $tds .= "<td ". $rowspan ." ".$class.">".$this->getFormattedDateForPrayer( $azan, $key)."</th>"; |
| 268 | } |
| 269 | |
| 270 | return $tds; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * @param $row |
| 275 | * @param bool $isSunrise |
| 276 | * |
| 277 | * @return string |
| 278 | */ |
| 279 | private function printJamahTime($row, $isSunrise=true) |
| 280 | { |
| 281 | $jamahTimes = $this->getJamahTime( $row ); |
| 282 | if (get_option('zawal')) { |
| 283 | if ($this->dptHelper->isZawalTimeNext($row)) { |
| 284 | $jamahTimes['sunrise'] = $this->dptHelper->getZawalTime($row['zuhr_begins']); |
| 285 | } |
| 286 | } |
| 287 | if (! $isSunrise) { |
| 288 | unset( $jamahTimes['sunrise'] ); |
| 289 | } |
| 290 | |
| 291 | $tds = ''; |
| 292 | $nextPrayer = $this->getNextPrayer( $row ); |
| 293 | foreach ($jamahTimes as $key => $azan) { |
| 294 | $class = $nextPrayer == $key ? 'class=highlight' : 'class=jamah'; |
| 295 | $tds .= "<td ".$class.">".$this->getFormattedDateForPrayer( $azan, $key, true )."</th>"; |
| 296 | } |
| 297 | |
| 298 | return $tds; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * @param $row |
| 303 | * @param bool $isFullTable |
| 304 | * |
| 305 | * @return string |
| 306 | */ |
| 307 | private function printVerticalTableTop($row, $isFullTable=false, $isAzanOnly=false) |
| 308 | { |
| 309 | if (! $row['hideTimeRemaining']) { |
| 310 | $nextIqamah = $isAzanOnly == true ? '' : $this->getNextIqamahTime($row); |
| 311 | } |
| 312 | |
| 313 | $colspan = ( $isFullTable == true ) ? 3 : 2; |
| 314 | |
| 315 | $colspanRamadan = $isFullTable == true ? "colspan='2'" : ''; |
| 316 | |
| 317 | |
| 318 | $ramadan = ''; |
| 319 | if ($this->isRamadan() && ! $row['hideRamadan']) { |
| 320 | $ramadan = ' |
| 321 | <tr> |
| 322 | <th class="highlight">' .$this->localHeaders['fast_begins']. '</th> |
| 323 | <th '.$colspanRamadan.' class="highlight">' .$this->formatDateForPrayer($row['fajr_begins'], true). '</th> |
| 324 | </tr> |
| 325 | <tr> |
| 326 | <th class="highlight">'.$this->localHeaders['fast_ends'].'</th> |
| 327 | <th '.$colspanRamadan.' class="highlight">'.$this->formatDateForPrayer($row['maghrib_begins']).'</th> |
| 328 | </tr> |
| 329 | '; |
| 330 | } |
| 331 | $table = ""; |
| 332 | $announcement = ''; |
| 333 | if(isset($row['announcement']) && ! empty( $row['announcement'] )) { |
| 334 | $announcement = "<tr><th colspan=".$colspan." style='text-align:center' class='notificationBackground notificationFont'>".$row['announcement']. "</th></tr>"; |
| 335 | } |
| 336 | |
| 337 | $table .= |
| 338 | '<table class="dptTimetable ' .$this->getTableClass().' customStyles dptUserStyles"> '.$announcement.' |
| 339 | <tr> |
| 340 | <th colspan='.$colspan.' style="text-align:center">' |
| 341 | .$row['widgetTitle']. ' '. date_i18n( get_option( 'date_format' ) ) .' '. $this->getHijriDate(date("d"), date("m"), date("Y"), $row).'' . $nextIqamah . ' |
| 342 | </th> |
| 343 | </tr>' |
| 344 | .$ramadan; |
| 345 | |
| 346 | return $table; |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * @param $row |
| 351 | * @param $display // i.e both, azan, iqamah |
| 352 | * |
| 353 | * @return string |
| 354 | */ |
| 355 | private function printVerticalRow($row, $display) |
| 356 | { |
| 357 | $trs = ''; |
| 358 | $nextPrayer = $this->getNextPrayer( $row ); |
| 359 | |
| 360 | $localPrayerNames = $this->localPrayerNames; |
| 361 | if (get_option('zawal')) { |
| 362 | if ($this->dptHelper->isZawalTimeNext($row)) { |
| 363 | $localPrayerNames = $this->toggleSunriseZawal($row, $localPrayerNames); |
| 364 | $row['sunrise'] = $this->dptHelper->getZawalTime($row['zuhr_begins']); |
| 365 | } else { |
| 366 | unset($localPrayerNames['zawal']); |
| 367 | } |
| 368 | } else { |
| 369 | unset($localPrayerNames['zawal']); |
| 370 | } |
| 371 | |
| 372 | foreach ($localPrayerNames as $key=>$prayerName) { |
| 373 | $begins = $key != 'sunrise' ? lcfirst( $key ).'_begins' : 'sunrise'; |
| 374 | $jamah = $key != 'sunrise' ? lcfirst( $key ).'_jamah' : 'sunrise'; |
| 375 | |
| 376 | $class = $nextPrayer == $key ? 'highlight' : ''; |
| 377 | $highlightForJamah = $nextPrayer == $key ? 'highlight' : ''; |
| 378 | |
| 379 | $trs .= '<tr> |
| 380 | <th class="prayerName ' .$class.'">' . $prayerName . '</th>'; |
| 381 | if ( ($key == 'sunrise') && $display == 'both') { |
| 382 | $trs .= '<td colspan="2" class="' . $class . '">'.$this->getFormattedDateForPrayer($row[$jamah], $key).'</td>'; |
| 383 | } elseif ($display == 'azan') { |
| 384 | $trs .='<td class="begins '.$class.'">'.$this->getFormattedDateForPrayer($row[$begins], $key).'</td> |
| 385 | </tr>'; |
| 386 | } elseif ($display == 'iqamah') { |
| 387 | $trs .='<td class="begins '.$class.'">'.$this->getFormattedDateForPrayer($row[$jamah], $key, true).'</td> |
| 388 | </tr>'; |
| 389 | } else { |
| 390 | $trs .='<td class="begins '.$class.'">'.$this->getFormattedDateForPrayer($row[$begins], $key).'</td> |
| 391 | <td class="jamah '.$highlightForJamah.'">'.$this->getFormattedDateForPrayer($row[$jamah], $key, true).'</td> |
| 392 | </tr>'; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | if ( get_option('jumuah1') && $display != 'azan' ) { |
| 397 | $trs .= '<tr> |
| 398 | <th class="prayerName"><span>' . stripslashes($this->getLocalHeaders()['jumuah']) . '</span></th> |
| 399 | <td colspan="2" class="jamah">' . $this->getJumuahTimesArray() . '</td> |
| 400 | </tr>'; |
| 401 | } |
| 402 | |
| 403 | return $trs; |
| 404 | } |
| 405 | |
| 406 | private function getFormattedDateForPrayer($time, $prayerName, $isJamatTime=false) |
| 407 | { |
| 408 | // $jumuahTime = get_option('jumuah1'); |
| 409 | // if ( ($prayerName === 'zuhr' && $this->todayIsFriday()) && $isJamatTime && $jumuahTime) { |
| 410 | // return $this->getJumuahTimesArray(); |
| 411 | // } |
| 412 | return $this->formatDateForPrayer($time); |
| 413 | } |
| 414 | |
| 415 | public function displayNextPrayer($row) |
| 416 | { |
| 417 | return $this->getNextIqamahTime($row); |
| 418 | |
| 419 | } |
| 420 | } |
| 421 |