作者:thrie
项目:yii2-statrepor
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;
}
作者:VictorGu
项目:yii2-swagge
/**
* 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;
}
作者:indicalab
项目:yii2-geolocatio
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);
}
作者:alissonct
项目:sg
public static function map($tipo)
{
//entrada ou saida
$tipo = self::find()->where(['tipo' => $tipo])->asArray()->all();
$tipoMap = ArrayHelper::map($tipo, 'id', 'descricao');
return $tipoMap;
}
作者:sanchezzzha
项目:kak-are
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']);
}
作者:engmohamedame
项目:teston
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;
}
作者:Liv102
项目:cm
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;
}
作者:mark3
项目:yii2-site-mn
/**
* 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);
}
作者:sedpr
项目:yii2-test-ap
/**
* 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;
}
作者:WittayaS
项目:yii2-ta
/**
* 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);
}
作者:Ent-c
项目:stock_aut
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);
}
作者:Liv102
项目:cm
/**
* @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);
}
作者:igribo
项目:question-lis
/**
* 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;
}
作者:secondsan
项目:mebe
public function setThumbnailSettings(array $config)
{
$params = ['width', 'height', 'mode'];
foreach ($params as $param) {
$this->_thumbnailSettings[$param] = ArrayHelper::getValue($config, $param, null);
}
}
作者:communityi
项目:yii2-use
/**
* @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);
}
作者:Andriy
项目:tea
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);
}
作者:lebeddim
项目:booking
/**
* @return mixed
*/
public static function getCountries()
{
$model = self::find()->all();
return self::getDb()->cache(function () use($model) {
return ArrayHelper::map($model, 'id', 'name');
}, 3600);
}
作者:vykhrystiu
项目:yii2-filter-ta
/**
*
*/
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);
}
作者:jorry200
项目:ture
/**
* 添加权限到角色
*/
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]);
}
作者:HeavyDot
项目:heavyCM
public function getOrderOfGalleryImagesForSortableWidget()
{
$galleryImages = $this->getGalleryImages()->select('id')->orderBy(['sort_order' => SORT_ASC])->all();
$galleryImageIds = ArrayHelper::getColumn($galleryImages, 'id');
$galleryImageIdsAsString = implode(',', $galleryImageIds);
return $galleryImageIdsAsString;
}