public function actionDetails($id) { // Нужен для возврата на страницу после логина // Возможно делается как-то проще Url::remember(); $trainingMatch = TrainingMatch::find()->with('greenPlayers', 'purplePlayers', 'refusedPlayers')->with(['greenPlayers.playerStars' => function ($query) use($id) { $query->where(['training_match_id' => $id]); }, 'purplePlayers.playerStars' => function ($query) use($id) { $query->where(['training_match_id' => $id]); }])->where(['id' => $id])->orderBy('')->asArray()->one(); // Merge all players // accepted or refused current match $players = array_merge($trainingMatch['greenPlayers'], $trainingMatch['purplePlayers'], $trainingMatch['refusedPlayers']); $playerIds = array_map(function ($player) { return $player['id']; }, $players); // Other players $otherPlayers = Player::find()->with('playerStatisticSummary')->where(['not in', 'id', $playerIds])->all(); // Sort players by games count usort($otherPlayers, function ($a, $b) { return $b['playerStatisticSummary']['count_games'] - $a['playerStatisticSummary']['count_games']; }); $matchTimestamp = strtotime($trainingMatch['date_time']); return $this->render('details', ['trainingMatch' => $trainingMatch, 'otherPlayers' => $otherPlayers, 'weather' => WeatherService::getWeather($matchTimestamp)]); }
/** * Lists all Book models. * @return mixed */ public function actionIndex() { Url::remember(Url::current(), 'books'); $searchModel = new BookSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * @return string */ public function actionList() { Url::remember(Url::current(), self::REMEMBER_NAME); $this->getView()->addBread('List'); $searchPrice = new SearchPrice(); return $this->render('list', ['searchPrice' => $searchPrice]); }
public function actionUpdateProfile($id) { \yii\helpers\Url::remember('', 'actions-redirect'); $user = $this->findModel($id); $profile = \backend\models\Profile::findOne(['user_id' => $user->id]); if ($profile == null) { $profile = Yii::createObject(\backend\models\Profile::className()); $profile->link('user', $user); } $this->performAjaxValidation($profile); if ($profile->load(Yii::$app->request->post())) { $profile->fileProfile = \yii\web\UploadedFile::getInstance($profile, 'fileProfile'); $save_fileProfile = ''; if ($profile->fileProfile) { $imagepath = 'uploads/profile/'; // Create folder under web/uploads/logo $profile->image_profile = $imagepath . rand(10, 100) . '-' . $profile->fileProfile->name; $save_fileProfile = 1; } if ($profile->save()) { if ($save_fileProfile) { $profile->fileProfile->saveAs($profile->image_profile); } else { echo 'ada yang salah'; } Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Profile details have been updated')); return $this->refresh(); } } return $this->render('_profile', ['user' => $user, 'profile' => $profile]); }
/** * Lists all Employee models. * @return mixed */ public function actionIndex() { $searchModel = new EmployeeSearch(); $dataProvider = $searchModel->search(isset($_GET['q']) ? $_GET['q'] : null); Url::remember(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public function run() { Url::remember('', $this->generateKey()); // create temporary file $model = $this->_model; $twigCode = $model ? $model->value : null; $tmpFile = \Yii::getAlias('@runtime') . '/' . md5($twigCode); file_put_contents($tmpFile, $twigCode); $render = new ViewRenderer(); try { $html = $render->render('renderer.twig', $tmpFile, []); } catch (\Twig_Error $e) { \Yii::$app->session->addFlash('warning', $e->getMessage()); $html = ''; } if (\Yii::$app->user->can(self::ACCESS_ROLE)) { $link = Html::a('prototype module', $model ? $this->generateEditRoute($model->id) : $this->generateCreateRoute()); if ($this->enableFlash) { \Yii::$app->session->addFlash($html ? 'success' : 'info', "Edit contents in {$link}, key: <code>{$this->generateKey()}</code>"); } if (!$model && $this->renderEmpty) { $html = $this->renderEmpty(); } } \Yii::trace('Twig widget rendered', __METHOD__); return $html; }
public function actionIndex() { Url::remember('', 'actions-redirect'); $searchModel = Yii::createObject(UserSearch::className()); $dataProvider = $searchModel->search(Yii::$app->request->get()); return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); }
/** * renders a page view from the database * * @param $id * @param null $pageName * @param null $parentLeave * * @return string * @throws HttpException */ public function actionPage($id, $pageName = null, $parentLeave = null) { Url::remember(); \Yii::$app->session['__crudReturnUrl'] = null; // Set layout $this->layout = '@app/views/layouts/main'; // Get active Tree object, allow access to invisible pages // @todo: improve handling, using also roles $pageQuery = Tree::find()->where([Tree::ATTR_ID => $id, Tree::ATTR_ACTIVE => Tree::ACTIVE, Tree::ATTR_ACCESS_DOMAIN => \Yii::$app->language]); // Show disabled pages for admins if (!\Yii::$app->user->can('pages')) { $pageQuery->andWhere([Tree::ATTR_DISABLED => Tree::NOT_DISABLED]); } // get page $page = $pageQuery->one(); if ($page !== null) { // Set page title $this->view->title = $page->page_title; // Register default SEO meta tags $this->view->registerMetaTag(['name' => 'keywords', 'content' => $page->default_meta_keywords]); $this->view->registerMetaTag(['name' => 'description', 'content' => $page->default_meta_description]); if (\Yii::$app->user->isGuest) { Yii::$app->response->headers->set('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', time() + (getenv("HTTP_EXPIRES") !== null ? getenv("HTTP_EXPIRES") : 0))); } // Render view return $this->render($page->view, ['page' => $page]); } else { throw new HttpException(404, \Yii::t('app', 'Page not found.') . ' [ID: ' . $id . ']'); } }
public function run() { $model = new Comments(); if (!is_string($this->model)) { $model->post_id = $this->model->getPrimaryKey(); $model->module = get_class($this->model); $order = ''; } else { $model->post_id = 0; $model->module = $this->model; $order = 'DESC'; } // Получаем комментарии этого модуля и пост айди $models = Comments::getComments($model->module, $model->post_id, $order); // Получаем кол-во страниц комментариев для редиректа $page = $models['pages']->totalCount / $models['pages']->pageSize + 1; if ($model->load(Yii::$app->request->post())) { if ($model->save()) { Url::remember(Url::current()); Yii::$app->getSession()->setFlash('success', '<i class="fa fa-check fa-1x"></i> Good! '); if (!is_string($this->model)) { return Yii::$app->getResponse()->redirect('/post/' . $this->model->slug . '/' . $model->post_id . '?page=' . round($page) . '#' . $model->id); } else { return Yii::$app->getResponse()->refresh(); } } } return $this->render('widgetComment', ['model' => $model, 'models' => $models['models'], 'pages' => $models['pages'], 'options' => $this->options]); }
/** * Lists all User models. * @return mixed */ public function actionIndex() { Url::remember(Yii::$app->getRequest()->getUrl()); $searchModel = new UserSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Lists all RedirectUrl models. * @return mixed */ public function actionIndex() { $searchModel = new RedirectUrlSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); Url::remember(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Lists all Model models. * @return mixed */ public function actionIndex() { $searchModel = new Search(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); Url::remember(Url::to(''), static::FILTERED_LINK_KEY); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'authorsAssoc' => \app\models\authors\Model::getAllAsAssoc()]); }
/** * Shows information about Payment. * * @param int $id * * @return string */ public function actionView($id) { Url::remember('', 'actions-redirect'); $payment = $this->findModel($id); $itemsDp = new ActiveDataProvider(['query' => $payment->getItems()]); return $this->render('view', ['model' => $payment, 'itemsDp' => $itemsDp]); }
public function actionMatrix() { $this->sidebar = ['parent' => 'sidebar-identity', 'child' => 'matrix']; // Remember return url for crud Url::remember(['permission/matrix'], 'roles'); return parent::actionMatrix(CoreGlobal::TYPE_SYSTEM); }
/** * renders a page view from the database. * * @param $pageId * @param null $pageName * @param null $parentLeave * * @return string * * @throws HttpException */ public function actionPage($pageId, $pageName = null, $parentLeave = null) { Url::remember(); \Yii::$app->session['__crudReturnUrl'] = null; // Set layout $this->layout = '@app/views/layouts/main'; // Get active Tree object, allow access to invisible pages // @todo: improve handling, using also roles $pageQuery = Tree::find()->where([Tree::ATTR_ID => $pageId, Tree::ATTR_ACTIVE => Tree::ACTIVE, Tree::ATTR_ACCESS_DOMAIN => \Yii::$app->language]); // Show disabled pages for admins if (!\Yii::$app->user->can('pages')) { $pageQuery->andWhere([Tree::ATTR_DISABLED => Tree::NOT_DISABLED]); } // get page $page = $pageQuery->one(); if ($page !== null) { // Set page title, use name as fallback $this->view->title = $page->page_title ?: $page->name; // Register default SEO meta tags $this->view->registerMetaTag(['name' => 'keywords', 'content' => $page->default_meta_keywords]); $this->view->registerMetaTag(['name' => 'description', 'content' => $page->default_meta_description]); // Render view return $this->render($page->view, ['page' => $page]); } else { if ($fallbackPage = $this->resolveFallbackPage($pageId)) { \Yii::trace('Resolved fallback URL for ' . $fallbackPage->id, __METHOD__); return $this->redirect($fallbackPage->createUrl(['language' => $fallbackPage->access_domain])); } else { throw new HttpException(404, \Yii::t('pages', 'Page not found.') . ' [ID: ' . $pageId . ']'); } } }
/** * @param ActiveRecord $model * @param array $actions Custom actions array in the form of * ```php * 'name' => function() { * * } * ``` * @param bool $addDefaultActions If true default actions will be added * @return \yii\web\Response * @throws BadRequestHttpException */ protected function getCreateUpdateResponse($model, $actions = [], $addDefaultActions = true) { $defaultActions = [AdminHtml::ACTION_SAVE_AND_STAY => function () use($model) { /** @var Controller | CrudControllerTrait $this */ return $this->redirect(['update', 'id' => $model->getPrimaryKey()]); }, AdminHtml::ACTION_SAVE_AND_CREATE => function () use($model) { /** @var Controller | CrudControllerTrait $this */ if ($url = Url::previous($this->createUrlParam)) { Url::remember(null, $this->createUrlParam); return $this->redirect($url); } return $this->redirect(['create']); }, AdminHtml::ACTION_SAVE_AND_LEAVE => function () use($model) { /** @var Controller | CrudControllerTrait $this */ if ($url = \Yii::$app->request->get('return')) { return $this->redirect($url); } if ($url = Url::previous($this->indexUrlParam)) { Url::remember(null, $this->indexUrlParam); return $this->redirect($url); } return $this->redirect(['index']); }]; if ($addDefaultActions) { $actions = array_merge($defaultActions, $actions); } $actionName = \Yii::$app->request->post(AdminHtml::ACTION_BUTTON_NAME, AdminHtml::ACTION_SAVE_AND_LEAVE); if (isset($actions[$actionName])) { return call_user_func($actions[$actionName]); } else { throw new BadRequestHttpException('Unknown action: ' . $actionName); } }
public function actionAll($id) { Url::remember(["all?id={$id}"], 'options'); $dataProvider = OptionService::getPagination(['conditions' => ['categoryId' => $id]]); $category = CategoryService::findById($id); return $this->render('@cmsgears/module-core/admin/views/category/option/all', ['dataProvider' => $dataProvider, 'category' => $category]); }
/** * @param int $characterID * * @return string * @throws \yii\web\NotFoundHttpException */ public function actionCreate($characterID) { Url::remember(Url::current(), self::REMEMBER_NAME); $character = $this->loadCharacter($characterID); $this->getView()->addBread(['label' => 'Demands', 'url' => ['demand/index', 'characterID' => $characterID]])->addBread(['label' => 'Create'])->setCharacter($character); $marketDemand = new MarketDemand(); $marketDemand->characterID = $characterID; $marketDemand->userID = \Yii::$app->user->id; if ($this->isAjax()) { $type = $this->get('sType'); if ($type == 'station') { $sql = '(SELECT sStation.stationID, sStation.stationName, sStation.stationTypeID FROM staStations as sStation WHERE sStation.stationName LIKE "%' . $_GET['q'] . '%") UNION (SELECT cStation.stationID, cStation.stationName, cStation.stationTypeID FROM api_eve_conquerableStation as cStation WHERE cStation.stationName LIKE "%' . $_GET['q'] . '%")'; } elseif ($type == 'item') { $sql = 'SELECT typeID, typeName FROM invTypes WHERE typeName LIKE "%' . $_GET['q'] . '%" AND published ="1" ORDER BY typeName'; } $return = \Yii::$app->db->createCommand($sql)->queryAll(); echo Json::encode($return); // @todo change response type \Yii::$app->end(); } elseif ($this->isPost() && $marketDemand->load($this->post())) { if ($marketDemand->save()) { UpdaterEveCentral::addType($marketDemand->typeID); return $this->redirect(['demand/list', 'characterID' => $characterID]); } } return $this->render('create', ['marketDemand' => $marketDemand]); }
public function actionIndex() { $model = new BookSearch(); Url::remember('', 'returnUrl'); // var_dump(\Yii::$app->request->get()); $dataProvider = $model->search(\Yii::$app->request->get()); return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]); }
/** * Lists all Books models. * @return mixed */ public function actionIndex() { $searchModel = new BooksSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); // Запоминаем путь с учетом фильтров Url::remember(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Lists all Books models. * @return mixed */ public function actionIndex() { $searchModel = new BooksSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); Yii::$app->formatter->locale = 'ru-RU'; Url::remember(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Lists all LanguageData models. * @return mixed */ public function actionIndex() { $searchModel = new LanguageDataSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $this->language_id = Yii::$app->request->queryParams['language_id']; Url::remember(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Lists all User models. * @return mixed */ public function actionIndex() { $searchModel = new UserSearch(); $pageSize = Yii::$app->session->get('admin.page.size', Yii::$app->params['admin.page.size']); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, ['pageSize' => $pageSize]); Url::remember(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'pageSize' => $pageSize]); }
/** * Lists all ProductTranslation models. * @return mixed */ public function actionIndex() { $searchModel = new ProductTranslationSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $this->product_id = Yii::$app->request->queryParams['product_id']; Url::remember(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public function init() { if (Yii::$app->user->getIsGuest()) { //return $this->render(Url::base()); } parent::init(); Url::remember(); }
/** * Lists all Book models. * @return mixed */ public function actionIndex() { $searchModel = new BookSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); Url::remember(); $dataProvider->sort->attributes['author_fullname'] = ['asc' => ['author.lastname' => SORT_ASC], 'desc' => ['author.lastname' => SORT_DESC]]; return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'authors' => Author::find()->all()]); }
/** * @return string */ public function actionShow() { $model = new RedisModel(); $model->restoreFilter(); $dataProvider = $model->search(\Yii::$app->request->getQueryParams()); Url::remember(\Yii::$app->request->getUrl(), 'show'); return $this->render('show', ['model' => $model, 'dataProvider' => $dataProvider]); }
/** * Lists all PersonsGroupRecord models. * @return mixed */ public function actionIndex() { $searchModel = new PersonsGroupSearch(); // $searchModel->Deleted = 0; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); Url::remember('', 'actions-redirect'); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Lists all PurchaseOrderDetail models. * @return mixed */ public function actionIndex() { $searchModel = new PurchaseOrderDetailSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $this->purchase_order_id = Yii::$app->request->queryParams['purchase_order_id']; Url::remember(); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public function afterAction($action, $result) { if (Yii::$app->request->pathInfo !== "auth/index") { Url::remember(Url::toRoute(["/" . Yii::$app->request->pathInfo]), 'safe_url'); } return parent::afterAction($action, $result); }