public function beforeAction($action) { //$css_file_id=''; $test = 11; $ref = Yii::$app->request->get('ref', ''); $id = Yii::$app->request->get('id', ''); $user_id = 0; if (!\Yii::$app->user->isGuest) { $user_id = \Yii::$app->user->identity->getId(); } if (!empty($ref)) { $user_id = AlphaId::id($ref, true); } $user_setting = UserSetting::findByUserId($user_id); if ($user_setting) { $this->getView()->params['css_file_id'] = $user_setting->css_file_id; $this->getView()->params['logo_url'] = $user_setting->logo_url; $this->getView()->params['ref_user_id'] = $user_id; $this->getView()->params['id'] = $id; $this->getView()->params['ref'] = $ref; } else { $this->getView()->params['css_file_id'] = ''; $this->getView()->params['logo_url'] = ''; } if ($user_id != 0) { $cartForm = new CartForm(); $rows = $cartForm->getUserCart($user_id, true); $this->getView()->params['cart_count'] = count($rows); $invoicies = Invoice::find()->where(['user_id' => $user_id, 'status' => Invoice::STATUS_NEW])->all(); $invoice = Invoice::findOne(['user_id' => $user_id, 'status' => Invoice::STATUS_NEW]); $invoice_id = 0; if ($invoice) { $invoice_id = $invoice->id; } $this->getView()->params['invoice_count'] = count($invoicies); $this->getView()->params['invoice_id'] = $invoice_id; if (!Yii::$app->user->isGuest && Yii::$app->user && Yii::$app->user->identity) { $this->getView()->params['demo'] = Yii::$app->user->identity->role == User::ROLE_DEMO ? true : false; } } else { $this->getView()->params['demo'] = 0; } return parent::beforeAction($action); }
public function save() { $old_setting = UserSetting::findByUserId($this->user_id); if (empty($old_setting)) { $setting = new UserSetting(); $setting->user_id = $this->user_id; $setting->color_1 = $this->color_1; $setting->color_2 = $this->color_2; $setting->primary_text_color = $this->primary_text_color; $setting->primary_back_color = $this->primary_back_color; $setting->primary_border_color = $this->primary_border_color; $setting->primary_active_border_color = $this->primary_active_border_color; $setting->primary_active_back_color = $this->primary_active_back_color; $setting->primary_active_text_color = $this->primary_active_text_color; $setting->default_text_color = $this->default_text_color; $setting->default_back_color = $this->default_back_color; $setting->default_border_color = $this->default_border_color; $setting->default_active_back_color = $this->default_active_back_color; $setting->default_active_text_color = $this->default_active_text_color; $setting->default_active_border_color = $this->default_active_border_color; $setting->active_link_color = $this->active_link_color; $setting->link_color = $this->link_color; $setting->css = $this->css; if ($this->logo_url) { $setting->logo_url = $this->logo_url; } else { unset($setting->logo_url); } $setting->css_file_id = $this->saveCss($setting->css); $setting->save(); return $setting; } else { $old_setting->color_1 = $this->color_1; $old_setting->color_2 = $this->color_2; $old_setting->primary_text_color = $this->primary_text_color; $old_setting->primary_back_color = $this->primary_back_color; $old_setting->primary_border_color = $this->primary_border_color; $old_setting->primary_active_border_color = $this->primary_active_border_color; $old_setting->primary_active_back_color = $this->primary_active_back_color; $old_setting->primary_active_text_color = $this->primary_active_text_color; $old_setting->default_text_color = $this->default_text_color; $old_setting->default_back_color = $this->default_back_color; $old_setting->default_border_color = $this->default_border_color; $old_setting->default_active_back_color = $this->default_active_back_color; $old_setting->default_active_text_color = $this->default_active_text_color; $old_setting->default_active_border_color = $this->default_active_border_color; $old_setting->active_link_color = $this->active_link_color; $old_setting->link_color = $this->link_color; $old_setting->css = $this->css; if ($this->logo_url) { $old_setting->logo_url = $this->logo_url; } else { unset($old_setting->logo_url); } $old_css_file_id = $old_setting->css_file_id; $old_setting->css_file_id = $this->saveCss($old_setting->css); $old_setting->update(); if (!empty($old_css_file_id) && $old_css_file_id !== 'pb-theme-color-default.css') { $css_file_path = UserUrl::css() . DIRECTORY_SEPARATOR . $old_css_file_id . '.css'; if (file_exists($css_file_path)) { unlink($css_file_path); } } return $old_setting; } return null; }
public function actionUsers() { $this->layout = 'default'; if (Yii::$app->user->isGuest) { $this->redirect(Url::toRoute(['user/logout'])); return; } if (Yii::$app->user->identity->role != User::ROLE_ADMIN) { $this->redirect(Url::toRoute(['user/logout'])); return; } $role = Yii::$app->request->get('role', User::ROLE_USER); $username = Yii::$app->request->get('username', null); $email = Yii::$app->request->get('email', null); $user_id = Yii::$app->request->get('user_id', null); $filter = ['username' => $username, 'email' => $email, 'user_id' => $user_id]; $sort = new Sort(['attributes' => ['updated_at' => SORT_ASC]]); $condition = ['role' => $role, 'status' => User::STATUS_ACTIVE]; if (!empty($email)) { $condition['email'] = $email; } if (!empty($user_id)) { $condition['id'] = $user_id; } $query = User::find()->where($condition); if (!empty($username)) { $query = $query->andFilterWhere(['like', 'username', $username]); } $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $users = $query->orderBy(['created_at' => SORT_DESC])->offset($pages->offset)->limit($pages->limit)->all(); $user_ids = []; foreach ($users as $key => $user) { $user_ids[] = $user->id; } //echo count($user_ids); $users_settings = UserSetting::find()->where(['user_id' => $user_ids])->all(); //echo count($users_settings); $mapUsersSettings = []; foreach ($users_settings as $key => $users_setting) { $mapUsersSettings[$users_setting->user_id] = $users_setting; } $sidemenus = [['title' => Yii::t('app', 'Пользователи'), 'role' => User::ROLE_USER, 'count' => User::find()->where(['role' => User::ROLE_USER, 'status' => User::STATUS_ACTIVE])->count()], ['title' => Yii::t('app', 'Супер администраторы'), 'role' => User::ROLE_ADMIN, 'count' => User::find()->where(['role' => User::ROLE_ADMIN, 'status' => User::STATUS_ACTIVE])->count()]]; return $this->render('users', ['users' => $users, 'pages' => $pages, 'users_settings' => $mapUsersSettings, 'sidemenus' => $sidemenus, 'role' => $role, 'filter' => $filter]); }
public function actionSettings() { if (Yii::$app->user->isGuest) { $this->redirect(Url::toRoute(['intro/index'])); return; } if (Yii::$app->user->identity->role == User::ROLE_DEMO) { $this->redirect(Url::toRoute(['user/signup-demo'])); return; } $this->layout = 'default'; $less_content = file_get_contents(Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'less' . DIRECTORY_SEPARATOR . 'pb-color-template.less'); $model = new UserSettingForm(); if ($model->load(Yii::$app->request->post(), 'UserSettingForm')) { if ($model->validate()) { $model->user_id = Yii::$app->user->identity->getId(); $file = UploadedFile::getInstance($model, 'logo_url'); if ($file) { if ($file->size !== 0) { $model->logo_url = $file; } else { $model->logo_url = null; } if ($file->size !== 0) { $old_file_id = ''; $user_setting = UserSetting::findByUserId($model->user_id); if ($user_setting) { $old_file_id = $user_setting->logo_url; } $file_id = AlphaId::id(rand(10000000000, 9999999999999)); $file_path = UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL, 'png'); $file->saveAs($file_path); $image = Yii::$app->image->load($file_path); $image->resize(0, 49, Yii\image\drivers\Image::HEIGHT); $image->save(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_SMALL, 'png')); $model->logo_url = $file_id; if (!empty($old_file_id)) { if (file_exists(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_ORIGINAL, 'png'))) { unlink(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_ORIGINAL, 'png')); } if (file_exists(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_SMALL, 'png'))) { unlink(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_SMALL, 'png')); } } } } else { $model->logo_url = null; } if (Yii::$app->request->post('defaultLogo', 0) == 1) { $model->logo_url = 'default-logo'; } if ($setting = $model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Настройки успешно сохранены.')); return $this->redirect(Url::toRoute('user/settings')); } } } else { if (!$model->loadByUserId(Yii::$app->user->identity->getId())) { } } return $this->render('settings', ['model' => $model, 'less_content' => $less_content]); }