本文整理汇总了PHP中Hash::flatten方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::flatten方法的具体用法?PHP Hash::flatten怎么用?PHP Hash::flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::flatten方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
public function check($modelName)
{
$this->loadModel($modelName);
$transformedFields = array();
foreach ($this->request->query['data'] as $association => $fields) {
$Model = $association === $modelName ? $this->{$modelName} : $this->{$modelName}->{$association};
if (!$Model) {
continue;
}
$transformedFields[$Model->name] = $this->__transformFields($Model, array($Model->alias), $fields);
}
$ChangeEvent = new CakeEvent('Form.change', $this, array('fields' => $transformedFields));
$this->getEventManager()->dispatch($ChangeEvent);
$fields = array();
foreach (Hash::flatten($ChangeEvent->data['fields']) as $key => $value) {
$fieldParts = explode('.', $key);
$lastPart = array_pop($fieldParts);
if (is_numeric($lastPart)) {
$lastPart = array_pop($fieldParts);
$fields[implode('.', $fieldParts)][$lastPart][] = $value;
} else {
$fields[implode('.', $fieldParts)][$lastPart] = $value;
}
}
$this->set('fields', $fields);
$this->set('_serialize', array('fields'));
}
示例2: config
/**
* Sets a configuration variable into this action
*
* If called with no arguments, all configuration values are
* returned.
*
* $key is interpreted with dot notation, like the one used for
* Configure::write()
*
* If $key is string and $value is not passed, it will return the
* value associated with such key.
*
* If $key is an array and $value is empty, then $key will
* be interpreted as key => value dictionary of settings and
* it will be merged directly with $this->settings
*
* If $key is a string, the value will be inserted in the specified
* slot as indicated using the dot notation
*
* @param mixed $key
* @param mixed $value
* @param boolean $merge
* @return mixed|CrudAction
*/
public function config($key = null, $value = null, $merge = true)
{
if ($key === null && $value === null) {
return $this->_settings;
}
if ($value === null) {
if (is_array($key)) {
if ($merge) {
$this->_settings = Hash::merge($this->_settings, $key);
} else {
foreach (Hash::flatten($key) as $k => $v) {
$this->_settings = Hash::insert($this->_settings, $k, $v);
}
}
return $this;
}
return Hash::get($this->_settings, $key);
}
if (is_array($value)) {
if ($merge) {
$value = array_merge((array) Hash::get($this->_settings, $key), $value);
} else {
foreach ($value as $k => $v) {
$this->_settings = Hash::insert($this->_settings, $k, $v);
}
}
}
$this->_settings = Hash::insert($this->_settings, $key, $value);
return $this;
}
示例3: 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);
}
示例4: upload
/**
* add method
*
* @return void
*/
public function upload()
{
//CakeLog::debug('add() $this->params=' . print_r($this->params, true));
//TODO: 権限チェック
if ($this->request->isPost()) {
CakeLog::debug('upload() $this->data=' . print_r($this->data, true));
$data = $this->data;
$data['File'] = $this->FileUpload->upload($this);
CakeLog::debug('upload() $data=' . print_r($data, true));
if (!($result = $this->FileModel->saveFile($data))) {
//TODO: Error
return;
}
$result[$this->FileModel->alias]['readableSize'] = CakeNumber::toReadableSize($result[$this->FileModel->alias]['size']);
$this->NetCommons->renderJson($result);
} else {
$ret = $this->FileModel->find('first', ['recursive' => -1]);
CakeLog::debug('FileController::upload() $ret=' . print_r($ret, true));
$this->layout = isset($this->params->query['layout']) ? $this->params->query['layout'] : 'FileDevs.modal';
$this->set('tabIndex', 0);
$postMaxSize = CakeNumber::fromReadableSize(ini_get('post_max_size'));
$uploadMaxFilesize = CakeNumber::fromReadableSize(ini_get('upload_max_filesize'));
$this->set('maxUploadSize', CakeNumber::toReadableSize($postMaxSize > $uploadMaxFilesize ? $uploadMaxFilesize : $postMaxSize));
$this->set('maxDiskSize', CakeNumber::toReadableSize(1073741824));
$this->set('useDiskSize', CakeNumber::toReadableSize(50000000));
$this->request->data = ['File' => ['role_type' => $this->params->query['roleType'] ? $this->params->query['roleType'] : ''], 'FilesPlugin' => ['plugin_key' => $this->params->query['pluginKey'] ? $this->params->query['pluginKey'] : ''], 'FilesRoom' => ['room_id' => isset($this->params->query['roomId']) ? (int) $this->params->query['roomId'] : 0], 'FilesUser' => ['user_id' => isset($this->params->query['userId']) ? (int) $this->params->query['userId'] : (int) $this->Auth->user('id')]];
$tokenFields = Hash::flatten($this->request->data);
$hiddenFields = ['File.role_type', 'FilesPlugin.plugin_key', 'FilesRoom.room_id', 'FilesUser.user_id'];
// $this->set('tokenFields', $tokenFields);
// $this->set('hiddenFields', $hiddenFields);
// $this->set('unlockField', 'File.' . FileModel::INPUT_NAME);
$this->set('fileOptions', $this->request->data);
$this->set('accept', $this->params->query['accept']);
}
}
示例5: filterConditions
public function filterConditions($query = null)
{
if ($query === null) {
$request = $this->Controller->request;
$query = $request->is('post') ? $request->data : $this->Controller->passedArgs;
}
$ignore = array('page', 'limit', 'sort', 'direction');
$conditions = array();
$query = Hash::flatten($query);
foreach ($query as $k => $v) {
if (strlen(trim($v)) < 1) {
continue;
}
if (in_array($k, $ignore)) {
continue;
}
// check for multiple searches
$searches = explode(';', $v);
foreach ($searches as $search) {
// check for operator e.g. "like: My search term"
$op = explode(':', $search);
if (count($op) == 1) {
$term = $op[0];
if (is_numeric($term) || is_bool($term)) {
$op = 'eq';
} else {
$op = 'like';
}
} else {
list($op, $term) = $op;
}
$term = trim($term);
//TODO sanitize user input
switch ($op) {
case "like":
case "%":
$conditions[] = sprintf("%s LIKE '%%%s%%'", $k, $term);
break;
case "llike":
case "l%":
$conditions[] = sprintf("%s LIKE '%s%%'", $k, $term);
break;
case "rlike":
case "r%":
$conditions[] = sprintf("%s LIKE '%%%s'", $k, $term);
break;
case "equal":
case "eq":
case "==":
$conditions[$k] = $term;
break;
}
}
}
return $conditions;
}
示例6: __construct
/**
* Constructor
*
* @param array $error list of validation errors
* @param integer $code code to report to client
* @return void
*/
public function __construct($errors, $code = 412)
{
$this->_validationErrors = array_filter($errors);
$flat = Hash::flatten($this->_validationErrors);
$errorCount = $this->_validationErrorCount = count($flat);
$this->message = __dn('crud', 'A validation error occurred', '%d validation errors occurred', $errorCount, array($errorCount));
if ($errorCount === 1) {
$code = $this->_deriveRuleSpecific($this->_validationErrors, $code);
}
parent::__construct($this->message, $code);
}
示例7: correction_callback_builder
private static function correction_callback_builder($assigns, $ptn)
{
return function ($data) use($assigns, $ptn) {
$str = implode("\n", array_filter(Hash::flatten($data), function ($value) {
return is_string($value);
}));
preg_match_all($ptn, $str, $matches, PREG_SET_ORDER);
$value = array_sum(array_map(function ($match) {
return $match[2] == '-' ? -$match[3] : $match[3];
}, $matches));
return $value ? $value : null;
};
}
示例8: addModelData
/**
* CSVファイルに追加する連想配列データ
*
* コンストラクタに$options['header']でカラム名が定義されてればそのカラムだけをCSVに追加する
*
* @param array $data モデルの連想配列データ
* @return void
*/
public function addModelData(array $data)
{
$header = Hash::get($this->_options, 'header', false);
if ($header) {
// ヘッダ指定されてれば指定されたカラムだけ出力
$fields = array_keys($header);
$line = array();
foreach ($fields as $field) {
$line[] = Hash::get($data, $field, '');
}
$this->add($line);
} else {
// ヘッダ未指定なら全カラム出力
$line = Hash::flatten($data);
$this->add($line);
}
}
示例9: update
/**
* Update all the settings. Validation rules are also configured here.
*
* @param array $data Associative array of all settings to save.
*
* @return boolean
*/
function update($data = array())
{
$flat_data = Hash::flatten($data);
$this->set($flat_data);
if ($this->validates()) {
$list = $this->find('list', array('fields' => array('key', 'id')));
foreach ($flat_data as $key => $value) {
if (array_key_exists($key, $list)) {
// This setting already exists in the DB, just update it.
$this->id = $list[$key];
$this->saveField('value', $value);
} else {
// This is a new setting, add a new entry.
$this->create();
$this->save(array('key' => $key, 'value' => $value));
}
}
return true;
}
return false;
}
示例10: _array_to_csv
private function _array_to_csv($array)
{
$csv = array();
// Flatten the given array
foreach ($array as $k => $item) {
$csv[$k] = is_array($item) ? Set::flatten($item) : $item;
}
// Create the Column names.
// This has to be done seperate because we don't have all of them beforehand.
$csvString = array('headers' => array());
foreach ($csv as $h => $lines) {
foreach ($lines as $header => $line) {
if (array_search($header, $csvString['headers']) === false && !empty($header)) {
$csvString['headers'][] = $header;
}
}
}
// Create the values this will also check for commas in the values
foreach ($csv as $c => $lines) {
$csvString['values'][$c] = '';
foreach ($csvString['headers'] as $h) {
if (isset($lines[$h])) {
if (is_array($lines[$h])) {
Hash::flatten($lines[$h], '|');
}
$csvString['values'][$c] .= is_int($lines[$h]) ? $lines[$h] . ',' : '"' . $this->_stipIllegalChars($lines[$h]) . '",';
// was a conflict, can probably delete // $csvString['values'][$c] .= is_int($lines[$h]) ? $lines[$h] . ',' : '"' . str_replace(',', '' , $lines[$h]) . '",';
} else {
$csvString['values'][$c] .= ',';
}
}
}
$output = '';
foreach ($csvString['headers'] as $i => $header) {
$csvString['headers'][$i] = '"' . $header . '"';
}
$output .= implode(',', str_replace('.', '_', $csvString['headers'])) . "\r\n";
$output .= implode("\r\n", $csvString['values']);
return $output;
}
示例11: __processFiles
/**
* Process $_FILES
*
* @author Anthony Putignano <anthony@wizehive.com>
* @since 1.0
* @return void
*/
protected function __processFiles()
{
if (!empty($_FILES)) {
$dimensions = Hash::dimensions($_FILES);
if ($dimensions === 2) {
$this->Controller->request->data = Hash::merge($this->Controller->request->data, $_FILES);
} else {
foreach ($_FILES as $key => $data) {
$parsed = array();
foreach (array('name', 'type', 'tmp_name', 'error') as $file_key) {
$flattened = Hash::flatten($_FILES[$key][$file_key]);
foreach ($flattened as $flat_key => $flat_value) {
$reflattened = $key . '.' . $flat_key . '.' . $file_key;
$parsed[$reflattened] = $flat_value;
}
}
$parsed = Hash::expand($parsed);
$this->Controller->request->data = Hash::merge($this->Controller->request->data, $parsed);
}
}
}
}
示例12: admin_index
/**
* Returns an array of server specific options
*/
public function admin_index()
{
$globalOptions = $this->Option->find('all');
$serverID = Configure::read('server_id');
$serverOptions = $this->ServerOption->getServerOptions($serverID);
$changedServerOptions = array();
foreach ($serverOptions as $k => $v) {
$changedServerOptions[$v['ServerOption']['name']] = $v['ServerOption']['value'];
}
$globalOptions = Hash::flatten($globalOptions);
//Replace global option values with server option values
foreach ($changedServerOptions as $k => $v) {
$key = array_search($k, $globalOptions, true);
if ($key) {
$key = explode('.', $key);
$n = $key[0];
foreach ($globalOptions as $i) {
$globalOptions[$n . '.Option.value'] = $v;
}
}
}
$serverOptions = Hash::expand($globalOptions);
//Remove locked options
foreach ($serverOptions as $k => $v) {
if ($v['Option']['locked'] == 1) {
unset($serverOptions[$k]);
}
}
//pr($serverOptions);
if ($this->request->is('requested')) {
return $serverOptions;
} else {
$this->set('serverOptions', $serverOptions);
}
$serverName = $this->getServerName($serverID);
$this->set('serverName', $serverName);
return null;
}
示例13: _handleNoRoute
/**
* A special fallback method that handles URL arrays that cannot match
* any defined routes.
*
* @param array $url A URL that didn't match any routes
* @return string A generated URL for the array
* @see Router::url()
*/
protected static function _handleNoRoute($url)
{
$named = $args = array();
$skip = array_merge(array('bare', 'action', 'controller', 'plugin', 'prefix'), self::$_prefixes);
$keys = array_values(array_diff(array_keys($url), $skip));
$count = count($keys);
// Remove this once parsed URL parameters can be inserted into 'pass'
for ($i = 0; $i < $count; $i++) {
$key = $keys[$i];
if (is_numeric($keys[$i])) {
$args[] = $url[$key];
} else {
$named[$key] = $url[$key];
}
}
list($args, $named) = array(Hash::filter($args), Hash::filter($named));
foreach (self::$_prefixes as $prefix) {
$prefixed = $prefix . '_';
if (!empty($url[$prefix]) && strpos($url['action'], $prefixed) === 0) {
$url['action'] = substr($url['action'], strlen($prefixed) * -1);
break;
}
}
if (empty($named) && empty($args) && (!isset($url['action']) || $url['action'] === 'index')) {
$url['action'] = null;
}
$urlOut = array_filter(array($url['controller'], $url['action']));
if (isset($url['plugin'])) {
array_unshift($urlOut, $url['plugin']);
}
foreach (self::$_prefixes as $prefix) {
if (isset($url[$prefix])) {
array_unshift($urlOut, $prefix);
break;
}
}
$output = implode('/', $urlOut);
if (!empty($args)) {
$output .= '/' . implode('/', array_map('rawurlencode', $args));
}
if (!empty($named)) {
foreach ($named as $name => $value) {
if (is_array($value)) {
$flattend = Hash::flatten($value, '%5D%5B');
foreach ($flattend as $namedKey => $namedValue) {
$output .= '/' . $name . "%5B{$namedKey}%5D" . self::$_namedConfig['separator'] . rawurlencode($namedValue);
}
} else {
$output .= '/' . $name . self::$_namedConfig['separator'] . rawurlencode($value);
}
}
}
return $output;
}
示例14: testFlattenInfiniteLoop
/**
* Test that flattening a large complex set doesn't loop forever.
*
* @return void
*/
public function testFlattenInfiniteLoop()
{
$data = array('Order.ASI' => '0', 'Order.Accounting' => '0', 'Order.Admin' => '0', 'Order.Art' => '0', 'Order.ArtChecker' => '0', 'Order.Canned' => '0', 'Order.Customer_Tags' => '', 'Order.Embroidery' => '0', 'Order.Item.0.Product.style_number' => 'a11222', 'Order.Item.0.Product.slug' => 'a11222', 'Order.Item.0.Product._id' => '4ff8b8d3d7bbe8ad30000000', 'Order.Item.0.Product.Color.slug' => 'kelly_green', 'Order.Item.0.Product.ColorSizes.0.Color.color' => 'Sport Grey', 'Order.Item.0.Product.ColorSizes.0.Color.slug' => 'sport_grey', 'Order.Item.0.Product.ColorSizes.1.Color.color' => 'Kelly Green', 'Order.Item.0.Product.ColorSizes.1.Color.slug' => 'kelly_green', 'Order.Item.0.Product.ColorSizes.2.Color.color' => 'Orange', 'Order.Item.0.Product.ColorSizes.2.Color.slug' => 'orange', 'Order.Item.0.Product.ColorSizes.3.Color.color' => 'Yellow Haze', 'Order.Item.0.Product.ColorSizes.3.Color.slug' => 'yellow_haze', 'Order.Item.0.Product.brand' => 'OUTER BANKS', 'Order.Item.0.Product.style' => 'T-shirt', 'Order.Item.0.Product.description' => 'uhiuhuih oin ooi ioo ioio', 'Order.Item.0.Product.sizes.0.Size.qty' => '', 'Order.Item.0.Product.sizes.0.Size.size' => '0-3mo', 'Order.Item.0.Product.sizes.0.Size.id' => '38', 'Order.Item.0.Product.sizes.1.Size.qty' => '', 'Order.Item.0.Product.sizes.1.Size.size' => '3-6mo', 'Order.Item.0.Product.sizes.1.Size.id' => '39', 'Order.Item.0.Product.sizes.2.Size.qty' => '78', 'Order.Item.0.Product.sizes.2.Size.size' => '6-9mo', 'Order.Item.0.Product.sizes.2.Size.id' => '40', 'Order.Item.0.Product.sizes.3.Size.qty' => '', 'Order.Item.0.Product.sizes.3.Size.size' => '6-12mo', 'Order.Item.0.Product.sizes.3.Size.id' => '41', 'Order.Item.0.Product.sizes.4.Size.qty' => '', 'Order.Item.0.Product.sizes.4.Size.size' => '12-18mo', 'Order.Item.0.Product.sizes.4.Size.id' => '42', 'Order.Item.0.Art.imprint_locations.0.id' => 2, 'Order.Item.0.Art.imprint_locations.0.name' => 'Left Chest', 'Order.Item.0.Art.imprint_locations.0.imprint_type.id' => 7, 'Order.Item.0.Art.imprint_locations.0.imprint_type.type' => 'Embroidery', 'Order.Item.0.Art.imprint_locations.0.art' => '', 'Order.Item.0.Art.imprint_locations.0.num_colors' => 3, 'Order.Item.0.Art.imprint_locations.0.description' => 'Wooo! This is Embroidery!!', 'Order.Item.0.Art.imprint_locations.0.lines.0' => 'Platen', 'Order.Item.0.Art.imprint_locations.0.lines.1' => 'Logo', 'Order.Item.0.Art.imprint_locations.0.height' => 4, 'Order.Item.0.Art.imprint_locations.0.width' => 5, 'Order.Item.0.Art.imprint_locations.0.stitch_density' => 'Light', 'Order.Item.0.Art.imprint_locations.0.metallic_thread' => true, 'Order.Item.0.Art.imprint_locations.1.id' => 4, 'Order.Item.0.Art.imprint_locations.1.name' => 'Full Back', 'Order.Item.0.Art.imprint_locations.1.imprint_type.id' => 6, 'Order.Item.0.Art.imprint_locations.1.imprint_type.type' => 'Screenprinting', 'Order.Item.0.Art.imprint_locations.1.art' => '', 'Order.Item.0.Art.imprint_locations.1.num_colors' => 3, 'Order.Item.0.Art.imprint_locations.1.description' => 'Wooo! This is Screenprinting!!', 'Order.Item.0.Art.imprint_locations.1.lines.0' => 'Platen', 'Order.Item.0.Art.imprint_locations.1.lines.1' => 'Logo', 'Order.Item.0.Art.imprint_locations.2.id' => 26, 'Order.Item.0.Art.imprint_locations.2.name' => 'HS - JSY Name Below', 'Order.Item.0.Art.imprint_locations.2.imprint_type.id' => 9, 'Order.Item.0.Art.imprint_locations.2.imprint_type.type' => 'Names', 'Order.Item.0.Art.imprint_locations.2.description' => 'Wooo! This is Names!!', 'Order.Item.0.Art.imprint_locations.2.sizes.S.0.active' => 1, 'Order.Item.0.Art.imprint_locations.2.sizes.S.0.name' => 'Benjamin Talavera', 'Order.Item.0.Art.imprint_locations.2.sizes.S.0.color' => 'Red', 'Order.Item.0.Art.imprint_locations.2.sizes.S.0.height' => '3', 'Order.Item.0.Art.imprint_locations.2.sizes.S.0.layout' => 'Arched', 'Order.Item.0.Art.imprint_locations.2.sizes.S.0.style' => 'Classic', 'Order.Item.0.Art.imprint_locations.2.sizes.S.1.active' => 0, 'Order.Item.0.Art.imprint_locations.2.sizes.S.1.name' => 'Rishi Narayan', 'Order.Item.0.Art.imprint_locations.2.sizes.S.1.color' => 'Cardinal', 'Order.Item.0.Art.imprint_locations.2.sizes.S.1.height' => '4', 'Order.Item.0.Art.imprint_locations.2.sizes.S.1.layout' => 'Straight', 'Order.Item.0.Art.imprint_locations.2.sizes.S.1.style' => 'Team US', 'Order.Item.0.Art.imprint_locations.2.sizes.M.0.active' => 1, 'Order.Item.0.Art.imprint_locations.2.sizes.M.0.name' => 'Brandon Plasters', 'Order.Item.0.Art.imprint_locations.2.sizes.M.0.color' => 'Red', 'Order.Item.0.Art.imprint_locations.2.sizes.M.0.height' => '3', 'Order.Item.0.Art.imprint_locations.2.sizes.M.0.layout' => 'Arched', 'Order.Item.0.Art.imprint_locations.2.sizes.M.0.style' => 'Classic', 'Order.Item.0.Art.imprint_locations.2.sizes.M.1.active' => 0, 'Order.Item.0.Art.imprint_locations.2.sizes.M.1.name' => 'Andrew Reed', 'Order.Item.0.Art.imprint_locations.2.sizes.M.1.color' => 'Cardinal', 'Order.Item.0.Art.imprint_locations.2.sizes.M.1.height' => '4', 'Order.Item.0.Art.imprint_locations.2.sizes.M.1.layout' => 'Straight', 'Order.Item.0.Art.imprint_locations.2.sizes.M.1.style' => 'Team US', 'Order.Job.0._id' => 'job-1', 'Order.Job.0.type' => 'screenprinting', 'Order.Job.0.postPress' => 'job-2', 'Order.Job.1._id' => 'job-2', 'Order.Job.1.type' => 'embroidery', 'Order.Postpress' => '0', 'Order.PriceAdjustment.0._id' => 'price-adjustment-1', 'Order.PriceAdjustment.0.adjustment' => '-20', 'Order.PriceAdjustment.0.adjustment_type' => 'percent', 'Order.PriceAdjustment.0.type' => 'grand_total', 'Order.PriceAdjustment.1.adjustment' => '20', 'Order.PriceAdjustment.1.adjustment_type' => 'flat', 'Order.PriceAdjustment.1.min-items' => '10', 'Order.PriceAdjustment.1.type' => 'min-items', 'Order.PriceAdjustment.1._id' => 'another-test-adjustment', 'Order.Purchasing' => '0', 'Order.QualityControl' => '0', 'Order.Receiving' => '0', 'Order.ScreenPrinting' => '0', 'Order.Stage.art_approval' => 0, 'Order.Stage.draft' => 1, 'Order.Stage.quote' => 1, 'Order.Stage.order' => 1, 'Order.StoreLiason' => '0', 'Order.Tag_UI_Email' => '', 'Order.Tags' => '', 'Order._id' => 'test-2', 'Order.add_print_location' => '', 'Order.created' => '2011-Dec-29 05:40:18', 'Order.force_admin' => '0', 'Order.modified' => '2012-Jul-25 01:24:49', 'Order.name' => 'towering power', 'Order.order_id' => '135961', 'Order.slug' => 'test-2', 'Order.title' => 'test job 2', 'Order.type' => 'ttt');
$expanded = Hash::expand($data);
$flattened = Hash::flatten($expanded);
$this->assertEquals($data, $flattened);
}
示例15: __setupViewParameters
/**
* __setupViewParameters method
*
* @param array $questionnaire アンケートデータ
* @param string $backUrl BACKボタン押下時の戻るパス
* @return void
*/
private function __setupViewParameters($questionnaire, $backUrl)
{
if (isset($questionnaire['Questionnaire']['origin_id'])) {
$isPublished = $this->Questionnaire->find('count', array('conditions' => array('is_active' => true, 'origin_id' => $questionnaire['Questionnaire']['origin_id'])));
} else {
$isPublished = 0;
}
// エラーメッセージはページ、質問、選択肢要素のそれぞれの場所に割り当てる
$flatError = Hash::flatten($this->qValidationErrors);
$newFlatError = array();
foreach ($flatError as $key => $val) {
if (preg_match('/^(.*)\\.(.*)\\.(.*)$/', $key, $matches)) {
$newFlatError[$matches[1] . '.error_messages.' . $matches[2] . '.' . $matches[3]] = $val;
}
}
$questionnaire = Hash::merge($questionnaire, Hash::expand($newFlatError));
$this->set('jsQuestionnaire', $this->camelizeKeyRecursive($this->_changeBooleansToNumbers($this->_sorted($questionnaire))));
$this->set('backUrl', $backUrl . $this->viewVars['frameId']);
$this->set('questionTypeOptions', $this->Questionnaires->getQuestionTypeOptionsWithLabel());
$this->set('newPageLabel', __d('questionnaires', 'page'));
$this->set('newQuestionLabel', __d('questionnaires', 'New Question'));
$this->set('newChoiceLabel', __d('questionnaires', 'new choice'));
$this->set('newChoiceColumnLabel', __d('questionnaires', 'new column choice'));
$this->set('newChoiceOtherLabel', __d('questionnaires', 'other choice'));
$this->set('isPublished', $isPublished);
}