• R/O
  • SSH
  • HTTPS

jinrousiki: Commit


Commit MetaInfo

Revision2300 (tree)
Time2018-12-11 22:47:05
Authorumethyl

Log Message

IconDB::GetList()

Change Summary

Incremental Difference

--- trunk/include/database/db_class.php (revision 2299)
+++ trunk/include/database/db_class.php (revision 2300)
@@ -342,6 +342,7 @@
342342 private $where_like = [];
343343 private $where_not_like = [];
344344 private $where_or = [];
345+ private $where_or_like = [];
345346 private $group = [];
346347 private $order = [];
347348 private $limit = [];
@@ -517,6 +518,12 @@
517518 return $this;
518519 }
519520
521+ //WHERE 句登録 (OR LIKE)
522+ public function WhereOrLike(array $list) {
523+ $this->where_or_like[] = $list;
524+ return $this;
525+ }
526+
520527 //GROUP BY 句登録
521528 public function Group(array $list) {
522529 return $this->Store('group', $list);
@@ -700,11 +707,16 @@
700707 $where_like = $this->where_like;
701708 $where_not_like = $this->where_not_like;
702709 $where_or = $this->where_or;
710+ $where_or_like = $this->where_or_like;
703711
704712 //OR の先頭グループを確保
705- $or_target = array_shift($this->where_or);
713+ $or_target = array_shift($where_or);
706714 $or_stack = [];
707715
716+ //OR LIKE の先頭グループを確保
717+ $or_like_target = array_shift($where_or_like);
718+ $or_like_stack = [];
719+
708720 $stack = [];
709721 foreach ($this->where as $value) {
710722 $data = ArrayFilter::Get($where_data, $value);
@@ -713,6 +725,7 @@
713725 $bool = ArrayFilter::Get($where_bool, $value);
714726 $upper = ArrayFilter::Get($where_upper, $value);
715727 $lower = ArrayFilter::Get($where_lower, $value);
728+ $like_flag = false;
716729 if (false === is_null($data)) {
717730 $query = $value . ' = ' . $data;
718731 array_shift($where_data);
@@ -754,9 +767,11 @@
754767 } elseif (true === in_array($value, $where_like)) {
755768 $query = $value . ' LIKE ?';
756769 array_shift($where_like);
770+ $like_flag = true;
757771 } elseif (true === in_array($value, $where_not_like)) {
758772 $query = $value . ' NOT LIKE ?';
759773 array_shift($where_not_like);
774+ $like_flag = true;
760775 } else {
761776 $query = $value . ' = ?';
762777 }
@@ -764,14 +779,19 @@
764779 if (ArrayFilter::IsInclude($or_target, $value)) {
765780 $or_stack[] = $query;
766781 array_shift($or_target);
767- } elseif (count($or_stack) > 0) {
768- //OR のバッファを登録
769- $stack[] = Text::Quote(ArrayFilter::Concat($or_stack, ' OR '));
770- $or_target = array_shift($where_or);
771- $or_stack = [];
772-
773- //このループの値はそのまま登録
774- $stack[] = $query;
782+ if (count($or_target) == 0) {
783+ $stack[] = Text::Quote(ArrayFilter::Concat($or_stack, ' OR '));
784+ $or_target = array_shift($where_or);
785+ $or_stack = [];
786+ }
787+ } elseif (true === $like_flag && ArrayFilter::IsInclude($or_like_target, $value)) {
788+ $or_like_stack[] = $query;
789+ array_shift($or_like_target);
790+ if (count($or_like_target) == 0) {
791+ $stack[] = Text::Quote(ArrayFilter::Concat($or_like_stack, ' OR '));
792+ $or_like_target = array_shift($where_or_like);
793+ $or_like_stack = [];
794+ }
775795 } else {
776796 $stack[] = $query;
777797 }
--- trunk/include/database/icon_db_class.php (revision 2299)
+++ trunk/include/database/icon_db_class.php (revision 2300)
@@ -31,26 +31,20 @@
3131 return (int)DB::FetchResult() + 1;
3232 }
3333
34- //カテゴリ取得
35- public static function GetCategory() {
36- $column = 'category';
37- $query = self::GetQuerySelect([$column])->WhereNotNull($column);
38- $query->Group([$column])->Order(['icon_no' => true]);
39- DB::Prepare($query->Build());
40- return DB::FetchColumn();
41- }
34+ //リスト取得
35+ public static function GetList(Query $query, array $list) {
36+ if (RQ::Get()->sort_by_name) {
37+ $query->Order(['icon_name' => true, 'icon_no' => true]);
38+ } else {
39+ $query->Order(['icon_no' => true, 'icon_name' => true]);
40+ }
4241
43- //リスト取得
44- public static function GetList(array $where) {
45- $format = self::SetSelect('*') . ' WHERE %s ORDER BY %s';
46- $where[] = 'icon_no > 0';
47- $sort = RQ::Get()->sort_by_name ? 'icon_name, icon_no' : 'icon_no, icon_name';
48- $query = sprintf($format, ArrayFilter::Concat($where, ' AND '), $sort);
4942 if (RQ::Get()->page != 'all') {
5043 $limit = max(0, IconConfig::VIEW * (RQ::Get()->page - 1));
51- $query .= Query::SetLimit($limit, IconConfig::VIEW);
44+ $query->Limit($limit, IconConfig::VIEW);
5245 }
53- DB::Prepare($query);
46+
47+ DB::Prepare($query->Build(), $list);
5448 return DB::FetchAssoc();
5549 }
5650
@@ -69,21 +63,9 @@
6963 return DB::FetchColumn();
7064 }
7165
72- //抽出条件生成
73- public static function GetInClause($type, array $list) {
74- if (in_array('__null__', $list)) return $type . ' IS NULL';
75- $stack = [];
76- foreach ($list as $value) {
77- $stack[] = sprintf("'%s'", Text::Escape($value));
78- }
79- return $type . Query::SetIn($stack);
80- }
81-
8266 //アイコン数取得
83- public static function Count(array $where) {
84- $format = self::SetSelect('icon_no') . ' WHERE %s';
85- $where[] = 'icon_no > 0';
86- DB::Prepare(sprintf($format, ArrayFilter::Concat($where, ' AND ')));
67+ public static function Count(Query $query, array $list) {
68+ DB::Prepare($query->Build(), $list);
8769 return DB::Count();
8870 }
8971
@@ -96,6 +78,7 @@
9678 //アイコン名存在判定
9779 public static function ExistsName($icon_name) {
9880 $query = self::GetQueryIconNo()->Where(['icon_name']);
81+
9982 DB::Prepare($query->Build(), [$icon_name]);
10083 return DB::Exists();
10184 }
@@ -103,6 +86,7 @@
10386 //アイコン名重複判定
10487 public static function Duplicate($icon_no, $icon_name) {
10588 $query = self::GetQueryIconNo()->WhereNot('icon_no')->Where(['icon_name']);
89+
10690 DB::Prepare($query->Build(), [$icon_no, $icon_name]);
10791 return DB::Exists();
10892 }
@@ -160,30 +144,29 @@
160144 return self::Update($icon_no, 'session_id = NULL');
161145 }
162146
163- //disable セット
164- public static function SetDisable() {
165- return 'disable IS NOT TRUE';
147+ //抽出条件 Query セット
148+ public static function SetQueryIn(Query $query, $type, array $list) {
149+ if (in_array('__null__', $list)) {
150+ $query->WhereNull($type);
151+ return [];
152+ } else {
153+ $query->WhereIn($type, count($list));
154+ return $list;
155+ }
166156 }
167157
168- //LIKE セット
169- public static function SetLike($str) {
158+ //LIKE 句セット
159+ public static function SetQueryLike(Query $query, $str) {
160+ $column_list = ['category', 'appearance', 'author', 'icon_name'];
170161 $stack = [];
171- foreach (['category', 'appearance', 'author', 'icon_name'] as $column) {
172- $stack[] = sprintf("%s LIKE '%%%s%%'", $column, $str);
162+ foreach ($column_list as $column) {
163+ $query->WhereLike($column);
164+ $stack[] = Query::GetLike($str);
173165 }
174- return Text::Quote(ArrayFilter::Concat($stack, ' OR '));
166+ $query->WhereOrLike($column_list);
167+ return $stack;
175168 }
176169
177- //共通 SELECT 句生成
178- private static function SetSelect($column) {
179- return Query::SetSelect('user_icon', $column);
180- }
181-
182- //共通 SQL 文生成
183- private static function SetQuery($column) {
184- return self::SetSelect($column) . Query::SetWhere('icon_no');
185- }
186-
187170 //共通 Query 取得
188171 private static function GetQuery(array $column) {
189172 return self::GetQuerySelect($column)->Where(['icon_no']);
--- trunk/include/html/media/icon_html_class.php (revision 2299)
+++ trunk/include/html/media/icon_html_class.php (revision 2300)
@@ -9,7 +9,9 @@
99 現時点では GET で直接検索を試みたユーザーのセッション情報まで配慮していないが、
1010 いずれ必要になるかも知れない (enogu)
1111 */
12- if (is_null(RQ::Get()->page)) Session::Clear('icon_view');
12+ if (is_null(RQ::Get()->page)) {
13+ Session::Clear('icon_view');
14+ }
1315
1416 //編集フォームの表示
1517 if ($url == 'icon_view') {
@@ -57,45 +59,36 @@
5759 //-- 検索フォームヘッダ出力 --//
5860 Text::Output(self::GetSearchHeader());
5961
60- $url_option = [];
61- $query_stack = [];
62- $category_list = IconDB::GetCategory();
63-
6462 //-- セレクタ出力 --//
65- $where = [];
63+ $query = Query::Init()->Table('user_icon')->Select()->WhereUpper('icon_no');
64+ $list = [0];
65+ $sql_stack = [];
66+ $url_option = [];
6667 if ($base_url == 'user_manager') {
67- $where[] = IconDB::SetDisable();
68+ $query->WhereNotTrue('disable');
6869 }
6970
70- $stack = self::OutputSelector(RequestDataIcon::CATEGORY, IconMessage::CATEGORY);
71- if (0 < count($stack)) {
72- foreach ($stack as $data) {
73- $url_option[] = URL::GetList(RequestDataIcon::CATEGORY, $data);
71+ $selector_list = [
72+ RequestDataIcon::CATEGORY => IconMessage::CATEGORY,
73+ RequestDataIcon::APPEARANCE => IconMessage::APPEARANCE,
74+ RequestDataIcon::AUTHOR => IconMessage::AUTHOR
75+ ];
76+ foreach ($selector_list as $request => $message) {
77+ $stack = self::OutputSelector($request, $message);
78+ if (0 < count($stack)) {
79+ foreach ($stack as $data) {
80+ $url_option[] = URL::GetList($request, $data);
81+ }
82+ ArrayFilter::Merge($list, IconDB::SetQueryIn($query, $request, $stack));
7483 }
75- $where[] = IconDB::GetInClause(RequestDataIcon::CATEGORY, $stack);
7684 }
7785
78- $stack = self::OutputSelector(RequestDataIcon::APPEARANCE, IconMessage::APPEARANCE);
79- if (0 < count($stack)) {
80- foreach ($stack as $data) {
81- $url_option[] = URL::GetList(RequestDataIcon::APPEARANCE, $data);
82- }
83- $where[] = IconDB::GetInClause(RequestDataIcon::APPEARANCE, $stack);
84- }
85-
86- $stack = self::OutputSelector(RequestDataIcon::AUTHOR, IconMessage::AUTHOR);
87- if (0 < count($stack)) {
88- foreach ($stack as $data) {
89- $url_option[] = URL::GetList(RequestDataIcon::AUTHOR, $data);
90- }
91- $where[] = IconDB::GetInClause(RequestDataIcon::AUTHOR, $stack);
92- }
93-
9486 $stack = self::OutputSelector(RequestDataIcon::KEYWORD, IconMessage::KEYWORD);
9587 if (0 < count($stack)) {
96- $where[] = IconDB::SetLike($stack[0]);
88+ $keyword = $stack[0];
89+ ArrayFilter::Merge($list, IconDB::SetQueryLike($query, $keyword));
9790 } else {
98- $stack = [''];
91+ $keyword = '';
9992 }
10093
10194 //-- 検索フォームフッタ出力 --//
@@ -102,7 +95,7 @@
10295 Text::Printf(self::GetSearchFooter(),
10396 UserIconConfig::COLUMN * 2,
10497 HTML::GenerateChecked(RQ::Get()->sort_by_name), IconMessage::SORT_BY_NAME,
105- IconMessage::KEYWORD_INPUT, $stack[0], IconMessage::SEARCH
98+ IconMessage::KEYWORD_INPUT, $keyword, IconMessage::SEARCH
10699 );
107100
108101 //検索結果の表示
@@ -124,7 +117,7 @@
124117 $CONF->view = IconConfig::VIEW;
125118 $CONF->page = IconConfig::PAGE;
126119 $CONF->url = $base_url;
127- $CONF->count = IconDB::Count($where);
120+ $CONF->count = IconDB::Count($query, $list);
128121 $CONF->current = RQ::Get()->page;
129122 $CONF->option = $url_option;
130123 $CONF->attributes = ['onClick' => 'return "return submit_icon_search(\'$page\');";'];
@@ -141,7 +134,7 @@
141134 //アイコン情報の表示
142135 if (isset($method)) {
143136 $column = 0;
144- foreach (IconDB::GetList($where) as $icon_info) {
137+ foreach (IconDB::GetList($query, $list) as $icon_info) {
145138 self::$method($icon_info, 162);
146139 TableHTML::OutputFold(++$column, UserIconConfig::COLUMN);
147140 }
Show on old repository browser