Currently its only purpose is to remove all html tags to prevent XSS.
Inheritance: extends CActiveRecord
Example #1
0
 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();
     }
 }
Example #2
0
 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));
 }
Example #3
0
 protected function isOrderExists($id)
 {
     $this->_order = BaseActiveRecord::model($this->orderModel)->findByPk((int) $id);
     if ($this->_order) {
         return true;
     }
     return false;
 }
Example #4
0
 /**
  * @param $relation
  * @return mixed
  * @throws CException
  */
 protected function getRelationDefnition($relation)
 {
     $relations = $this->model->relations();
     if (!array_key_exists($relation, $relations)) {
         throw new CException('Relation does not exist');
     }
     $relationDefinition = $relations[$relation];
     return $relationDefinition;
 }
Example #5
0
 public function __construct($scenario = 'insert')
 {
     parent::__construct($scenario);
     if (!self::$_isStart) {
         self::$_isStart = true;
         self::processModelRelation($this);
         self::$_isStart = false;
     }
 }
 public function afterValidate()
 {
     $one_of = array('site_id', 'subspecialty_id', 'firm_id');
     $found = false;
     foreach ($one_of as $attr) {
         if ($this->{$attr}) {
             $found = true;
         }
     }
     if (!$found) {
         $this->addError(null, 'At least one of ' . implode(', ', array_map(function ($attr) {
             return $this->getAttributeLabel($attr);
         }, $one_of)) . ' must be set.');
     }
     parent::afterValidate();
 }
Example #7
0
 /**
  * Takes an attribute name and makes sure appropriate relationships are included.
  *
  * This will take an attribute name many layers of relationship deep, make sure that all appropriate tables are
  * included with the result and return a string that is then acceptable to be used in a where clause.
  *
  * @param CDbCriteria $criteria
  * @param string      $attribute
  * @param string      $search
  *
  * @return string
  */
 protected function relationalAttribute(CDbCriteria $criteria, $attribute, $search)
 {
     $search = $this->model->getTableAlias() . '.' . $search;
     if (strpos($attribute, '.')) {
         $relationship = explode('.', $attribute);
         $relationshipArray = array();
         while (count($relationship) > 1) {
             $relationshipString = array_shift($relationship);
             $search = $relationshipString;
             if (count($relationshipArray)) {
                 $relationshipString = implode('.', $relationshipArray) . '.' . $relationshipString;
             }
             $relationshipArray[] = $relationshipString;
         }
         $search .= '.' . array_shift($relationship);
         $criteria->together = true;
         $criteria->with = array_merge($criteria->with, $relationshipArray);
     }
     return $search;
 }
Example #8
0
 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);
 }
Example #9
0
 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));
 }
Example #10
0
 public function attributeLabels()
 {
     $labels = parent::attributeLabels();
     // TODO: Change the autogenerated stub
     return ArrayHelper::merge($labels, ['user_id' => \Yii::$app->params['lang']['user_id'], 'email' => \Yii::$app->params['lang']['email'], 'user_name' => \Yii::$app->params['lang']['user_name'], 'password' => \Yii::$app->params['lang']['password'], 'question' => \Yii::$app->params['lang']['question'], 'answer' => \Yii::$app->params['lang']['answer'], 'sex' => \Yii::$app->params['lang']['sex'], 'birthday' => \Yii::$app->params['lang']['birthday'], 'user_money' => \Yii::$app->params['lang']['user_money'], 'frozen_money' => \Yii::$app->params['lang']['frozen_money'], 'pay_points' => \Yii::$app->params['lang']['pay_points'], 'rank_points' => \Yii::$app->params['lang']['rank_points'], 'address_id' => \Yii::$app->params['lang']['address_id'], 'reg_time' => \Yii::$app->params['lang']['reg_time'], 'last_login' => \Yii::$app->params['lang']['last_login'], 'last_time' => \Yii::$app->params['lang']['last_time'], 'last_ip' => \Yii::$app->params['lang']['last_ip'], 'visit_count' => \Yii::$app->params['lang']['visit_count'], 'user_rank' => \Yii::$app->params['lang']['user_rank'], 'is_special' => \Yii::$app->params['lang']['is_special'], 'salt' => \Yii::$app->params['lang']['salt'], 'parent_id' => \Yii::$app->params['lang']['parent_id'], 'flag' => \Yii::$app->params['lang']['flag'], 'alias' => \Yii::$app->params['lang']['alias'], 'msn' => \Yii::$app->params['lang']['msn'], 'qq' => \Yii::$app->params['lang']['qq'], 'office_phone' => \Yii::$app->params['lang']['office_phone'], 'home_phone' => \Yii::$app->params['lang']['home_phone'], 'mobile_phone' => \Yii::$app->params['lang']['mobile_phone'], 'is_validated' => \Yii::$app->params['lang']['is_validated'], 'credit_line' => \Yii::$app->params['lang']['credit_line']]);
 }
