本文整理汇总了PHP中yii\helpers\ArrayHelper::index方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::index方法的具体用法?PHP ArrayHelper::index怎么用?PHP ArrayHelper::index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionList
public function actionList()
{
$limit = 10;
$page = is_null(Yii::$app->request->get('page')) ? 1 : Yii::$app->request->get('page');
$offset = ((int) $page - 1) * $limit;
$order = ['service.order' => SORT_ASC, 'id' => SORT_DESC];
if (is_null(Yii::$app->request->get('section'))) {
$service = Service::find()->select(['service.id', 'service.sid', 'service.header'])->innerJoinWith('secs')->orderBy($order)->offset($offset)->limit($limit)->all();
$pagination = new Pagination(['totalCount' => Service::find()->count(), 'pageSize' => $limit]);
} else {
$service = Service::find()->select(['service.id', 'service.sid', 'service.header'])->innerJoinWith('secs')->where(['sec_service.sid' => Yii::$app->request->get('section')])->orderBy($order)->offset($offset)->limit($limit)->all();
$pagination = new Pagination(['totalCount' => Service::find()->innerJoinWith('secs')->where(['sec_service.sid' => Yii::$app->request->get('section')])->count(), 'pageSize' => $limit]);
}
$sections = SecService::find()->asArray()->all();
$pagination->pageSizeParam = false;
$page = Page::find()->where(['sid' => Yii::$app->controller->id])->select(['id', 'pid', 'sid', 'header'])->one();
$pages = Page::find()->select(['id', 'pid', 'sid', 'header'])->asArray()->indexBy('id')->all();
$mode = $pages[$page->id];
$branch[] = $mode;
while (!is_null($mode['pid'])) {
$mode = $pages[$mode['pid']];
$branch[] = $mode;
}
krsort($branch);
$sectionsBySid = ArrayHelper::index($sections, 'sid');
if (!is_null(Yii::$app->request->get('section'))) {
$branch[] = ['header' => $sectionsBySid[Yii::$app->request->get('section')]['header']];
}
return $this->render('list', ['service' => $service, 'sections' => $sections, 'pagination' => $pagination, 'branch' => $branch]);
}
示例2: 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;
}
示例3: internalUpdateRelations
public function internalUpdateRelations()
{
$_this = $this;
$modelsChecked = [];
$updateChildren = function ($model) use($_this, &$modelsChecked, &$updateChildren) {
if (in_array($model->id, $modelsChecked)) {
return true;
}
$modelsChecked[] = $model->id;
$currentChildRelations = $model->queryChildRelations()->all();
$currentChildRelations = ArrayHelper::index($currentChildRelations, function ($relation) {
return $relation->child_object_id;
});
$childModels = $model->dataObject->childModelsFromObjects();
$baseRelation = ['parent_object_id' => $model->id, 'active' => 1];
$childRelations = [];
foreach ($childModels as $childModel) {
$updateChildren($childModel);
if (isset($currentChildRelations[$childModel->id])) {
unset($currentChildRelations[$childModel->id]);
continue;
}
$childRelation = $baseRelation;
$childRelation['child_object_id'] = $childModel->id;
$childRelations[] = $childRelation;
}
$model->setRelationModels($childRelations);
$model->save();
foreach ($currentChildRelations as $childRelation) {
$childRelation->delete();
}
};
return $updateChildren($this->model);
}
示例4: goodsMovementApplied
/**
* Handler for Good Movement created.
* It used to update stock
* @param \biz\core\base\Event $event
*/
public function goodsMovementApplied($event)
{
/* @var $model MGoodsMovement */
$model = $event->params[0];
/*
* 200 = Sales
*/
if (!in_array($model->reff_type, [200])) {
return;
}
$sales = MSales::findOne($model->reff_id);
$salesDtls = ArrayHelper::index($sales->salesDtls, 'product_id');
// change total qty for reff document
/* @var $purcDtl \biz\core\sales\models\SalesDtl */
foreach ($model->goodsMovementDtls as $detail) {
$salesDtl = $salesDtls[$detail->product_id];
$salesDtl->total_release += $detail->qty;
$salesDtl->save(false);
}
$complete = true;
foreach ($salesDtls as $salesDtl) {
if ($salesDtl->total_release != $salesDtl->qty) {
$complete = false;
break;
}
}
if ($complete) {
$sales->status = MSales::STATUS_COMPLETE_RELEASE;
$sales->save(false);
} elseif ($sales->status == MSales::STATUS_DRAFT) {
$sales->status = MSales::STATUS_PARTIAL_RELEASE;
$sales->save(false);
}
}
示例5: goodsMovementApplied
/**
* Handler for Good Movement created.
* It used to update stock
* @param \biz\core\base\Event $event
*/
public function goodsMovementApplied($event)
{
/* @var $model MGoodsMovement */
$model = $event->params[0];
/*
* 100 = Purchase
*/
if (!in_array($model->reff_type, [100])) {
return;
}
$purchase = MPurchase::findOne($model->reff_id);
$purchaseDtls = ArrayHelper::index($purchase->purchaseDtls, 'product_id');
// change total qty for reff document
/* @var $purcDtl \biz\core\purchase\models\PurchaseDtl */
foreach ($model->goodsMovementDtls as $detail) {
$purcDtl = $purchaseDtls[$detail->product_id];
$purcDtl->total_receive += $detail->qty;
$purcDtl->save(false);
}
$complete = true;
foreach ($purchaseDtls as $purcDtl) {
if ($purcDtl->total_receive != $purcDtl->qty) {
$complete = false;
break;
}
}
if ($complete) {
$purchase->status = MPurchase::STATUS_PROCESS;
$purchase->save(false);
} elseif ($purchase->status == MPurchase::STATUS_DRAFT) {
$purchase->status = MPurchase::STATUS_PROCESS;
$purchase->save(false);
}
}
示例6: performSearch
private function performSearch($team_name, $player_mail)
{
$res = array_merge($this->performNameSearch($team_name), $this->performPlayerMailSearch($player_mail));
// remove dublicates with same key(id)
$res = yii\helpers\ArrayHelper::index($res, 'id');
return array_values($res);
}
示例7: InsertRecord
public static function InsertRecord($data)
{
if ($data) {
$array = [];
foreach ($data as $k => $v) {
$array[$v['idvisit']] = [$v['idvisit'], $v['idvisitor'], $v['user_id'], $v['custom_var_v2'], IP::binaryToStringIP($v['location_ip']), 0, $v['custom_var_v1']];
}
// \yii::error(var_export($array,1));
//查找所有已经存在的记录
$batchInsert = [];
if ($array) {
$findAll = ApiVisitorDetail::find()->where(['in', 'idvisit', array_keys($array)])->asArray()->all();
if ($findAll) {
$findAll = ArrayHelper::index($findAll, 'idvisit');
$batchInsert = array_diff_key($array, $findAll);
} else {
$batchInsert = $array;
}
$idvisits = ArrayHelper::getColumn($batchInsert, 0, false);
StatLogVisit::updateAll(['status' => 1], ['idvisit' => $idvisits]);
ApiVisitorDetail::xBatchInsert($batchInsert);
}
return count($batchInsert);
}
}
示例8: append
/**
* @param string $id
* @param array $data
* @param \biz\core\inventory\models\StockOpname $model
* @return \biz\core\inventory\models\StockOpname
*/
public function append($id, $data, $model = null)
{
/* @var $model MStockOpname */
$model = $model ?: $this->findModel($id);
$success = true;
$model->scenario = MStockOpname::SCENARIO_DEFAULT;
$model->load($data, '');
$this->fire('_append', [$model]);
$success = $model->save();
$stockOpnameDtls = ArrayHelper::index($model->stockOpnameDtls, 'product_id');
foreach ($data['details'] as $dataDetail) {
$index = $dataDetail['product_id'];
// product_id
if (isset($stockOpnameDtls[$index])) {
$detail = $stockOpnameDtls[$index];
} else {
$detail = new StockOpnameDtl(['id_opname' => $model->id_opname, 'product_id' => $dataDetail['product_id'], 'uom_id' => $dataDetail['uom_id'], 'qty' => 0]);
}
$detail->qty += $dataDetail['qty'];
$success = $success && $detail->save();
$stockOpnameDtls[$index] = $detail;
$this->fire('_append_body', [$model, $detail]);
}
$model->populateRelation('stockOpnameDtls', array_values($stockOpnameDtls));
if ($success) {
$this->fire('_appended', [$model]);
}
return $this->processOutput($success, $model);
}
示例9: __construct
public function __construct(array $config = [])
{
parent::__construct($config);
if (isset($config['fields']) == false) {
$this->fields = \yii\helpers\ArrayHelper::index(\Yii::$app->getModule('comments')->fields, 'name');
}
$this->fields_names = \yii\helpers\ArrayHelper::getColumn($this->fields, 'name');
}
示例10: run
/**
* @inheritdoc
*/
public function run()
{
if (is_null($this->date)) {
$this->date = date('Y-m');
}
$rows = (new Query())->select('COUNT(*) as count, DAY(date) as day')->from('{{%post}}')->where("DATE_FORMAT( DATE, '%Y-%m' ) = :month", [':month' => $this->date])->groupBy("DAY( `date` )")->all();
$rows = ArrayHelper::index($rows, 'day');
return $this->renderFile('@app/views/site/calendar.php', ['posts' => $rows, 'date' => $this->date, 'noControls' => $this->noControls]);
}
示例11: getRoots
public static function getRoots()
{
if (sizeof(self::$_roots)) {
return self::$_roots;
}
$roots = Category::find()->where(['parentid' => 0])->all();
self::$_roots = ArrayHelper::index($roots, 'name');
return self::$_roots;
}
示例12: getTranslateRelations
/**
* @return ActiveRecord[]
*/
protected function getTranslateRelations()
{
$records = $this->owner->getRelatedRecords();
if (!isset($records['currentTranslate']) && isset($records[$this->translateRelation])) {
$translations = ArrayHelper::index($this->owner->{$this->translateRelation}, $this->languageAttribute);
$this->setTranslateRelations($translations);
}
return $this->owner['currentTranslate'];
}
示例13: loadStates
/**
* Reloads the system states from the database
*/
public function loadStates()
{
$sql = "SELECT `key`, `value` FROM `{$this->tableName}`";
$items = $this->getDb()->createCommand($sql)->queryAll();
$items = ArrayHelper::index($items, 'key');
foreach ($items as $key => $value) {
$value = unserialize($value['value']);
$this->map[$key] = $value;
}
$this->updateCache();
}
示例14: cache
public static function cache($forceUpdate = false)
{
$key = "api_visitor_config";
$return = \yii::$app->cache->get($key);
if ($return == null || $forceUpdate) {
$data = self::find()->where(['is_closed' => 0])->asArray()->all();
$return = ArrayHelper::index($data, "type");
\yii::$app->cache->set($key, $return);
}
return $return;
}
示例15: convertToMyFields
/**
* 将ERP数据转换成云客字段
* @param type $erpData
* @param type $serviceName
* @return type
*/
public function convertToMyFields($erpData, $serviceName)
{
//return AsyncFields::convertToMyFields($this->orgcode, $erpData, $serviceName);
$fieldMappings = $this->getFields($serviceName);
$fieldMappings = \yii\helpers\ArrayHelper::index($fieldMappings, 'ErpField');
$result = [];
foreach ($erpData as $row) {
$newRow = $this->convertRowToMyFields($fieldMappings, $row);
$result[] = $newRow;
}
return $result;
}