public function save(waContact $contact, $fields) { if (!$this->model) { $this->model = new waContactModel(); } if ($contact->getId()) { return $this->model->updateById($contact->getId(), $fields); } else { return $this->model->insert($fields); } }
public function save(waContact $contact, $fields) { $this->getModel(); if (isset($fields['birthday']) && isset($fields['birthday']['value'])) { $fields = array_merge($fields, $fields['birthday']['value']); unset($fields['birthday']); } if ($contact->getId()) { return $this->model->updateById($contact->getId(), $fields); } else { return $this->model->insert($fields); } }
public function updateLastTime($force = false) { $time = $this->storage->read('user_last_datetime'); if (!$time || $force || $time == '0000-00-00 00:00:00' || time() - strtotime($time) > 120) { try { $login_log_model = new waLoginLogModel(); $last_activity = $login_log_model->getCurrent($this->id); } catch (waDbException $e) { if ($e->getCode() == 1146) { waSystem::getInstance()->getAuth()->clearAuth(); header("Location: " . wa()->getConfig()->getBackendUrl(true)); exit; } } $contact_model = new waContactModel(); $contact_info = $contact_model->getById($this->id); $auth = waSystem::getInstance()->getAuth(); if (!$auth->checkAuth($contact_info)) { header("Location: " . wa()->getConfig()->getRequestUrl(false)); exit; } if (!$contact_info || waSystem::getInstance()->getEnv() == 'backend' && !$contact_info['is_user']) { waSystem::getInstance()->getAuth()->clearAuth(); header("Location: " . wa()->getConfig()->getBackendUrl(true)); exit; } else { $this->setCache($contact_info); } if (!$last_activity) { $login_log_model->insert(array('contact_id' => $this->id, 'datetime_in' => date("Y-m-d H:i:s"), 'datetime_out' => null)); } elseif ($last_datetime = strtotime($time)) { if (time() - $last_datetime > self::$options['activity_timeout']) { $login_log_model->updateById($last_activity['id'], array('datetime_out' => $time)); $login_log_model->insert(array('contact_id' => $this->id, 'datetime_in' => date("Y-m-d H:i:s"), 'datetime_out' => null)); } } $t = date("Y-m-d H:i:s"); $contact_model->updateById($this->id, array('last_datetime' => $t)); $this->storage->write('user_last_datetime', $t); } }