Example #11
0
 public function actionView($id)
 {
     $model = BaseActiveRecord::model('User')->findByPk($id);
     if ($model === null) {
         $this->throw404Error();
     }
     $this->render('/view', array('model' => $model));
 }
 public function resetScope($resetDefault = true)
 {
     $this->enable_version = true;
     $this->fetch_from_version = false;
     return parent::resetScope($resetDefault);
 }
Example #13
0
 /**
  * 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;
 }
Example #14
0
 public function save($runValidation = true, $attributes = null, $allow_overriding = false)
 {
     if (isset($_SERVER['REMOTE_ADDR'])) {
         if (!($ipaddr = AuditIPAddr::model()->find('name=?', array($_SERVER['REMOTE_ADDR'])))) {
             $ipaddr = new AuditIPAddr();
             $ipaddr->name = $_SERVER['REMOTE_ADDR'];
             if (!$ipaddr->save()) {
                 throw new Exception("Unable to save audit IP address: " . print_r($ipaddr->getErrors(), true));
             }
         }
         if (isset($_SERVER['HTTP_USER_AGENT'])) {
             if (!($useragent = AuditUseragent::model()->find('name=?', array($_SERVER['HTTP_USER_AGENT'])))) {
                 $useragent = new AuditUseragent();
                 $useragent->name = $_SERVER['HTTP_USER_AGENT'];
                 if (!$useragent->save()) {
                     throw new Exception("Unable to save user agent: " . print_r($useragent->getErrors(), true));
                 }
             }
             $this->useragent_id = $useragent->id;
         }
         if (!($server = AuditServer::model()->find('name=?', array($_SERVER['SERVER_NAME'])))) {
             $server = new AuditServer();
             $server->name = $_SERVER['SERVER_NAME'];
             if (!$server->save()) {
                 throw new Exception("Unable to save server: " . print_r($server->getErrors(), true));
             }
         }
         $this->ipaddr_id = $ipaddr->id;
         $this->server_id = $server->id;
         $this->request_uri = $_SERVER['REQUEST_URI'];
         if ($this->user) {
             $this->site_id = Yii::app()->session['selected_site_id'];
             $this->firm_id = Yii::app()->session['selected_firm_id'];
         }
     }
     return parent::save($runValidation, $attributes, $allow_overriding);
 }
Example #15
0
 private function loadOwnOfferByIdInvoice($id, $criteria = null)
 {
     $offer = null;
     if ($invoice = BaseActiveRecord::model('Invoice')->findByPk($id, $criteria)) {
         $offer = $invoice->offer;
     }
     return $offer;
 }
Example #16
0
 protected function saveModel(\BaseActiveRecord $model)
 {
     if (!$model->save()) {
         throw new ValidationFailure("Validation failure on " . get_class($model), $model->errors);
     }
 }
Example #17
0
 public function run()
 {
     Yii::app()->user->setReturnUrl(Yii::app()->request->url);
     $feedback = BaseActiveRecord::newModel('Feedback');
     $this->render('feedback', array('model' => $feedback));
 }
Example #18
0
 protected function beforeSave()
 {
     if (!$this->isNewRecord) {
         $this->_pkBeforeSave = $this->getOldPrimaryKey();
     }
     return parent::beforeSave();
 }
 /**
  * Returns the static model of the specified AR class.
  * @return the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 protected function beforeValidate()
 {
     return parent::beforeValidate();
 }
Example #21
0
 /**
  * Pass through use_pas flag to allow pas supression.
  *
  * @see CActiveRecord::instantiate()
  */
 protected function instantiate($attributes)
 {
     $model = parent::instantiate($attributes);
     $model->use_pas = $this->use_pas;
     return $model;
 }
