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


PHP Hash::sort方法代码示例

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


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

示例1: index

 /**
  * List all broker
  *
  * @return void
  * @author Chaiwut <ichaiwut.s@gmail.com>
  * @since 16 July 2015
  */
 public function index()
 {
     //Set default for parmas
     if (!isset($this->params->query['name'])) {
         $this->params->query['name'] = '';
     }
     if (!isset($this->params->query['sort'])) {
         $this->params->query['sort'] = 3;
     }
     //set condition for text filter
     $conditions = array('Broker.name LIKE' => '%' . $this->params->query['name'] . '%');
     $this->Paginator->settings = array('conditions' => $conditions, 'limit' => 20, 'order' => array('Broker.created' => 'DESC'));
     $brokers = $this->Paginate('Broker');
     //Count and keep it in the same array
     foreach ($brokers as $key => $value) {
         $brokers[$key]['Broker']['point_sum'] = count($value['Point']);
         $brokers[$key]['Broker']['comment_sum'] = count($value['Comment']);
     }
     //Sorting array
     //Please see : http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::sort
     if ($this->params->query['sort'] == 1) {
         $brokers = Hash::sort($brokers, '{n}.Broker.point_sum', 'desc');
     } else {
         if ($this->params->query['sort'] == 2) {
             $brokers = Hash::sort($brokers, '{n}.Broker.comment_sum', 'desc');
         }
     }
     $this->set('brokers', $brokers);
     $this->set('title_for_layout', __('โบรกเกอร์ทั้งหมด'));
 }
开发者ID:alongkot-s,项目名称:Page,代码行数:37,代码来源:BrokersController.php

示例2: findRelated

 /**
  * Find all comments related to a specific content
  * @param string $ref Model linked with comments
  * @param int $ref_id ID of the content linked with the comments
  * @todo  Supprimer les commentaires inline : si le code est suffisamment clair cela se lit tout seul, sinon séparer en sous méthodes protected
  **/
 public function findRelated($ref, $ref_id, $options = array())
 {
     // We had the conditions to find linked comments only
     $options['conditions']['ref'] = $ref;
     $options['conditions']['ref_id'] = $ref_id;
     // We need to retrieve User informations
     if (!isset($options['contain']['User'])) {
         $fields = Configure::read('Plugin.Comment.user');
         unset($fields['model']);
         $fields[] = 'id';
         $fields = array_values($fields);
         $options['contain']['User'] = $fields;
     }
     $comments = $this->find('all', $options);
     if (Configure::read('Plugin.Comment.subcomments')) {
         $comments = Hash::combine($comments, '{n}.Comment.id', '{n}', '{n}.Comment.parent_id');
         if (!isset($comments[0])) {
             return array();
         }
         foreach ($comments[0] as $k => $coms) {
             $comments[0][$k]['Answer'] = array();
         }
         foreach ($comments as $parent_id => $coms) {
             if ($parent_id != 0) {
                 $comments[0][$parent_id]['Answer'] = Hash::sort($coms, '{n}.Comment.id', 'ASC');
             }
         }
         return $comments[0];
     } else {
         return $comments;
     }
 }
开发者ID:naveen-netgen,项目名称:CakePHP-Comment,代码行数:38,代码来源:Comment.php

