Exemplo n.º 1
0
 public function run($id = false, $model = false, $forceDelete = false)
 {
     $modelName = $this->model && is_string($this->model) ? $this->model : (request()->getParam('model') ? request()->getParam('model') : $this->controller->model);
     if ($id) {
         //delete one model
         $result = $this->controller->loadModel($modelName, $id)->delete();
         if (!request()->isAjaxRequest && $result) {
             $this->controller->redirect(user()->gridIndex);
         }
         Common::jsonSuccess(true);
     } else {
         $items = Common::getChecked('items');
         if ($items) {
             if (!$forceDelete) {
                 foreach ($items as $id) {
                     $this->controller->loadModel($modelName, $id)->delete();
                 }
             } else {
                 $criteria = new SDbCriteria();
                 $criteria->compare('id', $items);
                 CActiveRecord::model($modelName)->deleteAll($criteria);
             }
             Common::jsonSuccess(true);
         }
     }
     Common::jsonError("Ошибка");
 }
Exemplo n.º 2
0
 /**
  * Вернуть все комментарии для указанной реляции, в отформатированном виде
  * @return JSON - список комментариев
  */
 public function actionGetComments()
 {
     $ownerModelName = request()->getParam('ownerModelName');
     $idOwner = request()->getParam('idOwner');
     $commentsRelation = request()->getParam('commentsRelation');
     $additionalFields = request()->getParam('additionalFields');
     $model = $this->owner->loadModel($ownerModelName, $idOwner);
     $comments = $model->{$commentsRelation};
     if (!$comments && $additionalFields) {
         $additionalFields = CJSON::decode($additionalFields);
         $criteria = new SDbCriteria();
         foreach ($additionalFields as $field => $value) {
             $criteria->compare($field, $value);
         }
         $comments = ConsolidatedReportMonthlyComment::model()->findAll($criteria);
     }
     $result = [];
     foreach ($comments as $comment) {
         $result[] = $comment->render();
     }
     echo CJSON::encode($result);
 }
Exemplo n.º 3
0
 public function getApiKey($username, $password)
 {
     //тут используется та же логика что при авторизации
     $criteria = new SDbCriteria();
     $criteria->compare(String::isEmail($username) ? 'email' : 'username', $username);
     $user = self::model()->noSocial()->active()->find($criteria);
     if ($user && $user->validatePassword($password)) {
         return $user->api_key;
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Функция которая сбрасывает пароль на новый
  * @param  String $username Имя пользователя
  * @param  String $key      Ключ для сброса пароля, который был выслан ему по почте
  * @return
  */
 public function actionResetPassword($username, $key)
 {
     $criteria = new SDbCriteria();
     $criteria->compare('username', $username);
     $criteria->compare('is_social_user', Buyer::SOCIAL_BUYER_NO);
     $criteria->compare('reset_key', $key);
     $model = AR::model($this->model)->find($criteria);
     if (!$model) {
         exception(404);
     }
     $model->scenario = 'resetPassword';
     $model->password = '';
     $this->performAjaxValidation($model);
     if (isset($_POST[$this->model])) {
         $model->attributes = $_POST;
         //save new password and salt
         if ($model->save()) {
             //set flash message
             setFlash('password-changed', 'password-change-success');
         }
     }
     $this->pageTitle = t('user', 'Смена пароля');
     $this->render('forgotpassword', compact('model'));
 }
Exemplo n.º 5
0
 public static function getAlternativeProducts($id, $limit = 5)
 {
     $product = Product::model()->findByPk($id);
     if (!$product) {
         return false;
     }
     $category = $product->id_category;
     $price = $product->price;
     $up = $price + $price / 100 * self::PRICE_PERCENT;
     $down = $price - $price / 100 * self::PRICE_PERCENT;
     $criteria = new SDbCriteria();
     $criteria->addNotInCondition('id', [$id]);
     $criteria->compare('t.id_category', $category);
     $criteria->compare('t.price', '<' . $up);
     $criteria->compare('t.price', '>' . $down);
     $criteria->compare('active', self::ACTIVE);
     $criteria->group = 'id_brand';
     $products = Product::model()->findAll($criteria);
     if ($products) {
         $ids = CHtml::listData($products, 'id', 'id');
         shuffle($ids);
         $ids = array_slice($ids, 0, $limit);
         return $ids;
     }
     return false;
 }