Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 63 |
| Event | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
90.00 | |
0.00% |
0 / 63 |
| tableName | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| behaviors | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 5 |
|||
| rules | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 15 |
|||
| attributeLabels | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 18 |
|||
| getOrganizations | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getEventSpans | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getParticipants | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 10 |
|||
| getCountryName | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| find | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| <?php | |
| namespace common\models; | |
| use Yii; | |
| use yii\behaviors\TimestampBehavior; | |
| /** | |
| * This is the model class for table "{{%event}}". | |
| * | |
| * @property integer $id | |
| * @property string $name | |
| * @property string $date_from | |
| * @property string $date_to | |
| * @property string $address | |
| * @property string $postal_code | |
| * @property string $city | |
| * @property string $country | |
| * @property string $registration_from | |
| * @property string $registration_to | |
| * @property boolean $is_enabled | |
| * @property integer $created_at | |
| * @property integer $updated_at | |
| * | |
| * @property Organization[] $organizations | |
| * @property EventSpan[] $eventSpans | |
| */ | |
| class Event extends \yii\db\ActiveRecord | |
| { | |
| const STATUS_DISABLED = 0; | |
| const STATUS_ACTIVE = 1; | |
| /** | |
| * @inheritdoc | |
| */ | |
| public static function tableName() | |
| { | |
| return '{{%event}}'; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| TimestampBehavior::className(), | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['name', 'date_from', 'date_to', 'registration_from', 'registration_to', 'address', 'postal_code', 'city', 'country'], 'filter', 'filter' => 'trim'], | |
| [['name', 'date_from', 'date_to', 'address', 'postal_code', 'city', 'country'], 'required'], | |
| [['date_from', 'date_to', 'registration_from', 'registration_to'], 'safe'], | |
| [['is_enabled'], 'integer'], | |
| [['name', 'address', 'city', 'country'], 'string', 'max' => 255], | |
| [['postal_code'], 'string', 'max' => 10], | |
| ['is_enabled', 'default', 'value' => self::STATUS_DISABLED], | |
| ['is_enabled', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DISABLED]], | |
| ['date_to', 'compare', 'compareAttribute' => 'date_from', 'operator' => '>='], | |
| ['registration_to', 'compare', 'compareAttribute' => 'registration_from', 'operator' => '>='], | |
| [['name'], 'unique'] | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributeLabels() | |
| { | |
| return [ | |
| 'id' => Yii::t('app', 'ID'), | |
| 'name' => Yii::t('app', 'Event name'), | |
| 'date_from' => Yii::t('app', 'Date from'), | |
| 'date_to' => Yii::t('app', 'Date to'), | |
| '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'), | |
| 'registration_from' => Yii::t('app', 'Registration from'), | |
| 'registration_to' => Yii::t('app', 'Registration to'), | |
| 'is_enabled' => Yii::t('app', 'Is enabled'), | |
| 'created_at' => Yii::t('app', 'Created at'), | |
| 'updated_at' => Yii::t('app', 'Updated at'), | |
| ]; | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getOrganizations() | |
| { | |
| return $this->hasMany(Organization::className(), ['event_id' => 'id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getEventSpans() | |
| { | |
| return $this->hasMany(EventSpan::className(), ['event_id' => 'id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getParticipants() | |
| { | |
| $eventSpans = $this->getEventSpans()->select('id'); | |
| $query = Participant::find() | |
| ->from(Participant::tableName() . ' p') | |
| ->innerJoin('{{%participant_event_span}} pes', | |
| ['AND', 'pes.[[participant_id]] = p.[[id]]', | |
| ['IN', 'pes.[[event_span_id]]', $eventSpans]]); | |
| $query->multiple = true; | |
| return $query; | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getCountryName() | |
| { | |
| return Country::find()->where(['code' => $this->country])->one()->name; | |
| } | |
| /** | |
| * @inheritdoc | |
| * @return EventQuery | |
| */ | |
| public static function find() | |
| { | |
| return new EventQuery(get_called_class()); | |
| } | |
| } |