当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayHelper::multisort方法代码示例

本文整理汇总了PHP中yii\helpers\ArrayHelper::multisort方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::multisort方法的具体用法?PHP ArrayHelper::multisort怎么用?PHP ArrayHelper::multisort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\ArrayHelper的用法示例。


在下文中一共展示了ArrayHelper::multisort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: apply

 /**
  * @inheritdoc
  */
 public function apply($model)
 {
     if ($this->isDue() && in_array($model->ClassID, [6, 12])) {
         $userID = $model->contractor->id;
         \Yii::info('Проверка и применение акции "' . self::$name . '"' . "({$this->getModel()->id})" . ' для пользователя ' . Html::a($userID, ['/user/admin/update', 'id' => $userID]), 'info');
         $settings = $this->getModel()->parseSettings();
         if (empty($settings['attributes'])) {
             return false;
         }
         ArrayHelper::multisort($settings['attributes'], 'payment', SORT_DESC);
         $account = $model->contractor->account;
         foreach ($settings['attributes'] as $attributes) {
             $discount = $this->getModel()->getDiscount();
             $discount->setAttributes($attributes);
             if ($model->CashSum >= $discount->payment) {
                 \Yii::info('Применение акции с атрибутами: ' . Json::encode($attributes), 'info');
                 $account->BonusGames = $account->BonusGames + $discount->bonusGamesCount;
                 if ($account->save(false, ['BonusGames'])) {
                     $finance = new FinanceRecord();
                     $finance->CashSum = 0;
                     $finance->ClassID = 21;
                     //Начисление бонусов
                     $finance->ContractorID = $model->ContractorID;
                     $finance->Comment = $this->getDescription();
                     $finance->save();
                     return true;
                 }
             }
         }
     } else {
         //            var_export(in_array($model->ClassID, [6, 12]));
     }
     return false;
 }
开发者ID:just-leo,项目名称:cardgame-serial,代码行数:37,代码来源:BonusGameDiscount.php

示例2: applyOrderBy

 /**
  * Applies sort for given data.
  * @param array $data raw data.
  * @param array|null $orderBy order by.
  * @return array sorted data.
  */
 public function applyOrderBy(array $data, $orderBy)
 {
     if (!empty($orderBy)) {
         ArrayHelper::multisort($data, array_keys($orderBy), array_values($orderBy));
     }
     return $data;
 }
开发者ID:rockefys,项目名称:filedb,代码行数:13,代码来源:QueryProcessor.php

示例3: getMergedConfig

 public function getMergedConfig($modNames)
 {
     $result = ['menus' => [], 'mods' => []];
     if (!empty($modNames)) {
         $modulesDIR = Yii::getAlias('@backend') . DIRECTORY_SEPARATOR . 'modules';
         $modulesPath = realpath($modulesDIR);
         foreach ($modNames as $modName) {
             $configPath = $modulesPath . DIRECTORY_SEPARATOR . $modName . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'main.php';
             if (is_file($configPath)) {
                 $moduleConfig = (require $configPath);
                 if (isset($moduleConfig['menusConfig']) && !empty($moduleConfig['menusConfig'])) {
                     foreach ($moduleConfig['menusConfig'] as $moduleName => $moduleItems) {
                         if (!isset($result['menus'][$moduleName])) {
                             $result['menus'][$moduleName] = [];
                         }
                         $result['menus'][$moduleName] = ArrayHelper::merge($result['menus'][$moduleName], $moduleItems);
                     }
                 }
                 if (isset($moduleConfig['isInTopNav']) && $moduleConfig['isInTopNav']) {
                     $result['mods'][] = ['name' => $moduleConfig['name'], 'isCore' => $moduleConfig['isCore'], 'order' => $moduleConfig['order']];
                 }
             }
         }
         foreach ($result['menus'] as &$moduleItems) {
             ArrayHelper::multisort($moduleItems, 'order', SORT_ASC);
         }
         ArrayHelper::multisort($result['mods'], 'order', SORT_ASC);
     }
     return $result;
 }
开发者ID:timelessmemory,项目名称:uhkklp,代码行数:30,代码来源:ExtModule.php

