本文整理汇总了PHP中Hash::combine方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::combine方法的具体用法?PHP Hash::combine怎么用?PHP Hash::combine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::combine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
示例2: fetchList
/** Fetch a list of all matching items */
public function fetchList($field = 'title', $conditions = array(), $options = array())
{
$conditions = $this->prepare($conditions);
//Break out query and conditions and remember PDO is numbered from 1, not 0
if (!empty($conditions)) {
$query = $conditions[0];
unset($conditions[0]);
} else {
$query = "";
}
if (is_array($field)) {
$field1 = $field[0];
$field2 = $field[1];
} else {
$field1 = 'id';
$field2 = $field;
}
$f1 = $this->db->quotekey($field1);
$f2 = $this->db->quotekey($field2);
//Handle empty conditions
if (empty($query)) {
$query = "1=1";
}
$results = $this->db->exec("SELECT {$f1},{$f2} FROM {$this->name} WHERE " . $query, $conditions);
$output = Hash::combine($results, '{n}.' . $field1, '{n}.' . $field2);
return $output;
}
示例3: edit
public function edit($id = 0, $parent_id = '')
{
parent::edit($id, $parent_id);
// find all groups of params by category of product
$product = $this->Product->findById($this->parent_id);
$cat_id = $product['Product']['parent_id'];
$conditions = array('parent_id' => $cat_id, 'featured' => 1);
$order = 'sorting';
$aParamGroups = $this->ParamGroup->find('all', compact('conditions', 'order'));
$aParamGroups = Hash::combine($aParamGroups, '{n}.ParamGroup.id', '{n}');
$this->set('aFormGroups', $aParamGroups);
// find all params by groups
$conditions = array('object_type' => 'PMFormField', 'parent_id' => array_keys($aParamGroups));
$order = 'sorting';
$aParams = $this->PMFormField->find('all', compact('conditions', 'order'));
if ($aParams) {
$ids = Hash::extract($aParams, '{n}.PMFormField.id');
$aParams = Hash::combine($aParams, '{n}.PMFormField.id', '{n}', '{n}.PMFormField.parent_id');
}
$this->set('aForms', $aParams);
// get all values of params
$aValues = array();
if ($this->request->is(array('put', 'post'))) {
$aValues = $this->request->data('PMFormValue');
} elseif ($id) {
$aValues = $this->PMFormValue->getValues('ProductPackParam', $id);
}
$this->set('aValues', $aValues);
}
示例4: beforeRender
/**
* beforeRender
*
* @param Controller $controller Controller
* @return void
* @throws NotFoundException
*/
public function beforeRender(Controller $controller)
{
//RequestActionの場合、スキップする
if (!empty($controller->request->params['requested'])) {
return;
}
$this->controller = $controller;
$this->__prepare();
//pathからページデータ取得
if (isset($this->controller->viewVars['page'])) {
$page = $this->controller->viewVars['page'];
} else {
$this->Page = ClassRegistry::init('Pages.Page');
$page = $this->Page->getPageWithFrame(Current::read('Page.permalink'));
if (empty($page)) {
throw new NotFoundException();
}
}
if (Current::hasSettingMode() && Current::isSettingMode() && Current::permission('page_editable')) {
$this->controller->request->data['ContainersPage'] = Hash::combine($page, 'Container.{n}.type', 'Container.{n}.ContainersPage');
}
////cancelUrlをセット
//if (! isset($this->controller->viewVars['cancelUrl'])) {
// $this->controller->set('cancelUrl', $page['Page']['permalink']);
//}
//Pluginデータ取得
$pluginsRoom = ClassRegistry::init('PluginManager.PluginsRoom');
$plugins = $pluginsRoom->getPlugins($page['Page']['room_id'], Current::read('Language.id'));
//ページHelperにセット
$results = array('containers' => Hash::combine($page['Container'], '{n}.type', '{n}'), 'boxes' => Hash::combine($page['Box'], '{n}.id', '{n}', '{n}.container_id'), 'plugins' => $plugins);
$this->controller->helpers['Pages.PageLayout'] = $results;
}
示例5: afterFind
/**
* After find callback. Can be used to modify any results returned by find.
*
* @param Model $model Model using this behavior
* @param mixed $results The results of the find operation
* @param boolean $primary Whether this model is being queried directly (vs. being queried as an association)
*
* @return mixed An array value will replace the value of $results - any other value will be ignored.
*/
public function afterFind(Model $model, $results, $primary = false)
{
parent::afterFind($model, $results, $primary);
if ($primary && array_key_exists($model->alias, $results[0])) {
$arrObj = new ArrayObject($results);
$iterator = $arrObj->getIterator();
while ($iterator->valid()) {
$result = [];
if (isset($iterator->current()[$model->alias]) && count($iterator->current()[$model->alias]) > 0) {
$key = "{$model->alias}.{$this->settings[$model->alias]['key']}";
$value = "{$model->alias}.{$this->settings[$model->alias]['value']}";
$result = Hash::combine($iterator->current(), $key, $value);
}
if (!array_key_exists($this->settings[$model->alias]['key'], $iterator->current()[$model->alias]) && !array_key_exists($this->settings[$model->alias]['value'], $iterator->current()[$model->alias])) {
$results[$iterator->key()][$model->alias] = Hash::merge($iterator->current()[$model->alias], $result);
} else {
$results[$iterator->key()][$model->alias] = $result;
}
$iterator->next();
}
} elseif (array_key_exists($model->alias, $results)) {
$key = "{n}.{$model->alias}.{$this->settings[$model->alias]['key']}";
$value = "{n}.{$model->alias}.{$this->settings[$model->alias]['value']}";
$output = Hash::combine($results, $key, $value);
$results[$model->alias] = $output;
}
return $results;
}
示例6: index
/**
* index
*
* @return void
*/
public function index()
{
if (!$this->viewVars['blockId']) {
$this->autoRender = false;
return;
}
if (!$this->initLink(['linkFrameSetting'])) {
return;
}
$this->Categories->initCategories(true, '{n}.Category.id');
//条件
$conditions = $this->__setConditions();
//取得
$links = $this->Link->getLinks($conditions);
$links = Hash::combine($links, '{n}.Link.id', '{n}', '{n}.Category.id');
//Viewにセット
$results = array('links' => $links);
$results = $this->camelizeKeyRecursive($results);
$this->set($results);
//Tokenセット
$this->request->data = array('Frame' => array('id' => $this->viewVars['frameId']), 'Link' => array('id' => null, 'key' => null));
$tokenFields = Hash::flatten($this->request->data);
$hiddenFields = array('Frame.id');
$this->set('tokenFields', $tokenFields);
$this->set('hiddenFields', $hiddenFields);
}
示例7: index
public function index($parent_id = '')
{
// Process filter
if ($user_id = $this->request->query('user_id')) {
$this->paginate['conditions']['user_id'] = $user_id;
}
$status = $this->request->query('status');
if ($status != '') {
$this->paginate['conditions']['status'] = $status;
}
$id = $this->request->query('id');
if ($id) {
if (strpos($id, ',') !== false) {
$id = explode(',', $id);
}
$this->paginate['conditions']['id'] = $id;
}
$rowset = parent::index();
$ids = Hash::extract($rowset, '{n}.Order.id');
$orders = $this->Order->getOrder($ids);
$ids = Hash::extract($rowset, '{n}.Order.user_id');
$users = Hash::combine($this->User->findAllById($ids), '{n}.User.id', '{n}.User');
$aUserOptions = $this->User->find('list', array('fields' => array('id', 'username')));
$this->set(compact('orders', 'users', 'aUserOptions'));
}
示例8: testUpdateRssReaderItems
/**
* Expect RssReaderItem->updateRssReaderItems()
*
* @return void
*/
public function testUpdateRssReaderItems()
{
$rssReaderId = 1;
//コンテンツの公開権限true
$this->RssReader->Behaviors->attach('Publishable');
$this->RssReader->Behaviors->Publishable->setup($this->RssReader, ['contentPublishable' => true]);
//データ生成
$rssReader = $this->RssReader->find('first', array('recursive' => -1, 'conditions' => array('id' => $rssReaderId)));
$url = APP . 'Plugin' . DS . 'RssReaders' . DS . 'Test' . DS . 'Fixture' . DS . 'rss_v1.xml';
$xmlData = $this->RssReaderItem->serializeXmlToArray($url);
$xmlData = Hash::insert($xmlData, '{n}.rss_reader_id', $rssReaderId);
$data = array('RssReader' => $rssReader['RssReader'], 'RssReaderItem' => $xmlData);
//登録処理実行
$this->RssReaderItem->updateRssReaderItems($data);
//期待値の生成
$expected = $data;
//RssReaderのテスト実施
$now = date('Y-m-d H:i:s');
$rssReader = $this->RssReader->find('first', array('recursive' => -1, 'conditions' => array('id' => $rssReaderId)));
$date = new DateTime($rssReader['RssReader']['modified']);
$this->assertTrue($date->format('Y-m-d H:i:s') <= $now);
//RssReaderItemのテスト実施
$result = $this->RssReaderItem->find('all', array('fields' => array('id', 'rss_reader_id', 'title', 'summary', 'link', 'last_updated', 'serialize_value'), 'recursive' => -1, 'conditions' => array('rss_reader_id' => $rssReaderId)));
$result = Hash::combine($result, '{n}.RssReaderItem.id', '{n}.RssReaderItem');
$result = Hash::remove($result, '{n}.id');
$this->_assertArray(null, $expected['RssReaderItem'], array_values($result));
}
示例9: answerChoiceValidation
/**
* answerValidation 登録内容の正当性
*
* @param object &$model use model
* @param array $data Validation対象データ
* @param array $question 登録データに対応する項目
* @param array $allAnswers 入力された登録すべて
* @return bool
*/
public function answerChoiceValidation(&$model, $data, $question, $allAnswers)
{
if (!in_array($question['question_type'], $this->_choiceValidateType)) {
return true;
}
if (!isset($model->data['RegistrationAnswer']['answer_values'])) {
return true;
}
// 項目に設定されている選択肢を配列にまとめる
$list = Hash::combine($question['RegistrationChoice'], '{n}.id', '{n}.key');
$ret = true;
// 選択された選択肢IDすべてについて調査する
$choiceIds = array_keys($model->data['RegistrationAnswer']['answer_values']);
foreach ($choiceIds as $choiceId) {
// 選択されたIDは、ちゃんと用意されている選択肢の中のひとつであるか
if ($choiceId != '' && !Validation::inList(strval($choiceId), $list)) {
$ret = false;
$model->validationErrors['answer_value'][] = __d('registrations', 'Invalid choice');
}
// チェックされている選択肢が「その他」の項目である場合は
$choice = Hash::extract($question['RegistrationChoice'], '{n}[key=' . $choiceId . ']');
if ($choice && $choice[0]['other_choice_type'] != RegistrationsComponent::OTHER_CHOICE_TYPE_NO_OTHER_FILED) {
// 具体的なテキストが書かれていないといけない
if (empty($model->data['RegistrationAnswer']['other_answer_value'])) {
$ret = false;
$model->validationErrors['answer_value'][] = __d('registrations', 'Please enter something, if you chose the other item');
}
}
}
return $ret;
}
示例10: edit
/**
* edit
*
* @return void
*/
public function edit()
{
if (!$this->initLink()) {
return;
}
$this->Categories->initCategories(true);
$this->Paginator->settings = array('Link' => array('order' => array('LinkOrder.weight' => 'asc'), 'conditions' => array('Link.block_id' => $this->viewVars['blockId'], 'Link.is_latest' => true), 'limit' => -1));
$links = $this->Paginator->paginate('Link');
$links = Hash::combine($links, '{n}.LinkOrder.weight', '{n}', '{n}.Category.id');
//POST処理
$data = array();
if ($this->request->isPost()) {
//登録処理
$data = $this->data;
$this->LinkOrder->saveLinkOrders($data);
//validationError
if ($this->NetCommons->handleValidationError($this->LinkOrder->validationErrors)) {
//リダイレクト
$this->redirect(NetCommonsUrl::backToPageUrl());
return;
}
}
$data = Hash::merge(array('links' => $links), $data);
$results = $this->camelizeKeyRecursive($data);
$this->set($results);
}
示例11: _findCustomAjax
protected function _findCustomAjax($state, $query, $results = array())
{
if ($state == 'before') {
return $query;
}
return Hash::combine($results, 'TestDevice.id', 'TestDevice.name');
}
示例12: beforeFilter
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter()
{
parent::beforeFilter();
$userRoles = $this->UserRole->find('all', array('recursive' => -1, 'conditions' => array($this->UserRole->alias . '.language_id' => Current::read('Language.id'))));
$this->set('userRolesName', Hash::combine($userRoles, '{n}.UserRole.key', '{n}.UserRole.name'));
$this->set('userRolesDescription', Hash::combine($userRoles, '{n}.UserRole.key', '{n}.UserRole.description'));
}
示例13: checkboxPluginsRoom
/**
* Outputs room plugins
*
* @param string $roomId rooms.id
* @param array $attributes The HTML attributes of the select element.
* @return string Formatted CHECKBOX element
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
*/
public function checkboxPluginsRoom($roomId, $attributes = array())
{
$html = '';
//Modelの呼び出し
$this->Plugin = ClassRegistry::init('PluginManager.Plugin');
$this->PluginsRoom = ClassRegistry::init('PluginManager.PluginsRoom');
//findのoptionsセット
$findOptions = array('fields' => array($this->Plugin->alias . '.key', $this->Plugin->alias . '.name', $this->PluginsRoom->alias . '.room_id', $this->PluginsRoom->alias . '.plugin_key'), 'conditions' => array($this->Plugin->alias . '.type' => Plugin::PLUGIN_TYPE_FOR_FRAME, $this->Plugin->alias . '.language_id' => Configure::read('Config.languageId')), 'order' => array($this->Plugin->alias . '.weight' => 'asc'));
//データ取得
if (isset($attributes['all']) && $attributes['all']) {
$plugins = $this->Plugin->find('all', Hash::merge($findOptions, array('recursive' => -1, 'joins' => array(array('table' => $this->PluginsRoom->table, 'alias' => $this->PluginsRoom->alias, 'type' => 'LEFT', 'conditions' => array($this->Plugin->alias . '.key' . ' = ' . $this->PluginsRoom->alias . ' .plugin_key', $this->PluginsRoom->alias . '.room_id' => $roomId))))));
unset($attributes['all']);
} else {
$plugins = $this->PluginsRoom->find('all', Hash::merge($findOptions, array('recursive' => 0, 'conditions' => array($this->PluginsRoom->alias . '.room_id' => $roomId))));
}
//チェックボックスの設定
$options = Hash::combine($plugins, '{n}.Plugin.key', '{n}.Plugin.name');
$this->_View->request->data['Plugin']['key'] = array_keys($options);
foreach (array_keys($this->_View->request->data['Plugin']['key']) as $index) {
$html .= $this->Form->hidden('Plugin.' . $index . '.key');
}
$defaults = Hash::extract($plugins, '{n}.PluginsRoom[room_id=' . $roomId . ']');
$defaults = array_values(Hash::combine($defaults, '{n}.plugin_key', '{n}.plugin_key'));
$this->_View->request->data['PluginsRoom']['plugin_key'] = $defaults;
$html .= $this->Form->select('PluginsRoom.plugin_key', $options, Hash::merge($attributes, array('multiple' => 'checkbox')));
return $html;
}
示例14: l10n
/**
* Javascript strings Localization wrapper for Drupal
* @param $locale
*/
public function l10n($locale)
{
$strings = DruniqueAPIUtil::call('page_blocks.json', ['tag' => 'javascript'], $locale);
$strings = Hash::combine($strings, '{s}.title', '{s}.content');
$this->set(['result' => $strings, '_serialize' => 'result']);
$this->response->cache('-1 minute', '+1 days');
}
示例15: getValues
public function getValues($object_type, $parent_id)
{
$lang = $this->getLang();
$conditions = compact('lang', 'object_type', 'parent_id');
$rows = $this->find('all', compact('conditions'));
return Hash::combine($rows, '{n}.PMFormValue.field_id', '{n}.PMFormValue.value');
}