示例#1
3
 public function toArray()
 {
     $response = [];
     $response['status'] = $this->status;
     $response['table'] = [];
     $response['chart'] = [];
     if ($response['status'] == static::STATUS_SUCCESS) {
         if ($this->caption) {
             $response['caption'] = $this->caption;
         }
         foreach ($this->data as $key => $row) {
             $tableRow = [];
             $chartRow = [];
             foreach ($this->dataSeries as $s) {
                 if ($s->value !== null) {
                     $value = call_user_func($s->value, $row, $key);
                 } else {
                     $value = ArrayHelper::getValue($row, $s->name);
                 }
                 $value = $s->encode ? Html::encode($value) : $value;
                 $tableRow[] = $value;
                 if ($s->isInChart) {
                     $chartRow[] = $value;
                 }
             }
             $response['table'][] = $tableRow;
             $response['chart'][] = $chartRow;
         }
     } else {
         $response['message'] = $this->message;
     }
     return $response;
 }
示例#2
0
 /**
  * Returns fail response
  * @param integer $code
  * @param array $data
  * @return \yii\web\Response
  */
 public static function fail($code = 400, array $data = [])
 {
     $resp = \Yii::$app->response;
     $resp->setStatusCode($code);
     $resp->data = ArrayHelper::merge(['status' => 'error', 'message' => static::$httpStatuses[$code]], $data);
     return $resp;
 }
 public function __construct($config = array())
 {
     self::$plugins = array_diff(scandir(__DIR__ . '/plugins/'), array('..', '.'));
     $provider = ArrayHelper::getValue($config, 'config.provider');
     if (isset($provider)) {
         if (ArrayHelper::isIn($provider . '.php', self::$plugins)) {
             require __DIR__ . '/plugins/' . $provider . '.php';
             $format = ArrayHelper::getValue($config, 'config.return_formats');
             if (isset($format)) {
                 if (ArrayHelper::isIn($format, ArrayHelper::getValue($plugin, 'accepted_formats'))) {
                     self::$return_formats = $format;
                 } else {
                     self::$return_formats = ArrayHelper::getValue($plugin, 'default_accepted_format');
                 }
             }
             self::$provider = $plugin;
             self::$api_key = ArrayHelper::getValue($config, 'config.api_key', NULL);
         } else {
             throw new HttpException(404, 'The requested Item could not be found.');
         }
     } else {
         require __DIR__ . '/plugins/geoplugin.php';
         self::$provider = $plugin;
         self::$return_formats = $plugin['default_accepted_format'];
     }
     return parent::__construct($config);
 }
示例#4
0
 protected function renderButtonAdd()
 {
     Html::addCssClass($this->buttonOptions, 'btn');
     $this->buttonOptions = ArrayHelper::merge($this->buttonOptions, ['role' => 'area.add', 'data-tmpl' => $this->options['id']]);
     $templateButtonAdding = strtr($this->templateButtonAdding, ['{button}' => Html::button('+', $this->buttonOptions), '{label}' => Html::tag('label', $this->label)]);
     echo Html::tag('div', $templateButtonAdding, ['class' => 'form-group']);
 }
示例#5
0
 public static function FetchProducts()
 {
     $sql = 'SELECT * FROM easyii_catalog_items where category_id=2';
     $allProducts = Item::findBySql($sql)->all();
     $listData = ArrayHelper::map($allProducts, 'item_code', 'title');
     return $listData;
 }
示例#6
0
 public function run()
 {
     $rr = new RequestResponse();
     $pk = \Yii::$app->request->post($this->controller->requestPkParamName);
     $modelClass = $this->controller->modelClassName;
     $this->models = $modelClass::find()->where([$this->controller->modelPkAttribute => $pk])->all();
     if (!$this->models) {
         $rr->success = false;
         $rr->message = \Yii::t('app', "No records found");
         return (array) $rr;
     }
     $data = [];
     foreach ($this->models as $model) {
         $raw = [];
         if ($this->eachExecute($model)) {
             $data['success'] = ArrayHelper::getValue($data, 'success', 0) + 1;
         } else {
             $data['errors'] = ArrayHelper::getValue($data, 'errors', 0) + 1;
         }
     }
     $rr->success = true;
     $rr->message = \Yii::t('app', "Mission complete");
     $rr->data = $data;
     return (array) $rr;
 }
