public function loadCollection($data = null) { if (is_null($data)) { $data = \Yii::$app->request->post(); } return parent::loadCollection([['id' => ArrayHelper::remove($data, 'pk'), $data['name'] => ArrayHelper::remove($data, 'value', [])]]); }
public function init() { parent::init(); $request = AH::merge(['wrapper' => 'results', 'term' => 'search:term'], $this->uses); $requests = []; $back_request = []; foreach ($request as $k => $v) { if ($k === 'term') { $requests[] = $v; } elseif (is_array($v)) { $requests[] = "{$k}:" . json_encode($v); $back_request[] = "{$k}:" . json_encode($v); } else { $requests[] = "{$k}:'{$v}'"; $back_request[] = "{$k}:'{$v}'"; } } \Yii::configure($this, ['format' => 'html', 'filterInputOptions' => ['id' => 'id'], 'filter' => Select2::widget(['attribute' => 'id', 'model' => $this->grid->filterModel, 'url' => Url::toRoute(['list']), 'settings' => ['ajax' => ['data' => new JsExpression('function(term,page) { return {' . implode(', ', $requests) . '}; }')], 'initSelection' => new JsExpression('function (elem, callback) { var id=$(elem).val(); $.ajax("' . Url::toRoute(['list']) . '?id=" + id, { dataType: "json", data : {' . implode(', ', $back_request) . '} }).done(function(data) { callback(data.results[0]); }); }')]])]); }
/** * @param Resource[] $zones array of domain resources to be sorted * @return array sorted by the default zone resources */ public function orderZones($zones) { $result = ArrayHelper::index($zones, 'zone'); uasort($result, function ($a, $b) { return $a->zone === Domain::DEFAULT_ZONE; }); return $result; }
/** * @param integer $id Tariff ID * @param array $options that will be passed to the object as configuration * @return AbstractTariffManager|object * @throws NotFoundHttpException */ public static function createById($id, $options = []) { $model = Tariff::find()->byId($id)->details()->one(); if ($model === null) { throw new NotFoundHttpException('Tariff was not found'); } $model->scenario = ArrayHelper::getValue($options, 'scenario', $model::SCENARIO_DEFAULT); return Yii::createObject(array_merge(['class' => static::buildClassName($model->type), 'tariff' => $model], $options)); }
public function init() { parent::init(); if (!$this->combo instanceof Combo) { $this->combo = ArrayHelper::merge(['model' => $this->model, 'attribute' => $this->attribute], $this->combo); $this->combo = Yii::createObject($this->combo); } $this->combo->registerClientConfig(); $this->pluginOptions = ArrayHelper::merge(['type' => 'combo', 'placement' => 'bottom', 'combo' => $this->combo->getPluginOptions(), 'hash' => $this->combo->configId], $this->pluginOptions); $this->registerAssets(); }
/** * @param ServerResource[] $resources * @param array $order array of ordered values. $resources array will be re-ordered according this order * @param string $key the key that will be used to re-order * @return array */ private function sortResourcesByDefinedOrder($resources, $order, $key) { $result = []; $resources = ArrayHelper::index($resources, $key); foreach ($order as $type) { if (isset($resources[$type])) { $result[] = $resources[$type]; } } return $result; }
public function actionIndex($domain = null) { $model = new Whois(); $model->load(Yii::$app->request->get(), ''); if (!$model->validate()) { throw new UnprocessableEntityHttpException(); } /** @var DomainTariffRepository $repository */ $repository = Yii::createObject(DomainTariffRepository::class); $availableZones = ArrayHelper::getColumn($repository->getAvailableZones(), 'zone', false); return $this->render('index', ['model' => $model, 'availableZones' => $availableZones]); }
private function renderHtml() { $file = $this->file; $filename = $this->fileStorage->get($file); $contentType = $this->getContentType($file->id); if (mb_substr($contentType, 0, 5) === 'image') { $thumb = Image::thumbnail($filename, $this->thumbHeight, $this->thumbHeight); $base64 = 'data: ' . $contentType . ';base64,' . base64_encode($thumb); echo Html::a(Html::img($base64, ['class' => 'margin']), $this->getLink(), ArrayHelper::merge(['data-lightbox' => 'file-' . $file->id], $this->lightboxLinkOptions)); } else { echo Html::a(Html::tag('div', $this->getExtIcon($file->type), ['class' => 'margin file']), $this->getLink(true)); } }
/** {@inheritdoc} */ protected function renderDataCellContent($model, $key, $index) { if ($this->value !== null) { if (is_string($this->value)) { $value = ArrayHelper::getValue($model, $this->value); } else { $value = call_user_func($this->value, $model, $key, $index, $this); } } else { $value = $this->renderViewLink($model, $key, $index); } $note = $this->renderNoteLink($model, $key, $index); $extra = $this->renderExtra($model); $badges = $this->badges instanceof Closure ? call_user_func($this->badges, $model, $key, $index) : $this->badges; return $value . $extra . ($badges ? ' ' . $badges : '') . ($note ? '<br>' . $note : ''); }
public function run() { $session = \Yii::$app->getSession(); $flashes = $session->getAllFlashes(); $notifications = []; foreach ($flashes as $type => $data) { if (isset($this->alertTypes[$type])) { $data = (array) $data; foreach ($data as $message) { $message = $this->normalizeMessage($message); $notifications[] = ArrayHelper::merge(['type' => $type], $message); } $session->removeFlash($type); } } echo PNotify::widget(['notifications' => $notifications]); }
public function getTransferDataProvider() { $result = ['success' => null, 'error' => null]; $this->domains = trim($this->domains); $list = ArrayHelper::csplit($this->domains, "\n"); foreach ($list as $key => $value) { $strCheck .= "\n{$value}"; $strCheck = trim($strCheck); preg_match("/^([a-z0-9][0-9a-z.-]+)( +|\t+|,|;)(.*)/i", $value, $matches); if ($matches) { $domain = check::domain(trim(strtolower($matches[1]))); if ($domain) { $password = check::password(trim($matches[3])); if ($password) { $doms[$domain] = compact('domain', 'password'); } else { $dom2err[$domain] = 'wrong input password'; } } else { $dom2err[$value] = 'unknown error'; } } else { $dom2err[$value] = 'empty code'; } } return $result; }
/** * {@inheritdoc} */ public function searchAttributes() { return ArrayHelper::merge($this->defaultSearchAttributes(), ['nss_like' => Yii::t('hipanel', 'Name Servers'), 'domain_like' => Yii::t('hipanel', 'Domain')]); }
/** {@inheritdoc} */ public function getFilter() { return ArrayHelper::merge(parent::getFilter(), ['class' => ['format' => $this->profileClass]]); }
public function searchAttributes() { return ArrayHelper::merge($this->defaultSearchAttributes(), ['model_types', 'model_brands', 'model_type_like', 'model_brand_like', 'partno_like', 'serial_like', 'order_data_like', 'move_descr_like', 'src_name_like', 'dst_name_like', 'create_time_from', 'create_time_till']); }
public function actions() { return ['set-orientation' => ['class' => OrientationAction::class, 'allowedRoutes' => ['/hosting/vhost/index']], 'index' => ['class' => RedirectAction::class, 'url' => ['@hdomain/index']], 'search' => ['class' => SearchAction::class], 'view' => ['class' => RedirectAction::class, 'url' => ArrayHelper::merge(['@hdomain/view'], Yii::$app->request->get())], 'advanced-config' => ['class' => SmartUpdateAction::class, 'findOptions' => ['select' => 'advanced'], 'success' => Yii::t('hipanel:hosting', 'Advanced settings were updated successfully'), 'error' => Yii::t('hipanel:hosting', 'Error when updating advanced settings')], 'manage-proxy' => ['class' => SmartUpdateAction::class, 'findOptions' => ['select' => 'advanced', 'with_backends' => true], 'success' => Yii::t('hipanel:hosting', 'Domain proxy setting settings were changed'), 'error' => Yii::t('hipanel:hosting', 'Error when changing domain proxy settings')], 'validate-form' => ['class' => ValidateFormAction::class]]; }
public function init() { parent::init(); $this->pluginOptions = ArrayHelper::merge(['type' => 'remoteformat'], $this->pluginOptions); }
/** {@inheritdoc} */ public function getFilter() { return ArrayHelper::merge(parent::getFilter(), ['type_in' => ['format' => $this->clientType], 'order' => ['format' => ['loginlike' => 'desc']], 'limit' => ['format' => '50']]); }
public function searchAttributes() { return ArrayHelper::merge($this->defaultSearchAttributes(), []); }
/** * {@inheritdoc} */ public function behaviors() { return ArrayHelper::merge(parent::behaviors(), [['class' => VerbFilter::class, 'actions' => ['request-email-verification' => ['post'], 'request-phone-verification' => ['post']]]]); }
/** * {@inheritdoc} */ protected function renderDataCellContent($model, $key, $index) { return Yii::createObject(ArrayHelper::merge(['class' => XEditable::class, 'model' => $model, 'attribute' => $this->attribute, 'pluginOptions' => $this->pluginOptions, 'linkOptions' => ['style' => ['word-break' => 'break-all']]], $this->widgetOptions))->run(); }
public function actionExportHosts(array $type_in = ['a', 'aaaa', 'cname', 'txt', 'soa', 'ns', 'mx', 'srv']) { $searchModel = $this->searchModel(['scenario' => 'export-hosts']); $data = [$searchModel->formName() => ArrayHelper::merge(['hdomain_id_in' => Yii::$app->request->post('selection')], Yii::$app->request->post($searchModel->formName(), []))]; $dataProvider = $searchModel->search($data, ['pagination' => false]); if (empty($searchModel->hdomain_id_in)) { return $this->redirect('@dns/zone'); } return $this->render('export-hosts', ['dataProvider' => $dataProvider, 'model' => $searchModel]); }
/** * Renders the body of the Modal. * Triggers [[EVENT_BEFORE_BODY]] and [[EVENT_AFTER_BODY]] * Set `$event->handled = true` to prevent default body render. */ protected function renderBody() { $event = new Event(); $this->trigger(static::EVENT_BEFORE_BODY, $event); if ($event->handled) { return; } if ($this->warning) { echo Html::tag('div', Html::tag(ArrayHelper::remove($this->warning, 'tag', 'h4'), ArrayHelper::remove($this->warning, 'label'), $this->warning), ['class' => 'callout callout-warning']); } if ($this->blockReasons) { echo $this->modal->form->field($this->model, 'type')->dropDownList($this->blockReasons); } echo $this->modal->form->field($this->model, 'comment'); $this->trigger(static::EVENT_AFTER_BODY); }
public function actionSetContacts() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $post = Yii::$app->request->post(); $model = DynamicModel::validateData($post, [[Domain::$contactOptions, 'required']]); if ($model->hasErrors()) { return ['errors' => $model->errors]; } $ids = Yii::$app->request->post('id'); $data = iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator(array_map(function ($i) use($post) { return [$i => $post[$i]]; }, Domain::$contactOptions)))); $preparedData = []; foreach ($ids as $id) { $preparedData[] = ArrayHelper::merge(['id' => $id], $data); } try { $result = Domain::perform('SetContacts', $preparedData, true); } catch (\Exception $e) { $result = ['errors' => ['title' => $e->getMessage(), 'detail' => $e->getMessage()]]; } return $result; }
private function renderButton() { $options = ArrayHelper::merge(['title' => Html::encode($this->label), 'class' => $this->linkClasses, 'data-pjax' => $this->dataPjax], $this->buttonOptions); echo Html::a(sprintf('%s %s', $this->icon, Html::encode($this->label)), $this->url, $options); }
/** * {@inheritdoc} */ public function init() { $this->pjaxOptions = ArrayHelper::merge(['id' => 'dns_zone_view', 'enablePushState' => false, 'enableReplaceState' => false], $this->pjaxOptions); $this->progressOptions = ArrayHelper::merge(['id' => 'progress-bar', 'percent' => 100, 'barOptions' => ['class' => 'active progress-bar-striped', 'style' => 'width: 100%']], $this->progressOptions); }
/** * {@inheritdoc} */ public static function detailView(array $config = []) { $config = ArrayHelper::merge(['gridOptions' => ['resizableColumns' => ['resizeFromBody' => true]]], $config); return parent::detailView($config); }
public function searchAttributes() { return ArrayHelper::merge($this->defaultSearchAttributes(), ['client_like', 'with_data', 'realm', 'language']); }
public function prepareHtml($data) { $this->prepareValue($data); $this->prepareDataValue($data); $this->prepareDisplayValue($data); $this->registerMyJs($data); $params = ArrayHelper::merge(['id' => $this->getId(), 'class' => 'editable', 'data-pk' => $data['model']->primaryKey, 'data-name' => $data['attribute'], 'data-value' => $this->pluginOptions['data-value']], $this->linkOptions); return Html::a($this->pluginOptions['data-display-value'], '#', $params); }
/** * Renders a spoiler-button-activated hidden part. */ public function renderHiddenSpoiler() { $options = ArrayHelper::merge(['id' => $this->button['id'] . '-body', 'tag' => 'span', 'value' => implode($this->delimiter, $this->getSpoiledItems()), 'class' => 'collapse', 'data-spoiler-body' => true], $this->hidden); $this->parts['{hidden}'] = Html::tag(ArrayHelper::remove($options, 'tag'), ArrayHelper::remove($options, 'value'), $options); }
/** * {@inheritdoc} */ public function init() { parent::init(); $this->inputOptions = ArrayHelper::merge(['class' => 'form-control'], $this->inputOptions); $this->randomOptions = $this->randomOptions ?: ['weak' => ['label' => Yii::t('hipanel', 'Weak'), 'length' => 8, 'specialchars' => 0], 'medium' => ['label' => Yii::t('hipanel', 'Medium'), 'length' => 10], 'strong' => ['label' => Yii::t('hipanel', 'Strong'), 'length' => 14]]; }