作者:Liv102
项目:cm
/**
* @inheritdoc
*/
public function run()
{
try {
$this->_initAndValidate();
$valueArray = [];
$trees = [];
$valueSingle = "";
$select = "";
$singleInput = "";
if (in_array($this->mode, [self::MOD_COMBO, self::MOD_MULTI])) {
$valueArray = Html::getAttributeValue($this->model, $this->attribute);
$select = Html::activeListBox($this->model, $this->attribute, ['16' => "16"], ['multiple' => true, 'class' => 'sx-controll-element', 'style' => 'display: none;']);
$trees = Tree::find()->where(['id' => $valueArray])->all();
}
if (in_array($this->mode, [self::MOD_COMBO, self::MOD_SINGLE])) {
$singleInput = Html::activeInput("hidden", $this->model, $this->attributeSingle, ['class' => 'sx-single']);
$valueSingle = Html::getAttributeValue($this->model, $this->attributeSingle);
}
$src = UrlHelper::construct('/cms/admin-tree')->set('mode', $this->mode)->set('s', $valueArray)->setSystemParam(Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->setSystemParam(Module::SYSTEM_QUERY_NO_ACTIONS_MODEL, 'true')->enableAdmin()->toString();
$id = "sx-id-" . md5(serialize([$this->clientOptions, $this->mode, $this->attributeMulti, $this->attributeSingle]));
$selected = [];
foreach ($trees as $tree) {
$selected[] = $tree->id;
}
return $this->render('widget', ['widget' => $this, 'id' => $id, 'select' => $select, 'src' => $src, 'valueSingle' => $valueSingle, 'singleInput' => $singleInput, 'clientOptions' => Json::encode(['src' => $src, 'name' => $id, 'id' => $id, 'selected' => $selected, 'valueSingle' => $valueSingle])]);
//$this->registerClientScript();
} catch (Exception $e) {
echo $e->getMessage();
}
}
作者:skeeks-cm
项目:cms-sho
/**
* Подготовка данных для шаблона
* @return $this
*/
public function run()
{
if (!$this->user) {
return '-';
}
return (new AdminImagePreviewWidget(['image' => $this->user ? $this->user->image : null, 'maxWidth' => "25px"]))->run() . " " . Html::a($this->user->displayName, \skeeks\cms\helpers\UrlHelper::construct(['/shop/admin-buyer-user/update', 'pk' => $this->user->id])->enableAdmin(), ['data-pjax' => 0]);
}
作者:skeeks-cm
项目:cm
/**
* @inheritdoc
*/
protected function renderDataCellContent($model, $key, $index)
{
$userId = (int) $model->{$this->attribute};
$user = User::findOne($userId);
if ($user) {
if (!($srcImage = $user->getAvatarSrc())) {
$srcImage = \Yii::$app->cms->moduleAdmin->noImage;
}
$this->grid->view->registerCss(<<<CSS
.sx-user-preview
{
}
.sx-user-preview .sx-user-preview-controll
{
display: none;
}
.sx-user-preview:hover .sx-user-preview-controll
{
display: inline;
}
CSS
);
return "<div class='sx-user-preview'>" . Html::img($srcImage, ['width' => 25, 'style' => 'margin-right: 5px;']) . $user->getDisplayName() . "\n <div class='sx-user-preview-controll'>" . Html::a("<i class='glyphicon glyphicon-pencil' title='Редактировать'></i>", UrlHelper::construct(['/cms/admin-user/update', 'pk' => $user->id])->enableAdmin()->toString(), ['class' => 'btn btn-xs btn-default', 'data-pjax' => 0]) . '</div></div>';
} else {
return null;
}
}
作者:skeeks-cm
项目:cms-sho
public function create()
{
$rr = new RequestResponse();
$modelClass = $this->modelClassName;
$model = new $modelClass();
$model->loadDefaultValues();
if ($post = \Yii::$app->request->post()) {
$model->load($post);
}
$handler = $model->handler;
if ($handler) {
if ($post = \Yii::$app->request->post()) {
$handler->load($post);
}
}
if ($rr->isRequestPjaxPost()) {
if (!\Yii::$app->request->post($this->notSubmitParam)) {
$model->component_settings = $handler->toArray();
$handler->load(\Yii::$app->request->post());
if ($model->load(\Yii::$app->request->post()) && $model->validate() && $handler->validate()) {
$model->save();
\Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
return $this->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->requestPkParamName => $model->{$this->modelPkAttribute}])->toString());
} else {
\Yii::error(Json::encode($model->errors), self::className());
\Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save'));
}
}
}
return $this->render('_form', ['model' => $model, 'handler' => $handler]);
}
作者:skeeks-cm
项目:cm
/**
* @inheritdoc
*/
public function run()
{
if ($this->hasModel()) {
$name = Html::getInputName($this->model, $this->attribute);
$value = null;
if (is_array($this->model->{$this->attribute})) {
$value = StringHelper::base64EncodeUrl(serialize((array) $this->model->{$this->attribute}));
} else {
if (is_string($this->model->{$this->attribute})) {
$value = $this->model->{$this->attribute};
}
}
$this->options['id'] = Html::getInputId($this->model, $this->attribute);
//$element = Html::activeHiddenInput($this->model, $this->attribute, $this->options);
$element = Html::hiddenInput($name, $value, $this->options);
} else {
$element = Html::hiddenInput($this->name, $this->value, $this->options);
}
$this->registerPlugin();
$this->clientOptions['componentSelectId'] = $this->componentSelectId;
$this->clientOptions['componentSettingsId'] = Html::getInputId($this->model, $this->attribute);
$this->clientOptions['id'] = $this->id;
$this->clientOptions['backend'] = UrlHelper::construct('/cms/admin-universal-component-settings/index')->setSystemParam(Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->enableAdmin()->toString();
return $this->render('element', ['widget' => $this, 'element' => $element]);
}
作者:Insolit
项目:cm
/**
* Sends an email with a link, for resetting the password.
*
* @return boolean whether the email was send
*/
public function sendEmail()
{
/* @var $user \common\models\User */
$identityClassName = \Yii::$app->user->identityClass;
$user = $identityClassName::findByUsernameOrEmail($this->identifier);
//$user = $identityClassName::
if ($user) {
if (!$identityClassName::isPasswordResetTokenValid($user->password_reset_token)) {
$user->generatePasswordResetToken();
}
if ($user->save()) {
if (!$user->email) {
return false;
}
if ($this->isAdmin) {
$resetLink = \skeeks\cms\helpers\UrlHelper::construct('admin/auth/reset-password', ['token' => $user->password_reset_token])->enableAbsolute()->enableAdmin();
} else {
$resetLink = \skeeks\cms\helpers\UrlHelper::construct('cms/auth/reset-password', ['token' => $user->password_reset_token])->enableAbsolute();
}
$message = \Yii::$app->mailer->compose('@skeeks/cms/mail/passwordResetToken', ['user' => $user, 'resetLink' => $resetLink])->setFrom([\Yii::$app->cms->adminEmail => \Yii::$app->cms->appName])->setTo($user->email)->setSubject(\Yii::t('app', 'The request to change the password for') . \Yii::$app->cms->appName);
return $message->send();
}
}
return false;
}
作者:skeeks-cm
项目:cm
public function init()
{
parent::init();
if ($this->backendUrl === null) {
$this->backendUrl = UrlHelper::construct('cms/admin-storage-files/link-to-models')->enableAdmin()->toString();
}
}
作者:Liv102
项目:cm
public function run()
{
$modelClassName = $this->controller->modelClassName;
$model = new $modelClassName();
$scenarios = $model->scenarios();
if ($scenarios && $this->modelScenario) {
if (isset($scenarios[$this->modelScenario])) {
$model->scenario = $this->modelScenario;
}
}
$rr = new RequestResponse();
if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
return $rr->ajaxValidateForm($model);
}
if ($rr->isRequestPjaxPost()) {
if ($model->load(\Yii::$app->request->post()) && $model->save($this->modelValidate)) {
\Yii::$app->getSession()->setFlash('success', \Yii::t('app', 'Saved'));
if (\Yii::$app->request->post('submit-btn') == 'apply') {
return $this->controller->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->controller->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->controller->requestPkParamName => $model->{$this->controller->modelPkAttribute}])->toString());
} else {
return $this->controller->redirect($this->controller->indexUrl);
}
} else {
\Yii::$app->getSession()->setFlash('error', \Yii::t('app', 'Could not save'));
}
}
$this->viewParams = ['model' => $model];
return parent::run();
}
作者:Liv102
项目:cm
public function run()
{
if ($this->parentModel->isNewRecord) {
return "";
}
/**
* @var $controller AdminModelEditorController
*/
$controller = \Yii::$app->createController($this->controllerRoute)[0];
$rerlation = [];
foreach ($this->relation as $relationLink => $parent) {
if ($this->parentModel->getAttribute($parent)) {
$rerlation[$relationLink] = $this->parentModel->{$parent};
} else {
$rerlation[$relationLink] = $parent;
}
}
$createUrl = \skeeks\cms\helpers\UrlHelper::construct($this->controllerRoute . '/' . $this->controllerCreateAction, $rerlation)->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_NO_ACTIONS_MODEL, 'true')->enableAdmin()->toString();
$sortableUrl = \skeeks\cms\helpers\UrlHelper::construct($this->controllerRoute . '/' . $this->controllerSortableAction)->enableAdmin()->toString();
$search = new \skeeks\cms\models\Search($controller->modelClassName);
$search->getDataProvider()->query->where($rerlation);
if (isset($this->sort['defaultOrder'])) {
$search->getDataProvider()->sort->defaultOrder = $this->sort['defaultOrder'];
}
if ($this->dataProviderCallback && is_callable($this->dataProviderCallback)) {
$function = $this->dataProviderCallback;
$function($search->getDataProvider());
}
$pjaxId = "sx-table-" . md5($this->label . $this->hint . $this->parentModel->className());
$gridOptions = ArrayHelper::merge(['pjaxOptions' => ['id' => $pjaxId], "sortableOptions" => ['backend' => $sortableUrl], 'dataProvider' => $search->getDataProvider(), 'layout' => "\n{beforeTable}\n{items}\n{afterTable}\n{pager}", 'columns' => [['class' => \skeeks\cms\modules\admin\grid\ActionColumn::className(), 'controller' => $controller, 'isOpenNewWindow' => true]]], (array) $this->gridViewOptions);
return $this->render('related-models-grid', ['widget' => $this, 'createUrl' => $createUrl, 'controller' => $controller, 'gridOptions' => $gridOptions, 'pjaxId' => $pjaxId]);
}
作者:skeeks-cm
项目:cms-module-form
public function __construct($config = [])
{
$this->validationUrl = \skeeks\cms\helpers\UrlHelper::construct('form2/backend/validate')->toString();
$this->action = \skeeks\cms\helpers\UrlHelper::construct('form2/backend/submit')->toString();
$this->enableAjaxValidation = true;
parent::__construct($config);
}
作者:Liv102
项目:cm
/**
* Запрос пришел на валидацию ajax формы?
* @return bool
*/
public function isRequestOnValidateAjaxForm()
{
if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax && UrlHelper::getCurrent()->issetSystemParam(static::VALIDATION_AJAX_FORM_SYSTEM_NAME)) {
return true;
}
return false;
}
作者:dextercoo
项目:cm
public function init()
{
parent::init();
if (!$this->selectUrl) {
$additionalData = [];
$additionalData['callbackEvent'] = $this->getCallbackEvent();
$this->selectUrl = \skeeks\cms\helpers\UrlHelper::construct($this->baseRoute, $additionalData)->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->enableAdmin()->toString();
}
}
作者:Liv102
项目:cm
/**
* @return static
*/
public function run()
{
Yii::$app->user->logout();
if ($ref = UrlHelper::getCurrent()->getRef()) {
return Yii::$app->getResponse()->redirect($ref);
} else {
return Yii::$app->getResponse()->redirect(Yii::$app->getUser()->getReturnUrl());
}
}
作者:skeeks-cm
项目:cm
public function init()
{
$additionalData = [];
if ($this->relatedModel && ($this->relatedModel instanceof ActiveRecord && !$this->relatedModel->isNewRecord)) {
$additionalData = ['className' => $this->relatedModel->className(), 'pk' => $this->relatedModel->primaryKey];
}
$this->clientOptions['filebrowserImageBrowseUrl'] = UrlHelper::construct('cms/admin-tools/select-file', $additionalData)->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->enableAdmin()->toString();
parent::init();
}
作者:skeeks-cm
项目:cm
public function init()
{
if ($this->model && \Yii::$app->cmsToolbar) {
$controller = \Yii::$app->createController('cms/admin-cms-content-element')[0];
$adminControllerRoute = ['cms/admin-cms-content-element/update', $controller->requestPkParamName => $this->model->{$controller->modelPkAttribute}];
$urlEditModel = UrlHelper::construct($adminControllerRoute)->enableAdmin()->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->toString();
\Yii::$app->cmsToolbar->editUrl = $urlEditModel;
}
parent::init();
}
作者:skeeks-cm
项目:cm
/**
* @return string
*/
public function getIndexUrl()
{
$contentTypePk = null;
if ($this->model) {
if ($contentType = $this->model->contentType) {
$contentTypePk = $contentType->id;
}
}
return UrlHelper::construct(["cms/admin-cms-content-type/update", 'pk' => $contentTypePk])->enableAdmin()->toString();
}
作者:skeeks-cm
项目:cms-module-mone
/**
* @inheritdoc
*/
public function run()
{
try {
$this->_initAndValidate();
$this->registerClientScript();
$id = "sx-id-" . Yii::$app->security->generateRandomString(6);
$clientOptions = ArrayHelper::merge($this->clientOptions, ['fieldNameAmmount' => $this->fieldNameAmmount, 'fieldNameCurrency' => $this->fieldNameCurrency, 'backend' => \skeeks\cms\helpers\UrlHelper::construct('money/ajax/data')->toString()]);
return $this->render('money-input', ['widget' => $this, 'id' => $id, 'model' => $this->model, 'clientOptions' => $clientOptions, 'fieldNameAmmount' => $this->fieldNameAmmount, 'fieldNameCurrency' => $this->fieldNameCurrency]);
} catch (Exception $e) {
echo $e->getMessage();
}
}
作者:skeeks-cm
项目:cm
public function init()
{
if (\Yii::$app->request->get(static::REQUEST_PARAM_USERNAME) && !$this->user) {
throw new NotFoundHttpException("User not found or inactive");
} else {
if (\Yii::$app->request->get(static::REQUEST_PARAM_USERNAME) && \Yii::$app->cmsToolbar) {
$controller = \Yii::$app->createController('cms/admin-user')[0];
$adminControllerRoute = ['cms/admin-user/update', $controller->requestPkParamName => $this->user->{$controller->modelPkAttribute}];
$urlEditModel = UrlHelper::construct($adminControllerRoute)->enableAdmin()->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->toString();
\Yii::$app->cmsToolbar->editUrl = $urlEditModel;
}
}
}
作者:Liv102
项目:cm
/**
* Формируем данные для хлебных крошек.
* Эти данные в layout - е будут передаваться в нужный виджет.
*
* @return $this
*/
protected function _initBreadcrumbsData()
{
$baseRoute = $this->controller->module instanceof Application ? $this->controller->id : "/" . $this->controller->module->id . "/" . $this->controller->id;
if ($this->controller->name) {
$this->controller->view->params['breadcrumbs'][] = ['label' => $this->controller->name, 'url' => $this->controller->getIndexUrl()];
}
if ($this->controller->model) {
$this->controller->view->params['breadcrumbs'][] = ['label' => $this->controller->model->{$this->controller->modelShowAttribute}, 'url' => UrlHelper::constructCurrent()->setRoute($baseRoute . '/' . $this->controller->modelDefaultAction)->set($this->controller->requestPkParamName, $this->controller->model->{$this->controller->modelPkAttribute})->enableAdmin()->normalizeCurrentRoute()->toString()];
}
if (count($this->controller->actions) > 1) {
$this->controller->view->params['breadcrumbs'][] = $this->name;
}
return $this;
}
作者:Liv102
项目:cm
/**
* Denies the access of the user.
* The default implementation will redirect the user to the login page if he is a guest;
* if the user is already logged, a 403 HTTP exception will be thrown.
* @param User $user the current user
* @throws ForbiddenHttpException if the user is already logged in.
*/
protected function denyAccess($user)
{
$rr = new RequestResponse();
if ($user->getIsGuest()) {
$authUrl = UrlHelper::construct("admin/auth")->setCurrentRef()->enableAdmin()->createUrl();
if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
$rr->redirect = $authUrl;
return (array) $rr;
} else {
\Yii::$app->getResponse()->redirect($authUrl);
}
} else {
throw new ForbiddenHttpException(\Yii::t('yii', \Yii::t('app', 'You are not allowed to perform this action.')));
}
}