/** * {@inheritdoc} * * @param string $key The identifier to write to. * @param array $data The data to dump. * @return bool True on success or false on failure. */ public function dump($key, array $data) { $data = Hash::flatten($data); array_walk($data, [$this, '_persist'], $key); array_filter($data); return (bool) $data; }
/** * Wrap Moxiemanager's api.php in a controller action. * * @return void */ public function api() { try { $pluginPath = Plugin::path('CkTools'); define('MOXMAN_CLASSES', $pluginPath . 'src/Lib/moxiemanager/classes'); define('MOXMAN_PLUGINS', $pluginPath . 'src/Lib/moxiemanager/plugins'); define('MOXMAN_ROOT', $pluginPath . 'src/Lib/moxiemanager'); define('MOXMAN_API_FILE', __FILE__); $appConfig = Configure::read('CkTools.moxiemanager'); Configure::load('CkTools.moxiemanager'); $moxieManagerConfig = Configure::read('moxiemanager'); if (is_array($appConfig)) { $moxieManagerConfig = Hash::merge($moxieManagerConfig, $appConfig); } $GLOBALS['moxieManagerConfig'] = $moxieManagerConfig; require_once MOXMAN_CLASSES . '/MOXMAN.php'; $context = \MOXMAN_Http_Context::getCurrent(); $pluginManager = \MOXMAN::getPluginManager(); foreach ($pluginManager->getAll() as $plugin) { if ($plugin instanceof \MOXMAN_Http_IHandler) { $plugin->processRequest($context); } } } catch (Exception $e) { \MOXMAN_Exception::printException($e); } return $this->render(false, false); }
/** * Merge Configuration * * @param string $key Configure key * @param array $config New configuration to merge * @param return array Array of merged configurations */ public static function mergeConfig($key, $config) { $values = Configure::read($key); $values = Hash::merge((array) $values, $config); Configure::write($key, $values); return $values; }
/** * Index method * * @return void */ public function index() { if ($this->request->is(['post', 'put'])) { $settings = $this->Settings->find('all')->all(); $settings = $this->Settings->patchEntities($settings, $this->request->data()['Setting']); $result = $this->Settings->connection()->transactional(function () use($settings) { foreach ($settings as $setting) { $result = $this->Settings->save($setting, ['atomic' => false]); if (!$result) { return false; } } return true; }); if ($result) { $settings = $this->Settings->find()->combine('path', 'value')->toArray(); ksort($settings); $settings = Hash::expand($settings); Settings::dump('config', 'default', $settings); $this->Flash->success('The settings has been saved.'); $this->redirect(['action' => 'index']); } else { $this->Flash->error('The settings could not be saved. Please, try again.'); } } $settings = $this->Settings->find('extended')->find('editable')->toArray(); $this->set('settings', $settings['editable']); }
/** * Creates a Transport instance * * @param array $config transport-specific configuration options */ public function __construct(array $config) { $config = Hash::merge(Configure::read('Notifications.transports.sms'), $config); parent::__construct($config); $keys = Configure::read('Notifications.transports.sms'); $this->_smsClient = new \WebSmsCom_Client($keys['username'], $keys['password'], $keys['gateway']); }
/** * Initialization hook method. * * @return void */ public function initialize() { parent::initialize(); if (Configure::read('Swagger')) { $this->config = Hash::merge(static::$defaultConfig, Configure::read('Swagger')); } }
/** * Get format permission data. * * @param $acos * @param array $aros * @param array $options * @return array * @SuppressWarnings("unused") */ public function format($acos, array $aros, array $options = []) { $options = Hash::merge(['perms' => true, 'model' => 'Roles'], $options); $permissions = []; /** @var \Acl\Model\Entity\Aco $aco */ foreach ($acos as $aco) { $acoId = $aco->get('id'); $acoAlias = $aco->get('alias'); $path = $this->Acos->find('path', ['for' => $acoId]); $path = join('/', collection($path)->extract('alias')->toArray()); $data = ['path' => $path, 'alias' => $acoAlias, 'depth' => substr_count($path, '/')]; foreach ($aros as $key => $aroId) { $role = ['foreign_key' => $key, 'model' => $options['model']]; if ($options['perms']) { $isCheck = $this->check($role, $path); if ($key == Role::ADMIN_ID || $isCheck) { $data['roles'][$key] = 1; } else { $data['roles'][$key] = (int) $isCheck; } } $permissions[$acoId] = new Data($data); } } return $permissions; }
/** * Callback for Routing.beforeDispatch event. * * @param \Cake\Event\Event $event The event instance. * * @return \Cake\Network\Response Response instance. */ public function beforeDispatch(Event $event) { $request = $event->data['request']; $response = $event->data['response']; $path = urldecode($request->url); if (Configure::read('Glide.secureUrls')) { SignatureFactory::create(Security::salt())->validateRequest('/' . $path, $request->query); } $server = ServerFactory::create(Configure::read('Glide.serverConfig')); $cache = Configure::read('Glide.cache'); if ($cache) { $timestamp = $server->getSource()->getTimestamp($server->getSourcePath($path)); $response->modified($timestamp); if (!$response->checkNotModified($request)) { $response = $server->getImageResponse($path, $request->query); } $response->cache($timestamp, $cache); } else { $response = $server->getImageResponse($path, $request->query); } $headers = Hash::filter((array) Configure::read('Glide.headers')); foreach ($headers as $key => $value) { $response->header($key, $value); } return $response; }
/** * Resets user token * * @param string $reference User username or email * @param array $options checkActive, sendEmail, expiration * * @return string * @throws InvalidArgumentException * @throws UserNotFoundException * @throws UserAlreadyActiveException */ public function resetToken($reference, array $options = []) { if (empty($reference)) { throw new InvalidArgumentException(__d('CakeDC/Users', "Reference cannot be null")); } $expiration = Hash::get($options, 'expiration'); if (empty($expiration)) { throw new InvalidArgumentException(__d('CakeDC/Users', "Token expiration cannot be empty")); } $user = $this->_getUser($reference); if (empty($user)) { throw new UserNotFoundException(__d('CakeDC/Users', "User not found")); } if (Hash::get($options, 'checkActive')) { if ($user->active) { throw new UserAlreadyActiveException(__d('CakeDC/Users', "User account already validated")); } $user->active = false; $user->activation_date = null; } if (Hash::get($options, 'ensureActive')) { if (!$user['active']) { throw new UserNotActiveException(__d('CakeDC/Users', "User not active")); } } $user->updateToken($expiration); $saveResult = $this->_table->save($user); $template = !empty($options['emailTemplate']) ? $options['emailTemplate'] : 'CakeDC/Users.reset_password'; if (Hash::get($options, 'sendEmail')) { $this->Email->sendResetPasswordEmail($saveResult, null, $template); } return $saveResult; }
/** * Sets a JSON REST API option. * * @param mixed $path * @param mixed $value */ public function setJraOption($path, $value) { if (!isset($this->jraOptions)) { $this->jraOptions = []; } $this->jraOptions = Hash::insert($this->jraOptions, $path, $value); }
public function loadDataCsv($fileName, $column_list, $delimiter = ",", $array_encoding = 'utf8', $import_encoding = 'sjis-win') { //保存をするのでモデルを読み込み try { $data = array(); $csvData = array(); $file = fopen($fileName, "r"); while ($data = $this->fgetcsv_reg($file, 65536, $delimiter)) { //CSVファイルを","区切りで配列に mb_convert_variables($array_encoding, $import_encoding, $data); $csvData[] = $data; } $i = 0; foreach ($csvData as $line) { $this_data = array(); foreach ($column_list as $k => $v) { if (isset($line[$k])) { //先頭と末尾の"を削除 $b = $line[$k]; //カラムの数だけセット $this_data = Hash::merge($this_data, array($v => $b)); } else { $this_data = Hash::merge($this_data, array($v => '')); } } $data[$i] = $this_data; $i++; } } catch (\Exception $e) { return false; } return $data; }
/** * Returns the basepath for the current field/data combination. * If a `path` is specified in settings, then that will be used as * the replacement pattern * * @return string * @throws LogicException if a replacement is not valid for the current dataset */ public function basepath() { $defaultPath = 'webroot{DS}files{DS}{model}{DS}{field}{DS}'; $path = Hash::get($this->settings, 'path', $defaultPath); if (strpos($path, '{primaryKey}') !== false) { if ($this->entity->isNew()) { throw new LogicException('{primaryKey} substitution not allowed for new entities'); } if (is_array($this->table->primaryKey())) { throw new LogicException('{primaryKey} substitution not valid for composite primary keys'); } } $replacements = ['{primaryKey}' => $this->entity->get($this->table->primaryKey()), '{model}' => $this->table->alias(), '{table}' => $this->table->table(), '{field}' => $this->field, '{year}' => date("Y"), '{month}' => date("m"), '{day}' => date("d"), '{time}' => time(), '{microtime}' => microtime(), '{DS}' => DIRECTORY_SEPARATOR]; if (preg_match_all("/{field-value:(\\w+)}/", $path, $matches)) { foreach ($matches[1] as $field) { $value = $this->entity->get($field); if ($value === null) { throw new LogicException(sprintf('Field value for substitution is missing: %s', $field)); } elseif (!is_scalar($value)) { throw new LogicException(sprintf('Field value for substitution must be a integer, float, string or boolean: %s', $field)); } elseif (strlen($value) < 1) { throw new LogicException(sprintf('Field value for substitution must be non-zero in length: %s', $field)); } $replacements[sprintf('{field-value:%s}', $field)] = $value; } } return str_replace(array_keys($replacements), array_values($replacements), $path); }
/** * Parses a list of arguments into an array of indexes * * @param array $arguments A list of arguments being parsed * @return array **/ public function parseIndexes($arguments) { $indexes = []; $arguments = $this->validArguments($arguments); foreach ($arguments as $field) { preg_match('/^(\\w*)(?::(\\w*))?(?::(\\w*))?(?::(\\w*))?/', $field, $matches); $field = $matches[1]; $type = Hash::get($matches, 2); $indexType = Hash::get($matches, 3); $indexName = Hash::get($matches, 4); if (in_array($type, ['primary', 'primary_key'])) { $indexType = 'primary'; } if ($indexType === null) { continue; } $indexUnique = false; if ($indexType == 'primary') { $indexUnique = true; } elseif ($indexType == 'unique') { $indexUnique = true; } $indexName = $this->getIndexName($field, $indexType, $indexName, $indexUnique); if (empty($indexes[$indexName])) { $indexes[$indexName] = ['columns' => [], 'options' => ['unique' => $indexUnique, 'name' => $indexName]]; } $indexes[$indexName]['columns'][] = $field; } return $indexes; }
/** * Index method * * @return \Cake\Network\Response|null */ public function index() { // Get all tag IDs associated with members $tags = $this->Tags->find('all')->find('forMembers')->select(['id', 'parent_id'])->toArray(); $memberTagIds = Hash::extract($tags, '{n}.id'); // Get all of those tags' parent IDs $tagParentIds = Hash::extract($tags, '{n}.parent_id'); // Collect all parent tags that lead from member tags to the tag tree root $tagIds = $memberTagIds; while (!empty($tagParentIds)) { // Search for unrecognized parents $parentsToFind = []; foreach ($tagParentIds as $tagId) { if (!in_array($tagId, $tagIds)) { $parentsToFind[] = $tagId; } } if (empty($parentsToFind)) { break; } // Add these parent tag IDs to the full list $additionalTags = $this->Tags->find('all')->where([function ($exp, $q) use($parentsToFind) { return $exp->in('id', $parentsToFind); }])->select(['id', 'parent_id'])->order(['Tags.name' => 'ASC'])->toArray(); $tagIds = array_merge(Hash::extract($additionalTags, '{n}.id'), $tagIds); // Set up next round of searching for parents $tagParentIds = Hash::extract($additionalTags, '{n}.parent_id'); } $tags = $this->Tags->find('all')->find('threaded')->where([function ($exp, $q) use($tagIds) { return $exp->in('id', $tagIds); }])->select(['id', 'name', 'slug', 'parent_id'])->order(['Tags.name' => 'ASC'])->all(); $this->set(['pageTitle' => 'Art Tags', 'tags' => $tags, 'memberTagIds' => $memberTagIds]); }
/** * Update remember me and determine redirect url after user identified * @param array $user user data after identified * @param bool $socialLogin is social login * @return array */ protected function _afterIdentifyUser($user, $socialLogin = false) { $socialKey = Configure::read('Users.Key.Session.social'); if (!empty($user)) { $this->request->session()->delete($socialKey); $this->Auth->setUser($user); $event = $this->dispatchEvent(UsersAuthComponent::EVENT_AFTER_LOGIN); if (is_array($event->result)) { return $this->redirect($event->result); } $url = $this->Auth->redirectUrl(); return $this->redirect($url); } else { $message = __d('Users', 'Username or password is incorrect'); if ($socialLogin) { $socialData = $this->request->session()->read($socialKey); $socialDataEmail = null; if (!empty($socialData->info)) { $socialDataEmail = Hash::get((array) $socialData->info, Configure::read('data_email_key')); } $postedEmail = $this->request->data(Configure::read('Users.Key.Data.email')); if (Configure::read('Users.Email.required') && empty($socialDataEmail) && empty($postedEmail)) { return $this->redirect(['controller' => 'Users', 'action' => 'socialEmail']); } $message = __d('Users', 'There was an error associating your social network account'); } $this->Flash->error($message, 'default', [], 'auth'); } }
/** * @param int $id * @param array $options * * @return array */ public function neighbors($id, array $options = []) { if (!$id) { throw new InvalidArgumentException("The 'id' key is required for find('neighbors')"); } $sortField = $this->_table->hasField('created') ? 'created' : $this->_table->primaryKey(); $defaults = ['sortField' => $this->_table->alias() . '.' . $sortField]; $options += $defaults; $normalDirection = !empty($options['reverse']) ? false : true; $sortDirWord = $normalDirection ? ['ASC', 'DESC'] : ['DESC', 'ASC']; $sortDirSymb = $normalDirection ? ['>=', '<='] : ['<=', '>=']; if (empty($options['value'])) { $data = $this->_table->find('all', ['conditions' => [$this->_table->primaryKey() => $id]])->first(); list($model, $sortField) = pluginSplit($options['sortField']); $options['value'] = $data[$sortField]; } $return = []; $findOptions = []; if (isset($options['contain'])) { $findOptions['contain'] = $options['contain']; } if (!empty($options['fields'])) { $findOptions['fields'] = $options['fields']; } $findOptions['conditions'][$this->_table->alias() . '.' . $this->_table->primaryKey() . ' !='] = $id; $prevOptions = $findOptions; $prevOptions['conditions'] = Hash::merge($prevOptions['conditions'], [$options['sortField'] . ' ' . $sortDirSymb[1] => $options['value']]); $prevOptions['order'] = [$options['sortField'] => $sortDirWord[1]]; $return['prev'] = $this->_table->find('all', $prevOptions)->first(); $nextOptions = $findOptions; $nextOptions['conditions'] = Hash::merge($nextOptions['conditions'], [$options['sortField'] . ' ' . $sortDirSymb[0] => $options['value']]); $nextOptions['order'] = [$options['sortField'] => $sortDirWord[0]]; $return['next'] = $this->_table->find('all', $nextOptions)->first(); return $return; }
/** * Create and render navigation menu. * * @param array $items * @param string|int $key * @param array $options * @param int $level * @return string */ public function render($key, array $items = [], array $options = [], $level = 1) { $_options = ['active' => 'active', 'type' => self::MENU_TYPE_COLLAPSE, 'menuAttr' => ['class' => 'menu', 'id' => 'level-' . $level]]; $counter = 0; $out = ''; $options = Hash::merge($_options, $options); $menuAttr = $options['menuAttr']; $type = $options['type']; $sorted = Hash::sort($items, '{s}.weight', 'ASC'); foreach ($sorted as $link) { $child = ''; $counter = $counter + 1; $title = h($link['title']); $liAttr = $this->_setLiAttr($counter, $link, $options); $linkAttr = $this->_setLinkAttr($counter, $link, $options); if (count($link['children']) > 0) { list($child, $link, $linkAttr, $title, $level) = $this->_createChild($key, $link, $level, $linkAttr, $type); } $title = $this->_createIcon($title, $link); $linkItem = $this->link($title, $link['url'], $linkAttr); $out .= $this->tag('li', $linkItem . $child, $liAttr); $counter++; } return $this->tag('ul', $out, $menuAttr); }
/** * Class Constructor * * Merges defaults with * - Configure::read(Meta) * - Helper options * - viewVars _meta * in that order (the latter trumps) * * @param array $options */ public function __construct(View $View, $options = []) { parent::__construct($View, $options); $configureMeta = (array) Configure::read('Meta'); if (Configure::read('Meta.robots') && is_array(Configure::read('Meta.robots'))) { $configureMeta['robots'] = Hash::merge($this->meta['robots'], Configure::read('Meta.robots')); } $this->meta = $configureMeta + $this->meta; if (!empty($options['robots']) && is_array($options['robots'])) { $options['robots'] = Hash::merge($this->meta['robots'], $options['robots']); } $this->meta = $options + $this->meta; if (!empty($this->_View->viewVars['_meta'])) { $viewVarsMeta = (array) $this->_View->viewVars['_meta']; if (!empty($viewVarsMeta['robots']) && is_array($viewVarsMeta['robots'])) { $viewVarsMeta['robots'] = Hash::merge($this->meta['robots'], $viewVarsMeta['robots']); } $this->meta = $viewVarsMeta + $this->meta; } if ($this->meta['charset'] === null) { // By default include this $this->meta['charset'] = true; } if ($this->meta['icon'] === null) { // By default include this $this->meta['icon'] = true; } if ($this->meta['title'] === null) { $this->meta['title'] = __(Inflector::humanize(Inflector::underscore($this->request->params['controller']))) . ' - ' . __(Inflector::humanize(Inflector::underscore($this->request->params['action']))); } }
/** * Returns a counter string for the paged result set * * ### Options * * - `model` The model to use, defaults to PaginatorHelper::defaultModel(); * - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5' * set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing * the following placeholders `{{page}}`, `{{pages}}`, `{{current}}`, `{{count}}`, `{{model}}`, `{{start}}`, `{{end}}` and any * custom content you would like. * * @param string|array $options Options for the counter string. See #options for list of keys. * If string it will be used as format. * @return string Counter string. * @link http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-a-page-counter */ public function counter($options = []) { if (is_string($options)) { $options = ['format' => $options]; } $default = ['model' => $this->defaultModel(), 'format' => 'pages']; $options = \Cake\Utility\Hash::merge($default, $options); $paging = $this->params($options['model']); if (!$paging['pageCount']) { $paging['pageCount'] = 1; } $start = 0; if ($paging['count'] >= 1) { $start = ($paging['page'] - 1) * $paging['perPage'] + 1; } $end = $start + $paging['perPage'] - 1; if ($paging['count'] < $end) { $end = $paging['count']; } switch ($options['format']) { case 'range': case 'pages': $template = 'counter' . ucfirst($options['format']); break; default: $template = 'counterCustom'; $this->templater()->add([$template => $options['format']]); } $map = array_map([$this->Number, 'format'], ['page' => $paging['page'], 'pages' => $paging['pageCount'], 'current' => $paging['current'], 'count' => $paging['count'], 'start' => $start, 'end' => $end]); $map += ['model' => strtolower(Inflector::humanize(Inflector::tableize($options['model'])))]; return $this->templater()->format($template, $map); }
public function getUser(Request $request) { if (!isset($_SESSION)) { return false; } $provider = Hash::get($_SESSION, 'opauth.auth.provider'); if (!$provider) { return false; } $uid = Hash::get($_SESSION, 'opauth.auth.uid'); if (!$uid) { return false; } $userModel = $this->_config['userModel']; list(, $model) = pluginSplit($userModel); $fields = $this->_config['fields']; $conditions = [$model . '.' . $fields['auth_provider'] => $provider, $model . '.' . $fields['auth_uid'] => $uid]; $scope = $this->_config['scope']; if ($scope) { $conditions = array_merge($conditions, $scope); } $table = TableRegistry::get($userModel)->find('all'); $contain = $this->_config['contain']; if ($contain) { $table = $table->contain($contain); } $result = $table->where($conditions)->hydrate(false)->first(); if (empty($result)) { return false; } return $result; }
/** * Constructor. * * @param array $config Settings for the filter. */ public function __construct($config = []) { if (isset($config['languages'])) { $config['languages'] = Hash::normalize($config['languages']); } $this->config($config); }
/** * Default validation rules. * * @param Validator $validator The validator to customize. * @return Validator */ public function validationDefault(Validator $validator) { return $validator->notEmpty('username', __d('wasabi_core', 'Please enter a username.'))->notEmpty('email', __d('wasabi_core', 'Please enter an email address.'))->add('email', ['email' => ['rule' => 'email', 'message' => __d('wasabi_core', 'Please enter a valid email address.')]])->notEmpty('group_id', __d('wasabi_core', 'Please select a group this user belongs to.'))->notEmpty('password', __d('wasabi_core', 'Please enter a password.'), 'create')->add('password', ['length' => ['rule' => ['minLength', 6], 'message' => __d('wasabi_core', 'Ensure your password consists of at least 6 characters.')]])->notEmpty('password_confirmation', __d('wasabi_core', 'Please repeat your Password.'), function ($context) { if ($context['newRecord'] === true) { return true; } if (isset($context['data']['password']) && !empty($context['data']['password'])) { return true; } return false; })->add('password_confirmation', 'equalsPassword', ['rule' => function ($passwordConfirmation, $provider) { if ($passwordConfirmation !== $provider['data']['password']) { return __d('wasabi_core', 'The Password Confirmation does not match the Password field.'); } return true; }])->add('language_id', 'isValid', ['rule' => function ($languageId) { $languageIds = Hash::map(Configure::read('languages.backend'), '{n}', function ($language) { return $language->id; }); if (!in_array($languageId, $languageIds)) { return __d('wasabi_core', 'Invalid language selected.'); } return true; }])->add('timezone', 'isValid', ['rule' => function ($timezone) { if (!in_array($timezone, DateTimeZone::listIdentifiers())) { return __d('wasabi_core', 'Invalid timezone selected.'); } return true; }]); }
/** * Send mail using Mandrill (by MailChimp) * * @param \Cake\Network\Email\Email $email Cake Email * @return array */ public function send(Email $email) { $this->transportConfig = Hash::merge($this->transportConfig, $this->_config); // Initiate a new Mandrill Message parameter array $message = ['html' => $email->message(\Cake\Network\Email\Email::MESSAGE_HTML), 'text' => $email->message(\Cake\Network\Email\Email::MESSAGE_TEXT), 'subject' => $this->_decode($email->subject()), 'from_email' => key($email->from()), 'from_name' => current($email->from()), 'to' => [], 'headers' => ['Reply-To' => is_null(key($email->replyTo())) ? key($email->from()) : key($email->replyTo())], 'recipient_metadata' => [], 'attachments' => [], 'images' => []]; // Merge Mandrill Parameters $message = array_merge($message, Hash::merge($this->defaultParameters, $email->profile()['Mandrill'])); // Add receipients foreach (['to', 'cc', 'bcc'] as $type) { foreach ($email->{$type}() as $mail => $name) { $message['to'][] = ['email' => $mail, 'name' => $name, 'type' => $type]; } } // Attachments $message = $this->_attachments($email, $message); // Create a new scoped Http Client $this->http = new Client(['host' => 'mandrillapp.com', 'scheme' => 'https', 'headers' => ['User-Agent' => 'CakePHP Mandrill Plugin']]); // Sending as a template? Then in case we find mail content, we add this as a 'template_content'. // In you Mandrill template, use <div mc:edit="content"></div> to get the contents of your email if (!is_null($message['template_name']) && $message['html']) { if (!isset($message['template_content']) || !is_array($message['template_content'])) { $message['template_content'] = []; } $message['template_content'][] = ['name' => 'content', 'content' => $message['html']]; } // Are we sending a template? if (!is_null($message['template_name']) && !empty($message['template_content'])) { return $this->_sendTemplate($message, $this->transportConfig['async'], $this->transportConfig['ip_pool'], $message['send_at']); } else { return $this->_send($message, $this->transportConfig['async'], $this->transportConfig['ip_pool'], $message['send_at']); } }
/** * Index method * * @return \Cake\Network\Response|null */ public function index() { $treeRoles = $this->Roles->find('treeList')->toArray(); $roles = $this->Roles->find('all')->toArray(); $roles = Hash::combine($roles, '{n}.id', '{n}'); $this->set(compact('roles', 'treeRoles')); $this->set('_serialize', ['roles']); }
/** * Render ajax toggle element. * * @param array|string $url * @param array $data * @param Entity|\Cake\ORM\Entity $entity * @return string */ public function toggle($entity, $url = [], array $data = []) { if (empty($url)) { $url = ['action' => 'toggle', 'prefix' => $this->request->param('prefix'), 'plugin' => $this->request->param('plugin'), 'controller' => $this->request->param('controller'), (int) $entity->get('id'), (int) $entity->get('status')]; } $data = Hash::merge(['url' => $url, 'entity' => $entity], $data); return $this->_View->element(__FUNCTION__, $data); }
public function __construct($moduleDefintion) { parent::__construct($moduleDefintion); $moduleClass = Hash::get($moduleDefintion, 'meta.moduleId'); if ($moduleClass) { $this->instance = new $moduleClass(Hash::get($moduleDefintion, 'data')); } }
/** * Render an attachments area for the given entity * * @param EntityInterface $entity Entity to attach files to * @param array $options Override default options * @return string */ public function attachmentsArea(EntityInterface $entity, array $options = []) { if ($this->config('includeDependencies')) { $this->addDependencies(); } $options = Hash::merge(['label' => false, 'id' => 'fileupload-' . uniqid(), 'formFieldName' => false, 'mode' => 'full', 'style' => '', 'taggable' => false, 'isAjax' => false, 'panelHeading' => __d('attachments', 'attachments'), 'showIconColumn' => true, 'additionalButtons' => null], $options); return $this->_View->element('Attachments.attachments_area', compact('options', 'entity')); }
/** * Getting all aco records as tree * @return array */ public function getAll() { $acos = $this->Acos->find()->toArray(); $acos = Hash::combine($acos, '{n}.name', '{n}'); ksort($acos); // $acos = Hash::expand($acos, '/'); return $acos; }
/** * Constructor * * @param \Cake\ORM\Entity $entity Entity * @param int $code code to report to client */ public function __construct(Entity $entity, $code = 422) { $this->_validationErrors = array_filter((array) $entity->errors()); $flat = Hash::flatten($this->_validationErrors); $errorCount = $this->_validationErrorCount = count($flat); $this->message = __dn('crud', 'A validation error occurred', '{0} validation errors occurred', $errorCount, [$errorCount]); parent::__construct($this->message, $code); }
/** * Returns the filename for the current field/data combination. * If a `nameCallback` is specified in settings, then that callable * will be invoked with the current upload data. * * @return string */ public function filename() { $processor = Hash::get($this->settings, 'nameCallback', null); if (is_callable($processor)) { return $processor($this->data, $this->settings); } return $this->data['name']; }