本文整理汇总了PHP中yii\helpers\ArrayHelper::getColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::getColumn方法的具体用法?PHP ArrayHelper::getColumn怎么用?PHP ArrayHelper::getColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::getColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
/**
* Получение меню
* @return array
*/
public function getData($active)
{
if ($active != null) {
self::$data['menu']['active'] = $active;
}
// Берем список проектов пользователя
if (\Yii::$app->cache->exists('project:user:' . \Yii::$app->user->id)) {
$project = \Yii::$app->cache->get('project:user:' . \Yii::$app->user->id);
} else {
$project = Project::find()->where(['staff_id' => \Yii::$app->user->id])->all();
\Yii::$app->cache->set('project:user:' . \Yii::$app->user->id, $project, self::CACHE_PROJECT_TIME);
}
$idProject = ArrayHelper::getColumn($project, 'id');
// Получение списка профайлеров по проектам
$command = new ListProfiler\command\GetProfilerList();
$command->setClassModel('app\\models\\amop\\models\\ListProfiler');
$profiler = $command->setData($idProject)->execute();
// Формирование списка профайлеров для меню
foreach ($profiler as $valueProfiler) {
$profilerMenu = ['label' => $valueProfiler['message'], 'name' => "profiler_" . $valueProfiler['id'], 'class' => "profiler_" . $valueProfiler['id'], 'icon_class' => 'fa fa-cube', 'badges' => ['class' => "label pull-right bg-red"], 'url' => '/profiler/detail/' . $valueProfiler['id']];
self::$data['menu']['item'][1]['item'][] = $profilerMenu;
}
// Формирование списка проектов для меню
foreach ($project as $value) {
self::$data['menu']['item'][0]['item'][] = ['label' => $value->title, 'name' => "project_" . $value->id, 'icon_class' => 'fa fa-cube', 'url' => '/project/detail/' . $value->id];
}
self::$data['user']['data']['avatar'] = \Yii::$app->user->getIdentity()->avatar;
self::$data['user']['data']['name'] = \Yii::$app->user->getIdentity()->name;
self::$data['user']['data']['surname'] = \Yii::$app->user->getIdentity()->surname;
return self::$data;
}
示例2: getHotlinkTo
public function getHotlinkTo(Model $model, $action = null, $options = [])
{
if (!ArrayHelper::isIn($this->className(), ArrayHelper::getColumn($model->behaviors(), 'class'))) {
throw new InvalidRouteException('The "LinkableBehavior" is not attached to the specified model');
}
return $this->getHotlink(strtr('{route}/{action}', ['{route}' => $model->route, '{action}' => $action ?? $model->defaultAction]), $model->linkableParams, $options);
}
示例3: afterFind
public function afterFind()
{
parent::afterFind();
$empresasUsuarios = EmpresasUsuarios::findAll(['usuario_id' => $this->id]);
$this->empresa_id = \yii\helpers\ArrayHelper::getColumn($empresasUsuarios, 'empresa_id');
$this->user_role = \yii\helpers\ArrayHelper::getColumn(Yii::$app->authManager->getRolesByUser($this->id), 'name');
}
示例4: getLinkedIds
/**
* @param string $relation
*
* @return array
*/
protected function getLinkedIds($relation)
{
$models = (array) $this->owner->{$relation};
$ids = ArrayHelper::getColumn($models, 'primaryKey', false);
$ids = array_filter($ids);
return $ids;
}
示例5: attach
public function attach($owner)
{
parent::attach($owner);
if (!$this->owner->isNewRecord) {
$this->owner->values['category'] = \yii\helpers\ArrayHelper::getColumn($this->owner->categories, 'id');
}
}
示例6: getCategoryIds
public function getCategoryIds()
{
if ($this->_categoryIds) {
return $this->_categoryIds;
}
return ArrayHelper::getColumn($this->itemCategories, 'category_id');
}
示例7: actionSearch
public function actionSearch()
{
$get = Yii::$app->getRequest()->get();
$val = null;
if (isset($get['so'])) {
$soarr = explode('_', $get['so']);
$val = $soarr[1];
}
$query = AvRel::find()->where(['status' => AvRel::STATUS_ACTIVE]);
$query->andFilterWhere(['category_id' => $get['cate']])->andFilterWhere(['av_id' => $val]);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$avs = $query->offset($pages->offset)->limit($pages->limit)->select('goods_id')->asArray()->all();
$avs = ArrayHelper::getColumn($avs, 'goods_id');
$goods = Goods::find()->where(['status' => Goods::STATUS_ACTIVE])->andWhere(['id' => $avs])->asArray()->all();
$covers = ArrayHelper::getColumn($goods, 'cover');
$covers = Attachment::find()->where(['id' => $covers])->indexBy('id')->asArray()->all();
foreach ($goods as &$v) {
if (empty($v['cover'])) {
continue;
}
$co = $covers[$v['cover']];
$v['img'] = $co['path'] . '/tiny_' . $co['name'];
}
return $this->ajaxReturn(['list' => $goods]);
}
示例8: getActiveUsers
public static function getActiveUsers()
{
$array_ids = static::find()->select(['user_id'])->where('user_id > 0')->asArray()->all();
$ids = \yii\helpers\ArrayHelper::getColumn($array_ids, 'user_id');
$users = User::find()->select(['id', 'username'])->where(['IN', 'id', $ids])->asArray()->all();
return $users;
}
示例9: getElementsTypes
public function getElementsTypes()
{
if ($this->elements_types === null) {
$this->elements_types = array_unique(ArrayHelper::getColumn($this->app->elements, 'type'));
}
return $this->elements_types;
}
示例10: getOrderOfGalleryImagesForSortableWidget
public function getOrderOfGalleryImagesForSortableWidget()
{
$galleryImages = $this->getGalleryImages()->select('id')->orderBy(['sort_order' => SORT_ASC])->all();
$galleryImageIds = ArrayHelper::getColumn($galleryImages, 'id');
$galleryImageIdsAsString = implode(',', $galleryImageIds);
return $galleryImageIdsAsString;
}
示例11: afterSave
public function afterSave($insert, $changedAttributes)
{
//$oldCategorias = array("0"=>1);
$actualItens = [];
if (($actualItens = AuthItemChild::find()->andWhere("parent = '{$this->name}'")->asArray()->all()) !== null) {
$actualItens = ArrayHelper::getColumn($actualItens, 'child');
}
//verifica se é um array
$this->itemIds = is_array($this->itemIds) ? $this->itemIds : [$this->itemIds];
$inserirItens = array_diff($this->itemIds, $actualItens);
if (!empty($inserirItens)) {
//save the relations
foreach ($inserirItens as $id) {
$r = new AuthItemChild();
$r->parent = $this->name;
$r->child = $id;
$r->save();
}
}
$delItens = array_diff($actualItens, $this->itemIds);
if (!empty($delItens)) {
foreach ($delItens as $remove) {
$r = AuthItemChild::findOne(['child' => $remove, 'parent' => $this->name]);
$r->delete();
}
}
parent::afterSave($insert, $changedAttributes);
//don't forget this
}
示例12: actionUpdate
/**
* Updates an existing Task 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);
$projectId = $model->project_id;
$studentIds = Yii::$app->db->createCommand('SELECT * FROM student_evidence WHERE task_id=' . $model->id)->queryAll();
//$ids =
$model->students = ArrayHelper::getColumn($studentIds, 'student_id');
$status = Yii::$app->db->createCommand('SELECT * FROM student_evidence WHERE task_id=' . $model->id)->queryOne();
if ($model->load(Yii::$app->request->post())) {
if (strtotime($model->delivery_date) >= strtotime(Yii::$app->formatter->asDate('now', 'yyyy-MM-dd'))) {
$students = $_POST['Task']['students'];
$model->save();
foreach ($students as $value) {
if (!($status = StudentEvidence::findOne(['task_id' => $model->id, 'student_id' => $value]))) {
Yii::$app->db->createCommand()->insert('student_evidence', ['task_id' => $model->id, 'project_id' => $model->project_id, 'evidence_id' => null, 'student_id' => $value, 'status' => Task::NEW_TASK])->execute();
}
$this->setNotification($value, $model->id, $model->project_id, Notification::EDITED_TASK);
}
Yii::$app->getSession()->setFlash('success', 'Petición actualizada exitosamente');
return $this->redirect(['student-evidence/index']);
} else {
Yii::$app->getSession()->setFlash('danger', 'La fecha de entrega no puede ser anterior a la fecha actual');
return $this->render('update', ['model' => $model, 'projectId' => $projectId]);
}
} else {
return $this->render('update', ['model' => $model, 'projectId' => $projectId]);
}
}
示例13: extraFields
/**
* @inheritdoc
*/
public function extraFields()
{
$fields = parent::extraFields();
$fields['meta'] = function (Model $Model) {
return $Model->meta();
};
$fields['picture_300'] = function (Model $Model) {
$result = null;
$Media = $Model->pictureMedia;
if (!empty($Media)) {
$result = $Media->image()->resizeByWidth(300)->export();
}
return $result;
};
$fields['sections'] = function (Model $Model) {
$result = [];
$item_sections = $Model->getItemSections()->asArray()->all();
if (!empty($item_sections)) {
$result = ArrayHelper::getColumn($item_sections, 'section_id');
$result = array_map('intval', $result);
}
return $result;
};
ApiAttribute::datetimeFormat($fields, 'created_at');
ApiAttribute::datetimeFormat($fields, 'updated_at');
ApiAttribute::datetimeFormat($fields, 'published_at');
ApiAttribute::datetimeFormat($fields, 'archived_at');
ApiAttribute::datetimeFormat($fields, 'deleted_at');
ApiAttribute::datetimeFormat($fields, 'activated_at');
return $fields;
}
示例14: add
/**
* Добавляет записи для рассылки в таблицу рассылки
*
* @param SiteContentInterface | \app\models\SubscribeItem $item тема письма
*/
public static function add($item)
{
if ($item instanceof SiteContentInterface) {
$subscribeItem = $item->getMailContent();
} else {
$subscribeItem = $item;
}
switch ($subscribeItem->type) {
case self::TYPE_NEWS:
$where = ['subscribe_is_news' => 1];
break;
case self::TYPE_SITE_UPDATE:
$where = ['subscribe_is_site_update' => 1];
break;
case self::TYPE_MANUAL:
$where = ['subscribe_is_manual' => 1];
break;
}
$emailList = User::query($where)->select('email')->andWhere(['not', ['email' => null]])->andWhere(['is_active' => 1, 'is_confirm' => 1])->column();
$rows = [];
foreach ($emailList as $email) {
$urlUnSubscribe = Url::to(['subscribe/unsubscribe', 'mail' => $email, 'type' => $subscribeItem->type, 'hash' => self::hashGenerate($email, $subscribeItem->type)], true);
$rows[] = [str_replace('{linkUnsubscribe}', $urlUnSubscribe, $subscribeItem->text), str_replace('{linkUnsubscribe}', $urlUnSubscribe, $subscribeItem->html), $subscribeItem->subject, $email, time()];
}
\Yii::info(ArrayHelper::getColumn($rows, 3), 'gs\\subscribe');
if (count($rows) > 0) {
SubscribeMailItem::batchInsert(['text', 'html', 'subject', 'mail', 'date_insert'], $rows);
}
}
示例15: afterSave
public function afterSave($insert, $changedAttributes)
{
//$oldCategorias = array("0"=>1);
$actualAssignments = [];
if (($actualAssignments = AuthAssignment::find()->andWhere("user_id = {$this->id}")->asArray()->all()) !== null) {
$actualAssignments = ArrayHelper::getColumn($actualAssignments, 'item_name');
}
//verifica se é um array
$this->assignmentIds = is_array($this->assignmentIds) ? $this->assignmentIds : [$this->assignmentIds];
$inserirAssignments = array_diff($this->assignmentIds, $actualAssignments);
if (!empty($inserirAssignments)) {
//save the relations
foreach ($inserirAssignments as $id) {
$r = new AuthAssignment();
$r->user_id = $this->id;
$r->item_name = $id;
$r->save();
}
}
$delAssignments = array_diff($actualAssignments, $this->assignmentIds);
if (!empty($delAssignments)) {
foreach ($delAssignments as $remove) {
$r = AuthAssignment::findOne(['item_name' => $remove, 'user_id' => $this->id]);
$r->delete();
}
}
parent::afterSave($insert, $changedAttributes);
//don't forget this
}