示例4: up

 public function up()
 {
     $users = \bubasuma\simplechat\db\demo\User::find()->select(['id'])->asArray()->all();
     $data = (require __DIR__ . '/data/messages.php');
     $count = count($data);
     $messages = [];
     try {
         for ($i = 1; $i <= 10000; $i++) {
             shuffle($users);
             $sender = $users[0];
             $receiver = $users[1];
             $messages[] = ['sender_id' => $sender['id'], 'receiver_id' => $receiver['id'], 'created_at' => (new \DateTime())->sub(new \DateInterval('P' . mt_rand() % 500 . 'DT' . mt_rand() % 86400 . 'S'))->getTimestamp(), 'text' => $data[mt_rand(0, $count - 1)]];
         }
         ArrayHelper::multisort($messages, 'created_at', SORT_ASC, SORT_NUMERIC);
         foreach ($messages as $message) {
             $new = new \bubasuma\simplechat\db\demo\Message();
             $new->sender_id = $message['sender_id'];
             $new->receiver_id = $message['receiver_id'];
             $new->text = $message['text'];
             $new->is_new = 0;
             $new->created_at = date('Y-m-d H:i:s', $message['created_at']);
             $new->save();
         }
         return true;
     } catch (\yii\base\Exception $e) {
         return false;
     }
 }
开发者ID:marciocamello,项目名称:yii2-simplechat,代码行数:28,代码来源:m151121_105707_message_data.php

示例5: getData

 public function getData()
 {
     \Yii::beginProfile('admin-menu');
     if ($this->isLoaded) {
         return (array) $this->groups;
     }
     $paths[] = \Yii::getAlias('@common/config/admin/menu.php');
     $paths[] = \Yii::getAlias('@app/config/admin/menu.php');
     foreach (\Yii::$app->extensions as $code => $data) {
         if ($data['alias']) {
             foreach ($data['alias'] as $code => $path) {
                 $adminMenuFile = $path . '/config/admin/menu.php';
                 if (file_exists($adminMenuFile)) {
                     $menuGroups = (array) (include_once $adminMenuFile);
                     $this->groups = ArrayHelper::merge($this->groups, $menuGroups);
                 }
             }
         }
     }
     foreach ($paths as $path) {
         if (file_exists($path)) {
             $menuGroups = (array) (include_once $path);
             $this->groups = ArrayHelper::merge($this->groups, $menuGroups);
         }
     }
     ArrayHelper::multisort($this->groups, 'priority');
     $this->isLoaded = true;
     \Yii::endProfile('admin-menu');
     return (array) $this->groups;
 }
开发者ID:Liv1020,项目名称:cms,代码行数:30,代码来源:Menu.php

示例6: set

 /**
  * 设置菜单(如果菜单已存在则覆盖)
  * ~~~
  * Menu::set('user.name', [
  *     'label' => '用户列表',
  *     'url' => ['/user/admin/user/index'],
  *     'icon' => 'fa-user',
  *     'priority' => 9
  * ]);
  * ~~~
  * @param $menuKey 可以多级设置.最多设置二级
  * @param array $options 菜单设置
  * @return mixed
  * @throws \yii\base\InvalidConfigException
  */
 public static function set($menuKey, array $options)
 {
     $menuKeys = explode('.', $menuKey);
     if (count($menuKeys) > 2) {
         throw new InvalidConfigException("Can only support 2 levels of menus");
         // 最多只能支持二级菜单
     }
     $menus = static::get();
     $_menu =& $menus;
     while (count($menuKeys) > 1) {
         $menuKey = array_shift($menuKeys);
         if (!isset($_menu[$menuKey]) || !is_array($_menu[$menuKey])) {
             $_menu[$menuKey] = ['label' => $menuKey, 'priority' => 100];
         }
         if (!isset($_menu[$menuKey]['items'])) {
             $_menu[$menuKey]['items'] = [];
         }
         $_menu =& $_menu[$menuKey]['items'];
     }
     $menuKey = array_shift($menuKeys);
     $_menu[$menuKey] = array_merge(isset($_menu[$menuKey]) ? $_menu[$menuKey] : [], array_merge(['label' => ArrayHelper::remove($options, 'label', $menuKey), 'url' => ArrayHelper::remove($options, 'url'), 'priority' => ArrayHelper::remove($options, 'priority', 10)], $options));
     ArrayHelper::multisort($_menu, 'priority');
     // 排序
     return Yii::$app->get('config')->set(static::MENU_BASE_KEY, $menus);
 }
开发者ID:rocketyang,项目名称:huajuan,代码行数:40,代码来源:Menu.php

示例7: getLanguagesArray

 public static function getLanguagesArray()
 {
     $yiiLanguages = ['ar', 'az', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'es', 'et', 'fa', 'fi', 'fr', 'he', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt', 'lv', 'ms', 'nl', 'pl', 'pt', 'pt-BR', 'ro', 'ru', 'sk', 'sl', 'sr', 'sr-Latn', 'sv', 'th', 'tj', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW', 'en-US'];
     $dotPlantLanguages = ['en-US', 'ru', 'zh-CN'];
     $result = [];
     foreach ($yiiLanguages as $lang) {
         $result[] = ['language' => $lang, 'translated' => in_array($lang, $dotPlantLanguages)];
     }
     ArrayHelper::multisort($result, 'translated', SORT_DESC);
     return $result;
 }
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:11,代码来源:InstallerHelper.php

