Skip to content

Instantly share code, notes, and snippets.

@McGaiser
Created December 18, 2015 12:02
Show Gist options
  • Save McGaiser/ee9fa849e414b79cb7bc to your computer and use it in GitHub Desktop.
Save McGaiser/ee9fa849e414b79cb7bc to your computer and use it in GitHub Desktop.
public function editPrestige($id=null){
$prestigeLog = $this->PrestigeLogs->get($id,
['contain'=>[
'Members.Domains',
'PrestigeLogsItems'=> function ($q){
return $q->where(['approved_id IS NULL']);
}
]]);
debug($prestigeLog);
debug($this->request->data());
$prestigeLogsItems = $prestigeLog->prestige_logs_items;
if ($this->request->is(['post', 'put'])) {
//Update the object with request data.
$patched = $this->PrestigeLogs->PrestigeLogsItems->patchEntities($prestigeLogsItems, $this->request->data());
$valid = true;
foreach($patched as $entity){
$result = $this->PrestigeLogs->PrestigeLogsItems->save($entity);
if(!$result) $valid = false;
}
if ($valid) {
$this->Flash->success(__('The Prestige Log Items has been updated.'));
return $this->redirect(['action' => 'view', $id]);
}
$this->Flash->error(__('Unable to update the prestigeLog.'));
}
$affiliateId = $this->PrestigeLogs->PrestigeLogsItems->PrestigeItems->PrestigeCategories->Affiliates->getAffiliateIdByDomainId($this->request->session()->read('Auth.User.domain_id'));
$prestigeItems = $this->PrestigeLogs->PrestigeLogsItems->PrestigeItems->getPrestigeItemsList($affiliateId);
$domains = $this->PrestigeLogs->PrestigeLogsItems->Domains->find('list')->toArray();
$venues = $this->PrestigeLogs->PrestigeLogsItems->Venues->find('list')->contain(['Games'])->group(['Games.id'])->toArray();
$this->set(compact('prestigeLog', 'prestigeLogsItems', 'prestigeItems', 'domains', 'venues'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment