Пример #1
0
 function update($id, array $data)
 {
     foreach (array('first_contact', 'time_contract', 'end') as $date_field) {
         if (isset($data[$date_field]) && $data[$date_field] === '') {
             $data[$date_field] = NULL;
         }
     }
     return parent::update($id, $data);
 }
Пример #2
0
 function update($schedule_id, $data)
 {
     $schedule_id = intval($schedule_id);
     //attemp to convert date string to timestamp
     foreach (array('start', 'end', 'deadline') as $timepoint) {
         if (isset($data[$timepoint])) {
             if (strtotime($data[$timepoint])) {
                 $data[$timepoint] = strtotime($data[$timepoint]);
             }
         }
     }
     foreach (array('start', 'end', 'deadline', 'hours_own') as $var) {
         if (isset($data[$var])) {
             if ($data[$var] === '') {
                 $data[$var] = NULL;
             }
         }
     }
     //generate hours by start timestamp and end timestamp
     if (isset($data['start']) && isset($data['end'])) {
         $data['hours_own'] = round(($data['end'] - $data['start']) / 3600, 2);
     }
     if (array_key_exists('hours_own', $data) && is_null($data['hours_own'])) {
         $data['hours_own'] = $data['end'] = NULL;
     }
     $return = parent::update($schedule_id, $data);
     //generate end timestamp by start timestamp end hours
     if (isset($data['hours_own']) && is_numeric($data['hours_own'])) {
         $this->db->where('id', $schedule_id)->set('end', "start + 3600 * {$data['hours_own']}", false)->update('schedule');
     }
     return $return;
 }