From 9fcb5b7543065ef154ba29d9301390045bae8ff7 Mon Sep 17 00:00:00 2001 From: monkenWu <610877102@mail.nknu.edu.tw> Date: Tue, 28 Jan 2020 01:23:44 +0800 Subject: [PATCH] init circleci --- .circleci/config.yml | 18 +++++ .gitignore | 1 - composer.json | 26 ------- src/TablesIgniter.php | 158 ------------------------------------------ 4 files changed, 18 insertions(+), 185 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 .gitignore delete mode 100644 composer.json delete mode 100644 src/TablesIgniter.php diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..4397c05 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,18 @@ +version: 2 +jobs: + # branches: + # only: + # - feature/circleCI + build: + docker: + # Specify the version you desire here + - image: circleci/php:7.2-apache-stretch-node-browsers + steps: + - checkout + # - ls + # - pwd + # - scp script/start.sh + # - scp sourceCode + # - ssh SERVER_IP 'sh start.sh' + - run: echo "test and ok" + # - run: echo $SERVER_IP \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 57872d0..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/vendor/ diff --git a/composer.json b/composer.json deleted file mode 100644 index 54c22ae..0000000 --- a/composer.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "monken/tablesigniter", - "description": "This library will help you use jQuery Datatables based on CodeIgniter4.", - "type": "library", - "keywords": [ - "codeigniter", - "codeigniter4", - "Datatables" - ], - "authors": [ - { - "name": "monkenWu", - "email": "610877102@mail.nknu.edu.tw" - } - ], - "minimum-stability": "stable", - "require": { - "php" : "^7.1" - }, - "license": "MIT", - "autoload": { - "psr-4": { - "monken\\": "src/" - } - } -} diff --git a/src/TablesIgniter.php b/src/TablesIgniter.php deleted file mode 100644 index bc47b16..0000000 --- a/src/TablesIgniter.php +++ /dev/null @@ -1,158 +0,0 @@ - - * @link https://github.com/monkenWu/TablesIgniter - * - */ - -use Closure; - -class TablesIgniter{ - - protected $db; - protected $builder; - protected $outputColumn; - protected $defaultOrder = []; - protected $searchLike = false; - - public function __construct(&$db){ - $this->db =& $db; - } - - public function setTable(Closure $fun){ - $this->builder = $fun($this->db); - return $this; - } - - public function setSearch(array $like){ - $this->searchLike = $like; - return $this; - } - - /** - * 設定預設排序項目 - * - * @param string $item - * @param string $type - * @return mixed - */ - public function setDefaultOrder($item,$type="ASC"){ - $this->defaultOrder[] = array($item, $type); - return $this; - } - - /** - * 設定實際輸出的序列 - * @param array $columns - * @return mixed - */ - public function setOutput(array $column){ - $this->outputColumn = $column; - return $this; - } - - /** - * 搜索總筆數 - */ - private function getFiltered(){ - $bui = $this->extraConfig($this->builder); - $query = $bui->countAll(); - return $query; - } - - /** - * 總筆數 - */ - private function getTotal(){ - //$this->extra_config(); - $bui = $this->builder; - $query = $bui->countAllResults(); - return $query; - } - - /** - * 執行查詢 - * 在此停止ci->db類別紀錄規則 - * @return array - */ - private function getQuery(){ - $bui = $this->extraConfig($this->builder); - if(isset($_POST["length"])){ - if($_POST["length"] != -1) { - $bui->limit($_POST['length'], $_POST['start']); - } - } - $query = $bui->get(); - return $query; - } - - /** - * 合成每列資料的內容。 - * - * @param array $row - * @return array - */ - private function getOutputData($row){ - $subArray = array(); - foreach ($this->outputColumn as $colKey => $data) { - if(gettype($data) != "string"){ - $subArray[] = $data($row); - }else{ - $subArray[] = $row[$data]; - } - } - return $subArray; - } - - /** - * 查詢是否有有排序或搜索的要求 - */ - private function extraConfig($bui){ - if(!empty($_POST["search"]["value"])){ - foreach ($this->searchLike as $field) { - $bui->orLike($field,$_POST["search"]["value"]); - } - } - if(isset($_POST["order"])){ - $bui->orderby($_POST['order']['0']['column'], $_POST['order']['0']['dir']); - }else{ - if(count($this->defaultOrder)!=0){ - foreach ($this->defaultOrder as $value) { - $bui->orderby($value[0], $value[1]); - } - } - } - return $bui; - } - - /** - * 取得完整的Datatable Json字串 - * @return string - */ - public function getDatatable(){ - if($result = $this->getQuery()){ - $data = array(); - //print_r($result->getResult('array')); - foreach ($result->getResult('array') as $row){ - $data[] = $this->getOutputData($row); - } - $output = array( - "draw" => (int)$_POST["draw"] ?? -1, - "recordsTotal" => $this->getTotal(), - "recordsFiltered" => $this->getFiltered(), - "data" => $data - ); - return json_encode($output); - } - return $data; - } - -} \ No newline at end of file