30 lines
751 B
PHP
30 lines
751 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use CodeIgniter\Model;
|
||
|
|
|
||
|
|
class BaseUtcModel extends Model {
|
||
|
|
protected $beforeInsert = ['normalizeDatesToUTC'];
|
||
|
|
protected $beforeUpdate = ['normalizeDatesToUTC'];
|
||
|
|
protected $afterFind = ['convertDatesToUTCISO'];
|
||
|
|
protected $afterInsert = ['convertDatesToUTCISO'];
|
||
|
|
protected $afterUpdate = ['convertDatesToUTCISO'];
|
||
|
|
|
||
|
|
protected function normalizeDatesToUTC(array $data) {
|
||
|
|
helper('utc');
|
||
|
|
if (isset($data['data'])) {
|
||
|
|
$data['data'] = convert_array_to_utc($data['data']);
|
||
|
|
}
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function convertDatesToUTCISO(array $data) {
|
||
|
|
helper('utc');
|
||
|
|
if (isset($data['data'])) {
|
||
|
|
$data['data'] = convert_array_to_utc_iso($data['data']);
|
||
|
|
}
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
}
|