本文整理汇总了PHP中yii\helpers\ArrayHelper类的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper类的具体用法?PHP ArrayHelper怎么用?PHP ArrayHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayHelper类的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: fail
/**
* Returns fail response
* @param integer $code
* @param array $data
* @return \yii\web\Response
*/
public static function fail($code = 400, array $data = [])
{
$resp = \Yii::$app->response;
$resp->setStatusCode($code);
$resp->data = ArrayHelper::merge(['status' => 'error', 'message' => static::$httpStatuses[$code]], $data);
return $resp;
}
示例3: __construct
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);
}
示例4: map
public static function map($tipo)
{
//entrada ou saida
$tipo = self::find()->where(['tipo' => $tipo])->asArray()->all();
$tipoMap = ArrayHelper::map($tipo, 'id', 'descricao');
return $tipoMap;
}
示例5: renderButtonAdd
protected function renderButtonAdd()
{
Html::addCssClass($this->buttonOptions, 'btn');
$this->buttonOptions = ArrayHelper::merge($this->buttonOptions, ['role' => 'area.add', 'data-tmpl' => $this->options['id']]);
$templateButtonAdding = strtr($this->templateButtonAdding, ['{button}' => Html::button('+', $this->buttonOptions), '{label}' => Html::tag('label', $this->label)]);
echo Html::tag('div', $templateButtonAdding, ['class' => 'form-group']);
}
示例6: FetchProducts
public static function FetchProducts()
{
$sql = 'SELECT * FROM easyii_catalog_items where category_id=2';
$allProducts = Item::findBySql($sql)->all();
$listData = ArrayHelper::map($allProducts, 'item_code', 'title');
return $listData;
}
示例7: 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;
}
示例8: registerKCFinder
/**
* Registers KCFinder
*/
protected function registerKCFinder()
{
$register = KCFinderAsset::register($this->view);
$kcfinderUrl = $register->baseUrl;
$browseOptions = ['filebrowserBrowseUrl' => $kcfinderUrl . '/browse.php?opener=ckeditor&type=files', 'filebrowserUploadUrl' => $kcfinderUrl . '/upload.php?opener=ckeditor&type=files'];
$this->clientOptions = ArrayHelper::merge($browseOptions, $this->clientOptions);
}
示例9: getDropdownList
/**
* Get all authors for dropdownlist widget
* @return array|\yii\db\ActiveRecord[]
*/
public static function getDropdownList()
{
$authors = self::find()->all();
$authors = \yii\helpers\ArrayHelper::map($authors, 'id', 'fullName');
array_unshift($authors, '');
return $authors;
}
示例10: renderItems
/**
* 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);
}
示例11: actionStock
public function actionStock()
{
$debug = '';
$model = new DynamicModel(['vins', 'diller']);
$model->addRule('vins', 'string')->addRule('diller', 'integer')->addRule(['diller', 'vins'], 'required');
$list = ArrayHelper::map(Mod\cats\Stock::find()->all(), 'id', 'name');
$prompt = Yii::t('app', 'Select stock');
$arrError = [];
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$arrvin = explode("\n", $model->vins);
foreach ($arrvin as $vin) {
if ($car = Mod\Car::findOne(['vin' => trim($vin)])) {
$status = Mod\CarStatus::findOne(['car_id' => $car->id]);
$status->stock_id = $model->diller;
$status->save();
} else {
$arrError[] = $vin . ' не найден VIN';
}
}
// $debug = print_r($arrError, true);
$debug = implode('<br>', $arrError);
return $this->render('finish', ['debug' => $debug]);
}
$arrVars = ['model' => $model, 'list' => $list, 'prompt' => $prompt, 'selLabel' => 'Склад', 'title' => 'Пакетное перемещение'];
return $this->render('index', $arrVars);
}
示例12: instance
/**
* @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);
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Users::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$sort = $dataProvider->getSort();
$sort->attributes['officeName'] = ['asc' => ['questionlist_office.name' => SORT_ASC], 'desc' => ['questionlist_office.name' => SORT_DESC], 'label' => 'Имя офиса'];
$dataProvider->setSort($sort);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
$query->joinWith(['questionlist_office']);
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id]);
if ($this->roleName) {
$this->profile_office_role = $this->roleName;
}
$query->andFilterWhere(['like', 'profile_id', $this->profile_id])->andFilterWhere(['like', 'profile_office_role', $this->profile_office_role]);
if ($this->scenario == 'managerSearch') {
$userRoles = Users::findAll(['profile_id' => Yii::$app->user->identity->username, 'profile_office_role' => 'commercial_director']);
$userRegions = array_values(ArrayHelper::map($userRoles, 'region_id', 'region_id'));
$query->andFilterWhere(['like', 'profile_office_role', 'manager']);
$query->andFilterWhere(['in', 'questionlist_users_offices.region_id', $userRegions]);
}
$query->joinWith(['office' => function ($q) {
$q->andFilterWhere(['like', 'questionlist_office.name', $this->officeName]);
}]);
$query->joinWith(['region' => function ($q) {
$q->andFilterWhere(['like', 'questionlist_region.name', $this->regionName]);
}]);
return $dataProvider;
}
示例14: setThumbnailSettings
public function setThumbnailSettings(array $config)
{
$params = ['width', 'height', 'mode'];
foreach ($params as $param) {
$this->_thumbnailSettings[$param] = ArrayHelper::getValue($config, $param, null);
}
}
示例15: init
/**
* @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);
}