Call.php 2.99 KB
<?php
    
    namespace common\models;
    
    use yii\db\ActiveRecord;
    
    /**
     * This is the model class for table "call".
     *
     * @property int    $id
     * @property string $company
     * @property string $calldate
     * @property string $callerid
     * @property string $line
     * @property string $operator
     * @property string $status
     * @property string $queue
     * @property int    $duration
     * @property int    $billsec
     * @property string $record
     */
    class Call extends ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'call';
        }
        
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [
                        'company',
                        'calldate',
                        'callerid',
                        'status',
                        'duration',
                        'billsec',
                    ],
                    'required',
                ],
                [
                    [ 'calldate' ],
                    'safe',
                ],
                [
                    [
                        'duration',
                        'billsec',
                    ],
                    'default',
                    'value' => null,
                ],
                [
                    [
                        'duration',
                        'billsec',
                    ],
                    'integer',
                ],
                [
                    [
                        'company',
                        'callerid',
                        'line',
                        'operator',
                        'status',
                        'queue',
                        'record',
                    ],
                    'string',
                    'max' => 255,
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'id'       => 'ID',
                'company'  => 'Company',
                'calldate' => 'Calldate',
                'callerid' => 'Callerid',
                'line'     => 'Line',
                'operator' => 'Operator',
                'status'   => 'Status',
                'queue'    => 'Queue',
                'duration' => 'Duration',
                'billsec'  => 'Billsec',
                'record'   => 'Record',
            ];
        }
        
        public function afterSave($insert, $changedAttributes)
        {
            $monologComponent = \Yii::$app->monolog;
            $logger = $monologComponent->getLogger();
            /**
             * @var \Psr\Log\LoggerInterface $logger
             */
            $logger->info('Call added, id: ' . $this->id);
            
            parent::afterSave($insert, $changedAttributes);
        }
    }