コード例 #1
0
 /**
  * raiseMailEvent:
  *
  * @param  string $code - код
  * @param  array $data - данные
  * @throws CException
  * @return bool
  **/
 public function raiseMailEvent($code, array $data)
 {
     $mailEvent = MailEvent::model()->with('templates')->find(['condition' => 't.code = :code', 'params' => [':code' => $code]]);
     if (!$mailEvent) {
         throw new CException(Yii::t('MailModule.mail', 'MainEvent with "{code}" code was not found!'), [':code' => $code]);
     }
     if (!count($mailEvent->templates)) {
         throw new CException(Yii::t('MailModule.mail', 'MainEvent with code "{code}" don\'t contain any of active templates!'), [':code' => $code]);
     }
     foreach ($mailEvent->templates as $template) {
         $parsedData = $this->parseTemplate($template, $data);
         if ($this->message_layout) {
             if (isset(Yii::app()->controller)) {
                 $parsedData['body'] = Yii::app()->getController()->renderPartial($this->message_layout, ['content' => $parsedData['body']], true);
             } else {
                 $controller = new Controller('site');
                 $viewPath = Yii::getPathOfAlias('themes') . '/default/views/layouts/mail.php';
                 $parsedData['body'] = $controller->renderInternal($viewPath, ['content' => $parsedData['body']], true);
             }
         }
         if (!$this->getMailComponent()->send($parsedData['from'], $parsedData['from_name'], $parsedData['to'], $parsedData['theme'], $parsedData['body'])) {
             throw new CException(Yii::t('MailModule.mail', 'Error when sending mail!'));
         }
     }
     return true;
 }
コード例 #2
0
 /**
  * Вызывается при инициализации FrontController
  * Присваивает значения, необходимым переменным
  */
 public function init()
 {
     Yii::app()->eventManager->fire(YupeEvents::BEFORE_FRONT_CONTROLLER_INIT, new YupeControllerInitEvent($this, Yii::app()->getUser()));
     parent::init();
     Yii::app()->theme = $this->yupe->theme ?: 'default';
     $bootstrap = Yii::app()->getTheme()->getBasePath() . DIRECTORY_SEPARATOR . "bootstrap.php";
     if (is_file($bootstrap)) {
         require $bootstrap;
     }
 }
コード例 #3
0
 protected function beforeAction($action)
 {
     parent::beforeAction($action);
     if (\Yii::app()->user->isGuest) {
         if ($action->id == 'login') {
             return true;
         }
         $this->redirect(Yii::app()->createUrl('login'));
     } else {
         return true;
     }
 }
コード例 #4
0
 /**
  * Вызывается при инициализации FrontController
  * Присваивает значения, необходимым переменным
  */
 public function init()
 {
     Yii::app()->eventManager->fire(YupeEvents::BEFORE_FRONT_CONTROLLER_INIT, new YupeControllerInitEvent($this, Yii::app()->getUser()));
     parent::init();
     Yii::app()->theme = $this->yupe->theme ?: 'default';
     $this->mainAssets = Yii::app()->getTheme()->getAssetsUrl();
     $bootstrap = Yii::app()->getTheme()->getBasePath() . DIRECTORY_SEPARATOR . "bootstrap.php";
     if (is_file($bootstrap)) {
         require $bootstrap;
     }
     $this->metatitle = $this->yupe->siteName;
     $this->description = $this->yupe->siteDescription;
     $this->keywords = $this->yupe->siteKeyWords;
     $currency = isset($_COOKIE['currency']) ? (int) $_COOKIE['currency'] : 0;
     // Определяем выбранную валюту
     $this->_currentCurrency = $currency > 0 ? $currency : Yii::app()->getModule('realty')->defaultCurrency;
 }
コード例 #5
0
ファイル: BackController.php プロジェクト: alextravin/yupe
 /**
  * @param  \CAction $action
  * @return bool
  */
 protected function beforeAction($action)
 {
     /**
      * $this->module->getId() !== 'install' избавляет от ошибок на этапе установки
      * $this->id !== 'backend' || ($this->id == 'backend' && $action->id != 'modupdate') устраняем проблемы с зацикливанием
      */
     if (($this->id !== 'backend' || $this->id == 'backend' && $action->id != 'modupdate') && ($updates = Yii::app()->migrator->checkForUpdates([$this->module->getId() => $this->module])) !== null && count($updates) > 0) {
         Yii::app()->getUser()->setFlash(YFlashMessages::WARNING_MESSAGE, Yii::t('YupeModule.yupe', 'You must install all migration before start working with module.'));
         $this->redirect(['/yupe/backend/modupdate', 'name' => $this->module->getId()]);
     }
     return parent::beforeAction($action);
 }