/** * แสดงผล * * @param object $index ข้อมูลโมดูล */ public function render($index) { // รายการ $listitem = Grid::create('search', 'search', 'searchitem'); foreach ($index->items as $item) { if ($item->index == 0 && $item->owner == 'document') { // document $uri1 = \Document\Index\Controller::url($item->module, $item->alias, $item->id); $uri2 = \Document\Index\Controller::url($item->module, $item->alias, $item->id, false); } elseif ($item->index == 0 && $item->owner == 'board') { // board $uri1 = \Board\Index\Controller::url($item->module, 0, $item->id); $uri2 = $uri1; } else { // other if (self::$cfg->module_url == 1) { $uri1 = Gcms::createUrl($item->module, $item->alias); $uri2 = Gcms::createUrl($item->module, $item->alias, 0, 0, '', false); } else { $uri1 = Gcms::createUrl($item->module, '', 0, $item->id, ''); $uri2 = $uri1; } } $listitem->add(array('/{URL}/' => $uri1, '/{TOPIC}/' => $item->topic, '/{LINK}/' => $uri2, '/{DETAIL}/' => $item->description)); } // template search/search.html $template = Template::create('search', 'search', 'search'); // canonical $index->canonical = Gcms::createUrl($index->module); // current URL $uri = \Kotchasan\Http\Uri::createFromUri($index->canonical); if ($index->total > 0) { $list = Gcms::highlightSearch($listitem->render(), $index->q); } else { $list = $index->q == '' ? '' : '<div>' . Language::get('No results were found for') . ' <strong>' . $index->q . '</strong></div>'; $list .= '<div><strong>' . Language::get('Search tips') . ' :</strong>' . Language::get('<ul><li>make sure that the spelling correct</li><li>try changing or new phrases. synonyms</li><li>try to identify a non-specific too</li><li>specific keywords to search the most concise</li></ul>') . '</div>'; } // add template $template->add(array('/{LIST}/' => $list, '/{SPLITPAGE}/' => $uri->pagination($index->totalpage, $index->page), '/{SEARCH}/' => $index->q, '/{MODULE}/' => 'search', '/{RESULT}/' => $index->total == 0 ? '' : sprintf(Language::get('Search results <strong>%d - %d</strong> of about <strong>%d</strong> for <strong>%s</strong> (%s sec)'), $index->start + 1, $index->end, $index->total, $index->q, number_format(microtime(true) - REQUEST_TIME, 4)))); $search = Language::get('Search'); $index->detail = $template->render(); $index->topic = ($index->q == '' ? '' : $index->q . ' - ') . $search; $index->description = $index->topic; $index->keywords = $index->topic; $index->menu = 'search'; // breadcrumb ของหน้า Gcms::$view->addBreadcrumb($index->canonical, $search, $search); return $index; }
/** * Initial Class * * @param array $param */ public function __construct($param) { $this->id = 'datatable'; foreach ($param as $key => $value) { $this->{$key} = $value; } if (empty($this->uri)) { $this->uri = self::$request->getUri(); } elseif (is_string($this->uri)) { $this->uri = Uri::createFromUri($this->uri); } // รายการต่อหน้า มาจากการเลือกภายในตารง $count = self::$request->globals(array('POST', 'GET'), 'count')->toInt(); if ($count > 0) { $this->perPage = $count; $this->uri = $this->uri->withParams(array('count' => $count)); } // header ของตาราง มาจาก model หรือมาจากข้อมูล หรือ มาจากการกำหนดเอง if (isset($this->model)) { // create Recordset $this->rs = new Recordset($this->model); // ฟิลด์ที่กำหนด (หากแตกต่างจาก Model) $first = $this->rs->first($this->fields); // อ่านคอลัมน์ของตาราง if ($first === false) { if (!empty($this->fields)) { foreach ($this->fields as $field) { if (is_array($field)) { $this->columns[$field[1]] = array('text' => $field[1]); } elseif (preg_match('/(.*?[`\\s]+)?([a-z0-9_]+)`?$/i', $field, $match)) { $this->columns[$match[2]] = array('text' => $match[2]); } } } } else { foreach ($this->rs->getFields() as $k => $v) { $this->columns[$k] = array('text' => $v['name']); } } } elseif (isset($this->datas)) { // อ่านคอลัมน์จากข้อมูลเราการแรก $this->columns = array(); if (!empty($this->datas)) { foreach (reset($this->datas) as $key => $value) { $this->columns[$key] = array('text' => $key); } } } // จัดการ header, ตรวจสอบกับค่ากำหนดมา เรียงลำดับ header ตาม columns if (!empty($this->columns)) { $headers = array(); foreach ($this->columns as $field => $attributes) { if (!in_array($field, $this->hideColumns)) { if (isset($this->headers[$field])) { $headers[$field] = $this->headers[$field]; if (!isset($headers[$field]['text'])) { $headers[$field]['text'] = $field; } } else { $headers[$field]['text'] = $field; } } } $this->headers = $headers; } $this->sort = self::$request->globals(array('POST', 'GET'), 'sort', $this->sort)->toString(); if (!empty($this->sort)) { $this->uri = $this->uri->withParams(array('sort' => $this->sort)); } }