cfmgrv3 init..3

This commit is contained in:
최준흠 2023-06-21 11:49:43 +09:00
parent 0ff5e316f1
commit 6b2941dcdf
5 changed files with 117 additions and 46 deletions

View File

@ -82,15 +82,40 @@ class FirewallController extends APIController
$entity = $api->sync($entity); $entity = $api->sync($entity);
return parent::sync_process($entity); return parent::sync_process($entity);
} }
//Index관련
protected function index_getRows(int $page = 0, int $per_page = 0): array //index 모델 전처리
private function index_setCondition_builder($builder)
{
foreach ($this->_viewDatas['fieldFilters'] as $field) {
$value = $this->request->getVar($field) ? $this->request->getVar($field) : false;
if ($value) {
$builder->where("cloudflarefirewall.{$field}", $value);
}
}
$word = $this->request->getVar('word') ? $this->request->getVar('word') : '';
if (isset($word) && $word !== '') {
$builder->like('cloudflarefirewall.description', $word, 'both'); //befor , after , both
}
$start = $this->request->getVar('start') ? $this->request->getVar('start') : '';
$end = $this->request->getVar('end') ? $this->request->getVar('end') : '';
if (isset($start) && $start !== '' && isset($end) && $end !== '') {
$builder->where('cloudflarerecord.created_at >=', $start);
$builder->where('cloudflarerecord.created_at <=', $end);
}
return $builder;
}
//Index관련
protected function index_getRows_builder(int $page = 0, int $per_page = 0): array
{ {
//모델 조건절 처리작업
$this->index_setCondition();
//모델 Join //모델 Join
$builder = $this->_model->builder(); $builder = $this->_model->builder();
$builder->select("cloudflarefirewall.*"); $builder->select("cloudflarefirewall.*");
$builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarefirewall.zone_uid"); $builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarefirewall.zone_uid");
//Totalcount 처리
$this->index_setCondition();
$this->_viewDatas['total_count'] = $this->_model->countAllResults();
//Rows 처리
$this->index_setCondition();
//OrderBy //OrderBy
$order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid'; $order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid';
$order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC'; $order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC';
@ -98,11 +123,6 @@ class FirewallController extends APIController
//Limit //Limit
$builder->limit($per_page, $page * $per_page - $per_page); $builder->limit($per_page, $page * $per_page - $per_page);
// log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false)); // log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false));
$rows = $builder->get()->getResultArray(); return $builder->get()->getResultArray();
// foreach ($builder->get()->getResultArray() as $row) {
// array_push($rows, new FirewallEntity($row));
// }
// throw new \Exception(var_export($rows, true));
return $rows;
} }
} }

View File

@ -137,15 +137,42 @@ class RecordController extends APIController
$entity = $api->sync($entity); $entity = $api->sync($entity);
return parent::sync_process($entity); return parent::sync_process($entity);
} }
//Index관련 //index 모델 전처리
protected function index_getRows(int $page = 0, int $per_page = 0): array private function index_setCondition_builder($builder)
{ {
//모델 조건절 처리작업 foreach ($this->_viewDatas['fieldFilters'] as $field) {
$this->index_setCondition(); $value = $this->request->getVar($field) ? $this->request->getVar($field) : false;
//모델 Join if ($value) {
$builder->where("cloudflarerecord.{$field}", $value);
}
}
$word = $this->request->getVar('word') ? $this->request->getVar('word') : '';
if (isset($word) && $word !== '') {
$builder->like('cloudflarerecord.host', $word, 'before'); //befor , after , both
$builder->orWhere('cloudflarerecord.content', $word);
}
$start = $this->request->getVar('start') ? $this->request->getVar('start') : '';
$end = $this->request->getVar('end') ? $this->request->getVar('end') : '';
if (isset($start) && $start !== '' && isset($end) && $end !== '') {
$builder->where('cloudflarerecord.created_at >=', $start);
$builder->where('cloudflarerecord.created_at <=', $end);
}
return $builder;
}
//Index관련
protected function index_getRows_builder(int $page = 0, int $per_page = 0): array
{
//Totalcount 처리
$builder = $this->_model->builder(); $builder = $this->_model->builder();
$builder->select("cloudflarerecord.*"); $builder->select("cloudflarerecord.*");
$builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarerecord.zone_uid"); $builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarerecord.zone_uid");
$builder = $this->index_setCondition_builder($builder);
// log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false));
$this->_viewDatas['total_count'] = $builder->countAllResults();
//Rows 처리
$builder->select("cloudflarerecord.*");
$builder->join("cloudflarezone", "cloudflarezone.uid = cloudflarerecord.zone_uid");
$builder = $this->index_setCondition_builder($builder);
//OrderBy //OrderBy
$order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid'; $order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid';
$order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC'; $order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC';
@ -153,12 +180,7 @@ class RecordController extends APIController
//Limit //Limit
$builder->limit($per_page, $page * $per_page - $per_page); $builder->limit($per_page, $page * $per_page - $per_page);
// log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false)); // log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false));
$rows = $builder->get()->getResultArray(); return $builder->get()->getResultArray();
// foreach ($builder->get()->getResultArray() as $row) {
// array_push($rows, new RecordEntity($row));
// }
// throw new \Exception(var_export($rows, true));
return $rows;
} }
//CDN고정관련 //CDN고정관련
final public function cdnToggle(string $uid) final public function cdnToggle(string $uid)

