Пример #1
0
 public function getDeleteReason()
 {
     if (!$this->deleted_at) {
         return '';
     }
     // 刪除原因會寫在最後一次的編修記錄中的 reason
     return json_decode(ReportChangeLog::search(array('report_id' => $this->id))->max('updated_at')->new_values)->deleted_reason;
 }
 public function addAction()
 {
     if ($_POST['sToken'] != Helper::getStoken()) {
         return $this->alert('sToken 錯誤', '/');
     }
     try {
         $this->_checkReportData($_POST);
     } catch (Exception $e) {
         return $this->alert($e->getMessage(), '/');
     }
     if ($report = Report::find_by_news_link($_POST['news_link'])) {
         return $this->alert('這個連結已經被人回報過了,將會把您導向該回報去', '/index/log/' . $report->id);
     }
     if ($normaled_news_link = URLNormalizer::query($_POST['news_link']) and $report = Report::find_by_news_link_unique($normaled_news_link->normalized_id)) {
         return $this->alert('這個連結已經被人回報過了,將會把您導向該回報去', '/index/log/' . $report->id);
     }
     $now = time();
     $report = Report::insert(array('news_title' => strval($_POST['news_title']), 'news_link' => strval($_POST['news_link']), 'news_link_unique' => $normaled_news_link ? $normaled_news_link->normalized_id : '', 'report_title' => strval($_POST['report_title']), 'report_link' => strval($_POST['report_link']), 'created_at' => $now, 'updated_at' => $now));
     ReportChangeLog::insert(array('report_id' => $report->id, 'updated_at' => $now, 'updated_from' => intval(ip2long($_SERVER['REMOTE_ADDR'])), 'updated_by' => strval($this->view->user->user_id), 'old_values' => '', 'new_values' => json_encode($report->toArray())));
     return $this->alert('新增成功', '/index/log/' . $report->id);
 }