示例#7
0
 public static function map($tipo)
 {
     //entrada ou saida
     $tipo = self::find()->where(['tipo' => $tipo])->asArray()->all();
     $tipoMap = ArrayHelper::map($tipo, 'id', 'descricao');
     return $tipoMap;
 }
示例#8
0
 /**
  * Registers KCFinder
  */
 protected function registerKCFinder()
 {
     $register = KCFinderAsset::register($this->view);
     $kcfinderUrl = $register->baseUrl;
     $browseOptions = ['filebrowserBrowseUrl' => $kcfinderUrl . '/browse.php?opener=ckeditor&type=files', 'filebrowserUploadUrl' => $kcfinderUrl . '/upload.php?opener=ckeditor&type=files'];
     $this->clientOptions = ArrayHelper::merge($browseOptions, $this->clientOptions);
 }
示例#9
0
 /**
  * Get all authors for dropdownlist widget
  * @return array|\yii\db\ActiveRecord[]
  */
 public static function getDropdownList()
 {
     $authors = self::find()->all();
     $authors = \yii\helpers\ArrayHelper::map($authors, 'id', 'fullName');
     array_unshift($authors, '');
     return $authors;
 }
示例#10
0
 /**
  * Recursively renders the menu items (without the container tag).
  * @param array $items the menu items to be rendered recursively
  * @return string the rendering result
  */
 protected function renderItems($items)
 {
     $n = count($items);
     $lines = [];
     foreach ($items as $i => $item) {
         $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', []));
         $tag = ArrayHelper::remove($options, 'tag', 'li');
         $class = [];
         if ($item['active']) {
             $class[] = $this->activeCssClass;
         }
         if ($i === 0 && $this->firstItemCssClass !== null) {
             $class[] = $this->firstItemCssClass;
         }
         if ($i === $n - 1 && $this->lastItemCssClass !== null) {
             $class[] = $this->lastItemCssClass;
         }
         if (!empty($class)) {
             if (empty($options['class'])) {
                 $options['class'] = implode(' ', $class);
             } else {
                 $options['class'] .= ' ' . implode(' ', $class);
             }
         }
         $menu = $this->renderItem($item);
         if (!empty($item['items'])) {
             $menu .= strtr($this->submenuTemplate, ['{show}' => $item['active'] ? "style='display: block'" : '', '{items}' => $this->renderItems($item['items'])]);
         }
         $lines[] = Html::tag($tag, $menu, $options);
     }
     return implode("\n", $lines);
 }
示例#11
0
 public function actionStock()
 {
     $debug = '';
     $model = new DynamicModel(['vins', 'diller']);
     $model->addRule('vins', 'string')->addRule('diller', 'integer')->addRule(['diller', 'vins'], 'required');
     $list = ArrayHelper::map(Mod\cats\Stock::find()->all(), 'id', 'name');
     $prompt = Yii::t('app', 'Select stock');
     $arrError = [];
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $arrvin = explode("\n", $model->vins);
         foreach ($arrvin as $vin) {
             if ($car = Mod\Car::findOne(['vin' => trim($vin)])) {
                 $status = Mod\CarStatus::findOne(['car_id' => $car->id]);
                 $status->stock_id = $model->diller;
                 $status->save();
             } else {
                 $arrError[] = $vin . ' не найден VIN';
             }
         }
         //			$debug = print_r($arrError, true);
         $debug = implode('<br>', $arrError);
         return $this->render('finish', ['debug' => $debug]);
     }
     $arrVars = ['model' => $model, 'list' => $list, 'prompt' => $prompt, 'selLabel' => 'Склад', 'title' => 'Пакетное перемещение'];
     return $this->render('index', $arrVars);
 }
示例#12
0
 /**
  * @param Tree $model
  * @param array $data
  * @return static
  */
 public static function instance($model, $data = [])
 {
     if ($package = ArrayHelper::getValue(static::$instances, $model->id)) {
         return $package;
     }
     return new static($model, $data);
 }