View File

@ -151,6 +151,52 @@ class ZoneController extends APIController
$entity = $api->sync($entity); $entity = $api->sync($entity);
return parent::sync_process($entity); return parent::sync_process($entity);
} }
//index 모델 전처리
private function index_setCondition_builder($builder)
{
foreach ($this->_viewDatas['fieldFilters'] as $field) {
$value = $this->request->getVar($field) ? $this->request->getVar($field) : false;
if ($value) {
$builder->where("cloudflarezone.{$field}", $value);
}
}
$word = $this->request->getVar('word') ? $this->request->getVar('word') : '';
if (isset($word) && $word !== '') {
$builder->like('domain', $word, 'after'); //befor , after , both
$builder->orWhere('cloudflarerecord.content', $word, 'both'); //befor , after , both
}
$start = $this->request->getVar('start') ? $this->request->getVar('start') : '';
$end = $this->request->getVar('end') ? $this->request->getVar('end') : '';
if (isset($start) && $start !== '' && isset($end) && $end !== '') {
$builder->where('cloudflarezone.created_at >=', $start);
$builder->where('cloudflarezone.created_at <=', $end);
}
return $builder;
}
//Index관련
protected function index_getRows_builder(int $page = 0, int $per_page = 0): array
{
//Totalcount 처리
$builder = $this->_model->builder();
$builder->select("cloudflarezone.*");
$builder->join("cloudflarerecord", "cloudflarezone.uid = cloudflarerecord.zone_uid");
$builder = $this->index_setCondition_builder($builder);
// log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false));
$this->_viewDatas['total_count'] = $builder->countAllResults();
//Rows 처리
$builder = $this->_model->builder();
$builder->select("cloudflarezone.*");
$builder->join("cloudflarerecord", "cloudflarezone.uid = cloudflarerecord.zone_uid");
$builder = $this->index_setCondition_builder($builder);
//OrderBy
$order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid';
$order_value = $this->request->getVar('order_value') ? $this->request->getVar('order_value') : 'DESC';
$builder->orderBy("cloudflarezone.domain ASC, cloudflarezone.{$order_field} {$order_value}");
//Limit
$builder->limit($per_page, $page * $per_page - $per_page);
// log_message("debug", __METHOD__ . "에서 호출\n" . $builder->getCompiledSelect(false));
return $builder->get()->getResultArray();
}
//Reload관련 //Reload관련
final public function reload($uid) final public function reload($uid)
{ {

View File

@ -105,7 +105,7 @@ class CommonController extends BaseController
//변경된 값 적용 //변경된 값 적용
$fieldDatas = array(); $fieldDatas = array();
foreach ($this->_viewDatas['fields'] as $field) { foreach ($this->_viewDatas['fields'] as $field) {
$fieldDatas[$field] = $this->request->getVar($field); $fieldDatas[$field] = rtrim($this->request->getVar($field));
Log::add("info", "{$field} : {$fieldDatas[$field]}"); Log::add("info", "{$field} : {$fieldDatas[$field]}");
} }
$this->_viewDatas['fieldDatas'] = $fieldDatas; $this->_viewDatas['fieldDatas'] = $fieldDatas;
@ -175,7 +175,7 @@ class CommonController extends BaseController
//변경된 값 적용 //변경된 값 적용
$fieldDatas = array(); $fieldDatas = array();
foreach ($this->_viewDatas['fields'] as $field) { foreach ($this->_viewDatas['fields'] as $field) {
$fieldDatas[$field] = $this->request->getVar($field); $fieldDatas[$field] = rtrim($this->request->getVar($field));
Log::add("info", "{$entity->getTitle()}{$field} : {$entity->$field}=>{$fieldDatas[$field]}"); Log::add("info", "{$entity->getTitle()}{$field} : {$entity->$field}=>{$fieldDatas[$field]}");
$entity->$field = $fieldDatas[$field]; $entity->$field = $fieldDatas[$field];
} }
@ -438,7 +438,10 @@ class CommonController extends BaseController
} }
protected function index_getRows(int $page = 0, int $per_page = 0): array protected function index_getRows(int $page = 0, int $per_page = 0): array
{ {
//모델 조건절 처리작업 //Totalcount 처리
$this->index_setCondition();
$this->_viewDatas['total_count'] = $this->_model->countAllResults();
//Rows 처리
$this->index_setCondition(); $this->index_setCondition();
//OrderBy //OrderBy
$order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid'; $order_field = $this->request->getVar('order_field') ? $this->request->getVar('order_field') : 'uid';
@ -470,19 +473,13 @@ class CommonController extends BaseController
} }
protected function index_process() protected function index_process()
{ {
//모델 조건절 처리작업 //모델 처리
$this->index_setCondition(); $this->_viewDatas['rows'] = $this->index_getRows((int)$this->_viewDatas['page'], (int)$this->_viewDatas['per_page']);
//Totalcount 처리
$total_count = $this->_model->countAllResults();
$this->_viewDatas['total_count'] = $total_count;
//Log::add("debug",__METHOD__."에서 호출:".$this->_model->getLastQuery());
//줄수 처리용 //줄수 처리용
$this->_viewDatas['pageOptions'] = array("" => "줄수선택"); $this->_viewDatas['pageOptions'] = array("" => "줄수선택");
for ($i = 10; $i <= $this->_viewDatas['total_count'] + $this->_viewDatas['per_page']; $i += 10) { for ($i = 10; $i <= $this->_viewDatas['total_count'] + $this->_viewDatas['per_page']; $i += 10) {
$this->_viewDatas['pageOptions'][$i] = $i; $this->_viewDatas['pageOptions'][$i] = $i;
} }
//모델 처리
$this->_viewDatas['rows'] = $this->index_getRows((int)$this->_viewDatas['page'], (int)$this->_viewDatas['per_page']);
//pagenation 처리 //pagenation 처리
$this->_viewDatas['pagination'] = $this->index_getPagination(); $this->_viewDatas['pagination'] = $this->index_getPagination();
} }

View File

@ -68,23 +68,9 @@ class FirewallModel extends Model
} }
//Index 검색용 //Index 검색용
private function getFindWordByDomain($word): array
{
//Zone의 Domain에서 검색후 해당 검색어의 Firewall정보 출력용
$query = $this->db()->table("cloudflarezone")->select("uid")->like("domain", $word, "both");
// throw new \Exception($query->getCompiledSelect());
$zone_uids = array();
foreach ($query->get()->getResult() as $row) {
array_push($zone_uids, $row->uid);
}
// throw new \Exception(var_export($zone_uids, true));
return $zone_uids;
}
public function setIndexWordFilter(string $word) public function setIndexWordFilter(string $word)
{ {
$this->like("description", $word, "both"); //befor , after , both $this->like("description", $word, "both"); //befor , after , both
// $this->orLike("filter_expression", $word, "both");
$this->orWhereIn("zone_uid", $this->getFindWordByDomain($word));
} }
public function setIndexDateFilter($start, $end) public function setIndexDateFilter($start, $end)
{ {