public function toArray() { $response = []; $response['status'] = $this->status; $response['table'] = []; $response['chart'] = []; if ($response['status'] == static::STATUS_SUCCESS) { if ($this->caption) { $response['caption'] = $this->caption; } foreach ($this->data as $key => $row) { $tableRow = []; $chartRow = []; foreach ($this->dataSeries as $s) { if ($s->value !== null) { $value = call_user_func($s->value, $row, $key); } else { $value = ArrayHelper::getValue($row, $s->name); } $value = $s->encode ? Html::encode($value) : $value; $tableRow[] = $value; if ($s->isInChart) { $chartRow[] = $value; } } $response['table'][] = $tableRow; $response['chart'][] = $chartRow; } } else { $response['message'] = $this->message; } return $response; }
/** * @param mixed $model * @param mixed $key * @param int $index * * @return string * * @throws Exception */ protected function renderDataCellContent($model, $key, $index) { if ($this->checkboxOptions instanceof Closure) { $options = call_user_func($this->checkboxOptions, $model, $key, $index, $this); } else { $options = $this->checkboxOptions; if (!isset($options['value'])) { $options['value'] = is_array($key) ? Json::encode($key) : $key; } } $options['id'] = ArrayHelper::getValue($options, 'id', rtrim($this->name, '[]') . '-' . $key); return Checkbox::widget(['name' => $this->name, 'checked' => !empty($options['checked']), 'inputOptions' => $options, 'clientOptions' => ['fireOnInit' => true, 'onChange' => new JsExpression('function() { var $parentCheckbox = $(".select-on-check-all").closest(".checkbox"), $checkbox = $("#' . $this->grid->options['id'] . '").find("input[name=\'' . $this->name . '\']").closest(".checkbox"), allChecked = true, allUnchecked = true; $checkbox.each(function() { if ($(this).checkbox("is checked")) { allUnchecked = false; } else { allChecked = false; } }); if(allChecked) { $parentCheckbox.checkbox("set checked"); } else if(allUnchecked) { $parentCheckbox.checkbox("set unchecked"); } else { $parentCheckbox.checkbox("set indeterminate"); } }')]]); }
/** * @param \yii\web\UrlManager $manager * @param string $route * @param array $params * @return bool|string */ public function createUrl($manager, $route, $params) { if ($route == 'cms/tree/view') { $id = (int) ArrayHelper::getValue($params, 'id'); $treeModel = ArrayHelper::getValue($params, 'model'); if (!$id && !$treeModel) { return false; } if ($treeModel && $treeModel instanceof Tree) { $tree = $treeModel; self::$models[$treeModel->id] = $treeModel; } else { if (!($tree = ArrayHelper::getValue(self::$models, $id))) { $tree = Tree::findOne(['id' => $id]); self::$models[$id] = $tree; } } if (!$tree) { return false; } if ($tree->dir) { $url = $tree->dir . ((bool) \Yii::$app->seo->useLastDelimetrTree ? DIRECTORY_SEPARATOR : "") . (\Yii::$app->urlManager->suffix ? \Yii::$app->urlManager->suffix : ''); } else { $url = ""; } ArrayHelper::remove($params, 'id'); ArrayHelper::remove($params, 'model'); if (!empty($params) && ($query = http_build_query($params)) !== '') { $url .= '?' . $query; } return $url; } return false; }
public function getFile() { $src = $this->owner->{$this->srcAttrName}; if (Yii::$app->fs->has($src) === false) { $src = Yii::$app->getModule('image')->noImageSrc; $errorImage = ErrorImage::findOne(['img_id' => $this->owner->id, 'class_name' => $this->owner->className()]); if ($errorImage === null) { $errorImage = new ErrorImage(); $errorImage->setAttributes(['img_id' => $this->owner->id, 'class_name' => $this->owner->className()]); $errorImage->save(); } } else { $fs = Yii::$app->fs; $components = ArrayHelper::index(Yii::$app->getModule('image')->components, 'necessary.class'); $adapterName = ArrayHelper::getValue($components, $fs::className() . '.necessary.srcAdapter', null); if ($adapterName === null) { throw new HttpException(Yii::t('app', 'Set src compiler adapter')); } if (class_exists($adapterName) === false) { throw new HttpException(Yii::t('app', "Class {$adapterName} not found")); } $adapter = new $adapterName(); if ($adapter instanceof CompileSrcInterface) { $src = $adapter->CompileSrc($src); } else { throw new HttpException(Yii::t('app', "Class {$adapterName} should implement CompileSrcInterface")); } } return $src; }
public function run() { $rr = new RequestResponse(); $pk = \Yii::$app->request->post($this->controller->requestPkParamName); $modelClass = $this->controller->modelClassName; $this->models = $modelClass::find()->where([$this->controller->modelPkAttribute => $pk])->all(); if (!$this->models) { $rr->success = false; $rr->message = \Yii::t('app', "No records found"); return (array) $rr; } $data = []; foreach ($this->models as $model) { $raw = []; if ($this->eachExecute($model)) { $data['success'] = ArrayHelper::getValue($data, 'success', 0) + 1; } else { $data['errors'] = ArrayHelper::getValue($data, 'errors', 0) + 1; } } $rr->success = true; $rr->message = \Yii::t('app', "Mission complete"); $rr->data = $data; return (array) $rr; }
protected function getMigrationFiles() { if ($this->_migrationFiles === null) { $this->_migrationFiles = []; $directories = array_merge($this->migrationLookup, [$this->migrationPath]); $extraPath = ArrayHelper::getValue(Yii::$app->params, 'yii.migrations'); if (!empty($extraPath)) { $directories = array_merge((array) $extraPath, $directories); } foreach (array_unique($directories) as $dir) { $dir = Yii::getAlias($dir, false); if ($dir && is_dir($dir)) { $handle = opendir($dir); while (($file = readdir($handle)) !== false) { if ($file === '.' || $file === '..') { continue; } $path = $dir . DIRECTORY_SEPARATOR . $file; if (preg_match('/^(m(\\d{6}_\\d{6})_.*?)\\.php$/', $file, $matches) && is_file($path)) { $this->_migrationFiles[$matches[1]] = $path; } } closedir($handle); } } ksort($this->_migrationFiles); } return $this->_migrationFiles; }
/** * @return array all directories */ protected function getDirectories() { if ($this->_paths === null) { $paths = ArrayHelper::getValue(Yii::$app->params, $this->paramVar, []); $paths = array_merge($paths, $this->migrationLookup); $extra = !empty($this->extraFile) && is_file($this->extraFile = Yii::getAlias($this->extraFile)) ? require $this->extraFile : []; $paths = array_merge($extra, $paths); $p = []; foreach ($paths as $path) { $p[Yii::getAlias($path, false)] = true; } unset($p[false]); $currentPath = Yii::getAlias($this->migrationPath); if (!isset($p[$currentPath])) { $p[$currentPath] = true; if (!empty($this->extraFile)) { $extra[] = $this->migrationPath; FileHelper::createDirectory(dirname($this->extraFile)); file_put_contents($this->extraFile, "<?php\nreturn " . VarDumper::export($extra) . ";\n", LOCK_EX); } } $this->_paths = array_keys($p); foreach ($this->migrationNamespaces as $namespace) { $path = str_replace('/', DIRECTORY_SEPARATOR, Yii::getAlias('@' . str_replace('\\', '/', $namespace))); $this->_paths[$namespace] = $path; } } return $this->_paths; }
/** * Start cron tasks * @param string $taskCommand * @throws \yii\base\InvalidConfigException */ public function actionStart($taskCommand = null) { /** * @var $cron Crontab */ $cron = $this->module->get($this->module->nameComponent); $cron->eraseJobs(); $common_params = $this->module->params; if (!empty($this->module->tasks)) { if ($taskCommand && isset($this->module->tasks[$taskCommand])) { $task = $this->module->tasks[$taskCommand]; $params = ArrayHelper::merge(ArrayHelper::getValue($task, 'params', []), $common_params); $cron->addApplicationJob(\Yii::getAlias('@app') . '/../yii', $task['command'], $params, ArrayHelper::getValue($task, 'min'), ArrayHelper::getValue($task, 'hour'), ArrayHelper::getValue($task, 'day'), ArrayHelper::getValue($task, 'month'), ArrayHelper::getValue($task, 'dayofweek'), $this->module->cronGroup); } else { foreach ($this->module->tasks as $commandName => $task) { $params = ArrayHelper::merge(ArrayHelper::getValue($task, 'params', []), $common_params); $cron->addApplicationJob(\Yii::getAlias('@app') . '/../yii', $task['command'], $params, ArrayHelper::getValue($task, 'min'), ArrayHelper::getValue($task, 'hour'), ArrayHelper::getValue($task, 'day'), ArrayHelper::getValue($task, 'month'), ArrayHelper::getValue($task, 'dayofweek'), $this->module->cronGroup); } } $cron->saveCronFile(); // save to my_crontab cronfile $cron->saveToCrontab(); // adds all my_crontab jobs to system (replacing previous my_crontab jobs) echo $this->ansiFormat('Cron Tasks started.' . PHP_EOL, Console::FG_GREEN); } else { echo $this->ansiFormat('Cron do not have Tasks.' . PHP_EOL, Console::FG_GREEN); } }
/** * @inheritdoc */ public function validateValue($value, $params = []) { $clef = \yii\helpers\ArrayHelper::getValue($params, 'clef', self::DEFAULT_CLEF); if (strlen($clef) < 1) { return false; } if (!is_numeric($clef)) { return false; } if (!is_string($value)) { return false; } if (strlen($value) < 2) { return false; } $chiffres = str_split($value); $rang = array_reverse(array_keys($chiffres)); $chiffresOrdonnes = array(); foreach ($rang as $i => $valeurRang) { $chiffresOrdonnes[$valeurRang + 1] = $chiffres[$i]; } $resultats = array(); foreach ($chiffresOrdonnes as $cle => $valeur) { $resultats[$valeur] = $cle % 2 == 0 ? $valeur * 1 : $valeur * 2; } $addition = 0; foreach ($resultats as $cle => $valeur) { $addition += array_sum(str_split($valeur)); } $clefValide = str_split($addition); $clefValide = 10 - array_pop($clefValide); return $clef === $clefValide; }
public function beginFooter($options = []) { $actionsOptions = ArrayHelper::getValue($options, 'actionsOptions', []); ArrayHelper::remove($options, 'actionsOptions'); parent::beginFooter($options); echo Html::beginTag('div', array_merge($this->actionsOptions, $actionsOptions)); }
public function renderItem($header, $item, $index) { if (array_key_exists('content', $item)) { $id = $this->options['id'] . '-collapse' . $index; $options = ArrayHelper::getValue($item, 'contentOptions', []); $options['id'] = $id; $expanded = false; if (array_key_exists('expanded', $item)) { $expanded = $item['expanded']; } Html::addCssClass($options, 'panel-collapse collapse' . ($expanded ? ' in' : '')); $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; if ($encodeLabel) { $header = Html::encode($header); } $headerToggle = Html::a($header, '#' . $id, ['class' => 'collapse-toggle', 'data-toggle' => 'collapse', 'data-parent' => '#' . $this->options['id']]) . "\n"; $header = Html::tag('h4', $headerToggle, ['class' => 'panel-title']); if (is_string($item['content'])) { $content = Html::tag('div', $item['content'], ['class' => 'panel-body']) . "\n"; } elseif (is_array($item['content'])) { $content = Html::ul($item['content'], ['class' => 'list-group', 'itemOptions' => ['class' => 'list-group-item'], 'encode' => false]) . "\n"; if (isset($item['footer'])) { $content .= Html::tag('div', $item['footer'], ['class' => 'panel-footer']) . "\n"; } } else { throw new InvalidConfigException('The "content" option should be a string or array.'); } } else { throw new InvalidConfigException('The "content" option is required.'); } $group = []; $group[] = Html::tag('div', $header, ['class' => 'panel-heading']); $group[] = Html::tag('div', $content, $options); return implode("\n", $group); }
public function actionIndex() { $LoadApi = new LoadApi(); // $jsonField = array_keys(array_change_key_case($jsonData->arrayperson[0],CASE_LOWER)); $apiPerson = $LoadApi->person; // $apiPerson = [''] if (count($apiPerson) > 0) { $apiField = ArrayHelper::getValue($apiPerson, 'field'); $apiData = ArrayHelper::getValue($apiPerson, 'data'); // $apiField = ['exc1','exc2']; if (count($apiField) > 0) { $fieldList = new FieldList(); // $dbField = $fieldList->find()->select('field')->orderBy(['field' => SORT_ASC])->asArray()->all(); $dbField = $fieldList::loadFields(); // $f = $fieldList::loadFields($dbField,1); // $insertedField = 0; //Check if database is blank. if (count($dbField[0]) === 0 && count($dbField[1]) === 0) { //Insert all new json field into the database. $dbField = FieldList::saveMultipleField($apiField); } else { //Check for new field, excluded field and update existing field from excluded to new //Check for new field $new = array_diff($apiField, array_merge($dbField[0], $dbField[1])); $exclude = array_diff($dbField[0], $apiField); $renew = array_intersect($apiField, $dbField[1]); $dbField = FieldList::loadAllFields(); if (count($new) > 0) { $dbField = FieldList::saveMultipleField($new); } if (count($exclude) > 0) { $dbField = FieldList::excludeMultipleFields($exclude); } if (count($renew) > 0) { $dbField = FieldList::renewMultipleFields($renew); } } } else { //Load Data from Local Database (Not included in this version). //Below for test only $apiField = $apiPerson; $apiData = $apiPerson; } } else { //Load Data from Local Database (Not included in this version). //Below for test only $apiField = $apiPerson; $apiData = $apiPerson; } $exclude = array_filter($dbField, function ($ar) { return (int) $ar['excluded'] === 1; }); $exclude = new ArrayDataProvider(['key' => 'id', 'allModels' => $exclude]); $include = array_filter($dbField, function ($ar) { return (int) $ar['excluded'] === 0; }); $include = new ArrayDataProvider(['key' => 'id', 'allModels' => $include]); $searchModel = $dbField; return $this->render('index', ['include' => $include, 'exclude' => $exclude, 'searchModel' => $searchModel]); }
/** * improve data & save it * * @param array $newData * @return \common\models\RgnPostcode */ public function improveData($newData) { $improved = FALSE; $attributes = ['province_id', 'city_id', 'district_id', 'subdistrict_id']; /* * compare each attributes */ foreach ($attributes as $attr) { $oldValue = $this->getAttribute($attr); $newValue = ArrayHelper::getValue($newData, $attr); /* * if old value is empty but new value exist, improve it */ if (empty($oldValue) && $newValue > 0) { $this->setAttribute($attr, $newValue); $improved = TRUE; } else { if ($oldValue > 0 && $newValue > 0 && $oldValue != $newValue) { break; } } } /* * if data improved, save it */ if ($improved) { $this->save(FALSE); } return $this; }
public function prepareOptions() { $defaultItem = $this->getDefaultItem(); $this->options['item'] = ArrayHelper::getValue($this->options, 'item', $defaultItem); $this->options['itemOptions'] = $this->listOptions; Html::addCssClass($this->options, 'grouped inline fields'); }
/** * @param RabotaFizLica $rabota * @return string */ private function renderDolzhnosti($rabota) { foreach ($rabota->getDolzhnosti_fiz_lica_na_rabote_rel()->each() as $dolzhnost) { $dolzhnosti[] = ArrayHelper::getValue($dolzhnost, 'dolzhnost_rel.nazvanie'); } return isset($dolzhnosti) ? Html::ul($dolzhnosti, ['class' => 'dolzhnosti', 'encode' => false]) : ''; }
public static function save($field_name = null) { if (0 == count($_FILES)) { throw new Exception('没有文件被上传'); } if (!$field_name) { $field_name = array_keys($_FILES)[0]; } if (!isset($_FILES[$field_name])) { throw new Exception('指定上传字段不存在'); } try { $uploader = UploadedFile::getInstanceByName($field_name); $basepath = realpath(\Yii::$app->basePath . '/../cdn'); $from = ArrayHelper::getValue($_POST, 'from', 'imgs'); $path = sprintf('%s/%s/%s', $basepath, $from, date('Y/m/d')); if (!is_dir($path)) { mkdir($path, 0777, true); } $filename = substr(md5('nisnaker' . microtime()), 16); $new_file = sprintf('%s/%s.%s', $path, $filename, $uploader->extension); if ($uploader->saveAs($new_file)) { $url = substr($new_file, strlen($basepath)); return 'http://' . \Yii::$app->params['site.cdn.domain'] . $url; } else { throw new Exception('文件上传失败'); } } catch (Exception $e) { throw $e; } }
/** * @param null $name * @param null $default * @return array|mixed */ public function getData($name = null, $default = null) { if (is_string($name)) { return ArrayHelper::getValue($this->data, $name, $default); } return $this->data; }
/** * @param ATOM|RSS2 $feed * @return ATOM|RSS2 */ protected function generateFeed($feed) { /* @var Post[] $posts */ $site_name = ArrayHelper::getValue(Yii::$app->params, 'site_name', Yii::$app->name); $posts = Post::find()->where(['status' => Post::STATUS_PUBLISHED])->orderBy(['post_time' => SORT_DESC, 'update_time' => SORT_DESC])->limit(20)->all(); $feed->setTitle($site_name); $feed->setLink(Url::home(true)); $feed->setSelfLink(Url::to(['feed/rss'], true)); $feed->setAtomLink(Url::to(['feed/atom'], true)); $feed->setDescription(ArrayHelper::getValue(Yii::$app->params, 'seo_description', '最新更新的文章')); if ($posts) { $feed->setDate($posts[0]->update_time); } else { $feed->setDate(time()); } foreach ($posts as $post) { $entry = $feed->createNewItem(); $entry->setTitle($post->title); $entry->setLink($post->getUrl(true)); $entry->setDate(intval($post->post_time)); $entry->setDescription($post->excerpt); $entry->setAuthor($post->author_name ? $post->author_name : $post->author->nickname); $entry->setId($post->alias); if ($feed instanceof ATOM) { $entry->setContent($post->content); } $feed->addItem($entry); } return $feed; }
public function normalizeItems() { $items = []; $i = 1; $isActive = false; foreach ($this->items as $item) { $item['labelOptions'] = array_merge($this->labelOptions, ArrayHelper::getValue($item, 'labelOptions', [])); $item['contentOptions'] = array_merge($this->contentOptions, ArrayHelper::getValue($item, 'contentOptions', [])); if (!array_key_exists('uniqueId', $item)) { $item['uniqueId'] = $this->getId() . '-tab-' . $i; } if (isset($item[self::STATE_ACTIVE])) { if ($item[self::STATE_ACTIVE] && !$isActive) { $isActive = true; } } else { $item[self::STATE_ACTIVE] = false; } $items[] = $item; $i++; } if (!$isActive && isset($items[0])) { $items[0][self::STATE_ACTIVE] = true; } $this->items = $items; }
protected function renderItem($item) { $this->validateItems($item); $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate); $url = Url::to(ArrayHelper::getValue($item, 'url', '#')); $linkOptions_ar = ArrayHelper::getValue($item, 'linkOptions'); $linkOptions = ''; if (!empty($linkOptions_ar)) { foreach ($linkOptions_ar as $key => $value) { $linkOptions .= ' ' . $key . '="' . $value . '"'; } } if (empty($item['top'])) { if (empty($item['items'])) { $template = str_replace('{icon}', $this->indItem . '{icon}', $template); } else { $template = isset($item['template']) ? $item['template'] : '<a href="{url}" class="kv-toggle">{icon}{label}</a>'; $openOptions = $item['active'] ? ['class' => 'opened'] : ['class' => 'opened', 'style' => 'display:none']; $closeOptions = $item['active'] ? ['class' => 'closed', 'style' => 'display:none'] : ['class' => 'closed']; $indicator = Html::tag('span', $this->indMenuOpen, $openOptions) . Html::tag('span', $this->indMenuClose, $closeOptions); $template = str_replace('{icon}', $indicator . '{icon}', $template); } } $icon = empty($item['icon']) ? '' : '<span class="' . $this->iconPrefix . $item['icon'] . '"></span> '; unset($item['icon'], $item['top']); return strtr($template, ['{url}' => $url, '{label}' => $item['label'], '{icon}' => $icon, '{linkOptions}' => $linkOptions]); }
protected function renderItems($items, $options = []) { $lines = []; foreach ($items as $i => $item) { if (isset($item['visible']) && !$item['visible']) { continue; } if (is_string($item)) { $lines[] = $item; continue; } if (!array_key_exists('label', $item)) { throw new InvalidConfigException("The 'label' option is required."); } $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; $label = $encodeLabel ? Html::encode($item['label']) : $item['label']; $itemOptions = ArrayHelper::getValue($item, 'options', []); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); $linkOptions['tabindex'] = '-1'; $url = array_key_exists('url', $item) ? $item['url'] : null; if (empty($item['items'])) { if ($url === null) { $content = $label; } else { $content = Html::a($label, $url, $linkOptions); } } else { $submenuOptions = $options; unset($submenuOptions['id']); $content = Html::a($label, $url === null ? '#' : $url, $linkOptions) . $this->renderItems($item['items'], $submenuOptions); } $lines[] = Html::tag('li', $content, $itemOptions); } return Html::tag('ul', implode("\n", $lines), $options); }
/** * Generate Url * @param $params * @return string */ private function buildUrl(array $params) { if (!ArrayHelper::getValue($params, 'format')) { $params['format'] = $this->format; } return $this->geoUrl . '?' . $this->buildQuery($params); }
public function __construct($config = array()) { self::$plugins = array_diff(scandir(__DIR__ . '/plugins/'), array('..', '.')); $provider = ArrayHelper::getValue($config, 'config.provider'); if (isset($provider)) { if (ArrayHelper::isIn($provider . '.php', self::$plugins)) { require __DIR__ . '/plugins/' . $provider . '.php'; $format = ArrayHelper::getValue($config, 'config.return_formats'); if (isset($format)) { if (ArrayHelper::isIn($format, ArrayHelper::getValue($plugin, 'accepted_formats'))) { self::$return_formats = $format; } else { self::$return_formats = ArrayHelper::getValue($plugin, 'default_accepted_format'); } } self::$provider = $plugin; self::$api_key = ArrayHelper::getValue($config, 'config.api_key', NULL); } else { throw new HttpException(404, 'The requested Item could not be found.'); } } else { require __DIR__ . '/plugins/geoplugin.php'; self::$provider = $plugin; self::$return_formats = $plugin['default_accepted_format']; } return parent::__construct($config); }
public function shareUrl($networkId, $url = null) { if (!$url) { $url = $this->url; } return str_replace('{url}', urlencode($url), ArrayHelper::getValue($this->shareUrlMap, $networkId)); }
/** * Recursively renders the menu items (without the container tag). * @param array $items the menu items to be rendered recursively * @return string the rendering result */ protected function renderItems($items) { $n = count($items); $lines = []; foreach ($items as $i => $item) { $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', [])); $tag = ArrayHelper::remove($options, 'tag', 'li'); $class = []; if ($item['active']) { $class[] = $this->activeCssClass; } if ($i === 0 && $this->firstItemCssClass !== null) { $class[] = $this->firstItemCssClass; } if ($i === $n - 1 && $this->lastItemCssClass !== null) { $class[] = $this->lastItemCssClass; } if (!empty($class)) { if (empty($options['class'])) { $options['class'] = implode(' ', $class); } else { $options['class'] .= ' ' . implode(' ', $class); } } $menu = $this->renderItem($item); if (!empty($item['items'])) { $menu .= strtr($this->submenuTemplate, ['{show}' => $item['active'] ? "style='display: block'" : '', '{items}' => $this->renderItems($item['items'])]); } $lines[] = Html::tag($tag, $menu, $options); } return implode("\n", $lines); }
/** * @inheritdoc */ public function run() { parent::run(); if (!is_null($this->objectModel)) { $groupedRatingValues = RatingValues::getValuesByObjectModel($this->objectModel); if (!empty($groupedRatingValues)) { $groups = []; foreach ($groupedRatingValues as $groupId => $group) { $ratingItem = RatingItem::findById($groupId); $groups[] = ['name' => !is_null($ratingItem) ? $ratingItem->name : Yii::t('app', 'Unknown rating'), 'rating' => call_user_func($this->calcFunction, $group), 'votes' => count($group)]; } } else { $groups = null; } return $this->render($this->viewFile, ['groups' => $groups]); } elseif (!is_null($this->reviewModel)) { $value = RatingValues::findOne(['rating_id' => $this->reviewModel->rating_id]); $groups = []; $ratingItem = RatingItem::findById(ArrayHelper::getValue($value, 'rating_item_id', 0)); $group = [ArrayHelper::getValue($value, 'value')]; $groups[] = ['name' => !is_null($ratingItem) ? $ratingItem->name : Yii::t('app', 'Unknown rating'), 'rating' => call_user_func($this->calcFunction, $group)]; return $this->render($this->viewFile, ['groups' => $groups]); } else { return ''; } }
/** * @param Tree $model * @param array $data * @return static */ public static function instance($model, $data = []) { if ($package = ArrayHelper::getValue(static::$instances, $model->id)) { return $package; } return new static($model, $data); }
public function setThumbnailSettings(array $config) { $params = ['width', 'height', 'mode']; foreach ($params as $param) { $this->_thumbnailSettings[$param] = ArrayHelper::getValue($config, $param, null); } }
/** * @inheritdoc */ public function init() { /** * @var Module $m */ $m = Yii::$app->getModule('user'); if (!$m->getRegistrationSetting('randomUsernames', $this->userType)) { $this->attributes['username'] = ['type' => Form::INPUT_TEXT, 'options' => ['autocomplete' => 'new-username']]; } if (!$m->getRegistrationSetting('randomPasswords', $this->userType)) { $password = ['type' => Form::INPUT_PASSWORD]; if (in_array(Module::SCN_REGISTER, $m->passwordSettings['strengthMeter'])) { $password = ['type' => Form::INPUT_WIDGET, 'widgetClass' => PasswordInput::classname(), 'options' => ['options' => ['placeholder' => Yii::t('user', 'Password'), 'autocomplete' => 'off']]]; } $this->attributes['password'] = $password; } $this->attributes['email'] = ['type' => Form::INPUT_TEXT]; $captcha = ArrayHelper::getValue($m->registrationSettings, 'captcha', false); if ($captcha !== false && is_array($captcha)) { $this->attributes['captcha'] = ['type' => Form::INPUT_WIDGET, 'widgetClass' => Captcha::classname(), 'options' => $captcha['widget']]; } parent::init(); unset($this->attributes['rememberMe']); $this->leftFooter = $m->button(Module::BTN_HOME) . $m->button(Module::BTN_ALREADY_REGISTERED); $this->rightFooter = $m->button(Module::BTN_RESET_FORM) . ' ' . $m->button(Module::BTN_REGISTER); }
public function init() { \kartik\base\InputWidget::init(); $this->pluginOptions['theme'] = $this->theme; if (!empty($this->addon) || empty($this->pluginOptions['width'])) { $this->pluginOptions['width'] = '100%'; } $multiple = ArrayHelper::getValue($this->pluginOptions, 'multiple', false); unset($this->pluginOptions['multiple']); $multiple = ArrayHelper::getValue($this->options, 'multiple', $multiple); $this->options['multiple'] = $multiple; if ($this->hideSearch) { $css = ArrayHelper::getValue($this->pluginOptions, 'dropdownCssClass', ''); $css .= ' kv-hide-search'; $this->pluginOptions['dropdownCssClass'] = $css; } $this->initPlaceholder(); if ($this->data == null) { if (!isset($this->value) && !isset($this->initValueText)) { $this->data = []; } else { $key = isset($this->value) ? $this->value : ($multiple ? [] : ''); $val = isset($this->initValueText) ? $this->initValueText : $key; $this->data = $multiple ? array_combine($key, $val) : [$key => $val]; } } Html::addCssClass($this->options, 'form-control'); $this->initLanguage('language', true); $this->registerAssets(); $this->renderInput(); }