AdhanProcessor.php
1 year ago
CsvProcessor.php
2 months ago
DebugProcessor.php
1 year ago
DigitalScreenProcessor.php
1 month ago
HijriProcessor.php
3 years ago
LanguageProcessor.php
4 years ago
OtherProcessor.php
2 months ago
QuickUpdateProcessor.php
3 years ago
StartTimeProcessor.php
1 year ago
ThemeSettingsProcessor.php
1 year ago
QuickUpdateProcessor.php
59 lines
| 1 | <?php |
| 2 | if (!class_exists('DPTQuickUpdateProcessor')) { |
| 3 | class DPTQuickUpdateProcessor |
| 4 | { |
| 5 | /** |
| 6 | * @var array |
| 7 | */ |
| 8 | private $data; |
| 9 | |
| 10 | /** |
| 11 | * @param array $data |
| 12 | */ |
| 13 | public function __construct(array $data) |
| 14 | { |
| 15 | $this->data = $data; |
| 16 | } |
| 17 | |
| 18 | public function process() |
| 19 | { |
| 20 | $db = new DatabaseConnection(); |
| 21 | $this->validate($this->data); |
| 22 | $db->quickUpdateRow($this->data); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * validate user input of prayer time |
| 27 | */ |
| 28 | private function validate(array $rows) |
| 29 | { |
| 30 | foreach($rows as $row) { |
| 31 | foreach($row as $name => $time) { |
| 32 | if ($name == 'd_date') continue; |
| 33 | if ( ! $this->isValidateTimeFormat($time) ) { |
| 34 | return false; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @param string $time |
| 43 | * @return bool |
| 44 | */ |
| 45 | private function isValidateTimeFormat($time) |
| 46 | { |
| 47 | $time = trim($time); |
| 48 | $pattern1 = "/^([0-9]|[01][0-9]|2[0-3]):[0-5][0-9]$/"; // HH:MM or H:MM |
| 49 | $pattern2 = "/^([0-9]|[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/"; // HH:MM or H:MM |
| 50 | |
| 51 | if ( preg_match($pattern1, $time, $matches) || preg_match($pattern2, $time, $matches) ) { |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 |