本文整理汇总了PHP中yii\helpers\ArrayHelper::map方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::map方法的具体用法?PHP ArrayHelper::map怎么用?PHP ArrayHelper::map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSumPrice
/**
* @param integer $object_model_id
* @param string $type
* @return string
*/
public static function getSumPrice($object_model_id, $type)
{
$objects = static::find()->select('price')->where(['special_price_list_id' => ArrayHelper::map(SpecialPriceList::getModelsByKey($type), 'id', 'id'), 'object_model_id' => $object_model_id])->asArray()->all();
return array_reduce($objects, function ($result, $item) {
return $result += $item['price'];
}, 0);
}
示例2: run
public function run()
{
$request = Yii::$app->request;
$user = Yii::createObject($this->modelClass, ['scenario' => $this->scenario]);
$profile = Yii::createObject($this->profileClass);
$roles = [];
if ($this->roleArray !== null) {
$roles = call_user_func($this->roleArray, $this);
}
$roleArray = ArrayHelper::map($roles, 'name', 'description');
$statusArray = [];
if ($this->statusArray !== null) {
$statusArray = call_user_func($this->statusArray, $this);
}
if ($user->load($request->post()) && $profile->load($request->post())) {
if ($user->validate() && $profile->validate()) {
$user->populateRelation('profile', $profile);
if ($user->save(false)) {
$this->trigger('success', new Event(['data' => $user]));
return $this->controller->redirect(Url::to([$this->updateRoute, 'id' => $user->id]));
} else {
$this->trigger('success', new Event(['data' => Module::t('admin', 'Failed create user')]));
return $this->controller->refresh();
}
} elseif ($request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
}
}
return $this->render(compact(['user', 'profile', 'roleArray', 'statusArray']));
}
示例3: actionIndex
public function actionIndex()
{
$rate = new Rate();
$currency = new Currency();
$billing = ArrayHelper::map(Billing::find()->asArray()->all(), 'id', 'name');
return $this->render('index', ['rate' => $rate, 'billing' => $billing, 'currency' => $currency]);
}
示例4: actionIndex
/**
* Lists all Pay models.
* @return mixed
*/
public function actionIndex()
{
$ticketsArray = ArrayHelper::map(SeasonTicket::find()->asArray()->select('id, title')->orderBy('title')->all(), 'id', 'title');
$searchModel = new PaySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'ticketsArray' => $ticketsArray]);
}
示例5: actionSite
public function actionSite()
{
$params = ['today' => new \DateTime(), 'metrics' => empty(YII_DEBUG), 'review' => $day_review = Yii::$app->hryvna->getAvg(), 'banks_exchanges' => $banks_days = Yii::$app->hryvna->getBankDays(null, -10), 'banks_names' => $banks_names = ArrayHelper::map(models\Bank::find()->orderBy([new \yii\db\Expression('FIELD(rate, 0), rate, id')])->all(), 'id', 'title')];
// generate days
$periods = ['week' => ['delta' => 1, 'story_one' => 'останній тиждень', 'story_two' => 'десять днів'], 'month' => ['delta' => 3, 'story_one' => 'останній місяць', 'story_two' => 'тридцять днів'], 'kvartal' => ['delta' => 9, 'story_one' => 'останній квартал', 'story_two' => "дев'яносто днів"], 'halfyear' => ['delta' => 18, 'story_one' => 'останні півроку', 'story_two' => 'сто вісімдесят днів'], 'year' => ['delta' => 36, 'story_one' => 'останній рік', 'story_two' => 'триста шістдесят днів']];
$data_tank = [];
foreach ($periods as $period_code => $period_info) {
$data_tank[$period_code] = Storyteller::describePeriod($period_info['delta'], $period_info['story_one'], $period_info['story_two']);
}
$params['days'] = $data_tank;
// generate exchange rates table
$converter_exchanges = end($banks_days);
foreach ($converter_exchanges as $bank_id => $exchange) {
// change NBU to avg exchange rates
if ($bank_id == 1) {
$exchange['dollar_buy'] = ['value' => $day_review['dollar_buy_banks']['value']];
$exchange['dollar_sale'] = ['value' => $day_review['dollar_sale_banks']['value']];
$exchange['euro_buy'] = ['value' => $day_review['euro_buy_banks']['value']];
$exchange['euro_sale'] = ['value' => $day_review['euro_sale_banks']['value']];
$exchange['title'] = 'Середній банковий курс';
} else {
$exchange['title'] = $banks_names[$bank_id];
}
$converter_exchanges[$bank_id] = $exchange;
}
$params['converter_exchanges'] = $converter_exchanges;
// render site
$site = $this->view->render('@app/views/templates/site.tpl', $params);
$js = $this->view->render('@app/views/templates/js.tpl', $params);
// save generated files to public dir
echo file_put_contents(Yii::$app->params['site']['index'], $site) . PHP_EOL;
echo file_put_contents(Yii::$app->params['site']['js'], $js) . PHP_EOL;
}
示例6: getAvailableApis
/**
* Function return array map for drop down list
* @return array
*/
public static function getAvailableApis()
{
static::getEnabledApiId();
$all = static::find()->all();
$map = ArrayHelper::map($all, 'id', 'name');
return ArrayHelper::merge([0 => Yii::t('app', 'Not selected')], $map);
}
示例7: actionCreate
/**
* Creates a new ClnMedicineTest model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$user_id = 'admin';
$model = new ClnMedicineTest();
if ($model->load(Yii::$app->request->post())) {
$model->MEDICINE_GEN_NO = ClnMedicineTest::getNewID();
$model->CREATE_BY = $user_id;
$model->CREATE_DATE = new \yii\db\Expression('SYSDATE');
$model->UPDATE_BY = $user_id;
$model->UPDATE_DATE = new \yii\db\Expression('SYSDATE');
if ($model->save()) {
$data['result'] = 'success';
} else {
$data['result'] = 'error';
}
header('Content-type: application/json');
echo json_encode($data);
} else {
$getData = unserialize(base64_decode(Yii::$app->request->get('params')));
$cureItems = ArrayHelper::map(ClnCure::find()->all(), 'CURE_GEN_NO', 'CURE_NAME');
$model->TRAN_INJ_GEN_NO = $getData['TRAN_INJ_GEN_NO'];
$seqNumItems = Yii::$app->utilsHelper->getSeqNum10();
return $this->renderAjax('create', ['model' => $model, 'cureItems' => $cureItems, 'seqNumItems' => $seqNumItems]);
}
}
示例8: renderForActiveForm
/**
* @return \yii\widgets\ActiveField
*/
public function renderForActiveForm()
{
$field = parent::renderForActiveForm();
$find = CmsContentElement::find()->active();
if ($this->content_id) {
$find->andWhere(['content_id' => $this->content_id]);
}
if ($this->fieldElement == self::FIELD_ELEMENT_SELECT) {
$field = $this->activeForm->fieldSelect($this->model->relatedPropertiesModel, $this->property->code, ArrayHelper::map($find->all(), 'id', 'name'), []);
} else {
if ($this->fieldElement == self::FIELD_ELEMENT_SELECT_MULTI) {
$field = $this->activeForm->fieldSelectMulti($this->model->relatedPropertiesModel, $this->property->code, ArrayHelper::map($find->all(), 'id', 'name'), []);
} else {
if ($this->fieldElement == self::FIELD_ELEMENT_RADIO_LIST) {
$field = parent::renderForActiveForm();
$field->radioList(ArrayHelper::map($find->all(), 'id', 'name'));
} else {
if ($this->fieldElement == self::FIELD_ELEMENT_CHECKBOX_LIST) {
$field = parent::renderForActiveForm();
$field->checkboxList(ArrayHelper::map($find->all(), 'id', 'name'));
}
}
}
}
if (!$field) {
return '';
}
return $field;
}
示例9: init
public function init()
{
parent::init();
$this->layout = $this->layoutMittente;
//se sono il widget di destinazione per le scelte delle associazioni
if (!$this->targetUrl) {
$this->layout = $this->layoutTarget;
if (!$this->modelTargetSearch) {
throw new InvalidConfigException($this->throwErrorMessage('modelTargetSearch'));
}
if (!$this->modelTargetSearch['class']) {
throw new InvalidConfigException($this->throwErrorMessage('modelTargetSearch[class]'));
}
if (!$this->modelTargetSearch['action']) {
throw new InvalidConfigException($this->throwErrorMessage('modelTargetSearch[action]'));
}
$this->modelTarget = \Yii::createObject($this->modelTargetSearch['class']);
$this->modelTargetData = $this->modelTarget->{$this->modelTargetSearch['action']}(\Yii::$app->request->getQueryParams());
}
if (!$this->modelData) {
throw new InvalidConfigException($this->throwErrorMessage('modelData'));
}
if (!$this->modelId) {
throw new InvalidConfigException($this->throwErrorMessage('modelId'));
}
if (!$this->model) {
throw new InvalidConfigException($this->throwErrorMessage('model'));
}
$this->modelDataArr = ArrayHelper::map($this->modelData->all(), 'id', 'id');
}
示例10: actionProcess
public function actionProcess()
{
$order = $this->basket->getOrder();
$deliveries = ArrayHelper::map($order->getDeliveries(), "id", "title");
$payments = ArrayHelper::map($order->getPayments(), "id", "title");
return $this->render('process', ["order" => $order, "deliveries" => $deliveries, "payments" => $payments]);
}
示例11: getList
public static function getList()
{
if (!self::$_list) {
self::$_list = ArrayHelper::map(self::find()->all(), 'id', 'content.name');
}
return self::$_list;
}
示例12: activeRoleAssignmentsField
public static function activeRoleAssignmentsField($model, $attribute, $options = [])
{
$authManager = \Yii::$app->authManager;
$items = ArrayHelper::map($authManager->getItems(1), 'name', 'name');
$values = $model->isNewRecord ? [] : ArrayHelper::getColumn($authManager->getItemsByUser($model->getId()), 'name');
$options["values"] = $values;
if (!empty($_POST['RoleAssignments'])) {
$options["values"] = $_POST['RoleAssignments'];
}
$options["name"] = 'RoleAssignments';
$options['id'] = self::getInputId($model, $attribute);
$prompt = 'Select ' . $model->getAttributeLabel($attribute);
if (isset($options['prompt'])) {
$prompt = $options['prompt'];
unset($options['prompt']);
}
$retFields = '<div class="role-assigments">';
foreach ($authManager->getItems(1) as $item) {
if (empty($item->children)) {
$retFields .= self::wrapCheckbox($options["name"], $item->name, null, $options["values"]);
} else {
$retFields .= self::wrapCheckbox($options["name"], $item->name, null, $options["values"]);
foreach ($item->children as $child) {
$retFields .= self::wrapCheckbox($options["name"], $child->name, $item->name, $options["values"], 1);
}
}
}
$retFields .= '</div>';
\Yii::$app->view->registerJs("\n\n\t\t\t\$('.role-assigments input:checkbox').change(function() {\n\t\t\t\tvar isChecked = \$(this).attr('checked') !== undefined,\n\t\t\t\tparentItem = \$(this).attr('data-parent');\n\n\t\t\t\tif(isChecked && parentItem != null) {\n\t\t\t\t\tvar parentCheckedOnInit = \$('input[value=\"' + parentItem + '\"]').attr('data-checked') !== undefined;\n\n\t\t\t\t\tif(!parentCheckedOnInit)\n\t\t\t\t\t\t\$('input[value=\"' + parentItem + '\"]').prop('checked', false).removeAttr('checked').removeAttr('data-checked');\n\n\t\t\t\t\t\$(this).prop('checked', false).removeAttr('checked').removeAttr('data-checked');\n\t\t\t\t}\n\n\t\t\t\tif(!isChecked && parentItem != null) {\n\t\t\t\t\tvar parentCheckedOnInit = \$('input[value=\"' + parentItem + '\"]').attr('data-checked') !== undefined;\n\t\t\t\t\tif(!parentCheckedOnInit)\n\t\t\t\t\t\t\$('input[value=\"' + parentItem + '\"]').prop('checked', true).attr('checked', 'checked');\n\t\t\t\t\t\$(this).prop('checked', true).attr('checked', 'checked').attr('data-checked', 'true');\n\t\t\t\t}\n\n\t\t\t\tif(!isChecked && parentItem == null) {\n\t\t\t\t\t\$(this).attr('checked', 'checked');\n\t\t\t\t}\n\n\t\t\t\tif(isChecked && parentItem == null) {\n\t\t\t\t\t\$(this).removeAttr('checked').removeAttr('data-checked');\n\t\t\t\t\t\$('input[data-parent=\"' + \$(this).val() + '\"]').prop('checked', false).removeAttr('checked').removeAttr('data-checked');\n\t\t\t\t}\n\t\t\t});\n\t\t", View::POS_READY);
return $retFields;
}
示例13: actionView
public function actionView($id)
{
$model = new AssignmentForm();
$model->setScenario('auth');
$permissions = [];
$app = [];
$authManager = Yii::$app->authManager;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
foreach ($model->getAttributes() as $key => $value) {
if (empty($value)) {
$model->{$key} = [];
}
}
//Revokes all roles from a user.
try {
$authManager->revokeAll($id);
//角色
if (is_array($model->roles)) {
foreach ($model->roles as $name) {
$item = $authManager->getRole($name);
$authManager->assign($item, $id);
}
}
//权限
$roles = ArrayHelper::merge($model->permissions, $model->app);
if (is_array($roles)) {
foreach ($roles as $name) {
$item = $authManager->getPermission($name);
$authManager->assign($item, $id);
}
}
} catch (\Exception $e) {
Yii::$app->session->setFlash('fail', $e->getMessage());
$this->refresh();
Yii::$app->end();
}
Yii::$app->session->setFlash('success', '授权成功');
$this->redirect(['index']);
}
$roles = $authManager->getRoles();
$roles = ArrayHelper::map($roles, 'name', 'name');
foreach ($authManager->getPermissions() as $name => $role) {
if ($role->name[0] == '/') {
$permissions[$name] = $role->description;
} elseif (substr($role->name, 0, 3) == 'app') {
$app[$name] = $role->description;
}
}
foreach ($authManager->getAssignments($id) as $name => $item) {
if ($name[0] == '/') {
$model->permissions[$authManager->getPermission($name)->description] = $name;
} elseif (substr($name, 0, 3) == 'app') {
$model->app[$name] = $name;
} else {
$model->roles[$name] = $name;
}
}
$permissions = Tools::serializeRoutes($permissions);
return $this->render('view', ['model' => $model, 'roles' => $roles, 'permissions' => $permissions, 'app' => $app]);
}
示例14: actionView
public function actionView($id)
{
$roles = ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'description');
$user_permit = array_keys(Yii::$app->authManager->getRolesByUser($id));
$user = $this->findUser($id);
return $this->render('view', ['user' => $user, 'roles' => $roles, 'user_permit' => $user_permit, 'moduleName' => Yii::$app->controller->module->id]);
}
示例15: afterSaveEvent
public function afterSaveEvent()
{
//Обновление цены у родительского элемента если она есть
if ($this->product->cmsContentElement->parent_content_element_id) {
$parentProduct = $this->product->cmsContentElement->parentContentElement->shopProduct;
if ($parentProduct) {
$minPriceValue = $this->price;
$minPriceCurrency = $this->currency_code;
//У родительского элемента уже есть предложения
if ($offers = $parentProduct->tradeOffers) {
//Все цены оферов этого типа
$minPrice = ShopProductPrice::find()->where(['product_id' => ArrayHelper::map($offers, 'id', 'id')])->andWhere(['type_price_id' => $this->type_price_id])->orderBy(['price' => SORT_ASC])->one();
if ($minPrice) {
$minPriceValue = $minPrice->price;
$minPriceCurrency = $minPrice->currency_code;
}
}
$query = $parentProduct->getShopProductPrices()->andWhere(['type_price_id' => $this->type_price_id]);
/**
* @var $price self
*/
if ($price = $query->one()) {
$price->price = $minPriceValue;
$price->currency_code = $minPriceCurrency;
$price->save();
}
}
}
}