本文整理汇总了PHP中yii\helpers\ArrayHelper::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::getValue方法的具体用法?PHP ArrayHelper::getValue怎么用?PHP ArrayHelper::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toArray
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;
}
示例2: renderDataCellContent
/**
* @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");
}
}')]]);
}
示例3: createUrl
/**
* @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;
}
示例4: getFile
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;
}
示例5: run
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;
}
示例6: getMigrationFiles
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;
}
示例7: getDirectories
/**
* @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;
}
示例8: actionStart
/**
* 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);
}
}
示例9: validateValue
/**
* @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;
}
示例10: beginFooter
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));
}
示例11: renderItem
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);
}
示例12: actionIndex
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]);
}
示例13: improveData
/**
* 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;
}
示例14: prepareOptions
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');
}
示例15: renderDolzhnosti
/**
* @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]) : '';
}