示例3: adminMenus

 /** Generate Admin menus added by CroogoNav::add()
  *
  * @param array $menus
  * @param array $options
  * @return string menu html tags
  */
 public function adminMenus($menus, $options = array(), $depth = 0)
 {
     $options = Hash::merge(array('children' => true, 'htmlAttributes' => array('class' => 'nav nav-stacked')), $options);
     $aclPlugin = Configure::read('Site.acl_plugin');
     $userId = AuthComponent::user('id');
     if (empty($userId)) {
         return '';
     }
     $out = null;
     $sorted = Hash::sort($menus, '{s}.weight', 'ASC');
     if (empty($this->Role)) {
         $this->Role = ClassRegistry::init('Users.Role');
         $this->Role->Behaviors->attach('Croogo.Aliasable');
     }
     $currentRole = $this->Role->byId($this->Layout->getRoleId());
     foreach ($sorted as $menu) {
         $htmlAttributes = $options['htmlAttributes'];
         if ($currentRole != 'admin' && !$this->{$aclPlugin}->linkIsAllowedByUserId($userId, $menu['url'])) {
             continue;
         }
         if (empty($menu['htmlAttributes']['class'])) {
             $menuClass = Inflector::slug(strtolower('menu-' . $menu['title']), '-');
             $menu['htmlAttributes'] = Hash::merge(array('class' => $menuClass), $menu['htmlAttributes']);
         }
         $title = '';
         if (empty($menu['icon'])) {
             $menu['htmlAttributes'] += array('icon' => 'white');
         } else {
             $menu['htmlAttributes'] += array('icon' => $menu['icon']);
         }
         $title .= '<span>' . $menu['title'] . '</span>';
         $children = '';
         if (!empty($menu['children'])) {
             $childClass = 'nav nav-stacked sub-nav ';
             $childClass .= ' submenu-' . Inflector::slug(strtolower($menu['title']), '-');
             if ($depth > 0) {
                 $childClass .= ' dropdown-menu';
             }
             $children = $this->adminMenus($menu['children'], array('children' => true, 'htmlAttributes' => array('class' => $childClass)), $depth + 1);
             $menu['htmlAttributes']['class'] .= ' hasChild dropdown-close';
         }
         $menu['htmlAttributes']['class'] .= ' sidebar-item';
         $menuUrl = $this->url($menu['url']);
         if ($menuUrl == env('REQUEST_URI')) {
             if (isset($menu['htmlAttributes']['class'])) {
                 $menu['htmlAttributes']['class'] .= ' current';
             } else {
                 $menu['htmlAttributes']['class'] = 'current';
             }
         }
         $link = $this->Html->link($title, $menu['url'], $menu['htmlAttributes']);
         $liOptions = array();
         if (!empty($children) && $depth > 0) {
             $liOptions['class'] = ' dropdown-submenu';
         }
         $out .= $this->Html->tag('li', $link . $children, $liOptions);
     }
     return $this->Html->tag('ul', $out, $htmlAttributes);
 }
开发者ID:Demired,项目名称:CakeWX,代码行数:65,代码来源:CroogoHelper.php

示例4: getPrototypes

 public function getPrototypes()
 {
     $searchdirs['App'] = APP . 'View';
     $searchdirs['Basic'] = CakePlugin::path('Muffin');
     foreach (CakePlugin::loaded() as $plugin) {
         if ($plugin != 'Muffin') {
             $searchdirs[$plugin] = CakePlugin::path($plugin) . 'View';
         }
     }
     $configs = array();
     foreach ($searchdirs as $plugin => $searchdir) {
         $dir = new Folder($searchdir, false);
         if ($files = $dir->findRecursive('config.xml')) {
             $configs = Hash::merge($configs, array($plugin => $files));
         }
     }
     $prototypes = array();
     foreach ($configs as $plugin => $configFiles) {
         $i = 0;
         foreach ($configFiles as $configFile) {
             $xml = Xml::build($configFile);
             $items = $xml->xpath('menu/item');
             if (!is_array($items) || empty($items)) {
                 continue;
             }
             foreach ($items as $item) {
                 $item = Xml::toArray($item);
                 if (empty($item['item']['@label'])) {
                     continue;
                 }
                 if (!isset($item['item']['@id']) || empty($item['item']['@id'])) {
                     $id = ucfirst(Inflector::variable($item['item']['@label']));
                 } else {
                     $id = $item['item']['@id'];
                 }
                 $fields = array();
                 foreach ($item['item']['field'] as $key => $field) {
                     foreach ($field as $name => $value) {
                         $name = str_replace('@', '', $name);
                         $fields[$key][$name] = $value;
                     }
                 }
                 $prototypes[$plugin][$i]['Link']['id'] = $id;
                 $prototypes[$plugin][$i]['Link']['priority'] = !empty($item['item']['@priority']) ? $item['item']['@priority'] : '10';
                 $prototypes[$plugin][$i]['Link']['model'] = !empty($item['item']['@model']) ? $item['item']['@model'] : '';
                 $prototypes[$plugin][$i]['Link']['label'] = $item['item']['@label'];
                 $prototypes[$plugin][$i]['Field'] = $fields;
                 $i++;
             }
         }
     }
     foreach ($prototypes as $plugin => $section) {
         $prototypes[$plugin] = Hash::sort($section, '{n}.Link.priority', 'asc');
     }
     return $prototypes;
 }
开发者ID:mindforce,项目名称:cakephp-front-engine,代码行数:56,代码来源:LinksComponent.php

