/** * View method * * @param string|null $id Forumtopic id. * @return void * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function view($id = null) { $forumtopic = $this->Forumtopics->get($id, ['contain' => ['Users', 'Forumresponses']]); $forumresponses = tableRegistry::get('Forumresponses')->find()->select(['Forumresponses.id', 'Forumresponses.text', 'Forumresponses.created', 'User.id', 'User.name', 'User.photo'])->join(['User' => ['table' => 'users', 'type' => 'INNER', 'conditions' => 'User.id = Forumresponses.user_id']])->where(['Forumresponses.forumtopic_id' => $id]); $this->set('forumtopic', $forumtopic); $this->set('forumresponses', $forumresponses); $this->set('_serialize', ['forumtopic']); }
/** * View method * * @param string|null $id User id. * @return void * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function view($id = null) { $user = $this->Users->get($id); $comments = tableRegistry::get('Comments')->find()->select(['Comments.id', 'Comments.comment', 'Comments.created', 'Posts.title', 'Author.name'])->join(['Posts' => ['table' => 'posts', 'type' => 'INNER', 'conditions' => 'Posts.id = Comments.post_id'], 'Author' => ['table' => 'users', 'type' => 'INNER', 'conditions' => 'Author.id = Posts.user_id']])->where(['Comments.user_id' => $id]); $games = tableRegistry::get('Games')->find()->where(['and' => ['score_a IS NOT NULL', 'score_b IS NOT NULL'], 'or' => ['user_a_id' => $id, 'user_b_id' => $id]])->toArray(); $player['titles'] = tableRegistry::get('Tournaments')->find()->where(['champion_user_id' => $id, 'finished = 1'])->count(); $player['wins'] = 0; $player['draws'] = 0; $player['losses'] = 0; $player['goalsFor'] = 0; $player['goalsAgainst'] = 0; $player['goalsDifference'] = 0; foreach ($games as $key => $game) { if ($game['user_a_id'] == $id) { if ($game['score_a'] > $game['score_b']) { $player['wins'] += 1; } else { if ($game['score_a'] == $game['score_b']) { $player['draws'] += 1; } else { if ($game['score_a'] < $game['score_b']) { $player['losses'] += 1; } } } $player['goalsFor'] += $game['score_a']; $player['goalsAgainst'] += $game['score_b']; } else { if ($game['user_b_id'] == $id) { if ($game['score_b'] > $game['score_a']) { $player['wins'] += 1; } else { if ($game['score_b'] == $game['score_a']) { $player['draws'] += 1; } else { if ($game['score_b'] < $game['score_a']) { $player['losses'] += 1; } } } $player['goalsFor'] += $game['score_b']; $player['goalsAgainst'] += $game['score_a']; } } } $player['goalsDifference'] = $player['goalsFor'] - $player['goalsAgainst']; if ($user->club) { $this->loadModel('Teams'); $team = $this->Teams->get($user->club); $this->set('team', $team); } $this->set('user', $user); $this->set('player', $player); $this->set('comments', $comments); $this->set('_serialize', ['user']); }
public function entity_patch() { $this->layout = false; $this->autoRender = false; $this->request->data['name'] = 'xyz'; $this->request->data['service_id'] = 1; pr($this->request->data); $this->Registrations = tableRegistry::get('registrations'); $ent = $this->Registrations->newEntity($this->request->data); pr($ent); //TEST 1->in case of edit $singel_record = $this->Registrations->get(2); $pth = $this->Registrations->patchEntity($singel_record, $this->request->data); pr($pth); //TEST 2 $d['service_id'] = 2; $pth = $this->Registrations->patchEntity($ent, $d); pr($pth); //TEST 3 $this->request->data['service_id'] = 2; $pth = $this->Registrations->patchEntity($ent, $this->request->data); pr($pth); // if($this->Registrations->save($ent)) // { // echo 'saved'; // } // else // { // echo 'not saved'; // } //pr($ent); }