/** * @param Schedule $schedule * @return bool * @throws \yii\web\BadRequestHttpException */ public static function sendCalendarInvite($schedule) { if ($schedule->className() !== Schedule::className()) { throw new BadRequestHttpException('Invalid request'); } //Create Email Headers $mime_boundary = '----Meeting Booking----' . MD5(TIME()); $headers = "From: " . self::$from_name . " <" . self::$from_address . ">\n"; $headers .= "Reply-To: " . self::$from_name . " <" . self::$from_address . ">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"{$mime_boundary}\"\n"; $headers .= "Content-class: urn:content-classes:calendarmessage\n"; //Create Email Body (HTML) $message = "--{$mime_boundary}\r\n"; $message .= "Content-Type: text/html; charset=UTF-8\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= "<html>\n"; $message .= "<body>\n"; $message .= '<p>' . $schedule->description . '</p>'; $message .= "<h4>Tickets:</h4>\n"; $message .= "<ul>\n"; foreach ($schedule->notes as $note) { $message .= '<li>' . Html::a($note->ticket->fullName, Url::base(true) . Url::to(['/ticket/view', 'id' => $note->ticket_id])) . "</li>\n"; } $message .= "</ul>\n"; $message .= '(' . Html::a('view calendar event', Url::to(['/schedule/view', 'id' => $schedule->id], true)) . ")\n"; $message .= "</body>\n"; $message .= "</html>\n"; $message .= "--{$mime_boundary}\r\n"; $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST' . "\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= 'BEGIN:VCALENDAR' . "\r\n" . 'METHOD:REQUEST' . "\r\n" . 'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" . 'VERSION:2.0' . "\r\n" . 'BEGIN:VTIMEZONE' . "\r\n" . 'TZID:Pacific Standard Time' . "\r\n" . 'BEGIN:STANDARD' . "\r\n" . 'DTSTART:16010101T020000' . "\r\n" . 'TZOFFSETFROM:-0700' . "\r\n" . 'TZOFFSETTO:-0800' . "\r\n" . 'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" . 'END:STANDARD' . "\r\n" . 'BEGIN:DAYLIGHT' . "\r\n" . 'DTSTART:16010101T020000' . "\r\n" . 'TZOFFSETFROM:-0800' . "\r\n" . 'TZOFFSETTO:-0700' . "\r\n" . 'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" . 'END:DAYLIGHT' . "\r\n" . 'END:VTIMEZONE' . "\r\n" . 'BEGIN:VEVENT' . "\r\n" . 'ORGANIZER;CN="' . $schedule->createdBy->name . '":MAILTO:' . self::$from_address . "\r\n" . 'ATTENDEE;CN="' . $schedule->tech->name . '";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:' . $schedule->tech->email . "\r\n" . 'LAST-MODIFIED:' . date("Ymd\\TGis") . "\r\n" . 'UID:' . date("Ymd\\TGis", strtotime($schedule->start_time)) . rand() . "@" . self::$domain . "\r\n" . 'DTSTAMP:' . date("Ymd\\TGis") . "\r\n" . 'DTSTART;TZID="Pacific Standard Time":' . date("Ymd\\THis", strtotime($schedule->start_time)) . "\r\n" . 'DTEND;TZID="Pacific Standard Time":' . date("Ymd\\THis", strtotime($schedule->endTime)) . "\r\n" . 'TRANSP:OPAQUE' . "\r\n" . 'SEQUENCE:1' . "\r\n" . 'SUMMARY:' . $schedule->invoice->location->fullName . "\r\n" . 'LOCATION:' . $schedule->invoice->location->address . "\r\n" . 'CLASS:PUBLIC' . "\r\n" . 'PRIORITY:5' . "\r\n" . 'BEGIN:VALARM' . "\r\n" . 'TRIGGER:-PT60M' . "\r\n" . 'ACTION:DISPLAY' . "\r\n" . 'DESCRIPTION:Reminder' . "\r\n" . 'END:VALARM' . "\r\n" . 'END:VEVENT' . "\r\n" . 'END:VCALENDAR' . "\r\n"; return self::send($schedule->tech->email, $schedule->invoice->location->fullName, $message, $headers); }
/** * @return ScheduleQuery */ public function getSchedule() { return $this->hasOne(Schedule::className(), ['id' => 'schedule_id'])->inverseOf('labors'); }
/** * @return ScheduleQuery */ public function getSchedules() { return $this->hasMany(Schedule::className(), ['tech_id' => 'contact_id']); }
/** * @return \yii\db\ActiveQuery */ public function getSchedules() { return $this->hasMany(Schedule::className(), ['plant_id' => 'id'])->orderBy(['id' => SORT_ASC]); }
/** * @return ScheduleQuery */ public function getSchedules() { return $this->hasMany(Schedule::className(), ['invoice_id' => 'id'])->inverseOf('invoice'); }