示例5: get_for_parent

 public function get_for_parent($parent, $page)
 {
     $options = array('conditions' => array('Comment.object_id' => $parent), 'limit' => 5, 'page' => $page, 'order' => 'Comment.created DESC', 'contain' => array('Author' => array('fields' => array('id', 'first_name', 'last_name', 'avatar'))));
     $comments = $this->Comment->find('all', $options);
     $comments = Hash::sort($comments, '{n}.Comment.created', 'asc');
     $view = new View($this, false);
     $view->layout = false;
     $view->set('comments', $comments);
     $response['html'] = $view->render('get_for_parent');
     $view = new View($this->controller, false);
     $view->layout = 'ajax';
     $view->set('data', $response);
     $html = $view->render('/Shared/json/data');
     echo $html;
     die;
 }
开发者ID:eripoll,项目名称:lebiplan,代码行数:16,代码来源:CommentsController.php

示例6: dashboards

 /**
  * Gets the dashboard markup
  *
  * @return string
  */
 public function dashboards()
 {
     $registered = Configure::read('Dashboards');
     $userId = AuthComponent::user('id');
     if (empty($userId)) {
         return '';
     }
     $columns = array(CroogoDashboard::LEFT => array(), CroogoDashboard::RIGHT => array(), CroogoDashboard::FULL => array());
     if (empty($this->Role)) {
         $this->Role = ClassRegistry::init('Users.Role');
         $this->Role->Behaviors->attach('Croogo.Aliasable');
     }
     $currentRole = $this->Role->byId($this->Layout->getRoleId());
     $cssSetting = $this->Layout->themeSetting('css');
     if (!empty($this->_View->viewVars['boxes_for_dashboard'])) {
         $boxesForLayout = Hash::combine($this->_View->viewVars['boxes_for_dashboard'], '{n}.DashboardsDashboard.alias', '{n}.DashboardsDashboard');
         $dashboards = array();
         $registeredUnsaved = array_diff_key($registered, $boxesForLayout);
         foreach ($boxesForLayout as $alias => $userBox) {
             if (isset($registered[$alias]) && $userBox['status']) {
                 $dashboards[$alias] = array_merge($registered[$alias], $userBox);
             }
         }
         $dashboards = Hash::merge($dashboards, $registeredUnsaved);
         $dashboards = Hash::sort($dashboards, '{s}.weight', 'ASC');
     } else {
         $dashboards = Hash::sort($registered, '{s}.weight', 'ASC');
     }
     foreach ($dashboards as $alias => $dashboard) {
         if ($currentRole != 'admin' && !in_array($currentRole, $dashboard['access'])) {
             continue;
         }
         $opt = array('alias' => $alias, 'dashboard' => $dashboard);
         Croogo::dispatchEvent('Croogo.beforeRenderDashboard', $this->_View, compact('alias', 'dashboard'));
         $dashboardBox = $this->_View->element('Extensions.admin/dashboard', $opt);
         Croogo::dispatchEvent('Croogo.afterRenderDashboard', $this->_View, compact('alias', 'dashboard', 'dashboardBox'));
         if ($dashboard['column'] === false) {
             $dashboard['column'] = count($columns[0]) <= count($columns[1]) ? CroogoDashboard::LEFT : CroogoDashboard::RIGHT;
         }
         $columns[$dashboard['column']][] = $dashboardBox;
     }
     $dashboardTag = $this->settings['dashboardTag'];
     $columnDivs = array(0 => $this->Html->tag($dashboardTag, implode('', $columns[CroogoDashboard::LEFT]), array('class' => $cssSetting['dashboardLeft'] . ' ' . $cssSetting['dashboardClass'], 'id' => 'column-0')), 1 => $this->Html->tag($dashboardTag, implode('', $columns[CroogoDashboard::RIGHT]), array('class' => $cssSetting['dashboardRight'] . ' ' . $cssSetting['dashboardClass'], 'id' => 'column-1')));
     $fullDiv = $this->Html->tag($dashboardTag, implode('', $columns[CroogoDashboard::FULL]), array('class' => $cssSetting['dashboardFull'] . ' ' . $cssSetting['dashboardClass'], 'id' => 'column-2'));
     return $this->Html->tag('div', $fullDiv, array('class' => $cssSetting['row'])) . $this->Html->tag('div', implode('', $columnDivs), array('class' => $cssSetting['row']));
 }
开发者ID:saydulk,项目名称:croogo,代码行数:51,代码来源:DashboardsHelper.php

