Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 26 |
CRAP | |
0.00% |
0 / 189 |
| Meeting | |
0.00% |
0 / 1 |
|
0.00% |
0 / 26 |
1482.00 | |
0.00% |
0 / 189 |
| 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 |
20.00 | |
0.00% |
0 / 15 |
|||
| attributeLabels | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 16 |
|||
| getTime | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 8 |
|||
| getGuestParticipant | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getHostParticipant | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getTable | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getEventSpan | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getMeetingNotes | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getHostMeetingNote | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getGuestMeetingNote | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| generateHostConfirmationToken | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| removeHostConfirmationToken | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| generateGuestConfirmationToken | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| removeGuestConfirmationToken | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| findSurveysForUser | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 5 |
|||
| find | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| findByHostConfirmationToken | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 12 |
|||
| findByGuestConfirmationToken | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 12 |
|||
| sendHostConfirmationEmail | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| sendCanceledByHostEmail | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| sendGuestConfirmationEmail | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| sendAcceptedByGuestEmail | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| sendRefusedByGuestEmail | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
| sendCanceledByAdminEmail | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 22 |
|||
| <?php | |
| namespace common\models; | |
| use Yii; | |
| use yii\behaviors\TimestampBehavior; | |
| /** | |
| * This is the model class for table "{{%meeting}}". | |
| * | |
| * @property integer $id | |
| * @property boolean $is_confirmed_host | |
| * @property boolean $is_confirmed_guest | |
| * @property string $host_confirmation_token | |
| * @property string $guest_confirmation_token | |
| * @property integer $created_at | |
| * @property integer $updated_at | |
| * @property integer $event_span_id | |
| * @property integer $event_span_time_on | |
| * @property integer $table_id | |
| * @property integer $host_participant_id | |
| * @property integer $guest_participant_id | |
| * | |
| * @property Participant $guestParticipant | |
| * @property Participant $hostParticipant | |
| * @property Table $table | |
| * @property EventSpan $eventSpan | |
| * @property MeetingNote[] $meetingNotes | |
| */ | |
| class Meeting extends \yii\db\ActiveRecord | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public static function tableName() | |
| { | |
| return '{{%meeting}}'; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| TimestampBehavior::className(), | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['is_confirmed_host', 'is_confirmed_guest'], 'boolean'], | |
| [['event_span_id', 'event_span_time_on', 'table_id', 'host_participant_id', 'guest_participant_id'], 'required'], | |
| [['event_span_id', 'event_span_time_on', 'table_id', 'host_participant_id', 'guest_participant_id'], 'integer'], | |
| [['host_confirmation_token', 'guest_confirmation_token'], 'string', 'max' => 43], | |
| [['host_participant_id', 'guest_participant_id'], 'unique', 'targetAttribute' => ['host_participant_id', 'guest_participant_id'], 'message' => 'The combination of participants already exists.'], | |
| [['event_span_id', 'event_span_time_on', 'table_id'], 'unique', 'targetAttribute' => ['event_span_id', 'event_span_time_on', 'table_id'], 'message' => 'The meeting time spot has already been taken.'], | |
| ['event_span_time_on', function($attribute, $params) { | |
| if (!empty($this->eventSpan) && | |
| ($this->$attribute < 0 || $this->$attribute >= $this->eventSpan->time_quantity)) { | |
| $this->addError($attribute, Yii::t('app', 'The time not exists.')); | |
| } | |
| }], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributeLabels() | |
| { | |
| return [ | |
| 'id' => Yii::t('app', 'ID'), | |
| 'is_confirmed_host' => Yii::t('app', 'Is confirmed by host'), | |
| 'is_confirmed_guest' => Yii::t('app', 'Is confirmed by guest'), | |
| 'host_confirmation_token' => Yii::t('app', 'Host confirmation token'), | |
| 'guest_confirmation_token' => Yii::t('app', 'Guest confirmation token'), | |
| 'created_at' => Yii::t('app', 'Created at'), | |
| 'updated_at' => Yii::t('app', 'Updated at'), | |
| 'event_span_id' => Yii::t('app', 'Event span ID'), | |
| 'event_span_time_on' => Yii::t('app', 'Event span time ON'), | |
| 'table_id' => Yii::t('app', 'Table ID'), | |
| 'host_participant_id' => Yii::t('app', 'Host user'), | |
| 'guest_participant_id' => Yii::t('app', 'Guest organization user'), | |
| ]; | |
| } | |
| /** | |
| * @return int | |
| */ | |
| public function getTime() | |
| { | |
| $meetingTime = new \DateTime($this->eventSpan->time_from, new \DateTimeZone(Yii::$app->formatter->timeZone)); | |
| $meetingTime->setDate(1970, 1, 1); | |
| $interval = intval($this->eventSpan->time_interval) * EventSpan::TIME_INTERVAL_UNIT * intval($this->event_span_time_on); | |
| $meetingInterval = new \DateInterval('PT' . $interval . 'S'); | |
| $meetingTime->add($meetingInterval); | |
| return $meetingTime; | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getGuestParticipant() | |
| { | |
| return $this->hasOne(Participant::className(), ['id' => 'guest_participant_id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getHostParticipant() | |
| { | |
| return $this->hasOne(Participant::className(), ['id' => 'host_participant_id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getTable() | |
| { | |
| return $this->hasOne(Table::className(), ['id' => 'table_id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getEventSpan() | |
| { | |
| return $this->hasOne(EventSpan::className(), ['id' => 'event_span_id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getMeetingNotes() | |
| { | |
| return $this->hasMany(MeetingNote::className(), ['meeting_id' => 'id']); | |
| } | |
| /** | |
| * @return string Host MeetingNote | |
| */ | |
| public function getHostMeetingNote() | |
| { | |
| return $this->getMeetingNotes()->where(['type' => MeetingNote::TYPE_HOST])->one(); | |
| } | |
| /** | |
| * @return string Guest MeetingNote content | |
| */ | |
| public function getGuestMeetingNote() | |
| { | |
| return $this->getMeetingNotes()->where(['type' => MeetingNote::TYPE_GUEST])->one(); | |
| } | |
| /** | |
| * Generates new host confirmation token | |
| */ | |
| public function generateHostConfirmationToken() | |
| { | |
| $this->host_confirmation_token = Yii::$app->security->generateRandomString() . '_' . time(); | |
| } | |
| /** | |
| * Removes host confirmation token | |
| */ | |
| public function removeHostConfirmationToken() | |
| { | |
| $this->host_confirmation_token = null; | |
| } | |
| /** | |
| * Generates new guest confirmation token | |
| */ | |
| public function generateGuestConfirmationToken() | |
| { | |
| $this->guest_confirmation_token = Yii::$app->security->generateRandomString() . '_' . time(); | |
| } | |
| /** | |
| * Removes guest confirmation token | |
| */ | |
| public function removeGuestConfirmationToken() | |
| { | |
| $this->guest_confirmation_token = null; | |
| } | |
| /** | |
| * Generates new guest confirmation token | |
| */ | |
| public function findSurveysForUser($user_id){ | |
| return MeetingSurvey::find() | |
| ->availableForMeeting($this->id) | |
| ->availableForUser($user_id) | |
| ->all(); | |
| } | |
| /** | |
| * @inheritdoc | |
| * @return MeetingQuery | |
| */ | |
| public static function find() | |
| { | |
| return new MeetingQuery(get_called_class()); | |
| } | |
| /** | |
| * Finds meeting by host confirm token | |
| * | |
| * @param string $token host confirm token | |
| * @return static|null | |
| */ | |
| public static function findByHostConfirmationToken($token) | |
| { | |
| $expire = Yii::$app->params['meeting.confirm.hostTokenExpire']; | |
| $parts = explode('_', $token); | |
| $timestamp = (int) end($parts); | |
| if ($timestamp + $expire < time()) { | |
| // token expired | |
| return null; | |
| } | |
| return static::findOne([ | |
| 'host_confirmation_token' => $token, | |
| 'is_confirmed_host' => [null, false], | |
| ]); | |
| } | |
| /** | |
| * Finds meeting by guest confirm token | |
| * | |
| * @param string $token guest confirm token | |
| * @return static|null | |
| */ | |
| public static function findByGuestConfirmationToken($token) | |
| { | |
| $expire = Yii::$app->params['meeting.confirm.guestTokenExpire']; | |
| $parts = explode('_', $token); | |
| $timestamp = (int) end($parts); | |
| if ($timestamp + $expire < time()) { | |
| // token expired | |
| return null; | |
| } | |
| return static::findOne([ | |
| 'guest_confirmation_token' => $token, | |
| 'is_confirmed_guest' => null, | |
| ]); | |
| } | |
| public function sendHostConfirmationEmail() | |
| { | |
| $message = Yii::$app->mailer->compose('hostMeetingToken', ['meeting' => $this, 'participant' => $this->guestParticipant, 'user' => $this->hostParticipant->user]); | |
| $fromEmail = \Yii::$app->params['supportEmail']; | |
| $sourceEmail = $message->getFrom(); | |
| if (!empty($sourceEmail)) $fromEmail = key($sourceEmail); | |
| return $message->setFrom([$fromEmail => \Yii::$app->name . ' robot']) | |
| ->setReplyTo([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) | |
| ->setTo([$this->hostParticipant->user->email => $this->hostParticipant->user->fullname]) | |
| ->setSubject(Yii::t('app', 'Confirm the meeting invitation')) | |
| ->send(); | |
| } | |
| public function sendCanceledByHostEmail() | |
| { | |
| $message = Yii::$app->mailer->compose('infoMeetingWasCanceledByHost', ['meeting' => $this, 'participant' => $this->guestParticipant, 'user' => $this->guestParticipant->user]); | |
| $fromEmail = \Yii::$app->params['supportEmail']; | |
| $sourceEmail = $message->getFrom(); | |
| if (!empty($sourceEmail)) $fromEmail = key($sourceEmail); | |
| return $message->setFrom([$fromEmail => \Yii::$app->name . ' robot']) | |
| ->setReplyTo([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) | |
| ->setTo([$this->guestParticipant->user->email => $this->guestParticipant->user->fullname]) | |
| ->setSubject(Yii::t('app', 'Meeting was canceled by host')) | |
| ->send(); | |
| } | |
| public function sendGuestConfirmationEmail() | |
| { | |
| $message = Yii::$app->mailer->compose('guestMeetingToken', ['meeting' => $this, 'participant' => $this->guestParticipant, 'user' => $this->guestParticipant->user]); | |
| $fromEmail = \Yii::$app->params['supportEmail']; | |
| $sourceEmail = $message->getFrom(); | |
| if (!empty($sourceEmail)) $fromEmail = key($sourceEmail); | |
| return $message->setFrom([$fromEmail => \Yii::$app->name . ' robot']) | |
| ->setReplyTo([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) | |
| ->setTo([$this->guestParticipant->user->email => $this->guestParticipant->user->fullname]) | |
| ->setSubject(Yii::t('app', 'Meeting invitation')) | |
| ->send(); | |
| } | |
| public function sendAcceptedByGuestEmail() | |
| { | |
| $message = Yii::$app->mailer->compose('infoMeetingWasAcceptedByGuest', ['meeting' => $this, 'participant' => $this->guestParticipant, 'user' => $this->hostParticipant->user]); | |
| $fromEmail = \Yii::$app->params['supportEmail']; | |
| $sourceEmail = $message->getFrom(); | |
| if (!empty($sourceEmail)) $fromEmail = key($sourceEmail); | |
| return $message->setFrom([$fromEmail => \Yii::$app->name . ' robot']) | |
| ->setReplyTo([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) | |
| ->setTo([$this->hostParticipant->user->email => $this->hostParticipant->user->fullname]) | |
| ->setSubject(Yii::t('app', 'Meeting was accepted by guest')) | |
| ->send(); | |
| } | |
| public function sendRefusedByGuestEmail() | |
| { | |
| $message = Yii::$app->mailer->compose('infoMeetingWasRefusedByGuest', ['meeting' => $this, 'participant' => $this->guestParticipant, 'user' => $this->hostParticipant->user]); | |
| $fromEmail = \Yii::$app->params['supportEmail']; | |
| $sourceEmail = $message->getFrom(); | |
| if (!empty($sourceEmail)) $fromEmail = key($sourceEmail); | |
| return $message->setFrom([$fromEmail => \Yii::$app->name . ' robot']) | |
| ->setReplyTo([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) | |
| ->setTo([$this->hostParticipant->user->email => $this->hostParticipant->user->fullname]) | |
| ->setSubject(Yii::t('app', 'Meeting was refused by guest')) | |
| ->send(); | |
| } | |
| public function sendCanceledByAdminEmail() | |
| { | |
| $result = true; | |
| $message = Yii::$app->mailer->compose('infoMeetingWasCanceledByAdmin', ['meeting' => $this, 'participant' => $this->guestParticipant, 'user' => $this->hostParticipant->user]); | |
| $fromEmail = \Yii::$app->params['supportEmail']; | |
| $sourceEmail = $message->getFrom(); | |
| if (!empty($sourceEmail)) $fromEmail = key($sourceEmail); | |
| $result &= $message->setFrom([$fromEmail => \Yii::$app->name . ' robot']) | |
| ->setReplyTo([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) | |
| ->setTo([$this->hostParticipant->user->email => $this->hostParticipant->user->fullname]) | |
| ->setSubject(Yii::t('app', 'Meeting was canceled by admin')) | |
| ->send(); | |
| $message = Yii::$app->mailer->compose('infoMeetingWasCanceledByAdmin', ['meeting' => $this, 'participant' => $this->hostParticipant, 'user' => $this->guestParticipant->user]); | |
| $fromEmail = \Yii::$app->params['supportEmail']; | |
| $sourceEmail = $message->getFrom(); | |
| if (!empty($sourceEmail)) $fromEmail = key($sourceEmail); | |
| $result &= $message->setFrom([$fromEmail => \Yii::$app->name . ' robot']) | |
| ->setReplyTo([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) | |
| ->setTo([$this->guestParticipant->user->email => $this->guestParticipant->user->fullname]) | |
| ->setSubject(Yii::t('app', 'Meeting was canceled by admin')) | |
| ->send(); | |
| return $result; | |
| } | |
| } |