public function actionRegister() { $model = BaseActiveRecord::newModel('User', 'register'); $modelClass = get_class($model); $this->performAjaxValidation($model, 'register-form'); if (isset($_POST[$modelClass])) { $model->attributes = $_POST[$modelClass]; //Создаем indentity раньше сохранения модели //т.к. после сохранения поле user_password измениться на хеш $identity = new UserIdentity($model->name, $model->user_password); $model->onAfterSave = array($this, 'sendRegisterMessage'); if ($model->save()) { //если разрешено сразу авторизовать пользователя if (Yii::app()->getModule('user')->immediatelyAuthorization) { //загружаем модель пользователя $identity->authenticate(); //Сразу авторизуем пользователя Yii::app()->user->login($identity); Yii::app()->user->setFlash('registerSuccess', 'Регистрация успешно завершена.'); } else { Yii::app()->user->setFlash('registerSuccess', 'Регистрация успешно завершена. Теперь вы можете войти на сайт через форму авторизации.'); } $this->redirect(Yii::app()->createUrl($this->getRedirectRouteAfterRegister())); } } $this->render('/register', array('model' => $model)); }
public function afterSave($event) { $className = get_class(VotingAnswer::model()); $postAnswers = HU::post($className, array()); foreach ($this->answers as $answer) { /** * @var $answer VotingAnswer */ if (isset($postAnswers[$answer->id_voting_answer]['name']) && trim($postAnswers[$answer->id_voting_answer]['name']) != '') { $answer->name = trim($postAnswers[$answer->id_voting_answer]['name']); $answer->update(array('name')); } else { $answer->delete(); } } foreach ($postAnswers as $i => $name) { if ($i > 0) { continue; } if (trim($name['name']) == '') { continue; } $answer = BaseActiveRecord::newModel($className, 'backendInsert'); $answer->id_voting = $this->model->id_voting; $answer->name = trim($name['name']); $answer->save(); } }
public function actionView($id) { $quiz = $this->loadModel($id); $quiz->setScenario(Quiz::SCENARIO_ON_FORM_VALIDATE); $answer = BaseActiveRecord::newModel('QuizAnswerUser'); $captcha = new CaptchaForm(); // валидация по AJAX $this->performAjaxValidation(array($quiz, $answer, $captcha)); if (isset($_POST[get_class($quiz)], $_POST[get_class($answer)], $_POST[get_class($captcha)])) { $quiz->setAttributes($_POST[get_class($quiz)]); $answer->setAttributes($_POST[get_class($answer)]); $captcha->setAttributes($_POST[get_class($captcha)]); // проверяем $valid = $quiz->validate(); $valid = $answer->validate() && $valid; //$valid = $captcha->validate() && $valid; if ($valid) { //$answer->answer = QuizAnswerUser::prepareAnswerData($quiz); $answer->answer = $this->renderPartial('/user_answer', array('quiz' => $quiz), true); $answer->id_quiz = $quiz->getPrimaryKey(); if ($answer->save()) { $this->afterDataSave($answer); } } } $this->render('view', array('quiz' => $quiz, 'answer' => $answer, 'captcha' => $captcha)); }
public function actionPostComment() { $comment = BaseActiveRecord::newModel('CommentYii'); $className = get_class($comment); if (isset($_POST[$className]) && Yii::app()->request->isAjaxRequest) { $comment->attributes = $_POST[$className]; $comment->comment_date = time(); $comment->moderation = $comment->config['premoderate'] ? CommentYii::STATUS_PENDING : CommentYii::STATUS_APPROVED; $comment->id_parent = $comment->id_parent == 0 ? null : $comment->id_parent; Yii::app()->getModule('comments')->getEventHandlers('onNewComment')->insertAt(0, array($this, 'sendMessage')); if ($comment->save()) { return $this->getSuccessResultData($comment); } return $this->getFailResultData($comment); } }
public function actionIndex() { $model = BaseActiveRecord::newModel('Feedback'); $modelClass = get_class($model); if (isset($_POST['ajax']) && $_POST['ajax'] === 'feedbackForm') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST[$modelClass])) { $model->attributes = $_POST[$modelClass]; $model->onAfterSave = array($this, 'sendMessage'); //Регистрируем обработчик события if ($model->save()) { Yii::app()->user->setFlash('feedback-success', 'Спасибо за обращение. Ваше сообщение успешно отправлено.'); } else { // вообще сюда попадать в штатных ситуациях не должны // только если кул хацкер резвится Yii::app()->user->setFlash('feedback-message', CHtml::errorSummary($model, '<p>Не удалось отправить форму</p>')); } } $this->redirect(Yii::app()->user->returnUrl); }
public function actionIndex() { $model = BaseActiveRecord::newModel('Question'); $modelClass = get_class($model); if (isset($_POST['ajax'])) { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST[$modelClass])) { $model->attributes = $_POST[$modelClass]; $model->visible = $this->module->moderate ? BaseActiveRecord::FALSE_VALUE : BaseActiveRecord::TRUE_VALUE; $model->onAfterSave = array($this, 'sendMessage'); if ($model->save()) { Yii::app()->user->setFlash('questionAdd', 'Спасибо, ваш вопрос отправлен.'); $this->refresh(); } } $criteria = new CDbCriteria(); $criteria->condition = 'visible = 1'; $criteria->order = 'ask_date DESC'; $dataProvider = new CActiveDataProvider('Question', array('criteria' => $criteria, 'pagination' => array('pageSize' => $this->module->pageSize))); $this->render('/index', array('dataProvider' => $dataProvider, 'model' => $model)); }
/** * Create new comment model and initialize it with owner data * @return CommentYii */ protected function createNewComment() { $comment = BaseActiveRecord::newModel('CommentYii'); $comment->id_object = $this->model->getIdObject(); $comment->id_instance = $this->model->getIdInstance(); return $comment; }
public function run() { Yii::app()->user->setReturnUrl(Yii::app()->request->url); $feedback = BaseActiveRecord::newModel('Feedback'); $this->render('feedback', array('model' => $feedback)); }
protected function pay($offer) { $invoice = BaseActiveRecord::newModel('Invoice'); $invoice->amount = $offer->amount; $invoice->id_offer = $offer->primaryKey; $invoice->create_date = time(); if ($invoice->save()) { $billing = Yii::app()->billing; $sInvDesc = "Оплата заказа [ID = " . $offer->primaryKey . "]"; $billing->pay($invoice->amount, $invoice->primaryKey, $sInvDesc); } else { throw new ErrorException('Не удалось сохранить счет errors: ' . print_r($invoice->getErrors(), true)); } }