示例#13
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Users::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $sort = $dataProvider->getSort();
     $sort->attributes['officeName'] = ['asc' => ['questionlist_office.name' => SORT_ASC], 'desc' => ['questionlist_office.name' => SORT_DESC], 'label' => 'Имя офиса'];
     $dataProvider->setSort($sort);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         $query->joinWith(['questionlist_office']);
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     if ($this->roleName) {
         $this->profile_office_role = $this->roleName;
     }
     $query->andFilterWhere(['like', 'profile_id', $this->profile_id])->andFilterWhere(['like', 'profile_office_role', $this->profile_office_role]);
     if ($this->scenario == 'managerSearch') {
         $userRoles = Users::findAll(['profile_id' => Yii::$app->user->identity->username, 'profile_office_role' => 'commercial_director']);
         $userRegions = array_values(ArrayHelper::map($userRoles, 'region_id', 'region_id'));
         $query->andFilterWhere(['like', 'profile_office_role', 'manager']);
         $query->andFilterWhere(['in', 'questionlist_users_offices.region_id', $userRegions]);
     }
     $query->joinWith(['office' => function ($q) {
         $q->andFilterWhere(['like', 'questionlist_office.name', $this->officeName]);
     }]);
     $query->joinWith(['region' => function ($q) {
         $q->andFilterWhere(['like', 'questionlist_region.name', $this->regionName]);
     }]);
     return $dataProvider;
 }
示例#14
0
 public function setThumbnailSettings(array $config)
 {
     $params = ['width', 'height', 'mode'];
     foreach ($params as $param) {
         $this->_thumbnailSettings[$param] = ArrayHelper::getValue($config, $param, null);
     }
 }
示例#15
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     /**
      * @var Module $m
      */
     $m = Yii::$app->getModule('user');
     if (!$m->getRegistrationSetting('randomUsernames', $this->userType)) {
         $this->attributes['username'] = ['type' => Form::INPUT_TEXT, 'options' => ['autocomplete' => 'new-username']];
     }
     if (!$m->getRegistrationSetting('randomPasswords', $this->userType)) {
         $password = ['type' => Form::INPUT_PASSWORD];
         if (in_array(Module::SCN_REGISTER, $m->passwordSettings['strengthMeter'])) {
             $password = ['type' => Form::INPUT_WIDGET, 'widgetClass' => PasswordInput::classname(), 'options' => ['options' => ['placeholder' => Yii::t('user', 'Password'), 'autocomplete' => 'off']]];
         }
         $this->attributes['password'] = $password;
     }
     $this->attributes['email'] = ['type' => Form::INPUT_TEXT];
     $captcha = ArrayHelper::getValue($m->registrationSettings, 'captcha', false);
     if ($captcha !== false && is_array($captcha)) {
         $this->attributes['captcha'] = ['type' => Form::INPUT_WIDGET, 'widgetClass' => Captcha::classname(), 'options' => $captcha['widget']];
     }
     parent::init();
     unset($this->attributes['rememberMe']);
     $this->leftFooter = $m->button(Module::BTN_HOME) . $m->button(Module::BTN_ALREADY_REGISTERED);
     $this->rightFooter = $m->button(Module::BTN_RESET_FORM) . ' ' . $m->button(Module::BTN_REGISTER);
 }
示例#16
0
 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);
 }
示例#17
0
 /**
  * @return mixed
  */
 public static function getCountries()
 {
     $model = self::find()->all();
     return self::getDb()->cache(function () use($model) {
         return ArrayHelper::map($model, 'id', 'name');
     }, 3600);
 }
示例#18
0
 /**
  *
  */
 public function init()
 {
     if (!$this->model instanceof ActiveRecord) {
         throw new Exception('model must be ActiveRecord and required');
     }
     $methods = ['get', 'post'];
     if (!in_array($this->method, $methods)) {
         throw new Exception('method must be get or post');
     }
     $method = $this->method;
     if (empty($this->get)) {
         $this->get = Yii::$app->request->{$method}($this->getModelName());
     }
     if (!empty($this->columns)) {
         foreach ($this->columns as $column) {
             if (is_string($column)) {
                 $column = ['attribute' => $column];
             }
             $c = new ColumnsTab(ArrayHelper::merge($column, ['model' => $this->model, 'get' => $this->get]));
             $this->tabs[] = $c->getLabel();
         }
     } else {
         foreach ($this->get as $attr => $value) {
             $c = new ColumnsTab(['model' => $this->model, 'get' => $this->get, 'attribute' => $attr]);
             $this->tabs[] = $c->getLabel();
         }
     }
     $this->tabs = array_filter($this->tabs);
 }
