本文整理汇总了PHP中Set::extract方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::extract方法的具体用法?PHP Set::extract怎么用?PHP Set::extract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set::extract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: admin_edit
/**
* admin_edit method
*
* @param mixed $id
* @return void
*/
public function admin_edit($id = null)
{
$expenses = array();
if (!empty($this->request->data)) {
if ($this->Payment->saveAll($this->request->data)) {
$this->setFlash(__d('lil_expenses', 'Payment has been saved.'));
return $this->doRedirect();
}
$this->setFlash(__d('lil_expenses', 'There are some errors in the form. Please correct all marked fields below.'));
} else {
if (!empty($id)) {
if (!($this->request->data = $this->Payment->find('first', array('conditions' => array('Payment.id' => $id), 'contain' => array('PaymentsExpense'))))) {
// must redirect to index because of redirects from delete actions
$this->redirect(array('admin' => true, 'plugin' => 'lil_expenses', 'controller' => 'payments', 'action' => 'index'));
}
$expenses = $this->Payment->Expense->find('all', array('conditions' => array('Expense.id' => Set::extract('PaymentsExpense.{n}.expense_id', $this->request->data)), 'recursive' => 0));
} else {
if (!empty($this->request->params['named']['expense'])) {
if ($exp = $this->Payment->Expense->find('first', array('conditions' => array('Expense.id' => $this->request->params['named']['expense']), 'recursive' => 0))) {
$this->request->data['Payment']['dat_happened'] = strftime('%Y-%m-%d');
$this->request->data['Payment']['descript'] = $exp['Expense']['title'];
$this->request->data['Payment']['amount'] = $exp['Expense']['total'];
}
$expenses = array($exp);
} else {
return $this->error404();
}
}
}
$this->set(compact('expenses'));
$this->set('accounts', $accounts = $this->PaymentsAccount->findActive());
$this->setupRedirect();
}
示例2: admin_index
public function admin_index()
{
$this->set('title_for_layout', __('Content', true));
$this->Node->recursive = 0;
$this->paginate['Node']['order'] = 'Node.id DESC';
$this->paginate['Node']['conditions'] = array();
$types = $this->Node->Term->Vocabulary->Type->find('all');
$typeAliases = Set::extract('/Type/alias', $types);
$this->paginate['Node']['conditions']['Node.type'] = $typeAliases;
if (isset($this->params['named']['filter'])) {
$filters = $this->Croogo->extractFilter();
foreach ($filters as $filterKey => $filterValue) {
if (strpos($filterKey, '.') === false) {
$filterKey = 'Node.' . $filterKey;
}
$this->paginate['Node']['conditions'][$filterKey] = $filterValue;
}
$this->set('filters', $filters);
}
$nodes = $this->paginate('Node');
$this->set(compact('nodes', 'types', 'typeAliases'));
if (isset($this->params['named']['links'])) {
$this->layout = 'ajax';
$this->render('admin_links');
}
}
示例3: collaborators
public function collaborators()
{
$subscriptions = $this->Subscription->findAllByClassAndForeignId('Workspace', $this->Session->read('Workspace.id'));
$subscribers = Set::extract('/Subscription/user_id', $subscriptions);
$subscribers = $this->Subscription->User->find('all', array('conditions' => array('User.id' => $subscribers), 'fields' => array('id', 'name', 'email', 'facebook_id')));
$this->set('subscribers', $subscribers);
}
示例4: index
function index()
{
$this->name = 'feedbacks';
$feedbacks = $this->Feedback->getAllFeedbacks();
$user_ids = Set::extract('/Feedback/user_id', $feedbacks);
$this->set(array('feedbacks' => $feedbacks, 'feedback_posters' => $this->Profile->getProfilesInfoFromUserIds($user_ids), 'feedback_count' => $this->FeedbackComment->countFeedbackComments()));
}
示例5: admin_index
public function admin_index()
{
$this->set('title_for_layout', __('Content', true));
$this->Node->recursive = 0;
$this->paginate['Node']['order'] = 'Node.created DESC';
$this->paginate['Node']['conditions'] = array();
$types = $this->Node->Taxonomy->Vocabulary->Type->find('all');
$typeAliases = Set::extract('/Type/alias', $types);
$this->paginate['Node']['conditions']['Node.type'] = $typeAliases;
if (isset($this->params['named']['filter'])) {
$filters = $this->Croogo->extractFilter();
foreach ($filters as $filterKey => $filterValue) {
if (strpos($filterKey, '.') === false) {
$filterKey = 'Node.' . $filterKey;
}
$this->paginate['Node']['conditions'][$filterKey] = $filterValue;
}
$this->set('filters', $filters);
}
if (isset($this->params['named']['q'])) {
App::import('Core', 'Sanitize');
$q = Sanitize::clean($this->params['named']['q']);
$this->paginate['Node']['conditions']['OR'] = array('Node.title LIKE' => '%' . $q . '%', 'Node.excerpt LIKE' => '%' . $q . '%', 'Node.body LIKE' => '%' . $q . '%', 'Node.terms LIKE' => '%"' . $q . '"%');
}
$nodes = $this->paginate('Node');
$this->set(compact('nodes', 'types', 'typeAliases'));
if (isset($this->params['named']['links'])) {
$this->layout = 'ajax';
$this->render('admin_links');
}
}
示例6: _findCloud
/**
* Returns a tag cloud
*
* The result contains a "weight" field which has a normalized size of the tag
* occurrence set. The min and max size can be set by passing 'minSize" and
* 'maxSize' to the query. This value can be used in the view to controll the
* size of the tag font.
*
* @todo Ideas to improve this are welcome
* @param string
* @param array
* @param array
* @return array
* @access public
*/
public function _findCloud($state, $query, $results = array())
{
if ($state == 'before') {
$options = array('minSize' => 10, 'maxSize' => 20, 'page' => null, 'limit' => null, 'order' => null, 'joins' => null, 'offset' => null, 'contain' => 'Tag', 'conditions' => array(), 'fields' => 'Tag.*, Tagged.tag_id, COUNT(*) AS occurrence', 'group' => 'Tagged.tag_id');
foreach ($query as $key => $value) {
if (!empty($value)) {
$options[$key] = $value;
}
}
$query = $options;
if (isset($query['model'])) {
$query['conditions'] = Set::merge($query['conditions'], array('Tagged.model' => $query['model']));
}
return $query;
} elseif ($state == 'after') {
if (!empty($results) && isset($results[0][0]['occurrence'])) {
$weights = Set::extract($results, '{n}.0.occurrence');
$maxWeight = max($weights);
$minWeight = min($weights);
$spread = $maxWeight - $minWeight;
if (0 == $spread) {
$spread = 1;
}
foreach ($results as $key => $result) {
$size = $query['minSize'] + ($result[0]['occurrence'] - $minWeight) * (($query['maxSize'] - $query['minSize']) / $spread);
$results[$key]['Tag']['occurrence'] = $result[0]['occurrence'];
$results[$key]['Tag']['weight'] = ceil($size);
}
}
return $results;
}
}
示例7: testIndex
public function testIndex()
{
$vars = $this->testAction('involvement_leaders/index/Involvement:1', array('return' => 'vars'));
$results = Set::extract('/Leader', $vars['leaders']);
$expected = array(array('Leader' => array('id' => 2, 'user_id' => 1, 'model' => 'Involvement', 'model_id' => 1, 'created' => '2010-04-09 07:28:57', 'modified' => '2010-04-09 07:28:57')));
$this->assertEqual($results, $expected);
}
示例8: getTeamIds
function getTeamIds($model, $modelid)
{
$this->recursive = 0;
$teamsObjects = $this->find('all', array('conditions' => array('TeamsObject.status <> ' => 'Deleted', 'TeamsObject.model_id' => $modelid, 'TeamsObject.model' => $model, 'Team.status <> ' => 'Deleted'), 'contain' => array('Team')));
$teamIDs = Set::extract($teamsObjects, '{n}.Team.id');
return $teamIDs;
}
示例9: after
/**
* After migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
function after($direction)
{
$output = array();
// not used
if ($direction === 'up') {
if (!class_exists('Security')) {
App::import('Core', 'Security');
}
// create initial user
$User = $this->generateModel('User');
$user = array('User' => array('username' => 'admin', 'password' => Security::hash('GuideOnTheSideAdmin#1', null, true), 'role_id' => 2, 'deleted' => 0));
$this->output('insert_data', 'admin user');
$User->save($user);
// populate roles
$Role = $this->generateModel('Role');
$roles = array(array('id' => 1, 'name' => 'creator'), array('id' => 2, 'name' => 'admin'));
$this->output('insert_data', 'roles (' . implode(', ', Set::extract('{n}.name', $roles)) . ')');
$Role->saveAll($roles);
if (isset($this->callback)) {
// currently this just outputs a line break to the CLI
$this->callback->afterMigration($this->callback, $direction);
}
}
return true;
}
示例10: add
function add($model = null, $id = null, $uid = null)
{
if (!empty($this->data)) {
$model = Set::extract($this->data, 'Coment.model');
$id = Set::extract($this->data, 'Coment.project_id');
$a = ClassRegistry::init('Attachment');
if ($this->Coment->save($this->data)) {
$coment = $this->Coment->findById($uid);
//print_r($_REQUEST); die();
foreach ($this->data['Attachment'] as $file) {
$aa = $a->CustomUpload($file[0], $coment['Coment']['id']);
}
$this->Coment->create();
$this->data = array();
$this->set('successful', false);
$this->Session->setFlash(__('The Comment has been saved.', true));
} else {
$this->Session->setFlash(__('The Comment could not be saved. Please, try again.', true));
}
} else {
$this->data = array('Coment' => array('model' => $model, 'project_id' => $id));
}
$this->set('_model', $model);
$this->set('_project_id', $id);
}
示例11: testPaginate
public function testPaginate()
{
for ($i = 0; $i < 10; $i++) {
$u = new User();
$u->save(array('User' => array('username' => 'User ' . $i, 'password' => 'password ' . $i, 'salary' => 100 + $i)));
}
$u->flush();
$this->Controller->request->params['pass'] = array('1');
$this->Controller->request->query = array();
$this->Controller->constructClasses();
$this->Controller->Paginator->settings = array('limit' => 3);
$results = Set::extract($this->Controller->Paginator->paginate(), '{s}.User.username');
$this->assertEqual($results, array('User 0', 'User 1', 'User 2'));
$this->Controller->request->params['named'] = array('sort' => 'salary', 'direction' => 'desc');
$results = Set::extract($this->Controller->Paginator->paginate(), '{s}.User.username');
$this->assertEqual($this->Controller->params['paging']['User']['page'], 1);
$this->assertEqual($results, array('User 9', 'User 8', 'User 7'));
$this->Controller->request->params['named'] = array('sort' => 'User.salary', 'direction' => 'desc', 'page' => 2);
$results = Set::extract($this->Controller->Paginator->paginate(), '{s}.User.username');
$this->assertEqual($this->Controller->params['paging']['User']['page'], 2);
$this->assertEqual($results, array('User 6', 'User 5', 'User 4'));
$this->Controller->request->params['named'] = array();
$this->Controller->Paginator->settings = array('topPaid', 'limit' => 3);
$results = Set::extract($this->Controller->Paginator->paginate(), '{s}.User.username');
$this->assertEqual($this->Controller->params['paging']['User']['page'], 1);
$this->assertEqual($results, array('User 9', 'User 8', 'User 7'));
}
示例12: generateList4TreeData
function generateList4TreeData($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null)
{
if ($keyPath == null && $valuePath == null && $this->hasField($this->displayField)) {
$fields = array($this->primaryKey, $this->displayField);
} else {
$fields = null;
}
$recursive = $this->recursive;
if ($recursive >= 1) {
$this->recursive = -1;
}
$result = $this->findAllThreaded($conditions, $fields, $order);
$this->recursive = $recursive;
if (!$result) {
return false;
}
if ($keyPath == null) {
$keyPath = '{n}.' . $this->name . '.' . $this->primaryKey;
}
if ($valuePath == null) {
$valuePath = '{n}.' . $this->name . '.' . $this->displayField;
}
$keys = Set::extract($result, $keyPath);
$vals = Set::extract($result, $valuePath);
if (!empty($keys) && !empty($vals)) {
$return = array_combine($keys, $vals);
return $return;
}
return null;
}
示例13: returnSection
public function returnSection($section, $locale = 'en_us')
{
$en_us = $this->returnEnSection($section);
//get the us version of the section first
if ($locale == 'en_us') {
return $en_us;
}
//query up the languages
if (Set::check(self::$sections, $section . "." . $locale)) {
return self::$sections[$section][$locale];
} else {
$old_locale = $this->locale;
$this->setLanguage($locale);
$lang = $this->find("all", array("conditions" => array("Phrase.section" => $section)));
$this->setLanguage($old_locale);
foreach ($en_us as $k => $v) {
$p = Set::extract("/Phrase[token=/" . $k . "/i]/value", $lang);
if (count($p) > 0) {
$en_us[$k] = $p[0];
}
}
//cache the data
self::$sections[$section][$locale] = $en_us;
}
return self::$sections[$section][$locale];
}
示例14: read
/**
* read data
*
* this is the main method that reads data from the datasource and
* formats it according to the request from the model.
*
* @param mixed $model the model that is requesting data
* @param mixed $query the qurey that was sent
*
* @return the data requested by the model
*/
function read(&$model, $query)
{
$this->request = array_merge($this->request, $model->request);
$response = $this->__process($this->__getData($this->request));
if ($query['fields'] == 'count') {
if (isset($model->map['count'])) {
$count = Set::extract($model->map['count'], $response);
$result[0][$model->alias]['count'] = $count;
} else {
$count = count(Set::extract($model->map['data'], $response));
$result[0][$model->alias]['count'] = $count;
}
return $result;
}
if (isset($model->map['data'])) {
if (strtolower($query['conditions']) !== 'raw') {
$response = Set::extract($model->map['data'], $response);
}
}
$i = 0;
foreach ($response as $key => $value) {
if (isset($query['limit']) && $i >= $query['limit']) {
return $result;
}
$result[$key][$model->alias] = $value;
$i++;
}
return $result;
}
示例15: edit
public function edit($id = null)
{
if (!$this->Session->check('Workspace.id')) {
$this->Redirect->flash('not_in_workspace', array('controller' => 'workspaces', 'action' => 'index'));
}
if (!empty($this->data['TaskGroup'])) {
if (!empty($this->data['TaskGroup']['id']) && !empty($this->data['TaskGroup']['assigned_to_id'])) {
$this->TaskGroup->id = $this->data['TaskGroup']['id'];
$oldAssignedToId = $this->TaskGroup->field('assigned_to_id');
}
}
$Subscription = ClassRegistry::init('Subscription');
$subscribers = $Subscription->findAllByClassAndForeignId('Workspace', $this->Session->read('Workspace.id'));
$subscribers = Set::extract('/Subscription/user_id', $subscribers);
$assignedTos = $this->TaskGroup->User->findList(array('conditions' => array('User.id' => $subscribers), 'fields' => array('id', 'name')));
$this->set(compact('assignedTos'));
$milestones = $this->TaskGroup->Milestone->find('list', array('conditions' => array('workspace_id' => $this->Session->read('Workspace.id'))));
$this->set(compact('milestones'));
$stacksConditions = array();
if ($this->Session->check('Milestone.id')) {
$stacksConditions = array('conditions' => array('milestone_id' => $this->Session->read('Milestone.id')));
} else {
$stacksConditions = array('conditions' => array('workspace_id' => $this->Session->read('Workspace.id')));
}
$stacks = $this->TaskGroup->Stack->find('list', $stacksConditions);
$this->set(compact('stacks'));
parent::edit($id, array('controller' => 'tasks', 'action' => 'index'));
}