/** * Check selected option in list. * * @param array $options * @param string $selectedVal * @return array */ protected function _checkSelected(array $options, $selectedVal) { if (!empty($selectedVal) && !Arr::key($selectedVal, $options)) { $selectedVal = self::KEY_NO_EXITS_VAL; $options = array_merge(array(self::KEY_NO_EXITS_VAL => $this->_translate('No exits')), $options); } return array($options, $selectedVal); }
/** * Removes assets from collection. * * @param string|array $name * @return void */ public function remove($name) { $names = (array) $name; foreach ($names as $name) { if (Arr::key($name, $this->_assets)) { unset($this->_assets[$name]); } } }
/** * Crete button. * * @param string $name * @param string $content * @param array $attrs * @param string $type * @return string */ public function render($name = '', $content = '', array $attrs = array(), $type = 'submit') { $attrs = array_merge(array('text' => null, 'name' => $name), $attrs); $attrs = $this->_getBtnClasses($attrs); $attrs['type'] = $type; if (Arr::key('icon', $attrs)) { $content = '<i class="' . $this->_icon . '-' . $attrs['icon'] . '"></i> ' . $this->_translate($content); unset($attrs['icon']); } return '<button ' . $this->buildAttrs($attrs) . '>' . $content . '</button>'; }
/** * Create button classes. * * @param array $attrs * @return array */ protected function _getBtnClasses(array $attrs = array()) { if (Arr::key('button', $attrs)) { $classes = array($this->_btm); foreach ((array) $attrs['button'] as $btn) { $classes[] = $this->_btm . '-' . $btn; } $attrs = $this->_mergeAttr($attrs, implode(' ', $classes)); unset($attrs['button']); } return $attrs; }
/** * Create options group. * * @param string $key * @param array $gOptions * @param array $selected * @param array $options * @return string */ protected function _createGroup($key, array $gOptions, array $selected, array $options) { $label = is_int($key) ? sprintf($this->_translate('Select group %s'), $key) : $key; $output = array('<optgroup label="' . $this->_translate($label) . '">'); foreach ($gOptions as $value => $label) { if (Arr::key($value, $options)) { continue; } $classes = implode(' ', array($this->_jbSrt('option'), $this->_jbSrt('option-' . Str::slug($label)))); $isSelected = $this->_isSelected($value, $selected); $output[] = $this->_option($value, $isSelected, $classes, $label); } $output[] = '</optgroup>'; return implode(PHP_EOL, $output); }
/** * Create html tag. * * @param string $content * @param array|string $class * @param string $id * @param array $attrs * @return string */ public function render($content, $class = '', $id = '', array $attrs = array()) { $attrs = $this->_setId($attrs, $id); $attrs = $this->_cleanAttrs($attrs); if (!empty($class)) { $attrs = $this->_normalizeClassAttr($attrs, $class); } $tag = $this->_tag; if (Arr::key('tag', $attrs)) { $tag = $attrs['tag']; unset($attrs['tag']); } $format = !empty($attrs) ? '<%s %s>%s</%s>' : '<%s%s>%s</%s>'; $output = sprintf($format, $tag, $this->buildAttrs($attrs), $content, $tag); return $output; }
/** * Find main/required attributes in data array. * * @param array $data * @return array */ protected function _findMainAttr(array $data) { $id = $class = $value = ''; if (Arr::key('value', $data)) { $value = $data['value']; unset($data['value']); } if (Arr::key('class', $data)) { $class = $data['class']; unset($data['class']); } if (Arr::key('id', $data)) { $id = $data['id']; unset($data['id']); } return array($data, $value, $class, $id); }
public function testIsAttr() { $array = array('key' => 'asd', 'null' => null, 'false' => false); isTrue(Arr::key('key', $array)); isTrue(Arr::key('null', $array)); isTrue(Arr::key('false', $array)); isSame('asd', Arr::key('key', $array, true)); isSame(null, Arr::key('undefined', $array, true)); isSame(true, Arr::key('key', $array, false)); isSame(false, Arr::key('undefined', $array, false)); isFalse(Arr::key('undefined', $array)); isFalse(Arr::key('', $array)); isFalse(Arr::key(null, $array)); isFalse(Arr::key(false, $array)); }
/** * Rotates and/or flips an image automatically so the orientation will be correct (based on exif 'Orientation') * * @return $this * @codeCoverageIgnore * @throws Exception */ public function autoOrient() { if (!Arr::key('Orientation', $this->_exif)) { return $this; } $orient = (int) $this->_exif['Orientation']; if ($orient === 2) { // Flip horizontal $this->addFilter('flip', 'x'); } elseif ($orient === 3) { // Rotate 180 counterclockwise $this->addFilter('rotate', -180); } elseif ($orient === 4) { // Vertical flip $this->addFilter('flip', 'y'); } elseif ($orient === 5) { // Rotate 90 clockwise and flip vertically $this->addFilter('flip', 'y'); $this->addFilter('rotate', 90); } elseif ($orient === 6) { // Rotate 90 clockwise $this->addFilter('rotate', 90); } elseif ($orient === 7) { // Rotate 90 clockwise and flip horizontally $this->addFilter('flip', 'x'); $this->addFilter('rotate', 90); } elseif ($orient === 8) { // Rotate 90 counterclockwise $this->addFilter('rotate', -90); } return $this; }
/** * Merge attributes by given key. * * @param array $attrs * @param null $val * @param string $key * @return array */ protected function _mergeAttr(array $attrs = array(), $val = null, $key = 'class') { if (Arr::key($key, $attrs)) { $attrs[$key] .= ' ' . $val; } else { $attrs[$key] = $val; } return $attrs; }
/** * Controller success process. * * @param string $action * @param array $messages * @param array $redirect * @param array $ids * @return \Cake\Network\Response|null */ protected function _process($action, array $messages, array $redirect, array $ids) { if (Arr::key($action, $messages)) { $message = $messages[$action]; } else { $message = __d('union', '{0} processed.', Inflector::humanize($this->_controller->name)); } Event::dispatch($this->_getEventName($action, self::EVEN_POS_AFTER), $this->_controller, ['ids' => $ids]); $this->Flash->success($message); return $this->_controller->redirect($redirect); }
/** * Check serialize data for response types. * * @return bool */ protected function _needSerialize() { return !Arr::key('_serialize', $this->viewVars) && Arr::in($this->response->type(), $this->_serializeTypes); }
/** * Resolves asset dependencies. * * @param Asset|null $asset * @param Asset[] $resolved * @param Asset[] $unresolved * @return Asset[] * @throws Exception */ protected function _resolveDependencies(Asset $asset, &$resolved = [], &$unresolved = []) { $unresolved[$asset->getAlias()] = $asset; foreach ($asset->getDependencies() as $dependency) { if (!Arr::key($dependency, $resolved)) { if (isset($unresolved[$dependency])) { throw new Exception(sprintf('Circular asset dependency "%s > %s" detected.', $asset->getAlias(), $dependency)); } if ($dep = $this->_collection->get($dependency)) { $this->_resolveDependencies($dep, $resolved, $unresolved); } } } $resolved[$asset->getAlias()] = $asset; unset($unresolved[$asset->getAlias()]); return $resolved; }
/** * Process action. * * @return \Cake\Network\Response|null */ public function process() { list($action, $ids) = $this->Process->getRequestVars($this->name); $loggedId = $this->Auth->user('id'); if (Arr::key($loggedId, $ids) && $action == 'delete') { $this->Flash->warning(__d('community', 'It is impossible to delete your entry.')); unset($ids[$loggedId]); } return $this->Process->start($this->Users, $action, $ids); }