public function index($offset = 0, $orderField = '', $orderCriteria = '') { $model = SCallbacksQuery::create()->joinSCallbackStatuses(null, 'left join')->joinSCallbackThemes(null, 'left join'); if ($this->input->get('filterID') && $this->input->get('filterID') > 0) { $model = $model->filterById((int) $this->input->get('filterID')); } if ($this->input->get('user_name')) { $user_name = $this->input->get('user_name'); if (!strpos($user_name, '%')) { $user_name = '%' . $user_name . '%'; } $model->condition('name', 'SCallbacks.Name LIKE ?', $user_name); $model->where(array('name'), Criteria::LOGICAL_OR); } if ($this->input->get('phone')) { $phone = $this->input->get('phone'); if (!strpos($phone, '%')) { $phone = '%' . $phone . '%'; } $model->condition('phone', 'SCallbacks.Phone LIKE ?', $phone); $model->where(array('phone'), Criteria::LOGICAL_OR); } if ($this->input->get('ThemeId')) { if ((int) $this->input->get('ThemeId') > 0) { $model = $model->filterByThemeId((int) $this->input->get('ThemeId')); } if ($this->input->get('ThemeId') === 'without') { $model = $model->where('SCallbacks.ThemeId = ?', 0); } } if ($this->input->get('StatusId') && $this->input->get('StatusId') > 0) { $model = $model->filterByStatusId((int) $this->input->get('StatusId')); } if ($this->input->get('created_from')) { $model = $model->where('FROM_UNIXTIME(SCallbacks.Date, \'%Y-%m-%d\') >= ?', date('Y-m-d', strtotime($this->input->get('created_from')))); } if ($this->input->get('created_to')) { $model = $model->where('FROM_UNIXTIME(SCallbacks.Date, \'%Y-%m-%d\') <= ?', date('Y-m-d', strtotime($this->input->get('created_to')))); } if ($orderField !== '' && $orderCriteria !== '' && (method_exists($model, 'filterBy' . $orderField) || $orderField == 'SCallbackStatuses.Text' || $orderField == 'SCallbackThemes.Text')) { switch ($orderCriteria) { case 'ASC': $model = $model->orderBy($orderField, Criteria::ASC); $nextOrderCriteria = 'DESC'; break; case 'DESC': $model = $model->orderBy($orderField, Criteria::DESC); $nextOrderCriteria = 'ASC'; break; } } else { $model->orderById(Criteria::DESC); } $totalCallbacks = $this->_count($model); $model = $model->limit(10)->offset((int) $offset)->find(); $callbackStatuses = SCallbackStatusesQuery::create()->joinWithI18n(MY_Controller::defaultLocale(), Criteria::RIGHT_JOIN)->where('SCallbackStatusesI18n.Locale = "' . MY_Controller::defaultLocale() . '"')->orderBy('IsDefault', Criteria::DESC)->orderById()->find(); \CMSFactory\assetManager::create()->setData(array('model' => $model, 'totalCallbacks' => $totalCallbacks, 'nextOrderCriteria' => $nextOrderCriteria, 'orderField' => $orderField, 'callbackStatuses' => $callbackStatuses))->render('main'); }
/** * Get new callbacks count view * @param array $data * @return string */ public function getNewCallbacksCount($data = array()) { // SELECT `id` FROM `shop_callbacks_statuses` WHERE `is_default`=1; if (SHOP_INSTALLED) { if (count($data)) { $newCallbacksCount = array_shift($data); } else { $newStatus = \SCallbackStatusesQuery::create()->filterByIsDefault(TRUE)->findOne(); $newCallbacksCount = $newStatus ? \SCallbacksQuery::create()->filterByStatusId($newStatus->getId())->find()->count() : 0; } return $newCallbacksCount ? '<span class="menu-counter">' . $newCallbacksCount . '</span>' : ''; } return ''; }
public function index() { $success = FALSE; $this->load->library('Form_validation'); $this->form_validation->set_error_delimiters(FALSE, FALSE); $model = new SCallbacks(); if ($this->input->post()) { $this->form_validation->set_message('required', $model->validationMessage('required')); $this->form_validation->set_rules($model->rules()); if ($this->form_validation->run($this) !== FALSE) { $theme = SCallbackThemesQuery::create()->orderByPosition()->findOne(); if ($theme) { $model->setThemeId($theme->getId()); } else { $model->setThemeId(0); } $model->fromArray($this->input->post()); $model->setDate(time()); $model->setStatusId(SCallbackStatusesQuery::create()->filterByIsDefault(TRUE)->findOne()->getId()); $model->save(); $info = array(); $info['userName'] = $model->getName(); $info['userPhone'] = $model->getPhone(); $info['dateCreated'] = $model->getDate(); $info['callbackStatus'] = $model->getSCallbackStatuses()->getText(); if ($theme) { $info['callbackTheme'] = $model->getSCallbackThemes()->getText(); } $info['userComment'] = $model->getComment(); $this->composeAndSendEmail($info); $locale = \MY_Controller::getCurrentLocale(); $notif = $this->db->where('locale', $locale)->where('name', 'callback')->get('answer_notifications')->row(); $success = $notif->message; /** Register event 'category:load' */ CMSFactory\Events::create()->raiseEvent(['model' => $model], 'Shop:callback'); echo json_encode(array('msg' => $success, 'status' => true, 'close' => true, 'refresh' => $this->input->post('refresh') ? $this->input->post('refresh') : FALSE, 'redirect' => $this->input->post('redirect') ? $this->input->post('redirect') : FALSE)); } else { echo json_encode(array('msg' => validation_errors(), 'status' => false, 'validations' => array('Name' => form_error('Name'), 'Phone' => form_error('Phone'), 'Comment' => form_error('Comment')))); } } else { echo json_encode(array('msg' => "Ошибка, не достаточно данных", 'status' => false)); } }