kokjan/common/models/BannerReport.php

105 lines
3.9 KiB
PHP

<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "banner_report".
*
* @property int $id
* @property string $title คำนำหน้า
* @property string $name ชื่อ นามสกุล
* @property string $id_card หมายเลขบัตรประชาชน
* @property string|null $address ที่อยู่
* @property string $tel เบอร์โทรติดต่อ
* @property string|null $email E-mail
* @property string|null $topic เรื่องร้องเรียน
* @property string|null $description รายละเอียด
* @property string $process ข้าพเจ้าขอรับรองว่าข้อความข้างต้นเป็นความจริงทุกประการ
* @property string|null $files แนบหลักฐานร้องเรียน
* @property int|null $created_at เพิ่มเมื่อ
* @property int|null $updated_at แก้ไขเมื่อ
* @property int|null $status สถานะ
* @property string|null $proceed การดำเนินการ
* @property string|null $remark หมายเหตุ
*/
class BannerReport extends \yii\db\ActiveRecord
{
public $verifyCode;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'banner_report';
}
public function behaviors()
{
return [
TimestampBehavior::class,
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title', 'name', 'tel', 'process'], 'required'],
[['address', 'description', 'proceed', 'remark'], 'string'],
[['created_at', 'updated_at', 'status'], 'integer'],
[['title', 'id_card'], 'string', 'max' => 45],
[['id_card'], 'validateIdCard'],
[['name', 'topic'], 'string', 'max' => 200],
[['tel', 'email', 'process'], 'string', 'max' => 100],
[['files'], 'string', 'max' => 500],
['verifyCode', 'captcha'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'คำนำหน้า',
'name' => 'ชื่อ-สกุล (ผู้แจ้งเบาะแส)',
'id_card' => 'หมายเลขบัตรประชาชน',
'address' => 'ที่อยู่',
'tel' => 'เบอร์โทรศัพท์หรือการติดต่อผ่านช่องทางอื่นๆ (ผู้แจ้งเบาะแส)',
'email' => 'E-mail',
'topic' => 'เรื่องร้องเรียน',
'description' => 'สถานที่รุกล้ำ',
'process' => 'ข้าพเจ้าขอรับรองว่าข้อความข้างต้นเป็นความจริงทุกประการ',
'files' => 'แนบหลักฐานร้องเรียน',
'created_at' => 'เพิ่มเมื่อ',
'updated_at' => 'แก้ไขเมื่อ',
'status' => 'สถานะ',
'proceed' => 'การดำเนินการ',
'remark' => 'หมายเหตุ',
];
}
public function validateIdCard()
{
$id = str_split(str_replace('-', '', $this->id_card));
$digi = 13;
$sum = 0;
foreach ($id as $key){
$digi > 1 ? $sum += intval($key) * $digi : null;
$digi--;
}
$n13 = (11 - ($sum % 11)) % 10;
if ($n13 != $id[12]) {
$this->addError('id_card', 'หมายเลขบัตรประชาชนของท่านไม่ถูกต้อง');
}
}
}