本文整理汇总了PHP中Set::flatten方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::flatten方法的具体用法?PHP Set::flatten怎么用?PHP Set::flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set::flatten方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: admin_edit
function admin_edit($id = null)
{
if (!empty($this->request->data)) {
App::uses('Set', 'Utility');
if (empty($this->request->data['Role']['alias'])) {
App::uses('Inflector', 'Utility');
$this->request->data['Role']['alias'] = Inflector::slug($this->request->data['Role']['name'], '-');
}
$dataCapabilities = Set::flatten($this->request->data['RoleCapability']);
$this->Role->save($this->request->data);
$defaultCapabilities = $this->Role->Capability->find('list', array('conditions' => array('role_id' => $this->Role->id, 'args' => null), 'fields' => array('id', 'capability')));
$delete = array();
foreach ($defaultCapabilities as $id => $capability) {
if (empty($dataCapabilities[$capability])) {
$delete[] = $id;
}
}
foreach ($dataCapabilities as $capability => $ok) {
if ($ok && !in_array($capability, array_values($defaultCapabilities))) {
$this->Role->Capability->create();
$this->Role->Capability->save(array('capability' => $capability, 'role_id' => $this->Role->id));
}
}
if (!empty($delete)) {
$this->Role->Capability->deleteAll(array('Capability.id' => $delete));
}
$this->redirect(array($this->Role->id));
}
$this->request->data = $this->Role->findById($id);
}
示例2: checkNewMail
public function checkNewMail($account)
{
$mails = $this->find('all', array('conditions' => Set::flatten(array($this->alias => $account))));
// @todo save to the db here
// @todo delete messages from server here
return $mails;
}
示例3: frontend_css
public function frontend_css()
{
$this->layout = 'ajax';
$this->response->type('css');
$css = $this->Event->trigger('requireCssToLoad');
$this->set('css', array_filter(array_values(Set::flatten($css))));
}
示例4: importElements
private function importElements()
{
App::import('Core', 'GummFolder');
$Folder = new GummFolder(GUMM_LAYOUT_ELEMENTS);
$elementFiles = $Folder->findRecursive('.*\\.php');
$Folder->cd(GUMM_LAYOUT_ELEMENTS_SINGLE);
$elementFiles = array_merge($elementFiles, $Folder->findRecursive('.*\\.php'));
$availableElements = Set::flatten(Set::classicExtract(array_values(Configure::read('Data.BuilderElements')), '{n}.elements'));
$elementsAvaialbleMap = array();
foreach ($elementFiles as $layoutElementFullPath) {
$basename = basename($layoutElementFullPath, '.php');
if (in_array($basename, $availableElements)) {
$elementsAvaialbleMap[$basename] = $layoutElementFullPath;
}
}
foreach ($availableElements as $basename) {
if (isset($elementsAvaialbleMap[$basename])) {
require_once $elementsAvaialbleMap[$basename];
$className = Inflector::camelize($basename) . 'LayoutElement';
$settings = array();
if ($this->post) {
$settings['postId'] = $this->post->ID;
}
$obj = new $className($settings);
$this->elementsAvailable[Inflector::underscore($basename)] = $obj;
}
}
}
示例5: checkHabtmConditions
/**
* We only need to change the bind if the HABTM model is present
* somewhere in the conditions.
* To make array keys easier to search for a match, we flatten
* and implode the keys it into a string.
*/
private function checkHabtmConditions($Model, $query)
{
if (empty($query['conditions'])) {
$query['conditions'] = array();
}
$searchableConditions = implode('.', Set::flatten(array_keys($query['conditions'])));
return (bool) strpos($searchableConditions, $this->settings[$Model->alias]['habtmModel']);
}
示例6: checkHabtmConditions
/**
* checkHabtmConditions
* We only need to change the bind if the HABTM model is present
* somewhere in the conditions.
* To make array keys easier to search for a match, we flatten
* and implode the keys it into a string.
*
* @param mixed $model_name model
* @param mixed $query query
*
* @access private
* @return void
*/
private function checkHabtmConditions($model_name, $query)
{
if (empty($query['conditions'])) {
return false;
}
$searchableConditions = implode('.', Set::flatten(array_keys($query['conditions'])));
return strpos($searchableConditions, $model_name) !== false;
}
示例7: getFontsVendor
public function getFontsVendor($fontFamily)
{
$vendor = 'browser';
$browserFonts = Set::flatten(Set::reverse($this->getBrowserFontsList()->items));
if (!in_array($fontFamily, $browserFonts)) {
$vendor = 'google';
}
return $vendor;
}
示例8: findTargetsWith
/**
* Finds all targets that match a query.
*
* @param string $query
* @param integer $collection_id
* @return array
*/
public function findTargetsWith($query = '', $collection_id = null)
{
$conditions = array();
$conditions['Target.collection_id'] = $collection_id;
$query = trim($query);
if (mb_strlen($query) > 0) {
$conditions['OR'] = Set::flatten(array('Target' => array('display_name LIKE' => "%{$query}%", 'display_description LIKE' => "%{$query}%")));
}
$result = $this->Target->find('all', array('conditions' => $conditions, 'recursive' => -1));
return $result;
}
示例9: testValidation
/**
* Test Validation
*
* @return void
*/
public function testValidation()
{
$data1 = array('empty' => '', 'garbage' => 'trash', 'postal' => 'abcd', 'dimensions' => array('inches' => array('height' => 42.5, 'width' => 11.75, 'depth' => 3.25, 'girth' => 'a')));
$data2 = array('dimensions' => array('inches' => array('height' => 42.23)));
$this->MetaThing->id = 1;
$result1 = $this->MetaThing->invalidMeta($data1);
$this->assertCount(5, Set::flatten($result1));
$this->assertFalse($this->MetaThing->setMeta($data1));
$this->assertTrue($this->MetaThing->setMeta($data2));
$this->assertFalse($this->MetaThing->setMeta('dimensions.inches.height', 'forty-two'));
$this->assertCount(1, $this->MetaThing->validationErrorsMeta());
}
示例10: formErrorSummary
/**
* Tạo thông báo lỗi ở form
*
* @param mixed $validationErrs Mảng lỗi
* @param string $class Class thẻ sẽ chứa thông báo
* @return string HTML thông báo lỗi
*/
public static function formErrorSummary($validationErrs = NULL, $class = "n_error")
{
$html = "";
if (is_array($validationErrs) && !empty($validationErrs)) {
$_validationErrs = Set::flatten($validationErrs);
$html .= '<div class="' . $class . '">';
foreach ($_validationErrs as $err) {
$html .= "<p>{$err}</p>";
}
$html .= '</div>';
}
return $html;
}
示例11: test_global_activity
function test_global_activity()
{
$User =& ClassRegistry::init('User');
$user = $User->find_by_id_logged(2);
$events = $this->Issue->find_events('issues', $user, false, false, array());
# Issue of a private project
$this->assertTrue(in_array(1, Set::flatten(Set::extract('{n}.{n}.{n}.Issue.id', $events))));
$this->assertTrue(in_array(2, Set::flatten(Set::extract('{n}.{n}.{n}.Issue.id', $events))));
$this->assertTrue(in_array(3, Set::flatten(Set::extract('{n}.{n}.{n}.Issue.id', $events))));
$this->assertTrue(in_array(4, Set::flatten(Set::extract('{n}.{n}.{n}.Issue.id', $events))));
$this->assertTrue(in_array(5, Set::flatten(Set::extract('{n}.{n}.{n}.Issue.id', $events))));
$this->assertTrue(in_array(6, Set::flatten(Set::extract('{n}.{n}.{n}.Issue.id', $events))));
$this->assertTrue(in_array(7, Set::flatten(Set::extract('{n}.{n}.{n}.Issue.id', $events))));
}
示例12: conferenceValid
public function conferenceValid($confdata)
{
//$this->loadModel('Conference');
$conf = ClassRegistry::init('Conference');
if (!$conf->validates($confdata)) {
//debug($this->Conference->validationErrors); //displays array info
foreach (Set::flatten($conf->validationErrors) as $field => $message) {
//debug("field: ".$field." message: ".$message);
$conf->invalidate($field, $message);
}
return false;
} else {
return true;
}
}
示例13: transport
/**
* Displays a handful of useful debugging messages
*
* @param Mailer_Transport $transport
* @return null
* @access public
*/
public function transport(Mailer_Transport $transport)
{
if ($this->debug) {
$this->out("\r\nTransport");
$this->hr();
$this->debug('Class: ' . get_class($transport));
$this->out("\r\nSettings");
$this->hr();
foreach (Set::flatten($transport->settings) as $key => $value) {
$this->debug($key . ': ' . $value);
}
$this->out('');
$this->in('Press enter to continue...');
}
}
示例14: beforeFind
/**
* Before find callback
*
* @param object $model Model using this behavior
* @param array $query Data used to execute this query, i.e. conditions, order, etc.
* @return bool True if the operation should continue, false if it should abort
*/
public function beforeFind($model, $query)
{
$result = parent::beforeFind($model, $query);
if (empty($this->settings[$model->alias]['find']) || isset($query['defaultable']) && $query['defaultable'] === false || $result === false) {
return $result;
} else {
if (is_array($result)) {
$query = $result;
}
}
$Db = ConnectionManager::getDataSource($model->useDbConfig);
$defaultConditions = array();
foreach ($this->settings[$model->alias]['find'] as $field => $fieldValue) {
$fields = array($Db->name($model->alias) . '.' . $Db->name($field), $Db->name($field), $model->alias . '.' . $field, $field);
$include = true;
if (!empty($query['conditions'])) {
foreach (Set::flatten((array) $query['conditions']) as $key => $value) {
$condition = is_numeric($key) ? $value : $key;
foreach ($fields as $field) {
if (preg_match('/^((not|or)\\.)?' . preg_quote($field) . '/i', $condition) || preg_match('/^((not|or)\\.)?' . preg_quote($model->alias . '.' . $field) . '/i', $condition) || preg_match('/[^A-Z0-9_]+' . preg_quote($field) . '[^A-Z0-9_]+/i', $condition) || preg_match('/[^A-Z0-9_]+' . preg_quote($model->alias . '.' . $field) . '[^A-Z0-9_]+/i', $condition)) {
$include = false;
break;
}
}
if (!$include) {
break;
}
}
}
if ($include) {
$defaultConditions[$model->alias . '.' . $field] = $fieldValue;
}
}
if (!empty($defaultConditions)) {
if (empty($query['conditions'])) {
$query['conditions'] = array();
} else {
if (!is_array($query['conditions'])) {
$query['conditions'] = (array) $query['conditions'];
}
}
$query['conditions'] = array_merge($query['conditions'], $defaultConditions);
$result = $query;
}
return $result;
}
示例15: __construct
function __construct()
{
App::import('Lib', 'SparkForm.SparkFormConfig');
$preprocessors = SparkFormConfig::load('preprocessors');
$preprocessors = array_merge($this->preprocessors, (array) $preprocessors);
$customTypes = SparkFormConfig::load('customTypes');
$customTypes = array_merge($this->customTypes, (array) $customTypes);
$callbacklists = array(&$customTypes, &$preprocessors);
foreach ($callbacklists as &$list) {
$flat = Set::flatten($list, '.');
$final = array();
foreach ($flat as $key => $funct) {
if (!is_array($funct)) {
$keys = array_filter(explode('.', $key), array($this, '_notNumeric'));
$helper = null;
$plugin = null;
if (count($keys) == 1) {
$helper = $keys[0];
} elseif (count($keys) > 1) {
$plugin = array_shift($keys);
$helper = array_shift($keys);
}
$callback = array('funct' => $funct);
if ($helper) {
$fullName = $helper;
$callback['helper'] = $helper;
if ($plugin) {
$callback['plugin'] = $plugin;
$fullName = $plugin . '.' . $helper;
}
if (!in_array($fullName, $this->helpers)) {
$this->helpers[] = $fullName;
}
}
$final[$funct] = $callback;
} elseif (is_numeric($key)) {
$final[$funct['funct']] = $funct;
} else {
$final[$key] = $funct;
}
}
$list = $final;
}
$this->preprocessors = $preprocessors;
$this->customTypes = $customTypes;
}