Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 60 |
| EventSpan | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
132.00 | |
0.00% |
0 / 60 |
| 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 / 11 |
|||
| attributeLabels | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 14 |
|||
| beforeValidate | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| computeTimeQuantity | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 5 |
|||
| getTitle | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 7 |
|||
| getParticipants | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getEvent | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getMeetings | |
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_span}}". | |
| * | |
| * @property integer $id | |
| * @property string $date | |
| * @property string $time_from | |
| * @property string $time_to | |
| * @property integer $time_interval | |
| * @property integer $time_quantity | |
| * @property integer $tables_quantity | |
| * @property integer $created_at | |
| * @property integer $updated_at | |
| * @property integer $event_id | |
| * | |
| * @property Participant[] $participants | |
| * @property Event $event | |
| * @property Meeting[] $meetings | |
| */ | |
| class EventSpan extends \yii\db\ActiveRecord | |
| { | |
| const TIME_INTERVAL_UNIT = 60; | |
| /** | |
| * @inheritdoc | |
| */ | |
| public static function tableName() | |
| { | |
| return '{{%event_span}}'; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| TimestampBehavior::className(), | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['date', 'time_from', 'time_to', 'time_interval', 'time_quantity', 'tables_quantity'], 'filter', 'filter' => 'trim'], | |
| [['date', 'time_from', 'time_to', 'time_interval', 'time_quantity', 'tables_quantity', 'event_id'], 'required'], | |
| [['date'], 'date', 'format' => 'yyyy-MM-dd'], | |
| [['time_from', 'time_to'], 'date', 'format' => 'HH:mm'], | |
| [['time_interval', 'time_quantity', 'tables_quantity', 'event_id'], 'integer'], | |
| ['time_to', 'compare', 'compareAttribute' => 'time_from', 'operator' => '>='], | |
| [['date', 'time_from', 'time_to', 'event_id'], 'unique', 'targetAttribute' => ['date', 'time_from', 'time_to', 'event_id'], 'message' => 'The combination of Time span and Event has already been taken.'] | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributeLabels() | |
| { | |
| return [ | |
| 'id' => Yii::t('app', 'ID'), | |
| 'date' => Yii::t('app', 'Date'), | |
| 'time_from' => Yii::t('app', 'Time from'), | |
| 'time_to' => Yii::t('app', 'Time to'), | |
| 'time_interval' => Yii::t('app', 'Time interval'), | |
| 'time_quantity' => Yii::t('app', 'Time quantity'), | |
| 'tables_quantity' => Yii::t('app', 'Tables quantity'), | |
| 'created_at' => Yii::t('app', 'Created at'), | |
| 'updated_at' => Yii::t('app', 'Updated at'), | |
| 'event_id' => Yii::t('app', 'Event'), | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function beforeValidate(){ | |
| $this->computeTimeQuantity(); | |
| return true; | |
| } | |
| /** | |
| * @return void | |
| */ | |
| protected function computeTimeQuantity(){ | |
| $start_time = strtotime($this->time_from, 0); //TODO: AVOID strtotime | |
| $end_time = strtotime($this->time_to, 0); | |
| $interval = intval($this->time_interval) * self::TIME_INTERVAL_UNIT; | |
| $this->time_quantity = floor(($end_time - $start_time) / $interval); | |
| } | |
| public function getTitle() | |
| { | |
| return sprintf('%s %s - %s', | |
| Yii::$app->formatter->asDate($this->date), | |
| Yii::$app->formatter->asTime($this->time_from), | |
| Yii::$app->formatter->asTime($this->time_to) | |
| ); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getParticipants() | |
| { | |
| return $this->hasMany(Participant::className(), ['id' => 'participant_id'])->viaTable('{{%participant_event_span}}', ['event_span_id' => 'id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getEvent() | |
| { | |
| return $this->hasOne(Event::className(), ['id' => 'event_id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getMeetings() | |
| { | |
| return $this->hasMany(Meeting::className(), ['event_span_id' => 'id']); | |
| } | |
| /** | |
| * @inheritdoc | |
| * @return EventSpanQuery | |
| */ | |
| public static function find() | |
| { | |
| return new EventSpanQuery(get_called_class()); | |
| } | |
| } |