HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux dev1 5.15.83-1-pve #1 SMP PVE 5.15.83-1 (2022-12-15T00:00Z) x86_64
User: safarimaris (1000)
PHP: 7.2.34-54+ubuntu22.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /home/safarimaris/home/safarimaris/common/models/EntityBoat.php
<?php

namespace common\models;

use Yii;
use yii\db\Query;

/**
 * This is the model class for table "entity_boat".
 *
 * @property integer $id
 * @property integer $entityId
 * @property integer $fleetId
 * @property integer $year
 * @property integer $width
 * @property integer $length
 * @property integer $materialId
 * @property integer $countCabin
 * @property string $language
 * @property string $boatPlan
 * @property string $compressor
 * @property string $generator
 * @property string $engine
 * @property string $capacity
 * @property string $tender
 * @property string $socket
 * @property string $service
 * @property string $techEquip
 * @property string $disabilitiesEquip
 * @property string $waterCapacity
 * @property string $lastDockDate
 * @property string $lastRenovationDate
 *
 * @property DicMaterial $dicMaterial
 * @property Entity $entity
 * @property Fleet $fleet
 * @property DicNavigation[] $navigation_ids
 * @property DicFood[] $food_ids
 * @property DicService[] $service_ids
 * @property DicDiving[] $diving_ids
 */
class EntityBoat extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'entity_boat';
    }

    public function behaviors()
    {
        return [
            [
                'class' => \mongosoft\file\UploadImageBehavior::className(),
                'attribute' => 'boatPlan',
                'scenarios' => ['update', 'create'],
                'path' => '@imgPath/entity_boat',
                'url' => '@imgUrl/entity_boat',
                'thumbs' => Yii::$app->params['thumbs'],
            ],
            [
                'class' => \voskobovich\behaviors\ManyToManyBehavior::className(),
                'relations' => [
                    'navigation_ids' => 'navigations'
                ],
            ],
            [
                'class' => \voskobovich\behaviors\ManyToManyBehavior::className(),
                'relations' => [
                    'food_ids' => 'foods'
                ],
            ],
            [
                'class' => \voskobovich\behaviors\ManyToManyBehavior::className(),
                'relations' => [
                    'service_ids' => 'services'
                ],
            ],
            [
                'class' => \voskobovich\behaviors\ManyToManyBehavior::className(),
                'relations' => [
                    'diving_ids' => 'divings'
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['entityId',], 'required', 'on'=>array('create', 'update')],
            [['id', 'entityId', 'fleetId', 'year', 'width', 'length', 'capacity', 'materialId', 'countCabin', 'waterCapacity'], 'integer'],
            [['lastDockDate', 'lastRenovationDate'], 'safe'],
            [['compressor', 'generator', 'engine', 'tender', 'socket', 'techEquip', 'disabilitiesEquip'], 'string', 'max' => 255],
            [['boatPlan'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg'],
            [['materialId'], 'exist', 'skipOnError' => true, 'targetClass' => DicMaterial::className(), 'targetAttribute' => ['materialId' => 'id']],
            [['entityId'], 'exist', 'skipOnError' => true, 'targetClass' => Entity::className(), 'targetAttribute' => ['entityId' => 'id']],
            [['fleetId'], 'exist', 'skipOnError' => true, 'targetClass' => Fleet::className(), 'targetAttribute' => ['fleetId' => 'id']],
            [['navigation_ids'], 'each', 'rule' => ['integer']],
            [['food_ids'], 'each', 'rule' => ['integer']],
            [['service_ids'], 'each', 'rule' => ['integer']],
            [['diving_ids'], 'each', 'rule' => ['integer']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('model', 'ID'),
            'entityId' => Yii::t('model', 'Entity'),
            'fleetId' => Yii::t('model', 'Fleet'),
            'year' => Yii::t('model', 'Year built'),
            'width' => Yii::t('model', 'Width'),
            'length' => Yii::t('model', 'Length'),
            'materialId' => Yii::t('model', 'Material'),
            'countCabin' => Yii::t('model', 'Count Cabin'),
            'language' => Yii::t('model', 'Language'),
            'boatPlan' => Yii::t('model', 'Boat Plan'),
            'compressor' => Yii::t('model', 'Compressor'),
            'generator' => Yii::t('model', 'Generator'),
            'engine' => Yii::t('model', 'Engine'),
            'capacity' => Yii::t('model', 'Capacity'),
            'navigation_ids' => Yii::t('model', 'Navigation'),
            'tender' => Yii::t('model', 'Tender'),
            'socket' => Yii::t('model', 'Socket'),
            'techEquip' => Yii::t('model', 'Tech Equip'),
            'disabilitiesEquip' => Yii::t('model', 'Disabilities Equip'),
            'waterCapacity' => Yii::t('model', 'Water Capacity'),
            'lastDockDate' => Yii::t('model', 'Last Dock Date'),
            'lastRenovationDate' => Yii::t('model', 'Last Renovation Date'),
            'food_ids' => Yii::t('model', 'Food'),
            'service_ids' => Yii::t('model', 'Service'),
            'diving_ids' => Yii::t('model', 'Diving'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMaterial()
    {
        return $this->hasOne(DicMaterial::className(), ['id' => 'materialId']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEntity()
    {
        return $this->hasOne(Entity::className(), ['id' => 'entityId']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getFleet()
    {
        return $this->hasOne(Fleet::className(), ['id' => 'fleetId']);
    }

    public function getNavigations()
    {
        return $this->hasMany(DicNavigation::className(), ['id' => 'navigationId'])
            ->viaTable('{{%entity_boat_navigation_link}}', ['entityId' => 'id']);
    }

    public function getFoods()
    {
        return $this->hasMany(DicFood::className(), ['id' => 'foodId'])
            ->viaTable('{{%entity_boat_food_link}}', ['entityId' => 'id']);
    }

    public function getServices()
    {
        return $this->hasMany(DicService::className(), ['id' => 'serviceId'])
            ->viaTable('{{%entity_boat_service_link}}', ['entityId' => 'id']);
    }

    public function getDivings()
    {
        return $this->hasMany(DicDiving::className(), ['id' => 'divingId'])
            ->viaTable('{{%entity_boat_diving_link}}', ['entityId' => 'id']);
    }

    public function getGroupServices($method)
    {
        $methods = [
            'services' => ['services', 'common\models\DicService'],
            'navigations' => ['navigations', 'common\models\DicNavigation'],
            'foods' => ['foods', 'common\models\DicFood'],
            'divings' => ['divings', 'common\models\DicDiving']
        ];
        list($m1, $m2) = $methods[$method];

        $exist = [];
        foreach ($this->$m1 as $item) {
            $exist[$item['id']] = $item['name'];
        }

        foreach ($m2::find()->asArray()->all() as $item) {
            $all[] = [
                'name' => $item['name'],
                'avail' => array_key_exists($item['id'], $exist)
            ];
        }
        return $all;
    }

    public function getOther($countryId)
    {
        return (new Query())
            ->select([
                'c.url',
                'e.seoUrl',
                'e.name',
            ])
            ->from('{{%entity}} e')
            ->innerJoin('{{%entity_boat}} eb', 'eb.entityId=e.id')
            ->innerJoin('{{%country}} c', 'c.id=e.countryId')
            ->where('c.id = :countryId AND entityId != :entityId', ['countryId' => $countryId, 'entityId' => $this->entityId])
            ->orderBy('e.name')
            ->all();
    }
}