示例#19
0
 /**
  * 添加权限到角色
  */
 public function actionConfig($name)
 {
     $role = $name;
     $authManager = Yii::$app->getAuthManager();
     $roleModel = $this->findAuthItemModel($role);
     if (Yii::$app->getRequest()->post()) {
         //清空当角色的所有权限
         $authManager->removeItems($role);
         foreach (Yii::$app->getRequest()->post() as $key => $value) {
             if (!empty($value) && is_array($value)) {
                 if (in_array($key, $value)) {
                     //只存task
                     if (!$authManager->hasChild($authManager->getRole($role), $authManager->getTask($key))) {
                         $authManager->addChild($authManager->getRole($role), $authManager->getTask($key));
                     }
                 } else {
                     //只存permission
                     foreach ($value as $item) {
                         if (!$authManager->hasChild($authManager->getRole($role), $authManager->getPermission($item))) {
                             $authManager->addChild($authManager->getRole($role), $authManager->getPermission($item));
                         }
                     }
                 }
             }
         }
         //提示更新成功
         Yii::$app->getSession()->setFlash('success', Yii::t('auth', 'Update Role Success'));
     }
     $tasksAndPermissions = $authManager->getTasksAndPermissions();
     $selectItems = ArrayHelper::merge($authManager->getPermissionsByRole($role), $authManager->getTasksByRole($role));
     $selectItems = array_keys($selectItems);
     return $this->render('config', ['tasksAndPermissions' => $tasksAndPermissions, 'selectItems' => $selectItems, 'model' => $roleModel, 'name' => $role]);
 }
示例#20
0
 public function getOrderOfGalleryImagesForSortableWidget()
 {
     $galleryImages = $this->getGalleryImages()->select('id')->orderBy(['sort_order' => SORT_ASC])->all();
     $galleryImageIds = ArrayHelper::getColumn($galleryImages, 'id');
     $galleryImageIdsAsString = implode(',', $galleryImageIds);
     return $galleryImageIdsAsString;
 }
 /**
  * @param $name
  * @return VisioWidget
  */
 public function getWidget($name)
 {
     if (!ArrayHelper::keyExists($name, $this->_widgets)) {
         $this->addWidget($name);
     }
     return $this->_widgets[$name];
 }
 public function run()
 {
     $this->attributeName = $this->property->name;
     $this->minAttribute = 'minValue[' . $this->property->id . ']';
     $this->maxAttribute = 'maxValue[' . $this->property->id . ']';
     $this->changeFlagAttribute = 'changeValue[' . $this->property->id . ']';
     $get = ArrayHelper::merge(Yii::$app->request->get(), Yii::$app->request->post());
     if ($this->selects) {
         $this->minValue = (int) array_values($this->selects)[0]['value'];
         $this->maxValue = (int) array_values($this->selects)[0]['value'];
         foreach ($this->selects as $select) {
             $select['value'] = (int) $select['value'];
             $this->minValue = $select['value'] < $this->minValue ? $select['value'] : $this->minValue;
             $this->maxValue = $select['value'] > $this->maxValue ? $select['value'] : $this->maxValue;
         }
         if (isset($get[$this->minAttribute]) && is_numeric($get[$this->minAttribute])) {
             $this->changeFlagDefaultValue = 1;
             $this->minValueNow = $get[$this->minAttribute];
         } else {
             $this->minValueNow = $this->minValue;
         }
         if (isset($get[$this->maxAttribute]) && is_numeric($get[$this->maxAttribute])) {
             $this->changeFlagDefaultValue = 1;
             $this->maxValueNow = $get[$this->maxAttribute];
         } else {
             $this->maxValueNow = $this->maxValue;
         }
     }
     return parent::run();
 }