示例7: subscriptions

 public function subscriptions()
 {
     /*
     //test for members operate after subscription change
     $this->BillingSubscription->Behaviors->load('Billing.Limitable', array(
     	'remoteModel' => 'GroupLimit',
     	'remoteField' => 'members_limit',
     	'scope' => 'owner_id',
     ));
     $this->BillingSubscription->membersOperate(71);
     exit();
     */
     $this->layout = 'profile_new';
     $this->BillingSubscription->recursive = -1;
     $subscriptions = $this->BillingSubscription->find('all', array('conditions' => array('BillingSubscription.user_id' => $this->currUser['User']['id'], 'BillingSubscription.active' => true)));
     //maybe buggy
     foreach ($subscriptions as $key => $subscription) {
         if (isset($subscription['BraintreeSubscription']->status) && $subscription['BraintreeSubscription']->status == 'Canceled') {
             unset($subscriptions[$key]);
             $sameGroupCount = Hash::extract($subscriptions, "{n}.BillingSubscription[group_id=" . $subscription['BillingSubscription']['group_id'] . "]");
             if (count($sameGroupCount) > 0) {
                 $this->BillingSubscription->cancel($subscription['BillingSubscription']['id']);
             }
         } else {
             $this->BillingGroup->recursive = -1;
             $this->BillingGroup->unbindTranslations();
             $subscriptions[$key] = Hash::merge($subscriptions[$key], $this->BillingGroup->find('first', array('conditions' => array('BillingGroup.id' => $subscription['BillingSubscription']['group_id']), 'callbacks' => false)));
             $this->BillingPlan->recursive = -1;
             $this->BillingPlan->unbindTranslations();
             $billingPlans = $this->BillingPlan->find('first', array('conditions' => array('BillingPlan.id' => $subscription['BillingSubscription']['plan_id'])));
             unset($billingPlans['BraintreePlan']);
             $subscriptions[$key] = Hash::merge($subscriptions[$key], $billingPlans);
         }
     }
     $this->BillingPlan->recursive = 0;
     $plans = $this->BillingPlan->find('all');
     foreach ($plans as $plan) {
         $subscribedInGroup = Hash::extract($subscriptions, "{n}.BillingSubscription[group_id=" . $plan['BillingPlan']['group_id'] . "]");
         if ($plan['BillingPlan']['free'] == true && empty($subscribedInGroup)) {
             $subscriptions[] = Hash::merge(array('BillingSubscription' => array('group_id' => $plan['BillingPlan']['group_id'], 'plan_id' => $plan['BillingPlan']['id'], 'user_id' => $this->currUser['User']['id'], 'remote_subscription_id' => null, 'remote_plan_id' => null, 'limit_value' => $plan['BillingPlan']['limit_value'], 'active' => true, 'status' => 'Active', 'expires' => null, 'created' => $this->currUser['User']['created'], 'modified' => $this->currUser['User']['modified'])), $plan);
         }
     }
     $subscriptions = Hash::sort($subscriptions, '{n}.BillingSubscription.group_id', 'asc');
     $transactions = Braintree_Transaction::search([Braintree_TransactionSearch::customerId()->is('konstruktor-' . $this->currUser['User']['id'])]);
     $this->set(compact('subscriptions', 'transactions', 'plans'));
 }
开发者ID:nilBora,项目名称:konstruktor,代码行数:46,代码来源:BillingUserController.php

示例8: _sorted

 /**
  * _sorted method
  * to sort a given array by key
  *
  * @param array $obj data array
  * @return array ソート後配列
  */
 protected function _sorted($obj)
 {
     // シーケンス順に並び替え、かつ、インデックス値は0オリジン連番に変更
     // ページ配列もないのでそのまま戻す
     if (!Hash::check($obj, 'RegistrationPage.{n}')) {
         return $obj;
     }
     $obj['RegistrationPage'] = Hash::sort($obj['RegistrationPage'], '{n}.page_sequence', 'asc', 'numeric');
     foreach ($obj['RegistrationPage'] as &$page) {
         if (Hash::check($page, 'RegistrationQuestion.{n}')) {
             $page['RegistrationQuestion'] = Hash::sort($page['RegistrationQuestion'], '{n}.question_sequence', 'asc', 'numeric');
             foreach ($page['RegistrationQuestion'] as &$question) {
                 if (Hash::check($question, 'RegistrationChoice.{n}')) {
                     $question['RegistrationChoice'] = Hash::sort($question['RegistrationChoice'], '{n}.choice_sequence', 'asc', 'numeric');
                 }
             }
         }
     }
     return $obj;
 }
