本文整理汇总了PHP中ArrayHelper::map方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::map方法的具体用法?PHP ArrayHelper::map怎么用?PHP ArrayHelper::map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSettings
/**
* Gets all a combined map of all the settings.
* @return array
*/
public function getSettings()
{
$settings = static::find()->where(['active' => 1])->asArray()->all();
return array_merge_recursive(ArrayHelper::map($settings, 'key', 'value', 'section'), ArrayHelper::map($settings, 'key', 'type', 'section'));
}
示例2: listData
/**
* Получить массив собранных данных
* @param array $condition
* @return array
*/
public static function listData($condition = [])
{
$query = self::find();
if ($condition) {
$query->where($condition[0], !empty($condition[1]) ? $condition[1] : []);
}
return ArrayHelper::map($query->all(), 'id', 'title');
}
示例3: existe_uej
/**
* Verificar si tiene unidad ejecutora asociada
* @return bool
*/
public function existe_uej()
{
$resultado = ArrayHelper::map(AcEspUej::find()->limit(1)->where('id_ac_esp= :id', ['id' => $this->id])->all(), 'id', 'id_ue');
if (count($resultado) > 0) {
return 1;
} else {
return 0;
}
}
示例4: unserializeRecursive
public static function unserializeRecursive($value)
{
if (empty($value)) {
return $value;
}
if (is_array($value)) {
return ArrayHelper::map($value, function ($value) {
return static::unserializeRecursive($value);
}, true);
}
return static::unserialize($value, false);
}
示例5: createMultiple
public static function createMultiple($modelClass, $multipleModels = [])
{
$model = new $modelClass();
$formName = $model->formName();
$post = Yii::$app->request->post($formName);
$models = [];
if (!empty($multipleModels)) {
$keys = array_keys(ArrayHelper::map($multipleModels, 'id', 'id'));
$multipleModels = array_combine($keys, $multipleModels);
}
if ($post && is_array($post)) {
foreach ($post as $i => $item) {
if (isset($item['id']) && !empty($item['id']) && isset($multipleModels[$item['id']])) {
$models[] = $multipleModels[$item['id']];
} else {
$models[] = new $modelClass();
}
}
}
unset($model, $formName, $post);
return $models;
}
示例6: listAll
/**
* @param string $keyField
* @param string $valueField
* @param bool $asArray
* @return mixed
*/
public static function listAll($keyField = 'id', $valueField = 'name', $asArray = true)
{
$query = static::find();
if ($asArray) {
$query->select([$keyField, $valueField])->asArray();
}
return ArrayHelper::map($query->all(), $keyField, $valueField);
}
示例7: getUsersList
public static function getUsersList()
{
$sql = 'SELECT `id`, `nickname` FROM ' . self::tableName() . ' ORDER BY `nickname`';
$rows = Yii::$app->db->createCommand($sql)->queryAll();
return ArrayHelper::map($clients, 'id', 'nickname');
}
示例8: function
*/
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\widgets\Pjax;
/** @var IdentityInterface|ActiveRecord $identity */
$identity = Yii::$app->getUser()->identityClass;
$this->title = Module::t('Requests');
echo Breadcrumbs::widget(['links' => [$this->title]]);
?>
<div class="request-log-default-index">
<h3><?php
echo Html::encode($this->title);
?>
</h3>
<?php
Pjax::begin();
echo GridView::widget(['filterModel' => $searchModel, 'dataProvider' => $dataProvider, 'columns' => [['attribute' => 'id', 'value' => function ($model, $index, $dataColumn) {
/** @var RequestLog $model */
return $model->id;
}, 'filter' => false], 'app_id', 'route', 'params', ['attribute' => 'user_id', 'value' => function ($model, $index, $dataColumn) {
return $model->user ? $model->user->{Module::getInstance()->usernameAttribute} : Module::t('Guest');
}, 'filter' => ArrayHelper::map($identity::find()->all(), 'id', Module::getInstance()->usernameAttribute)], 'ip', ['attribute' => 'datetime', 'value' => function ($model, $index, $dataColumn) {
return $model->datetime;
}, 'filter' => false], ['attribute' => 'user_agent', 'value' => function ($model, $index, $dataColumn) {
return $model->user_agent;
}, 'filter' => false]]]);
Pjax::end();
?>
</div>
示例9:
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use common\models\Suppliers;
use common\models\Brands;
use common\models\Producttypes;
use common\models\Productcategories;
/* @var $this yii\web\View */
/* @var $model common\models\Products */
/* @var $form yii\bootstrap\ActiveForm */
$dataProductCategory = ArrayHelper::map(Productcategories::find()->asArray()->all(), 'ProductCategoryId', 'Name');
$dataSuppliers = ArrayHelper::map(Suppliers::find()->asArray()->all(), 'SupplierId', 'Name');
$dataBrands = ArrayHelper::map(Brands::find()->asArray()->all(), 'BrandId', 'Name');
$dataProducttypes = ArrayHelper::map(Producttypes::find()->asArray()->all(), 'ProducttypeId', 'Name');
?>
<div class="products-form">
<?php
$form = ActiveForm::begin(['layout' => 'horizontal']);
?>
<?php
echo $form->field($model, 'Name', ['horizontalCssClasses' => ['wrapper' => 'col-sm-4']])->textInput(['maxlength' => 500]);
?>
<?php
echo $form->field($model, 'ProductCategoryId', ['horizontalCssClasses' => ['wrapper' => 'col-sm-3']])->dropDownList($dataProductCategory, ['prompt' => '----------Choose a Category----------']);
?>
<?php
示例10: actionUpdatedealer
/**
* Updates an existing Dealership model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdatedealer($id)
{
$modelDealership = $this->findModel($id);
$modelsShowroom = $modelDealership->Showroomes;
if ($modelDealership->load(Yii::$app->request->post())) {
$oldIDs = ArrayHelper::map($modelsShowroom, 'id', 'id');
$modelsShowroom = Model::createMultiple(Showroom::classname(), $modelsShowroom);
Model::loadMultiple($modelsShowroom, Yii::$app->request->post());
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsShowroom, 'id', 'id')));
// ajax validation
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ArrayHelper::merge(ActiveForm::validateMultiple($modelsShowroom), ActiveForm::validate($modelDealership));
}
// validate all models
$valid = $modelDealership->validate();
$valid = $modelDealeraccount->validate();
$valid = Model::validateMultiple($modelsShowroom) && $valid;
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if (($flag = $modelDealership->save(false)) && ($flag = $modelDealeraccount->save(false))) {
if (!empty($deletedIDs)) {
Showroom::deleteAll(['id' => $deletedIDs]);
}
foreach ($modelsShowroom as $modelShowroom) {
$modelShowroom->Dealership_id = $modelDealership->id;
if (!($flag = $modelShowroom->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['view', 'id' => $modelDealership->id]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
}
return $this->render('update', ['modelDealership' => $modelDealership, 'modelsShowroom' => empty($modelsShowroom) ? [new Showroom()] : $modelsShowroom, 'modelsService' => empty($modelsService) ? [new Service()] : $modelsService]);
}
示例11:
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\PacienteSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="paciente-search">
<?php
$form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']);
?>
<?php
echo $form->field($model, 'persona_id')->dropDownList(ArrayHelper::map(Persona::find()->all(), 'id', 'fullName'), ['prompt' => 'Seleccionar Persona']);
?>
<?php
echo $form->field($model, 'descripcion');
?>
<div class="form-group">
<?php
echo Html::submitButton('Buscar', ['class' => 'btn btn-primary']);
?>
<?php
echo Html::resetButton('Reiniciar', ['class' => 'btn btn-default']);
?>
</div>
示例12: createFromInvoice
public function createFromInvoice($data, $model = null)
{
$pay_vals = ArrayHelper::map($data['details'], 'id_invoice', 'value');
$ids = array_keys($pay_vals);
$invoice_values = Invoice::find()->where(['id_invoice' => $ids])->indexBy('id_invoice')->asArray()->all();
$vendor = $inv_type = null;
$vendors = $inv_types = [];
foreach ($invoice_values as $row) {
$vendor = $row['id_vendor'];
$vendors[$vendor] = true;
$inv_type = $row['invoice_type'];
$inv_types[$inv_type] = true;
}
if (count($vendors) !== 1) {
throw new UserException('Vendor harus sama');
}
if (count($inv_types) !== 1) {
throw new UserException('Type invoice harus sama');
}
$invoice_paid = PaymentDtl::find()->select(['id_invoice', 'total' => 'sum(payment_value)'])->joinWith('idPayment')->where(['payment_type' => $inv_type, 'id_invoice' => $ids])->groupBy('id_invoice')->indexBy('id_invoice')->asArray()->all();
$data['id_vendor'] = $vendor;
$data['payment_type'] = $inv_type;
$details = [];
foreach ($inv_vals as $id => $value) {
$sisa = $invoice_values[$id]['invoice_value'];
if (isset($invoice_paid[$id])) {
$sisa -= $invoice_paid[$id]['total'];
}
if ($value > $sisa) {
throw new UserException('Tagihan lebih besar dari sisa');
}
$details[] = ['id_invoice' => $id, 'payment_value' => $value];
}
$data['details'] = $details;
return static::create($data, $model);
}
示例13: function
$colorPluginOptions = ['showPalette' => true, 'showPaletteOnly' => true, 'showSelectionPalette' => true, 'showAlpha' => false, 'allowEmpty' => false, 'preferredFormat' => 'name', 'palette' => [["white", "black", "grey", "silver", "gold", "brown"], ["red", "orange", "yellow", "indigo", "maroon", "pink"], ["blue", "green", "violet", "cyan", "magenta", "purple"]]];
$gridColumns = [['class' => 'kartik\\grid\\SerialColumn', 'contentOptions' => ['class' => 'kartik-sheet-style'], 'width' => '36px', 'header' => '', 'headerOptions' => ['class' => 'kartik-sheet-style']], ['class' => 'kartik\\grid\\RadioColumn', 'width' => '36px', 'headerOptions' => ['class' => 'kartik-sheet-style']], ['class' => 'kartik\\grid\\ExpandRowColumn', 'width' => '50px', 'value' => function ($model, $key, $index, $column) {
return GridView::ROW_COLLAPSED;
}, 'detail' => function ($model, $key, $index, $column) {
return Yii::$app->controller->renderPartial('_expand-row-details', ['model' => $model]);
}, 'headerOptions' => ['class' => 'kartik-sheet-style'], 'expandOneOnly' => true], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'name', 'pageSummary' => 'Total', 'vAlign' => 'middle', 'width' => '210px', 'readonly' => function ($model, $key, $index, $widget) {
return !$model->status;
// do not allow editing of inactive records
}, 'editableOptions' => function ($model, $key, $index) use($colorPluginOptions) {
return ['header' => 'Name', 'size' => 'md', 'afterInput' => function ($form, $widget) use($model, $index, $colorPluginOptions) {
return $form->field($model, "color")->widget(\kartik\widgets\ColorInput::classname(), ['showDefaultPalette' => false, 'options' => ['id' => "color-{$index}"], 'pluginOptions' => $colorPluginOptions]);
}];
}], ['attribute' => 'color', 'value' => function ($model, $key, $index, $widget) {
return "<span class='badge' style='background-color: {$model->color}'> </span> <code>" . $model->color . '</code>';
}, 'width' => '8%', 'filterType' => GridView::FILTER_COLOR, 'filterWidgetOptions' => ['showDefaultPalette' => false, 'pluginOptions' => $colorPluginOptions], 'vAlign' => 'middle', 'format' => 'raw', 'noWrap' => $this->noWrapColor], ['attribute' => 'author_id', 'vAlign' => 'middle', 'width' => '180px', 'value' => function ($model, $key, $index, $widget) {
return Html::a($model->author->name, '#', ['title' => 'View author detail', 'onclick' => 'alert("This will open the author page.\\n\\nDisabled for this demo!")']);
}, 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Author::find()->orderBy('name')->asArray()->all(), 'id', 'name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => 'Any author'], 'format' => 'raw'], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'publish_date', 'hAlign' => 'center', 'vAlign' => 'middle', 'width' => '9%', 'format' => 'date', 'xlFormat' => "mmm\\-dd\\, \\-yyyy", 'headerOptions' => ['class' => 'kv-sticky-column'], 'contentOptions' => ['class' => 'kv-sticky-column'], 'readonly' => function ($model, $key, $index, $widget) {
return !$model->status;
// do not allow editing of inactive records
}, 'editableOptions' => ['header' => 'Publish Date', 'size' => 'md', 'inputType' => \kartik\editable\Editable::INPUT_WIDGET, 'widgetClass' => 'kartik\\datecontrol\\DateControl', 'options' => ['type' => \kartik\datecontrol\DateControl::FORMAT_DATE, 'displayFormat' => 'dd.MM.yyyy', 'saveFormat' => 'php:Y-m-d', 'options' => ['pluginOptions' => ['autoclose' => true]]]]], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'buy_amount', 'readonly' => function ($model, $key, $index, $widget) {
return !$model->status;
// do not allow editing of inactive records
}, 'editableOptions' => ['header' => 'Buy Amount', 'inputType' => \kartik\editable\Editable::INPUT_SPIN, 'options' => ['pluginOptions' => ['min' => 0, 'max' => 5000]]], 'hAlign' => 'right', 'vAlign' => 'middle', 'width' => '7%', 'format' => ['decimal', 2], 'pageSummary' => true], ['attribute' => 'sell_amount', 'vAlign' => 'middle', 'hAlign' => 'right', 'width' => '7%', 'format' => ['decimal', 2], 'pageSummary' => true], ['class' => 'kartik\\grid\\FormulaColumn', 'header' => 'Buy + Sell<br>(BS)', 'vAlign' => 'middle', 'value' => function ($model, $key, $index, $widget) {
$p = compact('model', 'key', 'index');
return $widget->col(7, $p) + $widget->col(8, $p);
}, 'headerOptions' => ['class' => 'kartik-sheet-style'], 'hAlign' => 'right', 'width' => '7%', 'format' => ['decimal', 2], 'mergeHeader' => true, 'pageSummary' => true, 'footer' => true], ['class' => 'kartik\\grid\\FormulaColumn', 'header' => 'Buy %<br>(100 * B/BS)', 'vAlign' => 'middle', 'hAlign' => 'right', 'width' => '7%', 'value' => function ($model, $key, $index, $widget) {
$p = compact('model', 'key', 'index');
return $widget->col(9, $p) != 0 ? $widget->col(7, $p) * 100 / $widget->col(9, $p) : 0;
}, 'format' => ['decimal', 2], 'headerOptions' => ['class' => 'kartik-sheet-style'], 'mergeHeader' => true, 'pageSummary' => true, 'pageSummaryFunc' => GridView::F_AVG, 'footer' => true], ['class' => 'kartik\\grid\\BooleanColumn', 'attribute' => 'status', 'vAlign' => 'middle'], ['class' => 'kartik\\grid\\ActionColumn', 'dropdown' => $this->dropdown, 'dropdownOptions' => ['class' => 'pull-right'], 'urlCreator' => function ($action, $model, $key, $index) {
return '#';
}, 'viewOptions' => ['title' => 'This will launch the book details page. Disabled for this demo!', 'data-toggle' => 'tooltip'], 'updateOptions' => ['title' => 'This will launch the book update page. Disabled for this demo!', 'data-toggle' => 'tooltip'], 'deleteOptions' => ['title' => 'This will launch the book delete action. Disabled for this demo!', 'data-toggle' => 'tooltip'], 'headerOptions' => ['class' => 'kartik-sheet-style']], ['class' => 'kartik\\grid\\CheckboxColumn', 'headerOptions' => ['class' => 'kartik-sheet-style']]];
示例14: function
$this->title = 'Заказы';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="orders-index">
<h1><?php
echo Html::encode($this->title);
?>
</h1>
<?php
// echo $this->render('_search', ['model' => $searchModel]);
?>
<p>
<?php
echo Html::a('Создать заказ', ['create'], ['class' => 'btn btn-success']);
?>
</p>
<?php
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'consumer_id', 'label' => 'Заказчик', 'format' => 'text', 'content' => function ($data) {
return $data->getConsumerName();
}], 'qty', 'sum', 'paid', ['attribute' => 'order_status_id', 'label' => 'Статус', 'format' => 'text', 'content' => function ($data) {
return $data->getOrderStatusName();
}, 'value' => function ($model, $key, $index, $column) {
return Html::activeDropDownList($model, 'order_status_id', ArrayHelper::map(backend\models\OrdersStatus::find()->all(), 'id', 'name'));
}, 'filter' => backend\models\Orders::getOrderStatusList()], 'comment:ntext', ['attribute' => 'created_at', 'label' => 'Создано', 'format' => ['date', 'dd/MM/Y HH:mm:ss'], 'headerOptions' => ['width' => '200']], ['attribute' => 'updated_at', 'format' => ['date', 'dd/MM/Y HH:mm:ss'], 'options' => ['width' => '200']], ['label' => 'Содержимое', 'format' => 'raw', 'value' => function ($data) {
return Html::a('Перейти', $data->getUrlReservationInfo(), ['title' => 'Смелей вперед!', 'target' => '_blank']);
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>
</div>
示例15: actionUpdate
/**
* Updates an existing Po model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$modelsPoItem = $model->poItems;
if ($model->load(Yii::$app->request->post())) {
$oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id');
$modelsPoItem = Model::createMultiple(Address::classname(), $modelsPoItem);
Model::loadMultiple($modelsPoItem, Yii::$app->request->post());
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id')));
// ajax validation
/*if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ArrayHelper::merge(
ActiveForm::validateMultiple($modelsPoItem),
ActiveForm::validate($model)
);
}*/
// validate all models
$valid = $model->validate();
$valid = Model::validateMultiple($modelsPoItem) && $valid;
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
if (!empty($deletedIDs)) {
Address::deleteAll(['id' => $deletedIDs]);
}
foreach ($modelsPoItem as $modelPoItem) {
$modelPoItem->po_id = $model->id;
if (!($flag = $modelPoItem->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['view', 'id' => $model->id]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
}
return $this->render('update', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]);
}