/** * Lists all models. * @return mixed */ public function actionIndex() { $sourceLanguage = 'en-US'; $languages = Yii::$app->yee->languages; $categories = MessageSource::getMessageCategories(); unset($languages[$sourceLanguage]); $currentLanguage = Yii::$app->getRequest()->get('translation', NULL); $currentCategory = Yii::$app->getRequest()->get('category', NULL); if (!in_array($currentLanguage, array_keys($languages))) { $currentLanguage = NULL; } if (!in_array($currentCategory, array_keys($categories))) { $currentCategory = NULL; } if ($currentLanguage && $currentCategory) { Message::initMessages($currentCategory, $currentLanguage); $messageIds = MessageSource::getMessageIdsByCategory($currentCategory); $sourceTable = MessageSource::tableName(); $messageTable = Message::tableName(); $messages = Message::find()->andWhere(['IN', 'source_id', $messageIds])->andWhere(['language' => $currentLanguage])->indexBy('id')->all(); } else { $messages = []; } if (User::hasPermission('updateTranslations') && Message::loadMultiple($messages, Yii::$app->request->post()) && Model::validateMultiple($messages)) { foreach ($messages as $message) { $message->save(false); } Yii::$app->session->setFlash('crudMessage', 'Your item has been updated.'); return $this->refresh(); } return $this->render('index', ['messages' => $messages, 'languages' => $languages, 'categories' => $categories, 'currentLanguage' => $currentLanguage, 'currentCategory' => $currentCategory]); }
public function run() { if (User::hasPermission('viewMedia')) { $recent = MediaModel::find()->orderBy(['id' => SORT_DESC])->limit($this->recentLimit)->all(); return $this->render('media', ['height' => $this->height, 'width' => $this->width, 'position' => $this->position, 'recent' => $recent]); } }
protected function getRedirectPage($action, $model = null) { if (!User::hasPermission('editPosts') && $action == 'create') { return ['view', 'id' => $model->id]; } switch ($action) { case 'update': return ['update', 'id' => $model->id]; break; case 'create': return ['update', 'id' => $model->id]; break; default: return parent::getRedirectPage($action, $model); } }
public function run() { if (!$this->options) { $this->options = $this->getDefaultOptions(); } if (User::hasPermission('viewPosts')) { $searchModel = new PostSearch(); $formName = $searchModel->formName(); $recentPosts = Post::find()->orderBy(['id' => SORT_DESC])->limit($this->recentLimit)->all(); foreach ($this->options as &$option) { $count = Post::find()->filterWhere($option['filterWhere'])->count(); $option['count'] = $count; $option['url'] = [$this->indexAction, $formName => $option['filterWhere']]; } return $this->render('posts', ['height' => $this->height, 'width' => $this->width, 'position' => $this->position, 'posts' => $this->options, 'recentPosts' => $recentPosts]); } }
/** * Check if user has access to current route * * @param Action $action the action to be executed. * * @return boolean whether the action should continue to be executed. */ public function beforeAction($action) { if ($action->id == 'captcha') { return true; } $route = '/' . $action->uniqueId; if (Route::isFreeAccess($route, $action)) { return true; } if (Yii::$app->user->isGuest) { $this->denyAccess(); } // If user has been deleted, then destroy session and redirect to home page if (!Yii::$app->user->isGuest and Yii::$app->user->identity === null) { Yii::$app->getSession()->destroy(); $this->denyAccess(); } // Superadmin owns everyone if (Yii::$app->user->isSuperadmin) { return true; } if (Yii::$app->user->identity and Yii::$app->user->identity->status != User::STATUS_ACTIVE) { Yii::$app->user->logout(); Yii::$app->getResponse()->redirect(Yii::$app->getHomeUrl()); } if (User::canRoute($route)) { $modelId = Yii::$app->getRequest()->getQueryParam('id'); $modelClass = isset($this->owner->modelClass) ? $this->owner->modelClass : null; //Check access for owners if ($modelClass && YeeHelper::isImplemented($modelClass, OwnerAccess::CLASSNAME) && !User::hasPermission($modelClass::getFullAccessPermission()) && $modelId) { $model = $modelClass::findOne(['id' => $modelId]); if ($model && Yii::$app->user->identity->id == $model->{$modelClass::getOwnerField()}) { return true; } } else { return true; } } if (isset($this->denyCallback)) { call_user_func($this->denyCallback, null, $action); } else { $this->denyAccess(); } return false; }
/** * Lists all models. * @return mixed */ public function actionIndex() { $modelClass = $this->modelClass; $searchModel = $this->modelSearchClass ? new $this->modelSearchClass() : null; $searchLinkModel = $this->modelLinkSearchClass ? new $this->modelLinkSearchClass() : null; $restrictAccess = YeeHelper::isImplemented($modelClass, OwnerAccess::CLASSNAME) && !User::hasPermission($modelClass::getFullAccessPermission()); if ($searchModel) { $searchName = StringHelper::basename($searchModel::className()); $params = Yii::$app->request->getQueryParams(); if ($restrictAccess) { $params[$searchName][$modelClass::getOwnerField()] = Yii::$app->user->identity->id; } $dataProvider = $searchModel->search($params); } else { $restrictParams = $restrictAccess ? [$modelClass::getOwnerField() => Yii::$app->user->identity->id] : []; $dataProvider = new ActiveDataProvider(['query' => $modelClass::find()->where($restrictParams)]); } return $this->renderIsAjax('index', compact('dataProvider', 'searchModel', 'searchLinkModel')); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params = []) { $queryParams = Yii::$app->request->getQueryParams(); $query = MenuLink::find()->joinWith('translations'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => -1], 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]); $this->load($queryParams); foreach ($params as $key => $value) { $this->{$key} = $value; } $restrictLinkAccess = YeeHelper::isImplemented(MenuLink::className(), OwnerAccess::CLASSNAME) && !User::hasPermission(MenuLink::getFullAccessPermission()); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } if ($restrictLinkAccess) { $query->andFilterWhere([MenuLink::getOwnerField() => Yii::$app->user->identity->id]); } $query->andWhere(['menu_id' => $this->menu_id])->andFilterWhere(['alwaysVisible' => $this->alwaysVisible])->andFilterWhere(['like', 'id', $this->id])->andWhere(['parent_id' => $this->parent_id]); return $dataProvider; }
</legend> <?php echo Html::checkboxList('child_permissions', ArrayHelper::map($currentPermissions, 'name', 'name'), ArrayHelper::map($permissions, 'name', 'description')); ?> </fieldset> <br/> </div> <?php } ?> </div> <hr/> <?php if (User::hasPermission('manageRolesAndPermissions')) { ?> <?php echo Html::submitButton(Yii::t('yee', 'Save'), ['class' => 'btn btn-primary btn-sm']); ?> <?php } ?> <?php echo Html::endForm(); ?> </div> </div> </div>
/** * Deactivate all selected grid items */ public function actionBulkDelete() { if (Yii::$app->request->post('selection')) { $modelClass = $this->modelClass; $restrictAccess = YeeHelper::isImplemented($modelClass, OwnerAccess::CLASSNAME) && !User::hasPermission($modelClass::getFullAccessPermission()); foreach (Yii::$app->request->post('selection', []) as $id) { $where = ['id' => $id]; if ($restrictAccess) { $where[$modelClass::getOwnerField()] = Yii::$app->user->identity->id; } $model = $modelClass::findOne($where); if ($model) { $model->delete(); } } } }
</div> </div> <?php Pjax::begin(['id' => 'user-grid-pjax']); ?> <?php echo GridView::widget(['id' => 'user-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'user-grid'], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['attribute' => 'username', 'controller' => '/user/default', 'class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'title' => function (User $model) { if (User::hasPermission('editUsers')) { return Html::a($model->username, ['/user/default/update', 'id' => $model->id], ['data-pjax' => 0]); } else { return $model->username; } }, 'buttonsTemplate' => '{update} {delete} {permissions} {password}', 'buttons' => ['permissions' => function ($url, $model, $key) { return Html::a(Yii::t('yee/user', 'Permissions'), Url::to(['user-permission/set', 'id' => $model->id]), ['title' => Yii::t('yee/user', 'Permissions'), 'data-pjax' => '0']); }, 'password' => function ($url, $model, $key) { return Html::a(Yii::t('yee/user', 'Password'), Url::to(['default/change-password', 'id' => $model->id]), ['title' => Yii::t('yee/user', 'Password'), 'data-pjax' => '0']); }], 'options' => ['style' => 'width:300px']], ['attribute' => 'email', 'format' => 'raw', 'visible' => User::hasPermission('viewUserEmail')], ['attribute' => 'gridRoleSearch', 'filter' => ArrayHelper::map(Role::getAvailableRoles(Yii::$app->user->isSuperAdmin), 'name', 'description'), 'value' => function (User $model) { return implode(', ', ArrayHelper::map($model->roles, 'name', 'description')); }, 'format' => 'raw', 'visible' => User::hasPermission('viewUserRoles')], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'superadmin', 'visible' => Yii::$app->user->isSuperadmin, 'options' => ['style' => 'width:60px']], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'status', 'optionsArray' => [[User::STATUS_ACTIVE, Yii::t('yee', 'Active'), 'primary'], [User::STATUS_INACTIVE, Yii::t('yee', 'Inactive'), 'info'], [User::STATUS_BANNED, Yii::t('yee', 'Banned'), 'default']], 'options' => ['style' => 'width:60px']]]]); ?> <?php Pjax::end(); ?> </div> </div> </div>
</div> <div class="col-sm-6 text-right"> <?php echo GridPageSize::widget(['pjaxId' => 'trip-grid-pjax']); ?> </div> </div> <?php Pjax::begin(['id' => 'trip-grid-pjax']); ?> <?php echo GridView::widget(['id' => 'trip-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'trip-grid', 'actions' => [Url::to(['bulk-delete']) => Yii::t('yee', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['attribute' => 'vehicle_model', 'class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/trip/default', 'title' => function (Trip $model) { $vehicle = $model->getVehicles()[$model->vehicle] . ' > ' . Html::encode($model->vehicle_model); return Html::a($vehicle, ['update', 'id' => $model->id], ['data-pjax' => 0]); }, 'buttonsTemplate' => '{update} {delete}', 'options' => ['style' => 'width:260px']], 'city_from', 'city_to', ['attribute' => 'created_by', 'filter' => User::getUsersList(), 'value' => function (Trip $model) { return Html::a(Html::encode($model->author->username), ['/user/default/update', 'id' => $model->created_by], ['data-pjax' => 0]); }, 'format' => 'raw', 'visible' => User::hasPermission('viewUsers')], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'type', 'optionsArray' => Trip::getTypeOptionsList(), 'options' => ['style' => 'width:60px']], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'status', 'optionsArray' => Trip::getStatusOptionsList(), 'options' => ['style' => 'width:60px']]]]); ?> <?php Pjax::end(); ?> </div> </div> </div>
<div class="col-sm-6 text-right"> <?php echo GridPageSize::widget(['pjaxId' => 'post-grid-pjax']); ?> </div> </div> <?php Pjax::begin(['id' => 'post-grid-pjax']); ?> <?php echo GridView::widget(['id' => 'post-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'post-grid', 'actions' => [Url::to(['bulk-activate']) => Yii::t('yee', 'Publish'), Url::to(['bulk-deactivate']) => Yii::t('yee', 'Unpublish'), Url::to(['bulk-delete']) => Yii::t('yii', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/post/default', 'title' => function (Post $model) { return Html::a($model->title, ['/post/default/view', 'id' => $model->id], ['data-pjax' => 0]); }], ['attribute' => 'created_by', 'filter' => yeesoft\models\User::getUsersList(), 'value' => function (Post $model) { return Html::a($model->author->username, ['/user/default/update', 'id' => $model->created_by], ['data-pjax' => 0]); }, 'format' => 'raw', 'visible' => User::hasPermission('viewUsers'), 'options' => ['style' => 'width:180px']], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'status', 'optionsArray' => Post::getStatusOptionsList(), 'options' => ['style' => 'width:60px']], ['class' => 'yeesoft\\grid\\columns\\DateFilterColumn', 'attribute' => 'published_at', 'value' => function (Post $model) { return '<span style="font-size:85%;" class="label label-' . (time() >= $model->published_at ? 'primary' : 'default') . '">' . $model->publishedDate . '</span>'; }, 'format' => 'raw', 'options' => ['style' => 'width:150px']]]]); ?> <?php Pjax::end(); ?> </div> </div> </div>
/** * Set default options */ protected function setDefaultOptions() { if (!$this->links) { $model = $this->model; $formName = $this->searchModel->formName(); if (!$this->options) { $this->options = $this->defaultOptions; if (is_array($this->labels)) { $this->options = ArrayHelper::merge($this->options, self::addKeyToValue($this->labels, 'label')); } } foreach ($this->options as $option) { if ($this->showCount) { if (YeeHelper::isImplemented($model, OwnerAccess::CLASSNAME) && !User::hasPermission($model::getFullAccessPermission())) { $option['filterWhere'][$model::getOwnerField()] = Yii::$app->user->identity->id; } $count = $model::find()->filterWhere($option['filterWhere'])->count(); $count = " ({$count})"; } $label = $option['label'] . ($count ? $count : ''); $url = [$this->action, $formName => $option['filterWhere']]; $this->links[$label] = $url; } } }
echo Alert::widget(['options' => ['class' => 'alert-danger menu-link-alert'], 'body' => Yii::t('yee/menu', 'An error occurred during saving menu!')]); ?> <?php echo Alert::widget(['options' => ['class' => 'alert-info menu-link-alert'], 'body' => Yii::t('yee/menu', 'The changes have been saved.')]); ?> </div> </div> <div class="row"> <div class="col-sm-4"> <div class="panel panel-default"> <div class="panel-body"> <?php echo GridView::widget(['id' => 'menu-grid', 'dataProvider' => $dataProvider, 'layout' => '{items}', 'columns' => [['class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/menu/default', 'buttonsTemplate' => '{update} {delete}', 'title' => function (Menu $model) { if (User::hasPermission('viewMenuLinks')) { return Html::a($model->title, ['/menu/default/index', 'SearchMenuLink[menu_id]' => $model->id], ['data-pjax' => 0]); } else { return Html::a($model->title, ['/menu/default/view', 'id' => $model->id], ['data-pjax' => 0]); } }]]]); ?> </div> </div> </div> <div class="col-sm-8"> <div class="panel panel-default"> <div class="panel-body"> <div class="sortable-container menu-itemes"> <?php
/** * Delete model with medias * @param $id * @return array */ public function actionDelete($id) { Yii::$app->response->format = Response::FORMAT_JSON; $routes = $this->module->routes; $tableName = Media::tableName(); /** * @var yeesoft\media\models\Media */ $model = Media::findOne(["{$tableName}.id" => $id]); if (User::hasPermission('deleteMedia')) { if ($model->isImage()) { $model->deleteThumbs($routes); } $model->deleteFile($routes); $model->delete(); return ['success' => 'true']; } else { die(Yii::t('yii', 'You are not allowed to perform this action.')); } }
/** * Deletes an existing model. * If deletion is successful, the browser will be redirected to the 'index' page. * * @param integer $id * * @return mixed */ public function actionDelete($id) { $model = $this->findModel($id); if ($model->immutable && !User::hasPermission('updateImmutableSourceMessages')) { throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); } $model->delete(); Yii::$app->session->setFlash('crudMessage', 'Your item has been deleted.'); return $this->redirect($this->getRedirectPage('delete', $model)); }
<?php echo $form->field($searchModel, 'album_id')->dropDownList(ArrayHelper::merge(['' => Yii::t('yee/media', 'All Media Items')], Album::getAlbums(true, true)), ['prompt' => '']); ?> </td> <td style="width: auto;"> <?php echo $form->field($searchModel, 'title')->textInput(['placeholder' => $searchModel->attributeLabels()['title']]); ?> </td> <td style="width: auto;"> <?php echo $form->field($searchModel, 'created_at')->widget(DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd', 'options' => ['placeholder' => $searchModel->attributeLabels()['created_at'], 'class' => 'form-control']]); ?> </td> <?php if (User::hasPermission('uploadMedia')) { ?> <td style="width: 1%;"> <?php echo Html::a(Yii::t('yee/media', 'Upload New File'), $mode == 'modal' ? ['/media/manage/uploader', 'mode' => 'modal'] : ['/media/manage/uploader'], ['class' => 'btn btn-primary pull-right']); ?> </td> <?php } ?> </tr> </thead> </table> <?php
<div class="help-block"></div> </div> <?php } else { ?> <?php echo Html::hiddenInput('url', $model->url); } ?> <?php echo Html::hiddenInput('id', $model->id); ?> <?php if (User::hasPermission('editMedia') && $mode != 'modal') { ?> <?php echo Html::submitButton(Yii::t('yee', 'Save'), ['class' => 'btn btn-primary']); } ?> <?php if ($mode == 'modal') { ?> <?php echo Html::button(Yii::t('yee', 'Insert'), ['id' => 'insert-btn', 'class' => 'btn btn-primary']); } ?> <?php
echo $form->field($model, 'email_confirmed')->checkbox(); ?> <?php } ?> <?php echo $form->field($model, 'skype')->textInput(['maxlength' => 64]); ?> <?php echo $form->field($model, 'phone')->textInput(['maxlength' => 24]); ?> <?php if (User::hasPermission('bindUserToIp')) { ?> <?php echo $form->field($model, 'bind_to_ip')->textInput(['maxlength' => 255])->hint(Yii::t('yee', 'For example') . ' : 123.34.56.78, 234.123.89.78'); ?> <?php } ?> </div> </div> </div> <div class="panel panel-default"> <div class="panel-body"> <div class="record-info">
$links = ''; if (User::hasPermission('updateSourceMessages') && (!$message->source->immutable || User::hasPermission('updateImmutableSourceMessages'))) { $links .= ' ' . Html::a('<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>', ['/translation/source/update', 'id' => $message->source_id]); } ?> <?php echo $form->field($message, "[{$index}]translation")->label($message->source->message . $links); ?> <?php } ?> <?php if (User::hasPermission('updateSourceMessages')) { ?> <?php echo Html::submitButton(Yii::t('yee', 'Save All'), ['class' => 'btn btn-primary']); ?> <?php } ?> <?php ActiveForm::end(); ?> <?php } ?>
<div class="panel-body"> <div class="row"> <div class="col-sm-12 text-right"> <?php echo GridPageSize::widget(['pjaxId' => 'page-grid-pjax']); ?> </div> </div> <?php Pjax::begin(['id' => 'block-grid-pjax']); ?> <?php echo GridView::widget(['id' => 'block-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'block-grid', 'actions' => [Url::to(['bulk-delete']) => Yii::t('yii', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['attribute' => 'slug', 'class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/block/default', 'title' => function (Block $model) { return Html::a($model->slug, ['/block/default/update', 'id' => $model->id], ['data-pjax' => 0]); }, 'buttonsTemplate' => '{update} {delete}'], ['attribute' => 'created_by', 'filter' => User::getUsersList(), 'value' => function (Block $model) { return Html::a($model->author->username, ['/user/default/update', 'id' => $model->created_by], ['data-pjax' => 0]); }, 'format' => 'raw', 'visible' => User::hasPermission('viewUsers'), 'options' => ['style' => 'width:180px']]]]); ?> <?php Pjax::end(); ?> </div> </div> </div>