开发者ID:NetCommons3,项目名称:Registrations,代码行数:27,代码来源:RegistrationsAppController.php

示例9: afterFind

 public function afterFind(Model $Model, $results, $primary = false)
 {
     if (!$primary) {
         return parent::afterFind($results, $primary);
     }
     foreach ($results as $key => $val) {
         if ($primary && array_key_exists($Model->alias, $val) && array_key_exists('id', $val[$Model->alias])) {
             $Comment = ClassRegistry::init('Social.Comment');
             // Getting total Comments
             $totalComments = $Comment->find('count', array('conditions' => array('Comment.object_id' => $val[$Model->alias]['id'], 'Comment.object' => $Model->alias)));
             $results[$key]['Commented']['total'] = $totalComments;
         }
         // Reorder the Comments by creation order
         // (even though we got them by descending order)
         if (array_key_exists('Comment', $val) && count($val['Comment'])) {
             $results[$key]['Comment'] = Hash::sort($val['Comment'], '{n}.created', 'asc');
         }
     }
     return $results;
 }
开发者ID:eripoll,项目名称:lebiplan,代码行数:20,代码来源:CommentableBehavior.php

示例10: getTimezone

 /**
  * タイムゾーンの取得
  *
  * @param Model $model Model ビヘイビア呼び出し元モデル
  * @param string $what タイムゾーン(地域)
  * @param string $country 2文字のISO3166-1互換の国コード
  * @return array タイムゾーン配列
  */
 public function getTimezone(Model $model, $what = null, $country = null)
 {
     $results = array();
     if (isset($country)) {
         $what = DateTimeZone::PER_COUNTRY;
     }
     if (!isset($what)) {
         $what = DateTimeZone::ALL;
     }
     $timezoneIdentifiers = DateTimeZone::listIdentifiers($what, $country);
     foreach ($timezoneIdentifiers as $timezone) {
         $date = new DateTime('now', new DateTimeZone($timezone));
         if ($timezone === 'UTC') {
             $timezoneValue = __d('data_types', '(UTC%s)', '') . ' ';
         } else {
             $timezoneValue = __d('data_types', '(UTC%s)', $date->format('P')) . ' ';
         }
         $results[] = array('key' => $timezone, 'name' => $timezoneValue . __d('data_types', $timezone), 'code' => $timezone, 'language_id' => Current::read('Language.id'), 'sort' => $date->format('Z'));
     }
     $results = Hash::sort($results, '{n}.sort', 'asc');
     return $results;
 }
开发者ID:NetCommons3,项目名称:DataTypes,代码行数:30,代码来源:TimezoneBehavior.php

示例11: view

 /**
  * view method
  *
  * @throws NotFoundException
  * @param string $id
  * @return void
  */
 public function view($id = null)
 {
     if (!$this->Question->exists($id)) {
         throw new NotFoundException(__('Invalid question'));
     }
     $options1 = array('conditions' => array('Question.' . $this->Question->primaryKey => $id), 'recursive' => 0);
     $value = $this->Question->find('first', $options1);
     $value['Question']['numVotos'] = $this->Question->VoteQuestion->getVotes($value['Question']['id']);
     if (AuthComponent::user()) {
         $user = $this->Auth->User('id');
         $votoQ = $this->Question->VoteQuestion->find('first', array('conditions' => array('question_id' => $value['Question']['id'], 'user_id' => $user), 'recursive' => -1, 'fields' => array('VoteQuestion.value')));
         if ($votoQ != null) {
             $value['Question']['voted'] = $votoQ['VoteQuestion']['value'];
         }
         $answers = $this->Question->Answer->getAnswersloged($value['Question']['id'], $user);
     } else {
         $answers = $this->Question->Answer->getAnswers($value['Question']['id']);
     }
     $this->set('question', $value);
     $this->set('answersV', Hash::sort($answers, '{n}.Answer.numVotos', 'desc'));
     $this->set('answersR', Hash::sort($answers, '{n}.Answer.date', 'desc'));
 }
开发者ID:hectorn,项目名称:Soru,代码行数:29,代码来源:QuestionsController.php

