Exemplo n.º 1
0
 public function save()
 {
     if (!$this->id_item) {
         $RItems = new RItems();
         $RItems->date = time();
     } else {
         $RItems = RItems::findOne($this->id_item);
     }
     $RItems->id_user = $this->id_user;
     $RItems->id_city = $this->id_city;
     $RItems->phone = $this->phone;
     $RItems->description = $this->text;
     $RItems->name = $this->name;
     $RItems->id_parent = $this->id_category;
     $RItems->save();
     $this->id_item = $RItems->id;
     if ($this->price) {
         foreach ($this->price as $id_unit => $value) {
             $this->priceSave($id_unit, $value);
         }
     }
     if ($this->field) {
         foreach ($this->field as $id_field => $value) {
             $this->fieldSave($id_field, $value);
         }
     }
     if ($this->image) {
         foreach ($this->image as $image) {
             $this->saveImage($image);
         }
     }
 }
Exemplo n.º 2
0
 public function init()
 {
     $session = Yii::$app->session;
     //Yii::$app->user->logout();
     if ($session->isActive) {
         $session->open();
     }
     $post = Yii::$app->request->post();
     $this->geo = new Geo();
     if (isset($post["setCity"])) {
         $this->geo->setGeo($post);
     }
     $this->loginForm = new LoginForm();
     if (Yii::$app->request->post("auth")) {
         $this->loginForm->load(Yii::$app->request->post());
         $this->loginForm->login();
     }
     Yii::$app->view->params['countItems'] = RItems::find()->isActive()->city($this->geo)->count();
     Yii::$app->view->params['city'] = $this->geo->getName();
 }
Exemplo n.º 3
0
 public function actionSearch()
 {
     $query = RItems::find();
     $get = Yii::$app->request->get();
     $searchForm = new SearchForm();
     $searchForm->load($get);
     $query = $searchForm->setQuery($query);
     $query = $query->isActive();
     if (isset($session["GEO"])) {
         $query = $query->city($this->geo);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 10]);
     $items = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('search', ['items' => $items, 'pages' => $pages, 'searchForm' => $searchForm]);
 }
Exemplo n.º 4
0
 public function getItems()
 {
     return $this->hasMany(RItems::className(), ['id_city' => 'id']);
 }
Exemplo n.º 5
0
 public function getArrayUsers()
 {
     if ($this->bool_item == 1) {
         $items = RItems::find()->where(['id_parent' => $this->id])->all();
         foreach ($items as $item) {
             $id_user[] = $item->id_user;
         }
     } else {
         $cats = FCategory::find()->where(['parent_id' => $this->id])->all();
         $id_user = array();
         foreach ($cats as $cat) {
             if ($cat->arrayUsers) {
                 $id_user = ArrayHelper::merge($id_user, $cat->arrayUsers);
             }
         }
     }
     if (isset($id_user) and count($id_user) > 0) {
         return $id_user;
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 public function getRecord()
 {
     return $this->hasOne(RItems::className(), ['id' => 'id_item']);
 }
Exemplo n.º 7
0
 public function getCountActiveRecord()
 {
     return $this->hasMany(RItems::className(), ['id_user' => 'id'])->rightJoin(RActiveItems::tableName(), "r_items.id = r_active_items.id_item")->count();
 }
Exemplo n.º 8
0
 public function actionModalPlan($id)
 {
     $item = RItems::findOne($id);
     $post = Yii::$app->request->post();
     $RActivateWeeksItem = RActivateWeeksItem::find()->where(['id_item' => $id])->all();
     $weeks = "";
     foreach ($RActivateWeeksItem as $week) {
         $weeks[$week->week] = true;
     }
     if (isset($post["save"])) {
         $RActivateWeeksItem = RActivateWeeksItem::deleteAll(['id_item' => $id]);
         foreach ($post["week"] as $week) {
             $model = new RActivateWeeksItem();
             $model->id_item = $id;
             $model->week = $week;
             $model->time = $post["time"];
             $model->status = 1;
             $model->save();
         }
         $this->redirect(['user/index']);
     }
     return $this->renderPartial('modalPlan', ['item' => $item, 'weeks' => $weeks]);
 }