/** * Логгирование. * * @param \common\models\Lead|Model $lead * @param $action * @param array $data * @return mixed|void * @throws LeadLoggerException */ public function write(Model $lead, $action, $data = []) { if (!$this->checkAvailableAction($action)) { throw new LeadLoggerException('Не допустимое действие для логирования.'); } $leadActionLog = new LeadActionLog(); $leadActionLog->setAction($action); $leadActionLog->setLeadId($lead->getLeadId()); $leadActionLog->setCompanyId($lead->getCompanyId()); $leadActionLog->setUserId($lead->getUserId()); $leadActionLog->setLeadStatus($lead->getStatus()); if (!empty($data)) { $leadActionLog->setData(json_encode($data)); } $leadActionLog->save(); }