Author: nadar
Inheritance: extends yii\helpers\BaseArrayHelper
コード例 #1
0
 public function getData()
 {
     $cleandata = [];
     foreach ($this->_data as $key => $value) {
         $cleandata[] = ['value' => $key, 'label' => $value];
     }
     return ArrayHelper::typeCast($cleandata);
 }
コード例 #2
0
 protected function getItems()
 {
     $data = [];
     foreach ($this->data as $value => $label) {
         $data[] = ['value' => $value, 'label' => $label];
     }
     return ['items' => ArrayHelper::typeCast($data)];
 }
コード例 #3
0
ファイル: Decimal.php プロジェクト: luyadev/luya-module-admin
 public function onAfterExpandFind($event)
 {
     $fieldValue = $event->sender->getAttribute($this->name);
     if (is_array($fieldValue)) {
         $event->sender->setAttribute($this->name, ArrayHelper::typeCast($fieldValue));
     } else {
         $event->sender->setAttribute($this->name, (double) $fieldValue);
     }
 }
コード例 #4
0
ファイル: ArrayHelperTest.php プロジェクト: luyadev/luya
 public function testSearch()
 {
     $data = [['name' => 'Foo Bar', 'description' => 'same', 'id' => 1], ['name' => 'Baz foo', 'description' => 'same', 'id' => 2]];
     $this->assertSame(1, count(ArrayHelper::search($data, '1')));
     $this->assertSame(1, count(ArrayHelper::search($data, 1)));
     $this->assertSame(2, count(ArrayHelper::search($data, 'FOO')));
     $this->assertSame(2, count(ArrayHelper::search($data, 'foo')));
     $this->assertSame(2, count(ArrayHelper::search($data, 'Foo')));
     $this->assertSame(2, count(ArrayHelper::search($data, 'fo')));
     $this->assertSame(1, count(ArrayHelper::search($data, 'Foo', true)));
 }
コード例 #5
0
ファイル: Config.php プロジェクト: krystian-thiede/luya
 public function addField($pointer, $field, array $options = [])
 {
     if ($this->hasField($pointer, $field)) {
         return false;
     }
     $options = ArrayHelper::merge(['name' => null, 'i18n' => false, 'alias' => null, 'plugins' => [], 'i18n' => false, 'extraField' => false], $options);
     // can not unshift non array value, create array for this pointer.
     if (empty($this->_config[$pointer])) {
         $this->_config[$pointer] = [];
     }
     $this->_config[$pointer] = ArrayHelper::arrayUnshiftAssoc($this->_config[$pointer], $field, $options);
     return true;
 }
コード例 #6
0
 public function getMenu()
 {
     if ($this->_menu === null) {
         $menu = [];
         $menus = Yii::$app->getModule('admin')->moduleMenus;
         foreach ($menus as $k => $v) {
             if (is_object($v) && $v instanceof AdminMenuBuilderInterface) {
                 $data = $v->menu();
             } else {
                 $data = $v;
             }
             $menu = ArrayHelper::merge($data, $menu);
         }
         $this->_menu = $menu;
     }
     return $this->_menu;
 }
コード例 #7
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['json_config_values', 'json_config_cfg_values'], function ($attribute, $params) {
         // if its not an array, the attribute is not dirty and has not to be serialized from input.
         if (is_array($this->{$attribute})) {
             $data = ArrayHelper::typeCast($this->{$attribute});
             foreach ($data as $key => $value) {
                 if ($value === null) {
                     unset($data[$key]);
                 }
             }
             if (isset($data['__e']) && count($data) >= 2) {
                 unset($data['__e']);
             }
             if (empty($data)) {
                 $data['__e'] = '__v';
             }
             $this->{$attribute} = Json::encode($data, JSON_FORCE_OBJECT);
         }
     }, 'skipOnEmpty' => false], [['block_id', 'nav_item_page_id', 'prev_id', 'is_dirty', 'create_user_id', 'update_user_id', 'timestamp_create', 'timestamp_update', 'sort_index', 'is_hidden'], 'integer'], [['placeholder_var'], 'required'], [['json_config_values', 'json_config_cfg_values'], 'string'], [['placeholder_var'], 'string', 'max' => 80]];
 }
コード例 #8
0
 public function actionDataMenu()
 {
     return ['items' => ArrayHelper::typeCast(MenuHelper::getItems()), 'drafts' => ArrayHelper::typeCast(MenuHelper::getDrafts()), 'containers' => ArrayHelper::typeCast(MenuHelper::getContainers()), 'hiddenCats' => ArrayHelper::typeCast(Yii::$app->adminuser->identity->setting->get("togglecat", []))];
 }
コード例 #9
0
ファイル: Plugin.php プロジェクト: luyadev/luya-module-admin
 /**
  * Helper method to create a span tag with the ng-model in angular context for the crud overview
  * @param string $ngModel
  * @param array $options An array with options to pass to the list tag
  * @return string
  */
 public function createListTag($ngModel, array $options = [])
 {
     return $this->createTag('span', null, ArrayHelper::merge(['ng-bind' => $ngModel], $options));
 }