示例8: actionProgram

 public function actionProgram($id)
 {
     /* @var $model \common\models\Program */
     Yii::$app->response->format = Response::FORMAT_JSON;
     $programs = [];
     $models = Program::find()->where(['id_faculty' => $id])->all();
     foreach ($models as $model) {
         $programs[] = $model->toArray(['id'], ['fullName']);
     }
     ArrayHelper::multisort($programs, 'fullName');
     return $programs;
 }
开发者ID:vastander,项目名称:yii2-eer,代码行数:12,代码来源:HistoryController.php

示例9: getAll

 /**
  * Get all of the time zones with the offsets sorted by their offset
  *
  * @return array
  */
 public static function getAll()
 {
     $timeZones = [];
     $timeZoneIdentifiers = \DateTimeZone::listIdentifiers();
     foreach ($timeZoneIdentifiers as $timeZone) {
         $date = new \DateTime('now', new \DateTimeZone($timeZone));
         $offset = $date->getOffset() / 60 / 60;
         $timeZones[] = ['timezone' => $timeZone, 'name' => "{$timeZone} (UTC " . ($offset > 0 ? '+' : '') . "{$offset})", 'offset' => $offset];
     }
     \yii\helpers\ArrayHelper::multisort($timeZones, 'offset', SORT_DESC, SORT_NUMERIC);
     return $timeZones;
 }
开发者ID:lnch,项目名称:yii2-user-control,代码行数:17,代码来源:Timezone.php

示例10: getAll

 /**
  * Get all of the time zones with the offsets sorted by their offset
  * @return array
  */
 public static function getAll()
 {
     $timezones = [];
     $identifiers = DateTimeZone::listIdentifiers();
     foreach ($identifiers as $identifier) {
         $date = new DateTime("now", new DateTimeZone($identifier));
         $offsetText = $date->format("P");
         $offsetInHours = $date->getOffset() / 60 / 60;
         $timezones[] = ["identifier" => $identifier, "name" => "(GMT{$offsetText}) {$identifier}", "offset" => $offsetInHours];
     }
     ArrayHelper::multisort($timezones, "offset", SORT_ASC, SORT_NUMERIC);
     return $timezones;
 }
开发者ID:cicsolutions,项目名称:yii2-user,代码行数:17,代码来源:Timezone.php

示例11: getSoureListByNear

 public static function getSoureListByNear(Town $town)
 {
     $rawSources = Source::find()->all();
     $sources = [];
     foreach ($rawSources as $source) {
         $source->distance = $source->totalDistance($town);
         $sources[] = $source;
     }
     ArrayHelper::multisort($sources, function ($source) {
         return $source->distance;
     });
     return $sources;
 }
开发者ID:Ravend6,项目名称:yii_sinoptik_junior,代码行数:13,代码来源:Source.php

示例12: run

 public function run($logId, $tag)
 {
     $this->controller->loadData($tag);
     $timings = $this->panel->calculateTimings();
     ArrayHelper::multisort($timings, 3, SORT_DESC);
     if (!isset($timings[$logId])) {
         throw new HttpException(404, 'Log message not found.');
     }
     $message = $timings[$logId][1];
     if (($pos = mb_strpos($message, "#")) !== false) {
         $url = mb_substr($message, 0, $pos);
         $body = mb_substr($message, $pos + 1);
     } else {
         $url = $message;
         $body = null;
     }
     list($dbname, $action) = explode('.', $url);
     /* @var $db Database */
     $db = Yii::$app->get($this->com)->getDatabase($dbname);
     $time = microtime(true);
     switch ($action) {
         case 'findAll':
             $docs = $db->getSearch()->setLimit(3)->setQuery($body)->search();
             $result = '<strong>Estimated Matched: </strong>' . $db->getLastCount();
             foreach ($docs as $doc) {
                 $result .= '<br/>' . $doc->rank() . '. (' . $doc->percent() . '%)';
                 $result .= "<br/>" . Json::encode($doc->getFields(), 448) . "\n";
             }
             if ($db->getLastCount() > 3) {
                 $result .= '<br/> ... other ' . ($db->getLastCount() - 3) . ' results ...';
             }
             break;
         case 'findOne':
             $docs = $db->getSearch()->setLimit(1)->setQuery($body)->search();
             if (count($docs) === 0) {
                 $result = '<span class="label label-danger">no found</span>';
             } else {
                 $result = "<br/>\n" . Json::encode($docs[0]->getFields(), 448);
             }
             break;
         case 'count':
             $count = $db->getSearch()->setQuery($body)->count();
             $result = '<strong>Estimated Matched: </strong>' . $count;
             break;
         default:
             throw new NotSupportedException("Action '{$action}' is not supported by xunsearch.");
     }
     $result = '<strong>DB Total: </strong>' . $db->getDbTotal() . '<br/>' . '<strong>Parsed Query: </strong>' . $db->getQuery() . '<br/>' . $result;
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ['time' => sprintf('%.1f ms', (microtime(true) - $time) * 1000), 'result' => $result];
 }
