ItemLang.php 1.24 KB
<?php

namespace frontend\modules\map\models;

use yii\helpers\ArrayHelper;

/**
 * Class ItemLang
 *
 * @package frontend\modules\map\models
 * @author FilamentV <vortex.filament@gmail.com>
 * @copyright (c), Thread
 */
class ItemLang extends \common\modules\map\models\ItemLang
{
    /**
     * @return array
     */
    public function rules()
    {
        return ArrayHelper::merge(parent::rules(), [
            [[
                'title', 'initiator', 'contact_details_of_project_promoter',
                'annual_power_production', 'annual_heat_production',
                'expected_financial_return', 'investment', 'description'
            ], 'required'],
            ['rid', 'exist', 'targetClass' => Item::class, 'targetAttribute' => 'id'],
            ['title', 'string', 'max' => 256],
            [['description', 'contact_details_of_project_promoter'], 'string', 'max' => 1024],
            [['description', 'contact_details_of_project_promoter', 'total_investment'], 'default', 'value' => ' '],
        ]);
    }

    /**
     * @param bool $insert
     * @return bool
     */
    public function beforeSave($insert)
    {
        $this->licenses = implode(",", $_POST['ItemLang']['licenses'] ?? '');
        return parent::beforeSave($insert);
    }
}