コード例 #1
0
ファイル: datatable.php プロジェクト: limweb/kotchasan
 /**
  * inint Class
  *
  * @param array $param
  */
 public function __construct($param)
 {
     $this->id = 'datatable';
     foreach ($param as $key => $value) {
         $this->{$key} = $value;
     }
     if (!empty($this->actions) && $this->checkCol == -1) {
         $this->checkCol = 1;
     }
     // รายการต่อหน้ามาจากการ POST หรือ GET
     if (isset($this->perPage)) {
         $this->perPage = \Input::get($_REQUEST, 'count', 30);
     }
     // header ของตาราง มาจาก model หรือมาจากข้อมูล หรือ มาจากการกำหนดเอง
     if (isset($this->model)) {
         // Recordset
         $this->rs = \Core\Orm\Recordset::create($this->model);
         // ฟิลด์ที่กำหนด (หากแตกต่างจาก Model)
         $this->rs->first($this->fields);
         // อ่านคอลัมน์ของตาราง
         $this->columns = $this->rs->getFileds();
     } 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;
     }
 }