public function add() { //if project files is not empty -- to be removed if (!empty($data['Project']['project_file'])) { $attached_files = json_decode($data['Project']['project_file'], true); $this->set('attached_files', $attached_files); } if ($this->request->is(array('post', 'put'))) { if (!empty($this->request->data['Project']['project_file'])) { $this->request->data['Project']['project_file'] = json_encode($this->request->data['Project']['project_file']); } // store project owner name instead of id if selected in form if (!empty($this->request->data['Project']['owner'])) { $this->User->id = $this->request->data['Project']['owner']; $this->request->data['Project']['owner'] = $this->User->field('name'); } // set project start date and store in sql format if (!empty($this->request->data['Project']['project_start'])) { $this->request->data['Project']['project_start'] = sqlFormatDate($this->request->data['Project']['project_start']); } else { $this->request->data['Project']['project_start'] = gmdate('Y-m-d'); } // set project deadline if (!empty($this->request->data['Project']['deadline'])) { $this->request->data['Project']['deadline'] = sqlFormatDate($this->request->data['Project']['deadline']); } /* if(empty($this->request->data['Deliverable']['project_id'])){ echo 'no project selected'; $this->Session->setFlash(__('No project selected!')); return false; } */ if ($this->Project->saveAll($this->request->data)) { $this->Session->setFlash('Project Created!'); $this->redirect(array('action' => 'index')); } } }
public function beforeFind($queryData) { if (isset(Router::getRequest()->query['Search'])) { $search = Router::getRequest()->query['Search']; if (isset($search['Table']) && $search['Table'] == $this->alias) { unset($search['Table']); foreach ($search as $key => $val_parent) { foreach ($val_parent as $key_child => $val) { if (is_array($val) && !empty($val)) { if (isset($val['from']) && $val['from'] != '') { $queryData['conditions'][$key . '.' . $key_child . ' >= '] = $val['from']; } if (isset($val['from_date']) && $val['from_date'] != '') { $queryData['conditions'][$key . '.' . $key_child . ' >= '] = sqlFormatDate($val['from_date']); } if (isset($val['to']) && $val['to'] != '') { $queryData['conditions'][$key . '.' . $key_child . ' <= '] = $val['to']; } if (isset($val['to_date']) && $val['to_date'] != '') { $queryData['conditions'][$key . '.' . $key_child . ' <= '] = sqlFormatDate($val['to_date']); } } else { if ($val != '') { if ($key_child == 'id') { $queryData['conditions'][$key . '.' . $key_child . ' = '] = $val; } else { $queryData['conditions'][$key . '.' . $key_child . ' LIKE '] = '%' . $val . '%'; } } } } } //print_r($queryData);die; return $queryData; } } }
public function edit($id = null) { $this->User->id = $id; // $group_id = $this->User->Group->find('list', array( // 'fields' => 'id, group_id', // 'conditions' => array('user_id' => $id) // )); if (!$this->User->exists()) { throw new NotFoundException(__('Invalid user')); } if ($this->request->is('post') || $this->request->is('put')) { /* if(!$this->request->data['User']['password']){ unset($this->request->data['User']['password']); } */ $error_status = false; $error_message = ''; $groups = array(); foreach ($this->request->data['Group']['Group'] as $key => $value) { if (!empty($value)) { $groups[] = $value; } else { unset($this->request->data['Group']['Group'][$key]); } } if (empty($groups)) { $error_status = true; $error_message .= __('Group not empty') . '<br />'; } if (in_array(Configure::read('Settings.Company.JobGroupId'), $groups)) { if (empty($this->request->data['User']['candidate_address'])) { $error_status = true; $error_message .= __('Candidate address not empty') . '<br />'; } if (!empty($this->request->data['User']['candidate_dob'])) { $this->request->data['User']['candidate_dob'] = sqlFormatDate($this->request->data['User']['candidate_dob']); } else { $error_status = true; $error_message .= __('Candidate date of birth not empty') . '<br />'; } if (empty($this->request->data['User']['candidate_last_drawn_salary'])) { $error_status = true; $error_message .= __('Candidate last drawn salary not empty') . '<br />'; } if (empty($this->request->data['User']['candidate_expected_salary'])) { $error_status = true; $error_message .= __('Candidate expected salary not empty') . '<br />'; } if (!empty($this->request->data['User']['candidate_resume'])) { $this->request->data['User']['candidate_resume'] = json_encode($this->request->data['User']['candidate_resume']); } else { $error_status = true; $error_message .= __('Candidate resume birth not empty') . '<br />'; } if (!empty($this->request->data['User']['candidate_portfolio_files'])) { $this->request->data['User']['candidate_portfolio_files'] = json_encode($this->request->data['User']['candidate_portfolio_files']); } } else { unset($this->request->data['User']['candidate_dob']); unset($this->request->data['User']['candidate_address']); unset($this->request->data['User']['candidate_last_drawn_salary']); unset($this->request->data['User']['candidate_expected_salary']); unset($this->request->data['User']['candidate_resume']); unset($this->request->data['User']['candidate_portfolio_link']); unset($this->request->data['User']['candidate_portfolio_files']); } if (!$error_status) { if ($this->User->save($this->request->data)) { $this->Session->setFlash(__('The user has been saved')); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The user could not be saved. Please, try again.'), 'warning'); } } else { $this->request->data['User']['candidate_dob'] = formatDate($this->request->data['User']['candidate_dob']); $this->Session->setFlash($error_message, 'warning'); } } else { $this->request->data = $this->User->read(null, $id); //$this->request->data['User']['group_id'] = $group_id; if (!empty($this->request->data['User']['candidate_dob'])) { $this->request->data['User']['candidate_dob'] = formatDate($this->request->data['User']['candidate_dob']); } $this->set('resume', json_decode($this->request->data['User']['candidate_resume'], true)); $this->set('portfolio_files', json_decode($this->request->data['User']['candidate_portfolio_files'], true)); unset($this->request->data['User']['password']); } }
function edit($id = null) { $this->Enquiry->id = $id; if (!$this->Enquiry->exists()) { throw new NotFoundException(__('Invalid Enquiry')); } $data = $this->Enquiry->read(null, $id); $data['Enquiry']['enq_date'] = formatDate($data['Enquiry']['enq_date']); //$this->set('channels', $this->Channel->find('list',array('fields' => 'id,name'))); $this->set('affiliates', $this->Affiliate->find('list', array('fields' => 'id,name', 'joins' => array(array('table' => 'users_groups', 'alias' => 'UsersGroup', 'type' => 'LEFT', 'conditions' => array('UsersGroup.user_id = Affiliate.id'))), 'conditions' => array('UsersGroup.group_id' => (int) Configure::read('Settings.Company.AffiliateGroupId'), 'Affiliate.active' => 1)))); $this->Captcha = $this->Components->load('Captcha'); $this->Enquiry->setCaptcha($this->Captcha->getVerCode()); $files_decode = json_decode($data['Enquiry']['file_list']); $this->set('files', $files_decode); $marketing_adv = array(); $marketing_adv = $this->AdvertisingLink->find('list', array('fields' => 'id,description', 'conditions' => array('AdvertisingLink.marketing_channels_id' => $data['Enquiry']['marketing_channels_id'], 'AdvertisingLink.history_status' => 1), 'recursive' => -1, 'permissionable' => false)); $this->set('advertisingLinks', $marketing_adv); if ($this->request->is('post') || $this->request->is('put')) { $this->request->data['Enquiry']['enq_date'] = sqlFormatDate($this->request->data['Enquiry']['enq_date']); if (isset($this->request->data['Enquiry']['files'])) { $dataImage = $this->request->data['Enquiry']['files']; $cv_files_decode = (array) $files_decode; $data_remove = array_diff($cv_files_decode, $dataImage); foreach ($data_remove as $key => $value) { $file = new File(WWW_ROOT . 'uploads/' . $value, false, 0777); $file->delete(); } //print_r( $this->request->data['Enquiry'] );die; $this->request->data['Enquiry']['file_list'] = json_encode($dataImage); } else { $this->request->data['Enquiry']['file_list'] = null; } if ($this->Enquiry->save($this->request->data)) { $this->Session->setFlash(__('The Enquiry has been saved')); return $this->redirect(array('action' => 'index')); } $this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.')); } else { $this->request->data = $data; } }
public function edit($id) { $this->ChangeRequest->id = $id; if (!$this->ChangeRequest->exists()) { throw new NotFoundException(__('Invalid Meeting Minute')); } if ($this->request->is(array('post', 'put'))) { $this->request->data['ChangeRequest']['id'] = $id; if (!in_array($this->request->data['ChangeRequest']['minute_taker'], $this->request->data['ChangeRequest']['attendees']) && !in_array($this->request->data['ChangeRequest']['minute_taker'], $this->request->data['ChangeRequest']['cc_list'])) { array_push($this->request->data['ChangeRequest']['attendees'], $this->request->data['ChangeRequest']['minute_taker']); } $this->request->data['ChangeRequest']['date'] = sqlFormatDate($this->request->data['ChangeRequest']['date']); $this->request->data['ChangeRequest']['attendees'] = json_encode($this->request->data['ChangeRequest']['attendees']); $this->request->data['ChangeRequest']['cc_list'] = json_encode($this->request->data['ChangeRequest']['cc_list']); foreach ($this->request->data['NoteDetail'] as $key => $value) { if (!empty($value['due_date'])) { $this->request->data['NoteDetail'][$key]['due_date'] = sqlFormatDateTime($value['due_date']); } } if ($this->ChangeRequest->saveAll($this->request->data)) { $this->Session->setFlash(__('The Meeting minute has been saved')); $this->redirect(array('action' => 'index')); } } else { $this->request->data = $this->ChangeRequest->read(null, $id); $this->request->data['ChangeRequest']['date'] = formatDate($this->request->data['ChangeRequest']['date']); $this->request->data['ChangeRequest']['attendees'] = json_decode($this->request->data['ChangeRequest']['attendees'], true); $this->request->data['ChangeRequest']['cc_list'] = json_decode($this->request->data['ChangeRequest']['cc_list'], true); $note_details = $this->NoteDetail->getByNote($id); $this->set('note_details', $note_details); } }
/** * @Description : public * * @return : form add * @Author : tungpa - tungbk29@gmail.com */ public function visitor() { if ($this->request->is(array('post', 'put'))) { $this->Captcha = $this->Components->load('Captcha'); $this->Brief->setCaptcha($this->Captcha->getVerCode()); $this->Brief->create(); $this->request->data['Brief']['date'] = sqlFormatDate($this->request->data['Brief']['date']); if (!empty($this->request->data['Brief']['attached_files'])) { $this->request->data['Brief']['attached_files'] = json_encode($this->request->data['Brief']['attached_files']); } $this->request->data['Brief']['created'] = gmdate('Y-m-d h:i:s'); $this->request->data['Brief']['user_created'] = 0; $this->request->data['Brief']['random_key'] = substr(md5(microtime()), rand(0, 26), 9); if ($this->Brief->save($this->request->data)) { //send notification to all staff $staffs = $this->User->find('list', array('fields' => 'User.id, User.email', 'joins' => array(array('table' => 'users_groups', 'alias' => 'UsersGroup', 'type' => 'LEFT', 'conditions' => array('User.id = UsersGroup.user_id'))), 'conditions' => array('UsersGroup.group_id' => Configure::read('Settings.Company.SalesStaffGroupId')), 'permissionable' => false)); $content = '<a href="' . Router::url(array('plugin' => false, 'controller' => 'briefs', 'action' => 'view', $id), true) . '">' . $this->request->data['Brief']['project_title'] . '</a>'; $arr_options = array('to' => $staffs, 'subject' => __('Client create brief'), 'viewVars' => array('content' => $content)); $this->_sendemail($arr_options); $this->Session->setFlash(__('Thank you!')); return $this->redirect(array('action' => 'visitor')); } } }
function edit($id) { $this->Event->id = $id; $data = $this->Event->read(); if ($this->request->is('post') || $this->request->is('put')) { $this->request->data['Event']['start_date'] = sqlFormatDate($this->request->data['Event']['start_date']); $this->request->data['Event']['end_date'] = sqlFormatDate($this->request->data['Event']['end_date']); if (strtotime($this->request->data['Event']['end_date']) < strtotime($this->request->data['Event']['start_date'])) { $this->Session->setFlash('End date cannot be earlier than start date!'); } else { $diff = array_diff($this->data['Event'], $data['Event']); if (!empty($diff)) { $this->request->data['Event']['history_link'] = 0; } if ($this->Event->save($this->request->data)) { //save history if (!empty($diff)) { $status = ''; if (in_array('name', array_keys($diff))) { $status .= empty($status) ? __('Change name') : ', ' . __('Change name'); } if (in_array('start_date', array_keys($diff))) { $status .= empty($status) ? __('Change start date') : ', ' . __('Change start date'); } if (in_array('end_date', array_keys($diff))) { $status .= empty($status) ? __('Change end date') : ', ' . __('Change end date'); } unset($data['Event']['id']); $data['Event']['history_status'] = 2; $data['Event']['history_link'] = $id; $data['Event']['name'] = $data['Event']['name'] . '-bk' . substr(md5(microtime()), rand(0, 26), 5); $this->Event->create(); $this->Event->disablePermissionable('Event'); if ($this->Event->save($data)) { $history['History']['plugin'] = 'marketing'; $history['History']['controller'] = 'Events'; $history['History']['action'] = 'view'; $history['History']['history_id'] = $this->Event->id; $history['History']['action_status'] = $status; $history['History']['original_id'] = $id; $history['History']['user_modified'] = $this->Session->read('Auth.User.id'); $history['History']['date_modified'] = gmdate('Y-m-d H:i:s'); $this->History->save($history); } else { prd($this->Event->validationErrors); } } $this->Session->setFlash('Your event has been updated.'); $this->redirect(array('action' => 'index')); } } } else { $data['Event']['start_date'] = formatDate($data['Event']['start_date']); if (strtotime($data['Event']['end_date']) != 0) { $data['Event']['end_date'] = formatDate($data['Event']['end_date']); } else { $data['Event']['end_date'] = ""; } $this->request->data = $data; } if (empty($this->data)) { } else { $data = $this->data; } }
public function followUp($id) { $this->Quotation->id = $id; if (!$this->Quotation->exists()) { throw new NotFoundException(__('Invalid Quotation')); } if ($this->request->is('post') || $this->request->is('put')) { if (!isset($this->request->data['Quotation']['choose_follow'])) { $this->Session->setFlash(__('Please select type follow up')); return $this->redirect(array('action' => 'followUp', $id)); } // if( if ($this->request->data['Quotation']['choose_follow'] == 0) { if (strtotime(sqlFormatDate($this->request->data['Quotation']['next_follow_up'])) - time() < 0) { $this->Session->setFlash(__('Min date is today')); return $this->redirect(array('action' => 'followUp', $id)); } $this->request->data['Quotation']['next_follow_up'] = sqlFormatDate($this->request->data['Quotation']['next_follow_up']); unset($this->request->data['Quotation']['follow_up_days']); } else { unset($this->request->data['Quotation']['next_follow_up']); } if ($this->Quotation->save($this->request->data)) { $this->Session->setFlash(__('Follow up setting has been saved')); return $this->redirect(array('action' => 'index')); } } else { $this->set('data', $this->Quotation->read(null, $id)); } }
function enquiries() { //find SaveReport $data['SaveReport'] = $this->SaveReport->find('all', array('conditions' => array('user_id' => $this->Session->read('Auth.User.id'), 'type' => 1))); if (!empty($this->request->query)) { //save filter if (!empty($this->request->query['save_filter'])) { // print_r($this->request->query);die; $_uri = $_SERVER['REQUEST_URI']; $n = strpos($_SERVER['REQUEST_URI'], '&title') - strlen($_SERVER['REQUEST_URI']); $_uri = substr($_uri, 0, $n); $url = "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER['HTTP_HOST'] . $_uri; $data['SaveReport']['url'] = $url; $data['SaveReport']['type'] = 1; $data['SaveReport']['created'] = gmdate('Y-m-d h:i:s'); $data['SaveReport']['title'] = $this->request->query['title']; $data['SaveReport']['type_report'] = $this->request->query['type_report']; switch ($this->request->query['type_report']) { case 'day_view': $data['SaveReport']['start_date'] = sqlFormatDate($this->request->query['start_date']); $data['SaveReport']['end_date'] = sqlFormatDate($this->request->query['end_date']); break; case 'day_of_week': $data['SaveReport']['start_date'] = sqlFormatDate($this->request->query['day_of_week']); break; default: $data['SaveReport']['start_date'] = sqlFormatDate($this->request->query['time_of_day']); break; } $this->SaveReport->save($data); $this->redirect($url); } if ($this->request->query['type_report'] == 'day_view') { if (strtotime(sqlFormatDate($this->request->query['end_date'])) - strtotime(sqlFormatDate($this->request->query['start_date'])) < 0) { } else { $data['title'] = __('Enquiry Report Chart - Day view'); // echo $day; $list_links = $this->AdvertisingLink->find('all', array('joins' => array(array('table' => 'marketing_enquiries', 'alias' => 'Enquiry', 'type' => 'LEFT', 'conditions' => array('Enquiry.marketing_advertising_links_id = AdvertisingLink.id', 'AdvertisingLink.history_status' => 1))), 'conditions' => array('Enquiry.enquiry_time >' => sqlFormatDate($this->request->query['start_date']), 'Enquiry.enquiry_time <' => sqlFormatDate($this->request->query['end_date'])), 'fields' => array('AdvertisingLink.id', 'AdvertisingLink.description, DAY(Enquiry.enquiry_time) day, MONTH(Enquiry.enquiry_time) month, YEAR(Enquiry.enquiry_time) year, count(Enquiry.id) as click'), 'group' => 'DAY(Enquiry.enquiry_time),AdvertisingLink.id', 'order' => 'AdvertisingLink.id ASC,Enquiry.enquiry_time ASC')); $start_date = strtotime(sqlFormatDate($this->request->query['start_date'])); $end_date = strtotime(sqlFormatDate($this->request->query['end_date'])); //rebuild data $arrItem = array(); $arrCate = array(); foreach ($list_links as $k => $item) { $arrItem[$item['AdvertisingLink']['id']]['title'] = $item['AdvertisingLink']['description']; $n = ''; for ($i = $start_date; $i <= $end_date; $i += 86400) { // echo $i.'<br />'; $_day = date('j', $i); $_month = date('n', $i); if ($k == 0) { $arrCate[] = "'" . date('D', $i) . " (" . formatDate(date('Y-m-d', $i)) . ")" . "'"; } if (!isset($arrItem[$item['AdvertisingLink']['id']]['day'][$_day . '-' . $_month])) { $arrItem[$item['AdvertisingLink']['id']]['day'][$_day . '-' . $_month] = 0; } if ($item[0]['day'] == $_day && $item[0]['month'] == $_month) { $arrItem[$item['AdvertisingLink']['id']]['day'][$_day . '-' . $_month] = $item[0]['click']; } } } $series = ''; foreach ($arrItem as $k => $item) { $series .= "{name: '" . $item['title'] . "', data: [" . implode(',', array_values($item['day'])) . "]},"; } //find event $events = $this->Event->find('all', array('conditions' => array('AND' => array('OR' => array(array('AND' => array(array('Event.start_date >=' => sqlFormatDate($this->request->query['start_date'])), array('Event.start_date <=' => sqlFormatDate($this->request->query['end_date'])))), array('AND' => array(array('Event.end_date >=' => sqlFormatDate($this->request->query['start_date'])), array('Event.end_date <=' => sqlFormatDate($this->request->query['end_date'])))), array('AND' => array(array('Event.start_date <=' => sqlFormatDate($this->request->query['start_date'])), array('Event.end_date >=' => sqlFormatDate($this->request->query['end_date'])))), array('AND' => array(array('Event.start_date >=' => sqlFormatDate($this->request->query['start_date'])), array('Event.end_date <=' => sqlFormatDate($this->request->query['end_date']))))), 'Event.history_status' => 1)), 'permissionable' => false, 'order' => 'Event.start_date ASC')); $data['events'] = $events; $series = substr($series, 0, -1); $data['series'] = $series; $data['category'] = implode(',', array_values($arrCate)); $data['count_series'] = count($arrCate); $data['start_date'] = $start_date; $data['end_date'] = $end_date; } } else { if ($this->request->query['type_report'] == 'day_of_week') { $data['title'] = __('Enquiry Report Chart - Day of Week view'); $first_day_of_week = strtotime('monday this week', strtotime(sqlFormatDate($this->request->query['day_of_week']))); $last_day_of_week = strtotime('sunday this week', strtotime(sqlFormatDate($this->request->query['day_of_week']))); if (Configure::read('Settings.Formats.start_week') == 0) { $first_day_of_week = strtotime('sunday last week', strtotime(sqlFormatDate($this->request->query['day_of_week']))); $last_day_of_week = strtotime('saturday this week', strtotime(sqlFormatDate($this->request->query['day_of_week']))); } //find list link $list_links = $this->AdvertisingLink->find('all', array('joins' => array(array('table' => 'marketing_enquiries', 'alias' => 'Enquiry', 'type' => 'LEFT', 'conditions' => array('Enquiry.marketing_advertising_links_id = AdvertisingLink.id', 'AdvertisingLink.history_status' => 1))), 'conditions' => array('Enquiry.enquiry_time >' => date('Y-m-d', $first_day_of_week), 'Enquiry.enquiry_time <' => date('Y-m-d', $last_day_of_week)), 'fields' => array('AdvertisingLink.id', 'AdvertisingLink.description, DAY(Enquiry.enquiry_time) day, MONTH(Enquiry.enquiry_time) month, YEAR(Enquiry.enquiry_time) year, count(Enquiry.id) as click'), 'group' => 'DAY(Enquiry.enquiry_time),AdvertisingLink.id', 'order' => 'AdvertisingLink.id ASC,Enquiry.enquiry_time ASC')); //rebuild data $arrItem = array(); $arrCate = array(); foreach ($list_links as $k => $item) { $arrItem[$item['AdvertisingLink']['id']]['title'] = $item['AdvertisingLink']['description']; $n = ''; for ($i = $first_day_of_week; $i <= $last_day_of_week; $i += 86400) { $_day = date('j', $i); $_month = date('n', $i); if ($k == 0) { $arrCate[] = "'" . date('D', $i) . " (" . formatDate(date('Y-m-d', $i)) . ")" . "'"; } if (!isset($arrItem[$item['AdvertisingLink']['id']]['day'][$_day . '-' . $_month])) { $arrItem[$item['AdvertisingLink']['id']]['day'][$_day . '-' . $_month] = 0; } if ($item[0]['day'] == $_day && $item[0]['month'] == $_month) { $arrItem[$item['AdvertisingLink']['id']]['day'][$_day . '-' . $_month] = $item[0]['click']; } } } $series = ''; foreach ($arrItem as $k => $item) { $series .= "{name: '" . $item['title'] . "', data: [" . implode(',', array_values($item['day'])) . "]},"; } $series = substr($series, 0, -1); //find event $events = $this->Event->find('all', array('conditions' => array('AND' => array('OR' => array(array('AND' => array(array('Event.start_date >=' => date('Y-m-d', $first_day_of_week)), array('Event.start_date <=' => date('Y-m-d', $last_day_of_week)))), array('AND' => array(array('Event.end_date >=' => date('Y-m-d', $first_day_of_week)), array('Event.end_date <=' => date('Y-m-d', $last_day_of_week)))), array('AND' => array(array('Event.start_date <=' => date('Y-m-d', $first_day_of_week)), array('Event.end_date >=' => date('Y-m-d', $last_day_of_week)))), array('AND' => array(array('Event.start_date >=' => date('Y-m-d', $first_day_of_week)), array('Event.end_date <=' => date('Y-m-d', $last_day_of_week))))), 'Event.history_status' => 1)), 'permissionable' => false, 'order' => 'Event.start_date ASC')); $data['events'] = $events; $data['series'] = $series; $data['category'] = implode(',', array_values($arrCate)); $data['count_series'] = count($arrCate); $data['start_date'] = $first_day_of_week; $data['end_date'] = $last_day_of_week; } else { $data['title'] = __('Enquiry Report Chart - Time of Day view'); //find list link $list_links = $this->AdvertisingLink->find('all', array('joins' => array(array('table' => 'marketing_enquiries', 'alias' => 'Enquiry', 'type' => 'LEFT', 'conditions' => array('Enquiry.marketing_advertising_links_id = AdvertisingLink.id', 'AdvertisingLink.history_status' => 1))), 'conditions' => array('DATE_FORMAT(Enquiry.enquiry_time,\'%Y-%m-%d\')' => sqlFormatDate($this->request->query['time_of_day'])), 'fields' => array('AdvertisingLink.id', 'AdvertisingLink.description, HOUR(Enquiry.enquiry_time) hour, DAY(Enquiry.enquiry_time) day, MONTH(Enquiry.enquiry_time) month, YEAR(Enquiry.enquiry_time) year, count(Enquiry.id) as click'), 'group' => 'HOUR(Enquiry.enquiry_time),AdvertisingLink.id', 'order' => 'AdvertisingLink.id ASC,Enquiry.enquiry_time ASC')); //rebuild data $arrItem = array(); $arrCate = array(); foreach ($list_links as $k => $item) { $arrItem[$item['AdvertisingLink']['id']]['title'] = $item['AdvertisingLink']['description']; $n = ''; for ($i = 0; $i <= 23; $i++) { $arrCate[] = $i; if (!isset($arrItem[$item['AdvertisingLink']['id']]['hour'][$i])) { $arrItem[$item['AdvertisingLink']['id']]['hour'][$i] = 0; } if ($item[0]['hour'] == $i) { $arrItem[$item['AdvertisingLink']['id']]['hour'][$i] = $item[0]['click']; } } } $series = ''; foreach ($arrItem as $k => $item) { $series .= "{name: '" . $item['title'] . "', data: [" . implode(',', array_values($item['hour'])) . "]},"; } $series = substr($series, 0, -1); $data['series'] = $series; $data['category'] = implode(',', array_values($arrCate)); $data['count_series'] = count($arrCate); $events = $this->Event->find('all', array('conditions' => array('AND' => array(array(array('Event.start_date <=' => sqlFormatDate($this->request->query['time_of_day']))), array(array('Event.end_date >=' => sqlFormatDate($this->request->query['time_of_day']))))), 'permissionable' => false, 'order' => 'Event.start_date ASC')); $data['events'] = $events; $data['start_date'] = strtotime(sqlFormatDate($this->request->query['time_of_day'])); $data['end_date'] = strtotime(sqlFormatDate($this->request->query['time_of_day'])); } } } $this->set('data', $data); }