Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 17
CRAP
0.00% covered (danger)
0.00%
0 / 95
Organization
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 17
342.00
0.00% covered (danger)
0.00%
0 / 93
 tableName
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 behaviors
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 5
 rules
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 15
 attributeLabels
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 27
 getOrganizationProfile
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getOrganizationType
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getEvent
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getSupervisor
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getActivityAreas
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getTables
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getParticipants
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getCountryName
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 find
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 getActivityAreasList
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 6
 setActivityAreasList
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
 afterFind
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 4
 afterSave
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 3
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
/**
 * This is the model class for table "{{%organization}}".
 *
 * @property integer $id
 * @property string $name
 * @property string $email
 * @property string $address
 * @property string $postal_code
 * @property string $city
 * @property string $country
 * @property string $phone
 * @property string $fax
 * @property string $website
 * @property string $founded
 * @property string $organization_size
 * @property string $image
 * @property string $description
 * @property string $offer
 * @property string $interest
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $organization_profile_id
 * @property integer $organization_type_id
 * @property integer $event_id
 * @property integer $supervisor_id
 *
 * @property OrganizationProfile $organizationProfile
 * @property OrganizationType $organizationType
 * @property Event $event
 * @property Supervisor $supervisor
 * @property ActivityArea[] $activityAreas
 * @property Table[] $tables
 * @property Participant[] $participants
 */
class Organization extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%organization}}';
    }
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'email', 'address', 'postal_code', 'city', 'country', 'organization_size', 'description', 'offer', 'interest', 'organization_profile_id', 'organization_type_id', 'activityAreasList'], 'required'],
            [['activityAreasList'], 'safe'],
            [['phone', 'fax', 'website', 'founded'], 'default'],
            [['description', 'offer', 'interest'], 'string'],
            [['founded'], 'integer', 'min' => 1, 'max' => date('Y')],
            [['organization_size'], 'integer', 'min' => 1],
            [['organization_profile_id', 'organization_type_id', 'event_id', 'supervisor_id'], 'integer'],
            [['name', 'email', 'address', 'city', 'country', 'website'], 'string', 'max' => 255],
            [['image'], 'image', 'on' => 'updateImage'],
            [['postal_code'], 'string', 'max' => 10],
            [['phone', 'fax'], 'string', 'max' => 20],
        ];
    }
    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'name' => Yii::t('app', 'Name'),
            'email' => Yii::t('app', 'Email'),
            'address' => Yii::t('app', 'Address'),
            'postal_code' => Yii::t('app', 'Postal code'),
            'city' => Yii::t('app', 'City'),
            'country' => Yii::t('app', 'Country'),
            'countryName' => Yii::t('app', 'Country'),
            'phone' => Yii::t('app', 'Phone'),
            'fax' => Yii::t('app', 'Fax'),
            'website' => Yii::t('app', 'Website'),
            'founded' => Yii::t('app', 'Founded'),
            'organization_size' => Yii::t('app', 'Organization size'),
            'image' => Yii::t('app', 'Image'),
            'description' => Yii::t('app', 'Description'),
            'offer' => Yii::t('app', 'Offer'),
            'interest' => Yii::t('app', 'Interest'),
            'created_at' => Yii::t('app', 'Created at'),
            'updated_at' => Yii::t('app', 'Updated at'),
            'organization_profile_id' => Yii::t('app', 'Organization profile'),
            'organization_type_id' => Yii::t('app', 'Organization type'),
            'event_id' => Yii::t('app', 'Event'),
            'supervisor_id' => Yii::t('app', 'Supervisor'),
        ];
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOrganizationProfile()
    {
        return $this->hasOne(OrganizationProfile::className(), ['id' => 'organization_profile_id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOrganizationType()
    {
        return $this->hasOne(OrganizationType::className(), ['id' => 'organization_type_id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEvent()
    {
        return $this->hasOne(Event::className(), ['id' => 'event_id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getSupervisor()
    {
        return $this->hasOne(Supervisor::className(), ['id' => 'supervisor_id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getActivityAreas()
    {
        return $this->hasMany(ActivityArea::className(), ['id' => 'activity_area_id'])->viaTable('{{%organization_activity_area}}', ['organization_id' => 'id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTables()
    {
        return $this->hasMany(Table::className(), ['id' => 'table_id'])->viaTable('{{%organization_table}}', ['organization_id' => 'id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getParticipants()
    {
        return $this->hasMany(Participant::className(), ['organization_id' => 'id']);
    }
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCountryName()
    {
        return Country::find()->where(['code' => $this->country])->one()->name;
    }
    /**
     * {@inheritdoc}
     * @return OrganizationQuery
     */
    public static function find()
    {
        return new OrganizationQuery(get_called_class());
    }
    private $isActivityAreasListReady;
    private $activityAreasList;
    public function getActivityAreasList(){
        if(!$this->isActivityAreasListReady){
            $this->isActivityAreasListReady = true;
            \common\components\RelationHelper::SetJunctionList($this, 'activityAreas');
        }
        return $this->activityAreasList;
    }
    public function setActivityAreasList($value){
        $this->isActivityAreasListReady = true;
        $this->activityAreasList = $value;
    }
    public function afterFind() {
        $this->isActivityAreasListReady = false;
        $this->activityAreasList = [];
        parent::afterFind();
    }
    public function afterSave($insert, $changedAttributes) {
        \common\components\RelationHelper::UpdateJunctionList($this, 'activityAreas');
        parent::afterSave($insert, $changedAttributes);
    }
}