本文整理汇总了PHP中Cake\ORM\TableRegistry::get方法的典型用法代码示例。如果您正苦于以下问题:PHP TableRegistry::get方法的具体用法?PHP TableRegistry::get怎么用?PHP TableRegistry::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\TableRegistry
的用法示例。
在下文中一共展示了TableRegistry::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterCasAuthenticate
public function afterCasAuthenticate(Event $event)
{
$user = $event->data();
if (empty($user['username'])) {
return null;
}
if (!array_key_exists('id', $user)) {
$user['id'] = $user['username'];
}
$localUser = TableRegistry::get('Users')->findOrCreateByNetid($user['username'], true);
//force PersonSummary update check
if (empty($localUser)) {
return null;
}
$user['id'] = $localUser->id;
if (empty($user['name']) && !empty($localUser->name)) {
$user['name'] = $localUser->name;
}
if (empty($user['byuId']) && !empty($localUser->byu_id)) {
$user['byuId'] = $localUser->byu_id;
}
$user['officers'] = TableRegistry::get('Officers')->listUserActive($localUser->id);
$user['advisors'] = TableRegistry::get('Advisors')->listUserApproved($localUser->id);
$user['members'] = TableRegistry::get('Members')->listActiveClubs($localUser->id);
$user['roles'] = TableRegistry::get('Roles')->listByUser($localUser->id);
$user['roles']['dean'] = TableRegistry::get('Departments')->listByDean($user['username']);
$homePrefixes = ['admin', 'dean', 'risk', 'review'];
//roles that have a default home, in descending preference order
foreach ($homePrefixes as $prefix) {
if (!empty($user['roles'][$prefix])) {
$user['default_home'] = ['prefix' => $prefix, 'controller' => 'clubs', 'action' => 'index'];
}
}
return $user;
}
示例2: setUp
/**
* setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->connection = ConnectionManager::get('test');
$this->user = TableRegistry::get('Users', ['table' => 'counter_cache_users', 'connection' => $this->connection]);
$this->post = new PostTable(['alias' => 'Post', 'table' => 'counter_cache_posts', 'connection' => $this->connection]);
}
示例3: _findUser
/**
* Find a user record using the standard options.
*
* @param string $username The username/identifier.
* @param string $password The password, if not provide password checking is
* skipped and result of find is returned.
* @return bool|array Either false on failure, or an array of user data.
*/
protected function _findUser($username, $password = null)
{
$userModel = $this->_config['userModel'];
list($plugin, $model) = pluginSplit($userModel);
$fields = $this->_config['fields'];
$conditions = [$model . '.' . $fields['username'] => $username];
$columns = [];
foreach ($this->_config['columns'] as $column) {
$columns[] = [$model . '.' . $column => $username];
}
$conditions = ['OR' => $columns];
if (!empty($this->_config['scope'])) {
$conditions = array_merge($conditions, $this->_config['scope']);
}
$table = TableRegistry::get($userModel)->find('all');
if ($this->_config['contain']) {
$table = $table->contain($this->_config['contain']);
}
$result = $table->where($conditions)->hydrate(false)->first();
if (empty($result)) {
return false;
}
if ($password !== null) {
$hasher = $this->passwordHasher();
$hashedPassword = $result[$fields['password']];
if (!$hasher->check($password, $hashedPassword)) {
return false;
}
$this->_needsPasswordRehash = $hasher->needsRehash($hashedPassword);
unset($result[$fields['password']]);
}
return $result;
}
示例4: afterSave
public function afterSave($event, $entity, $options)
{
$actions = $this->_config['actions'];
$Feed = TableRegistry::get('Social.Feeds');
$user_id = __LOGGEDINUSERID;
$feeds = [];
if ($entity->isNew()) {
// We need to check if the Object has a feed, and if not, create it
$objectFeed = $Feed->find()->where(['Feeds.object_id' => $entity->id, 'Feeds.object' => $this->alias])->first();
if (!$objectFeed) {
$objectFeed = $Feed->newEntity();
$data = ['object_id' => $entity->id, 'object' => $this->alias];
$objectFeed = $Feed->patchEntity($objectFeed, $data);
if ($Feed->save($objectFeed)) {
$this->log("The feed for " . $this->alias . " ID: " . $entity->id . " has been saved!", 'debug');
} else {
$this->log("The feed for " . $this->alias . " ID: " . $entity->id . " could not be saved!", 'debug');
}
}
$feeds[] = $objectFeed->id;
// We need to get the Users feed
$userFeed = $Feed->find()->where(['Feeds.object_id' => $user_id, 'Feeds.object' => 'User'])->first();
// Only add to the Object Feed if it is not the Subject itself
if ($userFeed->id !== $objectFeed->id) {
$feeds[] = $userFeed->id;
}
// If the Object is linked to a Pole, add the Activity to the Pole as well
if (isset($entity->pole_id)) {
$poleFeed = $Feed->find()->where(['Feeds.object_id' => $entity->pole_id, 'Feeds.object' => 'Pole'])->first();
// Only add to the Object Feed if it is not the Subject itself
$feeds[] = $poleFeed->id;
}
// Let's add Activities to all the feeds
$Activity = TableRegistry::get('Social.Activities');
if (array_key_exists('add', $actions)) {
foreach ($actions['add']['fields'] as $field => $options) {
if (isset($entity->{$field})) {
$activity = $Activity->newEntity();
$data = ['object_id' => $entity->id, 'object' => $this->alias, 'subject_id' => $user_id, 'verb' => 'created', 'text' => $options['text'], 'type' => $options['type'], 'pole_id' => isset($entity->pole_id) ? $entity->pole_id : null, 'data' => json_encode(array('field' => $field, 'value' => $entity->{$field})), 'feeds' => ['_ids' => $feeds]];
$activity = $Activity->patchEntity($activity, $data);
if (!$Activity->save($activity)) {
$this->log("The activity could not be saved!", 'debug');
}
}
}
}
// If the Object is not the Subject itself
// Subscribe the User to the Object Feed so that he can be notified
if (!($this->alias == 'User' && $user_id == $entity->id) && count($objectFeed)) {
$Subscription = TableRegistry::get('Social.Subscriptions');
$subscription = $Subscription->newEntity();
$data = ['feed_id' => $objectFeed->id, 'user_id' => $user_id, 'reason' => 'author'];
$subscription = $Subscription->patchEntity($subscription, $data);
if (!$Subscription->save($subscription)) {
$this->log("The subscription could not be saved!", 'debug');
}
}
return true;
}
}
示例5: home
public function home()
{
$search = $this->request->query('q');
$page = $this->request->query('p');
if ($search != null) {
$searchKeywordsEncoded = urlencode($search);
if ($page != null) {
if (!ctype_digit($page)) {
$page = 1;
} else {
if (intval($page) < 1) {
$page = 1;
} else {
if (intval($page) > 10) {
$page = 10;
}
}
}
} else {
$page = 1;
}
$this->set('doNotShowSearchBarInHeader', true);
$searchResult = $this->amazon->search($searchKeywordsEncoded, $page);
$tableOnly = $this->request->query('tableOnly') == "true";
$this->set(compact('searchResult', 'page', 'search', 'tableOnly'));
} else {
$this->set('doNotShowSearchBarInHeader', false);
$productsTable = TableRegistry::get('Products');
$query = $productsTable->find()->contain(['Prices'])->where(['image_link is not' => null])->limit(30);
$products = $query->toArray();
$this->set(compact("products"));
}
}
示例6: index
public function index()
{
$this->autoRender = false;
//array order is important for graph edge hierarchy
$connections = array("HasOne", "HasMany", "BelongsTo", "HasAndBelongsToMany");
$connectionArray = array();
$db = ConnectionManager::get('default');
$collection = $db->schemaCollection();
$tables = $collection->listTables();
foreach ($tables as $table) {
$connectionArray[$table] = [];
foreach ($connections as $edgeRank => $connection) {
$model = TableRegistry::get($table);
echo $table . "<br />";
// debug($model->associations());
foreach ($model->associations() as $key => $association) {
// debug($association);
$class = get_class($association);
$array = explode("\\", $class);
$type = array_pop($array);
echo "<span style='margin-left: 10px;'>" . $type . ": " . $key . "</span><br />";
// if (!empty($connectionArray[$table][$key])) {
// $currentVL = $connectionArray[$table][$key];
// } else {
// $currentVL = 0;
// }
// $connectionArray[$table][$key] = max(array($currentVL, $edgeRank));
}
}
// debug($connectionArray);
// $connectionArray = array_map("unserialize", array_unique(array_map("serialize", $connectionArray)));
// $connectionArray = array_intersect_key($connectionArray, array_unique(array_map('serialize', $connectionArray)));
}
// $this->set(compact('tables', 'connectionArray'));
}
示例7: main
/**
* Adds or drops the specified column.
*
* @return bool
*/
public function main()
{
$options = (array) $this->params;
$options['bundle'] = empty($options['bundle']) ? null : $options['bundle'];
if (empty($options['use'])) {
$this->err(__d('eav', 'You must indicate a table alias name using the "--use" option. Example: "Articles.Users"'));
return false;
}
try {
$table = TableRegistry::get($options['use']);
} catch (\Exception $ex) {
$table = false;
}
if (!$table) {
$this->err(__d('eav', 'The specified table does not exists.'));
return false;
} elseif (!$table->behaviors()->has('Eav')) {
$this->err(__d('eav', 'The specified table is not using EAV behavior.'));
return false;
}
$columns = $table->listColumns($options['bundle']);
ksort($columns, SORT_LOCALE_STRING);
$rows = [[__d('eav', 'Column Name'), __d('eav', 'Data Type'), __d('eav', 'Bundle'), __d('eav', 'Searchable')]];
foreach ($columns as $name => $info) {
$rows[] = [$name, $info['type'], !empty($info['bundle']) ? $info['bundle'] : '---', !empty($info['searchable']) ? 'no' : 'yes'];
}
$this->out();
$this->out(__d('eav', 'EAV information for table "{0}":', $options['use']));
$this->out();
$this->helper('table')->output($rows);
return true;
}
示例8: update
public function update($id)
{
$orders = TableRegistry::get('Orders');
$query = $orders->query();
$query->update()->set(['complete' => true])->where(['id' => $id])->execute();
return $this->redirect(['action' => 'index']);
}
示例9: saveCart
public function saveCart()
{
$session = $this->request->session();
$user = $session->read('authentication');
$cart = $session->read('my_cart');
if ($user) {
$ordersTable = TableRegistry::get('orders');
$order = $ordersTable->newEntity();
$order->customer_id = $user['customer_id'];
$orderSave = $ordersTable->save($order);
$cart = $session->read('my_cart');
if ($cart) {
$invoicesTable = TableRegistry::get('invoices');
$productsTable = TableRegistry::get('products');
foreach ($cart as $key => $value) {
$product = $productsTable->find('all')->where(['product_id' => $value['product_id']])->first();
$product->qty = $value['qty'] - $value['qty'];
$productsTable->save($product);
$invoice = $invoicesTable->newEntity();
$invoice->order_id = $orderSave->order_id;
$invoice = $invoicesTable->patchEntity($invoice, $value);
$invoicesTable->save($invoice);
}
// $this->redirect->
die;
}
} else {
$session->write('flash', ['controller' => 'products', 'action' => 'orderCart']);
$this->redirect(['controller' => 'users', 'action' => 'login']);
}
}
示例10: display
/**
* Default display method.
*
* @return void
*/
public function display($items = 30)
{
$this->loadModel('Occasions');
$occasionsTable = TableRegistry::get('ArticlesManager.Occasions');
$occasions = $occasionsTable->find('active')->order(['Occasions.date_from' => 'ASC'])->limit($items);
$this->set(compact('occasions'));
}
示例11: expiracao
public function expiracao()
{
$ldap = new LDAP(3);
$vazio = true;
$Usuario = TableRegistry::get("usuario");
$datas = array(5 => (new \DateTime('+ 5 days'))->format('Ymd'), 10 => (new \DateTime('+ 10 days'))->format('Ymd'), 20 => (new \DateTime('+ 20 days'))->format('Ymd'), 30 => (new \DateTime('+ 30 days'))->format('Ymd'));
$html = '';
$usuarios = array();
$chaves = array();
foreach ($datas as $chave => $data) {
$user = $ldap->getUsers("smtDataExpiracao={$data}");
if (count($user) > 1) {
$vazio = false;
$html .= $this->geraHtml($chave, $user);
}
}
if ($vazio) {
$html = "Não há usuários a expirar.";
}
$sus = $Usuario->find()->where(['usuario.idTipoUsuario' => 1]);
$emails = array();
foreach ($sus as $su) {
array_push($emails, $su->login . '@smt.ufrj.br');
}
$email = new Email('gmail');
$email->from(['netadmin@smt.ufrj.br' => 'Controle de Usuarios'])->emailFormat('html')->to($emails)->subject('Notificação de Usuarios a expirar')->send('Usuarios : <br><br>' . $html);
$aviso = new Email('gmail');
$aviso->from(['netadmin@smt.ufrj.br' => 'Controle de Usuarios'])->emailFormat('html')->to('suporte.intranetsmt@gmail.com')->subject('JOB Realizado')->send('Job Dados Expiração executado com sucesso.');
//return $this->redirect(['action' => 'index']);
$this->set(compact('datas', 'usuarios', 'chaves', 'html'));
}
示例12: find
/**
* Find data
*
* @param $tableName
* @param array $options
* @return array|\Cake\ORM\Query
*/
public function find($tableName, array $options = [])
{
// -- get table object
$table = TableRegistry::get($tableName);
$this->_tableName = $table->alias();
// -- get query options
$this->_processRequest();
$data = $table->find('all', $options);
// -- record count
$this->_viewVars['recordsTotal'] = $data->count();
// -- filter result
$data->where($this->config('conditions'));
foreach ($this->config('matching') as $association => $where) {
$data->matching($association, function ($q) use($where) {
return $q->where($where);
});
}
$this->_viewVars['recordsFiltered'] = $data->count();
// -- add limit
$data->limit($this->config('length'));
$data->offset($this->config('start'));
// -- sort
$data->order($this->config('order'));
// -- set all view vars to view and serialize array
$this->_setViewVars();
return $data;
}
示例13: setUp
/**
* startTest
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->ImageStorage = TableRegistry::get('Burzum/FileStorage.ImageStorage');
$listener = new LocalListener();
EventManager::instance()->on($listener);
}
示例14: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
//Log::drop('default');
//Log::config('default', array('className' => 'DatabaseLog.Database'));
$this->Logs = TableRegistry::get('DatabaseLog.DatabaseLogs');
parent::setUp();
}
示例15: beforeFind
public function beforeFind(Event $event, Query $query, $options, $primary)
{
if ($query->clause('limit') == 1) {
return $query;
}
foreach ($this->orderBy() as $field => $ord) {
$f = $this->aliasField($field);
$query->order([$this->aliasField($field) => $ord]);
}
if (!is_array($this->primaryKey())) {
return $query;
}
$query->sql();
// force evaluation of internal state/objects
foreach ($query->clause('join') as $join) {
if (!$this->association($join['table'])) {
continue;
}
$table = TableRegistry::get($join['table']);
$table->alias($join['alias']);
foreach ($table->orderBy() as $field => $ord) {
$query->order([$table->aliasField($field) => $ord]);
}
}
return $query;
}