示例12: formatResponse

 protected function formatResponse($response)
 {
     $service_code = array('01' => 'UPS Next Day Air', '02' => 'UPS 2nd Day Air', '03' => 'UPS Ground', '07' => 'UPS Worldwide Express', '08' => 'UPS Worldwide Expedited', '11' => 'UPS Standard', '12' => 'UPS 3 Day Select', '13' => 'UPS Next Day Air Saver', '14' => 'UPS Next Day Air Early A.M.', '54' => 'UPS Worldwide Express Plus', '59' => 'UPS 2nd Day Air A.M.');
     $service_enabled = array('01', '02', '12', '03');
     $results = array();
     $i = 0;
     foreach ($response['RatingServiceSelectionResponse']['RatedShipment'] as $result) {
         $code = $result['Service']['Code'];
         if (in_array($code, $service_enabled)) {
             $results[$i]['ServiceCode'] = $code;
             $results[$i]['ServiceName'] = $service_code[$code];
             $results[$i]['TotalCharges'] = $result['TotalCharges']['MonetaryValue'];
             $i++;
         }
     }
     $results = Hash::sort($results, '{n}.TotalCharges', 'ASC');
     return $results;
 }
开发者ID:kingsj,项目名称:cakephp-shopping-cart,代码行数:18,代码来源:UpsComponent.php