Example #22
0
 public function getOwnerModel()
 {
     if ($this->_ownerModel === false) {
         if ($this->id_object != null && $this->id_instance != null) {
             $commentsModule = Yii::app()->getModule('comments');
             $this->_ownerModel = BaseActiveRecord::model($commentsModule->modelClassMap[$this->id_object])->findByPk($this->id_instance);
         } else {
             $this->_ownerModel = null;
         }
     }
     return $this->_ownerModel;
 }
 /**
  * Получение дерева экземпляров модели
  * @param mixed $addCriteria параметры запроса на получение данных
  * @param string $cacheKey ключ для кэширования данных
  */
 public function getTree($addCriteria = array(), $cacheKey = null)
 {
     $cacheKey = $cacheKey == null ? $this->owner->tableName() : $cacheKey;
     if (isset(self::$_tree[$cacheKey])) {
         return self::$_tree[$cacheKey];
     }
     $tree = array();
     if (($cache = Yii::app()->{$this->cacheId}) !== null && ($val = $cache->get($cacheKey)) !== false) {
         $tree = $val;
     } else {
         $criteria = new CDbCriteria();
         $criteria->order = $this->order;
         if ($this->with != null) {
             $criteria->with = $this->with;
         }
         $criteria->mergeWith($addCriteria);
         $model = null;
         if ($this->owner instanceof BaseActiveRecord) {
             $model = BaseActiveRecord::model(get_class($this->owner));
         } else {
             $model = CActiveRecord::model(get_class($this->owner));
         }
         $items = $model->findAll($criteria);
         $child = array();
         $countIntems = count($items);
         $idParentField = $this->idParentField;
         for ($i = 0; $i < $countIntems; $i++) {
             $item = $items[$i];
             $id = $item->getPrimaryKey();
             $idParent = $item->{$idParentField};
             if ($idParent !== null) {
                 $child[$idParent][] = $item;
             }
         }
         $className = get_class($model);
         $tree = new $className();
         for ($i = 0; $i < $countIntems; $i++) {
             $item = $items[$i];
             $id = $item->getPrimaryKey();
             if (isset($child[$id])) {
                 $countChild = count($child[$id]);
                 for ($k = 0; $k < $countChild; $k++) {
                     $child[$id][$k]->setParent($item);
                 }
                 $item->setChild($child[$id]);
             }
             if ($item->{$idParentField} === null) {
                 $tree->addChild($item);
             }
         }
         if ($cache !== null) {
             $cacheKeys = $cache->get($this->getCacheKeysKey());
             if ($cacheKeys === false) {
                 $cacheKeys = array();
             }
             if (!isset($cacheKeys[$this->owner->tableName()])) {
                 $cacheKeys[$this->owner->tableName()] = array();
             }
             if (!in_array($cacheKey, $cacheKeys[$this->owner->tableName()])) {
                 $cacheKeys[$this->owner->tableName()][] = $cacheKey;
             }
             $cache->set($cacheKey, $tree, $this->cacheExpire);
             //кешируем ключи, чтобы в последствии была возможность очистить кеш при изменении модели
             $cache->set($this->getCacheKeysKey(), $cacheKeys, $this->cacheExpire);
         }
     }
     self::$_tree[$cacheKey] = $tree;
     return $tree;
 }
Example #24
0
 public function actionSetStatusApproveComment()
 {
     $result = array();
     $idComment = (int) Yii::app()->request->getPost('idComment');
     $comment = BaseActiveRecord::model('CommentYii')->findByPk($idComment);
     if ($comment != null && Yii::app()->user->checkAccess('approveComment', array('comment' => $comment))) {
         $comment->setApproved();
         return $this->getSuccessResultData($comment);
     }
     return $this->getFailResultData($comment);
 }