本文整理汇总了PHP中Cake\Utility\Hash::extract方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::extract方法的具体用法?PHP Hash::extract怎么用?PHP Hash::extract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Hash
的用法示例。
在下文中一共展示了Hash::extract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* 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]);
}
示例2: hasAllow
/**
* Check if current user has allow given acoName or not
* @param $acoName
* @return bool
*/
public function hasAllow($acoName)
{
if ($this->user('id')) {
$userAllowed = $this->Acl->checkUserAllow($this->user('id'), $acoName);
return !is_null($userAllowed) ? $userAllowed : $this->Acl->checkRoleAllow(Hash::extract($this->user('roles'), '{n}.id'), $acoName);
}
return false;
}
示例3: getErrorMessages
public function getErrorMessages()
{
if (!$this->hasErrors()) {
return false;
}
$messages = Hash::extract($this->errors(), '{s}.{s}');
return $messages;
}
示例4: roles
/**
* Normalizes roles.
*
* It will return the single role for single role setup, and a flat
* list of roles for multi role setup.
*
* @param string|array Roles as simple or complex (Role.id) array.
* @return array Roles
*/
public static function roles($roles)
{
if (!is_array($roles)) {
return (array) $roles;
}
if (isset($roles[0]['id'])) {
$roles = Hash::extract($roles, '{n}.id');
}
return $roles;
}
示例5: getComposerLockVersion
/**
* Retrieve the installed version of a Composer package by parsing composer.lock.
*
* @param string $path Full path to the directory holding the composer.lock file.
* @param string $package Name of the package to get the version for.
* @return mixed String containing value or false when key lookup fails
*/
public static function getComposerLockVersion($path, $package)
{
if (!file_exists("{$path}/composer.lock")) {
return false;
}
// escape / in package name to not break Xpath query
$package = str_replace('/', '\\/', $package);
$json = json_decode(file_get_contents("{$path}/composer.lock"), true);
return implode(Hash::extract($json, "packages.{n}[name=/{$package}/].version"));
}
示例6: onUserLoginSuccessfully
public function onUserLoginSuccessfully(Event $event)
{
$user =& $event->data['user'];
$user['roles'] = [];
$UsersRoles = TableRegistry::get('AclManager.UsersRoles');
$roles = $UsersRoles->find()->where(['user_id' => $user['id']])->contain(['Roles'])->toArray();
if (!empty($roles)) {
$user['roles'] = Hash::extract($roles, '{n}.role');
}
}
示例7: getThumbnail
public function getThumbnail($url, $config = [])
{
if (empty($this->_getUrlInfo())) {
$this->fetchUrlInfo($url, $config);
}
$thumbnail = Hash::extract($this->_getUrlInfo(), '{s}.thumbnail_url');
if (empty($thumbnail)) {
return false;
}
return $thumbnail[0];
}
示例8: getConditions
/**
* @param $query
* @return array
*/
private function getConditions($query)
{
$result = [];
if (!empty($query['spec'])) {
$uIDtmp = $this->UsersSpecializations->find('all', ['fields' => ['user_id'], 'conditions' => ['specialization_id' => $this->request->query['spec']]])->toArray();
if (!empty($uIDtmp)) {
$result['Users.id IN'] = Hash::extract($uIDtmp, '{n}.user_id');
}
}
return $result;
}
示例9: getSettingPrototype
protected function getSettingPrototype($path, $plugin = null)
{
$defaults = ['title' => null, 'description' => null, 'cell' => null, 'default' => null, 'options' => null, 'hidden' => false];
//TODO: maybe implement cache for reader results or remember results in table class in future
$settingsReader = new PhpConfig();
$input = 'settings';
if (!empty($plugin)) {
$input = $plugin . '.settings';
}
$settingPrototypes = $settingsReader->read($input);
if ($setting = Hash::extract($settingPrototypes, '{n}[path=' . $path . ']')[0]) {
return array_merge($defaults, $setting);
}
return [];
}
示例10: unsentRiskEmails
public function unsentRiskEmails($eventId)
{
//Make sure event exists, and grab existing Requests at the same time
$event = $this->Events->get($eventId, ['contain' => ['EventApprovalRequests']]);
$riskManagers = TableRegistry::get('Users')->roleEmails('risk');
$previouslySentEmails = Hash::extract($event->event_approval_requests, '{n}.email');
$toSend = [];
foreach ($riskManagers as $email => $name) {
if (is_numeric($email)) {
$email = $name;
}
if (in_array($email, $previouslySentEmails)) {
continue;
}
$toSend[] = $email;
}
return $toSend;
}
示例11: index
public function index()
{
$articlesRes = $this->Articles->find('all')->where(['Articles.article_status_id' => ARTICLE_STATUS_ACTIVE, 'Articles.article_type_id !=' => ARTICLE_TYPE_SYSTEM])->toArray();
$articles = array();
foreach ($articlesRes as $key => $article) {
if (is_object($article)) {
$articlesRes[$key] = $article->toArray();
}
$articles[$articlesRes[$key]['id']] = $articlesRes[$key];
}
$intro = $this->Articles->find('all', ['fields' => ['body'], 'conditions' => ['SystemPages.article_id = Articles.id', 'SystemPages.name' => 'intro'], 'contain' => ['SystemPages']])->first();
$featured = Hash::extract($articles, '{n}[article_type_id=2]');
array_splice($featured, 3);
$this->loadComponent('Util');
$articles = $this->Util->arrayDiff($articles, $featured);
$belowFooter = 'googlemap';
//TODO: make this into a more global and elegant construct
$this->set(compact('articles', 'featured', 'intro', 'belowFooter'));
}
示例12: getFeaturedImage
/**
* Loads the featured image (if any)
*
* @return void
*/
public function getFeaturedImage(Event $event, Entity $entity)
{
$featuredImage = Hash::extract($entity->meta, '{n}[key=featured_image]');
if (empty($featuredImage)) {
return;
}
$featuredImage = end($featuredImage);
$entity->featured_image_meta_id = $featuredImage->id;
$entity->featured_image_id = $featuredImage->value;
try {
$entity->featured_image = TableRegistry::get('Croogo/FileManager.Attachments')->get($entity->featured_image_id);
} catch (RecordNotFoundException $e) {
//Image does not exist
unset($entity->featured_image_id);
}
$entity->meta = collection($entity->meta)->reject(function ($item) {
return $item->key === 'featured_image';
})->toList();
}
示例13: search
/**
* @param $options (match_fields, paginate)
* @return \Cake\ORM\Query|bool
*/
public function search(array $options)
{
$index = isset($options['index']) ? $options['index'] : $this->config('defaultIndex');
$sphinx = SphinxQL::create($this->conn)->select('id')->from($index)->match(empty($options['match_fields']) ? "*" : $options['match_fields'], $options['term'])->limit(empty($options['limit']) ? 1000 : $options['limit']);
$result = $sphinx->execute()->fetchAllAssoc();
if (!empty($result)) {
$ids = Hash::extract($result, '{n}.id');
$query = $this->_table->find();
if (!empty($options['paginate']['fields'])) {
$query->select($options['paginate']['fields']);
}
if (!empty($options['paginate']['contain'])) {
$query->contain($options['paginate']['contain']);
}
$query->where([$this->_table->alias() . '.' . $this->_table->primaryKey() . ' IN' => $ids]);
return $query;
}
return false;
}
示例14: home
/**
* Index page.
*
* @return void
*/
public function home()
{
$this->loadModel('Users');
$this->loadModel('PremiumTransactions');
$usersCount = Number::format($this->Users->find()->where(['end_subscription >' => new Time()])->count());
$premiumTransactions = $this->PremiumTransactions->find()->select(['price'])->hydrate(false)->toArray();
$amountTotal = array_sum(Hash::extract($premiumTransactions, '{n}.price'));
$registeredDiscounts = $this->PremiumTransactions->find()->where(function ($exp) {
return $exp->isNotNull('premium_discount_id');
})->count();
$discounts = $this->PremiumTransactions->find()->contain(['PremiumDiscounts', 'PremiumOffers'])->where(function ($exp) {
return $exp->isNotNull('premium_discount_id');
})->toArray();
$discountAmountTotal = [];
foreach ($discounts as $discount) {
array_push($discountAmountTotal, $discount->discount);
}
$discountAmountTotal = array_sum($discountAmountTotal);
$this->set(compact('usersCount', 'amountTotal', 'registeredDiscounts', 'discountAmountTotal'));
}
示例15: view
/**
* View method
*
* @param string|null $id Gpio id.
* @return void
* @throws \Cake\Network\Exception\NotFoundException When record not found.
*/
public function view($id = 1)
{
$gpio = $this->Gpios->newEntity();
$pins = $gpio->readall();
if ($this->request->is('post')) {
$data = $this->request->data;
//debug($data);
if (!isset($data['v'])) {
$data['v'] = $pins[$data['physical']]['v'];
}
if ($data['mode'] === '0') {
$data['mode'] = GPIO_MODE_IN;
}
//debug($data); exit;
if ($data['mode'] != $pins[$data['physical']]['mode']) {
$result = $gpio->setMode($data['wpi'], $data['mode']);
if ($result['RC'] == 0) {
$this->Flash->success(__('Pin mode was changed.'));
} else {
$this->Flash->error(__('Pin mode could not be changed.'));
}
} else {
if ($data['v'] != $pins[$data['physical']]['v']) {
$result = $gpio->setValue($data['wpi'], $data['v']);
if ($result['RC'] == 0) {
$this->Flash->success(__('Pin was changed.'));
} else {
$this->Flash->error(__('Pin could not be changed.'));
}
} else {
$this->Flash->set(__('No change was made.'));
}
}
return $this->redirect(['action' => 'view', $data['physical']]);
}
$rowTop = Hash::extract($pins, '{n}[row=1]');
$rowBottom = Hash::extract($pins, '{n}[row=0]');
$this->set('pins', $pins);
$this->set('rows', [$rowTop, $rowBottom]);
$this->set('activePin', $id);
}