示例#23
0
 public static function FetchDistrict()
 {
     $sql = 'SELECT  DISTINCT district FROM app_customers_items  ';
     $countries = Item::findBySql($sql)->all();
     $listData = ArrayHelper::map($countries, 'district', 'district');
     return $listData;
 }
示例#24
0
 public function __construct($config = [])
 {
     if (\Yii::$app->admin->requestIsAdmin) {
         $config = ArrayHelper::merge(\Yii::$app->admin->getCkeditorOptions(), $config);
     }
     parent::__construct($config);
 }
示例#25
0
文件: Config.php 项目: hiqdev/hidev
 public function getItemConfig($id = null, array $config = [])
 {
     if (isset($config['class']) && $this->hasItem($config['class'])) {
         $config = array_merge($config, $this->_items[$config['class']]);
     }
     return ArrayHelper::merge(['class' => 'hidev\\controllers\\CommonController'], $config);
 }
示例#26
0
 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]);
 }
示例#27
0
 public function getUomList()
 {
     if ($this->_uomList === null) {
         $this->_uomList = ArrayHelper::map($this->uoms, 'id', 'name');
     }
     return $this->_uomList;
 }
示例#28
-1
 public function init()
 {
     \kartik\base\InputWidget::init();
     $this->pluginOptions['theme'] = $this->theme;
     if (!empty($this->addon) || empty($this->pluginOptions['width'])) {
         $this->pluginOptions['width'] = '100%';
     }
     $multiple = ArrayHelper::getValue($this->pluginOptions, 'multiple', false);
     unset($this->pluginOptions['multiple']);
     $multiple = ArrayHelper::getValue($this->options, 'multiple', $multiple);
     $this->options['multiple'] = $multiple;
     if ($this->hideSearch) {
         $css = ArrayHelper::getValue($this->pluginOptions, 'dropdownCssClass', '');
         $css .= ' kv-hide-search';
         $this->pluginOptions['dropdownCssClass'] = $css;
     }
     $this->initPlaceholder();
     if ($this->data == null) {
         if (!isset($this->value) && !isset($this->initValueText)) {
             $this->data = [];
         } else {
             $key = isset($this->value) ? $this->value : ($multiple ? [] : '');
             $val = isset($this->initValueText) ? $this->initValueText : $key;
             $this->data = $multiple ? array_combine($key, $val) : [$key => $val];
         }
     }
     Html::addCssClass($this->options, 'form-control');
     $this->initLanguage('language', true);
     $this->registerAssets();
     $this->renderInput();
 }
 /**
  * Renders the hint tag.
  * @param string $content the hint content. It will NOT be HTML-encoded.
  * @param array $options the tag options in terms of name-value pairs. These will be rendered as
  * the attributes of the hint tag. The values will be HTML-encoded using [[Html::encode()]].
  *
  * The following options are specially handled:
  *
  * - tag: this specifies the tag name. If not set, "div" will be used.
  *
  * @return static the field object itself
  */
 public function hint($content, $options = [])
 {
     $options = array_merge($this->hintOptions, $options, ['id' => 'hint-' . Html::getInputId($this->model, $this->attribute)]);
     $tag = ArrayHelper::remove($options, 'tag', 'p');
     $this->parts['{hint}'] = Html::tag($tag, $content, $options);
     return $this;
 }
示例#30
-1
 /**
  * Формирование Html кода поля для вывода в форме
  * @param ActiveForm $form объект форма
  * @param array $options массив html атрибутов поля
  * @param bool|int $index инднкс модели при табличном вводе
  * @return string
  */
 public function renderInput(ActiveForm $form, array $options = [], $index = false)
 {
     $options = ArrayHelper::merge($this->options, $options);
     $widgetOptions = ArrayHelper::merge(["options" => ["class" => "form-control", "prompt" => ""], "data" => $this->modelField->getDataValue()], $this->widgetOptions, ["options" => $options]);
     $attr = $this->modelField->attr;
     return $form->field($this->modelField->model, $this->getFormAttrName($index, $attr))->widget(DependDropDown::className(), $widgetOptions);
 }