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 ''; }