File: /home/safarimaris/home/safarimaris/common/models/EntityResort.php
<?php
namespace common\models;
use Yii;
use yii\db\Query;
/**
* This is the model class for table "entity_resort".
*
* @property integer $id
* @property integer $entityId
* @property string $checkinTime
* @property string $activities
* @property integer $countBoat
* @property integer $airportTransfer
* @property integer $decompressDistance
* @property integer $hotelTransfer
*
* @property Entity $entity
*/
class EntityResort extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'entity_resort';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['entityId'], 'required', 'on'=>array('create', 'update')],
[['entityId', 'countBoat', 'airportTransfer', 'decompressDistance', 'hotelTransfer'], 'integer'],
[['checkinTime', 'activities'], 'string', 'max' => 255],
[['entityId'], 'exist', 'skipOnError' => true, 'targetClass' => Entity::className(), 'targetAttribute' => ['entityId' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('model', 'ID'),
'entityId' => Yii::t('model', 'Entity ID'),
'checkinTime' => Yii::t('model', 'Checkin time'),
'activities' => Yii::t('model', 'Non Diving Activities'),
'countBoat' => Yii::t('model', 'Count Boat'),
'airportTransfer' => Yii::t('model', 'Airport Transfer'),
'decompressDistance' => Yii::t('model', 'Decompress Distance'),
'hotelTransfer' => Yii::t('model', 'Hotel Transfer'),
'language' => Yii::t('model', 'Language'),
'document' => Yii::t('model', 'Document')
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getEntity()
{
return $this->hasOne(Entity::className(), ['id' => 'entityId']);
}
public function getOther($countryId)
{
return (new Query())
->select([
'c.url',
'e.seoUrl',
'e.name',
])
->from('{{%entity}} e')
->innerJoin('{{%entity_resort}} er', 'er.entityId=e.id')
->innerJoin('{{%country}} c', 'c.id=e.countryId')
->where('c.id = :countryId AND entityId != :entityId', ['countryId' => $countryId, 'entityId' => $this->entityId])
->orderBy('e.ordinal, e.name')
->all();
}
}