/** * Возвращает модель по указанному идентификатору * Если модель не будет найдена - возникнет HTTP-исключение. * * @param integer $id - идентификатор нужной модели * * @return class $model * * @throws CHttpException */ public function loadModel($id) { if (($model = MailTemplate::model()->findByPk($id)) === null) { throw new CHttpException(404, Yii::t('MailModule.mail', 'Requested page was not found')); } return $model; }
/** * sendTemplate: * * @param string $code - код * @param array $data - данные * @return bool * @throws CException **/ public function sendTemplate($code, array $data) { $template = MailTemplate::model()->find(array('condition' => 't.code = :code', 'params' => array(':code' => $code))); if (!$template) { throw new CException(Yii::t('MailModule.mail', 'Template with "{code}" was not found!'), array('{code}' => $code)); } $parsedData = $this->parseTemplate($template, $data); if (!$this->getMailComponent()->send($parsedData['from'], $parsedData['to'], $parsedData['theme'], $parsedData['body'])) { throw new CException(Yii::t('MailModule.mail', 'Error when sending mail!')); } return true; }
public function sendCodes($controller) { if (!($student = Student::model()->findByAttributes(array('email' => $this->email)))) { return false; } $exercises = Exercise::model()->with('assignment')->sortByDuedate()->findAllByAttributes(array('student_id' => $student->id)); foreach ($exercises as $exercise) { $exercise->link = Yii::app()->controller->createAbsoluteSslUrl('exercise/info', array('k' => $exercise->generateAckKey())); } $options = array(); if (Helpers::getYiiParam('addOriginatingIP')) { $options['originating_IP'] = sprintf('[%s]', Yii::app()->request->userHostAddress); } return MailTemplate::model()->mailFromTemplate('send_codes', array($student->email => $student->name), array('student' => $student, 'exercises' => $exercises), $options); }
public function prepareMessages($students) { $result = array('prepared' => 0, 'failed' => 0); foreach ($students as $student) { if (!$student->email) { $result['failed']++; continue; } if (MailTemplate::model()->messageFromTemplate('direct_message', $student->id, array('student' => $student, 'subject' => $this->subject, 'body' => $this->body), $this->confirmed, $this->acknowledgement)) { $result['prepared']++; } else { $result['failed']++; } } return $result; }
/** * Displays the contact page */ public function actionContact($name = '', $subject = '', $body = '') { $model = new ContactForm(); $model->name = $name; $model->subject = $subject; $model->body = $body; if (isset($_POST['ContactForm'])) { $model->attributes = $_POST['ContactForm']; if ($model->validate()) { MailTemplate::model()->mailFromTemplate('contact_form', Helpers::getYiiParam('adminEmail'), array('subject' => $model->subject, 'name' => $model->name, 'email' => $model->email, 'body' => $model->body), array('replyto' => $model->email)); Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.'); $this->refresh(); } } $this->render('contact', array('model' => $model)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = MailTemplate::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Allows the upload of a file. */ public function actionUpload($code = '') { $model = new UploadForm(); if (!Yii::app()->user->isGuest) { $model->byteacher = true; } $model->code = $code; $model->setUrlExample(); if (isset($_POST['UploadForm'])) { $model->uploadedfile = CUploadedFile::getInstance($model, 'uploadedfile'); $model->attributes = $_POST['UploadForm']; if ($model->validate()) { if ($file = $model->saveData(Yii::app()->basePath . DIRECTORY_SEPARATOR . Helpers::getYiiParam('uploadDirectory'))) { if (!$model->byteacher) { if ($file->exercise->assignment->notification) { MailTemplate::model()->mailFromTemplate('new_work_notification', Helpers::getYiiParam('adminEmail'), array('student' => $model->exercise->student, 'file' => $file, 'url' => $this->createAbsoluteSslUrl('file/view', array('id' => $file->id, 'hash' => $file->md5)))); } if ($model->exercise->student->email) { MailTemplate::model()->mailFromTemplate('new_work_acknowledgement', array($model->exercise->student->email => $model->exercise->student), array('student' => $model->exercise->student, 'file' => $file, 'url' => $this->createAbsoluteSslUrl('file/view', array('id' => $file->id, 'hash' => $file->md5)))); Yii::app()->getUser()->setFlash('success', 'Work correctly uploaded / saved. An email has been sent to your address.'); } } else { Yii::app()->getUser()->setFlash('success', 'Work correctly uploaded / saved.'); } $this->redirect(array('file/view', 'id' => $file->id, 'hash' => $file->md5, 'status' => 1)); } else { Yii::app()->getUser()->setFlash('error', 'The work could not be saved.'); } } } $this->render('upload', array('model' => $model)); }
public function generateInvitation() { if (!$this->student->email) { return 0; } if (MailTemplate::model()->messageFromTemplate('new_assignment_notification', $this->student->id, array('student' => $this->student, 'assignment' => $this->assignment, 'exercise' => $this, 'link' => Yii::app()->controller->createAbsoluteSslUrl('exercise/info', array('k' => $this->generateAckKey()))), true, false)) { $this->increaseStatus(self::STATUS_NOTIFIED); } return 1; }