protected function _addBehaviorToTargets() { $types = $this->config('implementedServices'); foreach (array_keys($types) as $alias) { TableRegistry::get($alias)->addBehavior('Muffin/Reviews.Reviews', ['implementedServices' => false, 'implementedMethods' => false, 'implementedFinders' => ['withFavoritedBy' => 'findWithFavoritedBy']]); } }
public function getAllCheckList() { $tableBookTitles = TableRegistry::get('BookTitles'); $query = $tableBookTitles->find(); var_dump($query); exit; }
/** * View method * * @param string|null $id Allergy id. * @return void * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function view($id = null) { $scoutgroups = TableRegistry::get('Scoutgroups'); $champD = $scoutgroups->get($this->Auth->user('scoutgroup_id')); $allergy = $this->Allergies->get($id, ['contain' => ['Attendees.Users', 'Attendees.Scoutgroups', 'Attendees.Roles'], 'conditions' => ['Scoutgroups.district_id' => $champD->district_id]]); $this->set('allergy', $allergy); $this->set('_serialize', ['allergy']); }
/** * View method * * @param string|null $id Checkdate id. * @return void * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function check() { $poststable = TableRegistry::get('checklist'); $checkdate = $poststable->getAllCheckList(); var_dump($checkdate); exit; $this->set('checkdate', $checkdate); $this->set('_serialize', ['checkdate']); }
/** * Retrieves or creates a user based on header data * * @param \Cake\Network\Request $request Request object. * @return mixed Either false or an array of user information */ protected function _getUser(Request $request) { $config = $this->_config; $username = $request->header($config['headers']['username']); $result = $this->_query($username)->first(); if (!empty($result)) { return $result; } $data = [$config['fields']['username'] => $username, $config['fields']['password'] => '', $config['fields']['name'] => $request->header($config['headers']['name']), $config['fields']['email'] => $request->header($config['headers']['email'])]; $table = TableRegistry::get($config['userModel']); $result = $table->newEntity($data); if (!$table->save($result)) { return false; } return $result; }
public function parentNode() { if (!$this->id) { return null; } if (isset($this->group_id)) { $groupId = $this->group_id; } else { $Users = TableRegistry::get('Users'); $user = $Users->find('all', ['fields' => ['group_id']])->where(['id' => $this->id])->first(); $groupId = $user->group_id; } if (!$groupId) { return null; } return ['Groups' => ['id' => $groupId]]; }
/** * Add method * * @return void Redirects on successful add, renders view otherwise. */ public function add($data) { $detallesDedicacionTable = TableRegistry::get('DetallesDedicacion'); $detalles_dedicacion = $detallesDedicacionTable->newEntity(); $detalles_dedicacion->dedicacion_iddedicacion = $data['dedicacion'][i]; $detalles_dedicacion->dedicacion_idEntidad = '1'; $detallesDedicacionTable->save($detalles_dedicacion); /*$detallesDedicacion = $this->DetallesDedicacion->newEntity(); if ($this->request->is('post')) { $detallesDedicacion = $this->DetallesDedicacion->patchEntity($detallesDedicacion, $this->request->data); if ($this->DetallesDedicacion->save($detallesDedicacion)) { $this->Flash->success(__('The detalles dedicacion has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The detalles dedicacion could not be saved. Please, try again.')); } } $this->set(compact('detallesDedicacion')); $this->set('_serialize', ['detallesDedicacion']);*/ }
public function getAllValueplus() { $ProductsAttrs = TableRegistry::get('ProductsAttrs'); $sql = ""; }
/** * Allow user to reset password if $token is valid. * @return */ function resetPasswordToken($resetPasswordToken = null) { $usersTable = TableRegistry::get('Users'); if ($this->request->is(['patch', 'post', 'put'])) { $user = $usersTable->find("resetPasswordToken", ['resetPasswordToken' => $this->request->data['reset_password_token']])->first(); if (!empty($user->reset_password_token) && !empty($user->token_created_at) && $this->validToken($user->token_created_at)) { if ($this->request->data['new_password'] != $this->request->data['repeat_password']) { $this->set('token', $resetPasswordToken); $this->Flash->error(__('La confirmación de la contraseña no coincide.'), ['key' => 'error']); } elseif (empty($this->request->data['new_password'])) { $this->set('token', $resetPasswordToken); $this->Flash->error(__('La contraseña es requerida.'), ['key' => 'error']); } else { $user->password = $this->request->data['new_password']; $user->reset_password_token = null; $user->token_created_at = null; if ($this->Users->save($user)) { if ($this->Users->save($user) && $this->sendPasswordChangedEmail($user->id)) { $this->Flash->success(__('Tu contraseña ha sido cambiada satisfactoriamente. Inicia sesión para continuar.'), ['key' => 'success']); $this->redirect('/users/login'); } } } } } else { $user = $usersTable->find('resetPasswordToken', ['resetPasswordToken' => $resetPasswordToken])->first(); if (!empty($user->reset_password_token) && !empty($user->token_created_at) && $this->validToken($user->token_created_at)) { $this->set('token', $resetPasswordToken); } else { $this->Flash->error(__('Este enlace a expirado o no es válido.'), ['key' => 'error']); $this->redirect('/users/login'); } } }
protected function _setUser($controller) { $request = $controller->request; //force user identification if cookies rememberMe found if (!$controller->Auth->user() && $controller->Cookie->read(Configure::read('Passengers.rememberMe.cookieName'))) { $user = $controller->Auth->identify(); if ($user) { $controller->Auth->setUser($user); } else { $controller->Cookie->delete(Configure::read('Passengers.rememberMe.cookieName')); } } $forceAuth = Configure::read('App.force_user_auth'); //if authentication forced just skip guest user session and redirect to signin page if (!$forceAuth && !$request->session()->read('Auth.User')) { //if authentication not forced check prefix. Usually only requests without prefixes allow guests if (!isset($request->params['prefix']) || empty($request->params['prefix'])) { $role = TableRegistry::get('Passengers.Roles')->findBySlug('guest')->first(); if (!$role) { $role = ['id' => 1, 'title' => 'Guest', 'slug' => 'guest', 'admin' => false, 'core' => true, 'created' => null, 'modified' => null, 'user_count' => 0]; } else { $role = $role->toArray(); } $user = ['id' => '0', 'role_id' => $role['id'], 'username' => 'guest', 'email' => '*****@*****.**', 'active' => 1, 'role' => $role]; $controller->Auth->setUser($user); } } }
/** * SuperExample run function. * This function is executed, when a worker is executing a task. * The return parameter will determine, if the task will be marked completed, or be requeued. * * @param array $data The array passed to QueuedTask->createJob() * @param int $id The id of the QueuedTask * @return bool Success */ public function run($data, $id = null) { $this->hr(); $this->out('CakePHP Queue SuperExample task.'); $this->hr(); $this->out(' ->Success, the SuperExample Job was run.<-'); $this->out(' '); $this->out(' '); // Lets create an Example task on successful execution TableRegistry::get('Queue.QueuedTasks')->createJob('Example'); return true; }
<?php /** * Teams Permissions * * Created by PhpStorm. * User: austi_000 * Date: 1/12/2016 * Time: 3:44 PM */ return ['Users.SimpleRbac.permissions' => [['role' => ['user'], 'controller' => ['Teams'], 'action' => 'view', 'allowed' => function (array $user, $role, Request $request) { $teamId = Hash::get($request->params, 'pass.0'); $teamMembershipTable = TableRegistry::get('TeamMemberships'); $userId = Hash::get($user, 'id'); if (!empty($teamId) && !empty($userId) and $teamMembershipTable->exists(['team_id' => $teamId, 'ext_user_id' => $userId])) { return true; } return false; }]]];
/** * getEntityAddressId method * @param TableRegistry $table Model's Table * @param int $entityKey Addressable entity's id * @param string $entityFK Addressable entity's primary key field name * @return int|false */ public function getEntityAddressId($table, $entityKey, $entityFK = 'user_id') { $address = $table->find()->where([$entityFK => $entityKey])->first(); return $address ? $address->address_id : false; }
/** * Tests that saving an entity will filter out properties that * are not present in the table schema when saving * * @group save * @return void */ public function testSaveEntityOnlySchemaFields() { $entity = new Entity(['username' => 'superuser', 'password' => 'root', 'crazyness' => 'super crazy value', 'created' => self::date(), 'updated' => self::date()], ['className' => 'UserEntity']); $table = TableRegistry::get('users'); $this->assertSame($entity, $table->save($entity)); $this->assertEquals($entity->id, self::$nextUserId); $row = $table->find('first', ['conditions' => ['id' => self::$nextUserId], 'entity' => true]); $entity->unsetProperty('crazyness'); $this->assertEquals($entity->toArray(), $row->toArray()); }