开发者ID:waibo,项目名称:xunsearch,代码行数:51,代码来源:DebugAction.php

示例13: run

 public function run($logId, $tag)
 {
     $this->controller->loadData($tag);
     $timings = $this->panel->calculateTimings();
     ArrayHelper::multisort($timings, 3, SORT_DESC);
     if (!isset($timings[$logId])) {
         throw new HttpException(404, 'Log message not found.');
     }
     $message = $timings[$logId][1];
     if (($pos = mb_strpos($message, "#")) !== false) {
         $url = mb_substr($message, 0, $pos);
         $body = mb_substr($message, $pos + 1);
     } else {
         $url = $message;
         $body = null;
     }
     $method = mb_substr($url, 0, $pos = mb_strpos($url, ' '));
     $url = mb_substr($url, $pos + 1);
     $options = ['pretty' => true];
     /* @var $db Connection */
     $db = \Yii::$app->get($this->db);
     $time = microtime(true);
     switch ($method) {
         case 'GET':
             $result = $db->get($url, $options, $body, true);
             break;
         case 'POST':
             $result = $db->post($url, $options, $body, true);
             break;
         case 'PUT':
             $result = $db->put($url, $options, $body, true);
             break;
         case 'DELETE':
             $result = $db->delete($url, $options, $body, true);
             break;
         case 'HEAD':
             $result = $db->head($url, $options, $body);
             break;
         default:
             throw new NotSupportedException("Request method '{$method}' is not supported by elasticsearch.");
     }
     $time = microtime(true) - $time;
     if ($result === true) {
         $result = '<span class="label label-success">success</span>';
     } elseif ($result === false) {
         $result = '<span class="label label-danger">no success</span>';
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ['time' => sprintf('%.1f ms', $time * 1000), 'result' => $result];
 }
开发者ID:hiqdev,项目名称:yii2-hiar,代码行数:50,代码来源:DebugAction.php

示例14: run

 public function run()
 {
     $xml = @simplexml_load_file($this->channel);
     if ($xml === false) {
         die('Error parse Rss: ' . $rss);
     }
     $items = [];
     foreach ($xml->xpath('//item') as $item) {
         $items[] = $item;
     }
     ArrayHelper::multisort($items, function ($item) {
         return $item->pubDate;
     }, SORT_DESC);
     $provider = new ArrayDataProvider(['allModels' => $items, 'pagination' => ['pageSize' => $this->pageSize]]);
     return $this->render('wrap', ['provider' => $provider]);
 }
开发者ID:tugmaks,项目名称:yii2-rss-reader,代码行数:16,代码来源:RssReader.php

示例15: actionFetchTop

 /**
  * Fetches TOP-$count components from Bower ans saves to `config/bower.list`.
  *
  * @param int $count
  * @param bool $skipCache
  */
 public function actionFetchTop($count = 1000, $skipCache = false)
 {
     $result = [];
     $components = $this->getComponents($skipCache);
     ArrayHelper::multisort($components, 'stars', SORT_DESC, SORT_NUMERIC);
     foreach (array_slice($components, 0, $count) as $component) {
         $result[] = 'bower-asset/' . $component['name'];
         echo Console::renderColoredString("%R{$component['stars']}%N - %g{$component['name']}%N");
         Console::moveCursorTo(0);
         Console::clearLine();
     }
     $componentsListPath = Yii::getAlias('@hiqdev/assetpackagist/config/bower.list');
     file_put_contents($componentsListPath, implode("\n", $result));
     echo Console::renderColoredString('Fetched %YBower%N components list. Found %G' . count($components) . "%N components.\n");
     echo Console::renderColoredString('Only %bTOP-' . $count . "%N components were added to the packages list.\n");
     echo Console::renderColoredString('See %G' . $componentsListPath . "%N\n");
 }
开发者ID:hiqdev,项目名称:asset-packagist,代码行数:23,代码来源:BowerPackageController.php


注:本文中的yii\helpers\ArrayHelper::multisort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。