コード例 #10
0
ファイル: Image.php プロジェクト: efueger/luya
 public function get($imageId)
 {
     // get the real full image path to display this file.
     $data = StorageImage::find()->where(['id' => $imageId])->with('file')->one();
     if (!$data || !isset($data->file)) {
         return false;
     }
     $fileName = implode([$data->filter_id, $data->file->name_new_compound], '_');
     return ArrayHelper::toObject(['filter_id' => $data->filter_id, 'file_id' => $data->file_id, 'file_is_deleted' => $data->file->is_deleted, 'image_id' => $data->id, 'file_source' => $data->file->name_new_compound, 'image_source' => $fileName, 'source' => \yii::$app->storage->httpDir . $fileName]);
 }
コード例 #11
0
 public function actionDataLayouts()
 {
     return ArrayHelper::typeCast(Layout::find()->asArray()->all());
 }
コード例 #12
0
 /**
  * Get an array with all ids for the storage component. Only the image ids for the current
  * model/item id should be returned:
  *
  * ```php
  * return [1,2,3]; // where 1,2,3 are ids of the image from the storage component
  * ```
  *
  * @return array An array where only the images are returned.
  */
 public function flowListImages()
 {
     return ArrayHelper::getColumn((new Query())->select([$this->getConfigValue('imageField')])->from($this->getConfigValue('table'))->where([$this->getConfigValue('itemField') => $this->id])->indexBy($this->getConfigValue('imageField'))->all(), $this->getConfigValue('imageField'));
 }
コード例 #13
0
 private function getExtraAssignData()
 {
     $ids = ArrayHelper::getColumn($this->getContextConfigValue($this->varName, []), 'value');
     $provider = new ActiveDataProvider(['query' => $this->_query->andWhere(['in', 'id', $ids])]);
     return $provider->getModels();
 }
コード例 #14
0
 public function copyFrom($key, $removeFields = [])
 {
     $temp = $this->config[$key];
     foreach ($removeFields as $name) {
         if (array_key_exists($name, $temp)) {
             unset($temp[$name]);
         }
     }
     $this->config[$this->pointer] = ArrayHelper::merge($this->config[$this->pointer], $temp);
 }
コード例 #15
0
 private static function getNavGroupPermissions()
 {
     if (self::$_navGroupPermissions === null) {
         self::$_navGroupPermissions = ArrayHelper::index((new Query())->select(['group_id', 'nav_id'])->from("cms_nav_permission")->all(), null, 'group_id');
     }
     return self::$_navGroupPermissions;
 }
コード例 #16
0
 /**
  * Parse an array with fileId and caption into an {{\luya\admin\file\Iterator}} object.
  *
  * @param array $values The array with key 'fileId' like `[['fileId' => 1, 'caption' => 'test']]`.
  * @return \luya\admin\file\Iterator The iterator object from the parsed values or an empty array if empty.
  */
 protected function parseFileIteration(array $values)
 {
     if (empty($values)) {
         return [];
     }
     return (new Query())->where(['in', 'id', ArrayHelper::getColumn($values, 'fileId')])->all();
 }
コード例 #17
0
ファイル: Boot.php プロジェクト: gitter-badger/luya
 /**
  * Run Web-Application based on the provided config file.
  * 
  * @return string|void Returns the Yii Application run() method if mock is disabled. Otherwise returns void
  */
 public function applicationWeb()
 {
     $config = $this->getConfigArray();
     $this->includeYii();
     $this->app = new WebApplication(ArrayHelper::merge(['bootstrap' => ['luya\\web\\Bootstrap']], $config));
     if (!$this->mockOnly) {
         return $this->app->run();
     }
 }
コード例 #18
0
ファイル: MenuController.php プロジェクト: gitter-badger/luya
 public function actionDataMenu()
 {
     return ['items' => ArrayHelper::typeCast((new Query())->select(['cms_nav.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title'])->from('cms_nav')->leftJoin('cms_nav_item', 'cms_nav.id=cms_nav_item.nav_id')->orderBy('cms_nav.sort_index ASC')->where(['cms_nav_item.lang_id' => Lang::getDefault()['id'], 'cms_nav.is_deleted' => 0, 'cms_nav.is_draft' => 0])->all()), 'drafts' => ArrayHelper::typeCast((new Query())->select(['cms_nav.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title'])->from('cms_nav')->leftJoin('cms_nav_item', 'cms_nav.id=cms_nav_item.nav_id')->orderBy('cms_nav.sort_index ASC')->where(['cms_nav_item.lang_id' => Lang::getDefault()['id'], 'cms_nav.is_deleted' => 0, 'cms_nav.is_draft' => 1])->all()), 'containers' => ArrayHelper::typeCast((new Query())->select(['id', 'name'])->from('cms_nav_container')->where(['is_deleted' => 0])->orderBy(['cms_nav_container.id' => 'ASC'])->all())];
 }
コード例 #19
0
 public function getExtraVarValues()
 {
     $this->_extraVars = ArrayHelper::merge($this->_extraVars, $this->extraVars());
     return $this->_extraVars;
 }