示例13: read

 /**
  * Used to read records from the Datasource. The "R" in CRUD
  *
  * @param Model $model The model being read.
  * @param array $queryData An array of query data used to find the data you want
  * @return mixed
  */
 public function read(Model $model, $queryData = array(), $recursive = null)
 {
     if (!isset($model->records) || !is_array($model->records) || empty($model->records)) {
         $this->_requestsLog[] = array('query' => 'Model ' . $model->alias, 'error' => __('No records found in model.'), 'affected' => 0, 'numRows' => 0, 'took' => 0);
         return array($model->alias => array());
     }
     $startTime = microtime(true);
     $data = array();
     $i = 0;
     $limit = false;
     if ($recursive === null && isset($queryData['recursive'])) {
         $recursive = $queryData['recursive'];
     }
     if (!is_null($recursive)) {
         $_recursive = $model->recursive;
         $model->recursive = $recursive;
     }
     if (is_integer($queryData['limit']) && $queryData['limit'] > 0) {
         $limit = $queryData['page'] * $queryData['limit'];
     }
     foreach ($model->records as $pos => $record) {
         // Tests whether the record will be chosen
         if (!empty($queryData['conditions'])) {
             $queryData['conditions'] = (array) $queryData['conditions'];
             if (!$this->conditionsFilter($model, $record, $queryData['conditions'])) {
                 continue;
             }
         }
         $data[$i][$model->alias] = $record;
         $i++;
         // Test limit
         if ($limit !== false && $i == $limit && empty($queryData['order'])) {
             break;
         }
     }
     if ($queryData['fields'] === 'COUNT') {
         $this->_registerLog($model, $queryData, microtime(true) - $startTime, 1);
         if ($limit !== false) {
             $data = array_slice($data, ($queryData['page'] - 1) * $queryData['limit'], $queryData['limit'], false);
         }
         return array(array(array('count' => count($data))));
     }
     // Order
     if (!empty($queryData['order'])) {
         if (is_string($queryData['order'][0])) {
             $field = $queryData['order'][0];
             $alias = $model->alias;
             if (strpos($field, '.') !== false) {
                 list($alias, $field) = explode('.', $field, 2);
             }
             if ($alias === $model->alias) {
                 $sort = 'ASC';
                 if (strpos($field, ' ') !== false) {
                     list($field, $sort) = explode(' ', $field, 2);
                 }
                 if ($data) {
                     $data = Hash::sort($data, '{n}.' . $model->alias . '.' . $field, $sort);
                 }
             }
         }
     }
     // Limit
     if ($limit !== false) {
         $data = array_slice($data, ($queryData['page'] - 1) * $queryData['limit'], $queryData['limit'], false);
     }
     // Filter fields
     if (!empty($queryData['fields'])) {
         $listOfFields = array();
         foreach ((array) $queryData['fields'] as $field) {
             if (strpos($field, '.') !== false) {
                 list($alias, $field) = explode('.', $field, 2);
                 if ($alias !== $model->alias) {
                     continue;
                 }
             }
             $listOfFields[] = $field;
         }
         foreach ($data as $id => $record) {
             foreach ($record[$model->alias] as $field => $value) {
                 if (!in_array($field, $listOfFields)) {
                     unset($data[$id][$model->alias][$field]);
                 }
             }
         }
     }
     $this->_registerLog($model, $queryData, microtime(true) - $startTime, count($data));
     $_associations = $model->_associations;
     if ($model->recursive > -1) {
         foreach ($_associations as $type) {
             foreach ($model->{$type} as $assoc => $assocData) {
                 $linkModel = $model->{$assoc};
                 if ($model->useDbConfig == $linkModel->useDbConfig) {
                     $db = $this;
//.........这里部分代码省略.........
开发者ID:gourmet,项目名称:common,代码行数:101,代码来源:ArraySource.php

示例14: testMergeItems

 /**
  * testSyncWithSessionData
  *
  * @return void
  */
 public function testMergeItems()
 {
     $itemsBefore = $this->Cart->CartsItem->find('all', array('contain' => array(), 'conditions' => array('cart_id' => 'cart-1')));
     $itemCount = count($itemsBefore);
     $sessionData = array('Cart' => array(), 'CartsItem' => array(array('name' => 'CakePHP', 'model' => 'Item', 'foreign_key' => 'item-2', 'quantity' => 1, 'price' => 999.1), array('model' => 'Item', 'foreign_key' => 'item-1', 'quantity' => 2, 'price' => 12)));
     $result = $this->Cart->mergeItems('cart-1', $sessionData['CartsItem']);
     $this->assertEquals($result, 1);
     $itemsAfter = $this->Cart->CartsItem->find('all', array('contain' => array(), 'conditions' => array('cart_id' => 'cart-1')));
     // Sort the items by name so that we can be sure an item is at a certain index in the array
     $itemsAfter = Hash::sort($itemsAfter, '{n}.CartsItem.name', 'desc');
     $this->assertEquals(count($itemsAfter), $itemCount + 1);
     $this->assertEquals($itemsAfter[0]['CartsItem']['name'], 'Eizo Flexscan S2431W');
     $this->assertEquals($itemsAfter[0]['CartsItem']['quantity'], 2);
 }
开发者ID:mikebirch,项目名称:cakephp-cart-plugin,代码行数:19,代码来源:CartTest.php

示例15: admin_index

 /**
  * プラグインの一覧を表示する
  *
  * @return void
  * @access public
  */
 public function admin_index()
 {
     $this->Plugin->cacheQueries = false;
     $datas = $this->Plugin->find('all', array('order' => 'Plugin.priority'));
     if (!$datas) {
         $datas = array();
     }
     // プラグインフォルダーのチェックを行う。
     $pluginInfos = array();
     $paths = App::path('Plugin');
     foreach ($paths as $path) {
         $Folder = new Folder($path);
         $files = $Folder->read(true, true, true);
         foreach ($files[0] as $file) {
             $pluginInfos[basename($file)] = $this->_getPluginInfo($datas, $file);
         }
     }
     $pluginInfos = array_values($pluginInfos);
     // Hash::sortの為、一旦キーを初期化
     $pluginInfos = array_reverse($pluginInfos);
     // Hash::sortの為、逆順に変更
     $availables = $unavailables = array();
     foreach ($pluginInfos as $pluginInfo) {
         if (isset($pluginInfo['Plugin']['priority'])) {
             $availables[] = $pluginInfo;
         } else {
             $unavailables[] = $pluginInfo;
         }
     }
     //並び替えモードの場合はDBにデータが登録されていないプラグインを表示しない
     if (!empty($this->passedArgs['sortmode'])) {
         $sortmode = true;
         $pluginInfos = Hash::sort($availables, '{n}.Plugin.priority', 'asc', 'numeric');
     } else {
         $sortmode = false;
         $pluginInfos = array_merge(Hash::sort($availables, '{n}.Plugin.priority', 'asc', 'numeric'), $unavailables);
     }
     // 表示設定
     $this->set('datas', $pluginInfos);
     $this->set('corePlugins', Configure::read('BcApp.corePlugins'));
     $this->set('sortmode', $sortmode);
     if ($this->request->is('ajax')) {
         $this->render('ajax_index');
     }
     $this->subMenuElements = array('plugins');
     $this->pageTitle = 'プラグイン一覧';
     $this->help = 'plugins_index';
 }
开发者ID:kenz,项目名称:basercms,代码行数:54,代码来源:PluginsController.php


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