logic check full slot code example

Example: logic check full slot

-- add
$result_EventPost = $this->MemberBookEvent->EventPost->get_obj($data['MemberBookEvent']['event_post_id']);
if (!$result_EventPost) {
  $db->rollback();
  $this->Session->setFlash(__('retreive_data_not_successfully'), 'flash/warning');
  $this->redirect(array('action' => 'index'));
}

$total_joined_participants = $this->MemberBookEvent->get_joined_participants($data['MemberBookEvent']['event_post_id']);

if ($total_joined_participants >= $result_EventPost['EventPost']['total_participants']) {
  $db->rollback();
  $this->Session->setFlash(__d('member', 'full_slot_already'), 'flash/warning');
  $this->redirect(array('action' => 'index'));
}


-- edit (dont count myself)

$result_EventPost = $this->MemberBookEvent->EventPost->get_obj($data['MemberBookEvent']['event_post_id']);
if (!$result_EventPost) {
  $db->rollback();
  $this->Session->setFlash(__('retreive_data_not_successfully'), 'flash/warning');
  $this->redirect(array('action' => 'index'));
}

$total_joined_participants = $this->MemberBookEvent->get_joined_participants($data['MemberBookEvent']['event_post_id']);

if ($total_joined_participants > $result_EventPost['EventPost']['total_participants']) {
  $db->rollback();
  $this->Session->setFlash(__d('member', 'full_slot_already'), 'flash/warning');
  $this->redirect(array('action' => 'index'));
}

Tags:

Php Example