]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
init of advanced search
authorBanana <mail@bananas-playground.net>
Thu, 31 Dec 2020 11:53:03 +0000 (12:53 +0100)
committerBanana <mail@bananas-playground.net>
Thu, 31 Dec 2020 11:53:03 +0000 (12:53 +0100)
webclient/lib/managecollectionfields.class.php
webclient/lib/trite.class.php
webclient/view/default/advancedsearch/advancedsearch.html [new file with mode: 0644]
webclient/view/default/advancedsearch/advancedsearch.php [new file with mode: 0644]
webclient/view/default/system/menu.php

index df2824bfcbe2230ffc0e3e752a97a67b0e14faf7..c73aba113a1fe308b1de9a23a22aab2f91635d01 100644 (file)
@@ -52,7 +52,7 @@ class ManageCollectionFields {
        );
 
        /**
-        * Store existing fileds info for runtime
+        * Store existing fields info for runtime
         *
         * @var array
         */
index 3b6bcbcaaba866d896dc9bb719d30ce415368c5f..65cc39089f3d84f1fb28bdee14cf283a46fbd9dd 100644 (file)
@@ -176,6 +176,33 @@ class Trite {
                return $ret;
        }
 
+       /**
+        * Fields for the loaded collection.
+        *
+        * @return array
+        */
+       public function getCollectionFields() {
+               $ret = array();
+
+               $queryStr = "SELECT `cf`.`fk_field_id` AS id, `sf`.`type`, `sf`.`displayname`, `sf`.`identifier`
+                                               FROM `".DB_PREFIX."_collection_fields_".$this->_id."` AS cf
+                                               LEFT JOIN `".DB_PREFIX."_sys_fields` AS sf ON `cf`.`fk_field_id` = `sf`.`id`
+                                               ORDER BY `cf`.`sort`";
+               $query = $this->_DB->query($queryStr);
+               try {
+                       if($query !== false && $query->num_rows > 0) {
+                               while(($result = $query->fetch_assoc()) != false) {
+                                       $ret[$result['id']] = $result;
+                               }
+                       }
+               } catch (Exception $e) {
+                       if(DEBUG) error_log("[DEBUG] ".__METHOD__."  mysql query: ".$queryStr);
+                       error_log("[ERROR] ".__METHOD__."  mysql catch: ".$e->getMessage());
+               }
+
+               return $ret;
+       }
+
        /**
         * set some defaults by init of the class
         *
diff --git a/webclient/view/default/advancedsearch/advancedsearch.html b/webclient/view/default/advancedsearch/advancedsearch.html
new file mode 100644 (file)
index 0000000..4bf643e
--- /dev/null
@@ -0,0 +1,56 @@
+<?php if(!empty($TemplateData['loadedCollection'])) { ?>
+<div class="uk-grid-small uk-grid-row-small uk-grid-row-small" uk-grid>
+       <div class="uk-width-1-2">
+
+               <form class="uk-form-horizontal uk-margin-small" method="post">
+                       <div class="uk-margin">
+                               <label class="uk-form-label" for="search">Search for</label>
+                               <div class="uk-form-controls">
+                                       <input class="uk-input" id="search" type="text" autocomplete="off" name="fdata[search]"
+                                              placeholder="See search syntax for options">
+                               </div>
+                       </div>
+
+                       <div class="uk-margin">
+                               <button class="uk-button uk-button-primary" type="submit" name="submitForm">
+                                       Search
+                               </button>
+                       </div>
+               </form>
+       </div>
+       <div class="uk-width-1-2">
+               <h4>Syntax</h4>
+               <p>To search within the collection default search field, like the ordinary search, just type the search term and go.</p>
+               <p>To search within the possible fields of a collection type the field identifier followed by : and then a space.</p>
+               eg.: <code>title: starwars</code>
+               <p>Available fields in <b><?php echo Summoner::ifset($TemplateData['loadedCollection'], 'name'); ?></b> are:</p>
+               <pre style="white-space: normal">
+               <?php
+               foreach($TemplateData['collectionFields'] as $k=>$v) {
+                       echo $v['identifier']." ";
+               }
+               ?>
+               </pre>
+               <p>Possible search operators:</p>
+               <p>
+                       * = The asterisk serves as the truncation (or wildcard) operator. Unlike the other operators,
+                       it is appended to the word to be affected. Words match if they begin with the word preceding the * operator.
+               </p>
+               <p>+ = A leading plus sign indicates that this word must be present in each row that is returned.</p>
+               <p>- = A leading minus sign indicates that this word must not be present in any of the rows that are returned.</p>
+               <p>" = A phrase that is enclosed within double quote (") characters matches only rows that contain the phrase literally, as it was typed.</p>
+       </div>
+</div>
+<?php } else { ?>
+<h3 class="uk-h3">Collection overview</h3>
+<div class="uk-grid-small uk-grid-row-small uk-grid-row-small" uk-grid>
+       <div class="uk-width-2-3@m uk-width-1-2@xl">
+               <dl class="uk-description-list uk-description-list-divider">
+                       <?php foreach($TemplateData['collections'] as $k=>$v) { ?>
+                       <dt><a href="index.php?p=advancedsearch&collection=<?php echo $k; ?>"><?php echo $v['name']; ?></a></dt>
+                       <dd><?php echo $v['description']; ?></dd>
+                       <?php } ?>
+               </dl>
+       </div>
+</div>
+<?php } ?>
diff --git a/webclient/view/default/advancedsearch/advancedsearch.php b/webclient/view/default/advancedsearch/advancedsearch.php
new file mode 100644 (file)
index 0000000..b3fbb4d
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Bibliotheca webclient
+ *
+ * Copyright 2018-2021 Johannes Keßler
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+require_once 'lib/trite.class.php';
+$Trite = new Trite($DB,$Doomguy);
+
+$_collection = false;
+if(isset($_GET['collection']) && !empty($_GET['collection'])) {
+       $_collection = trim($_GET['collection']);
+       $_collection = Summoner::validate($_collection,'digit') ? $_collection : false;
+}
+
+$TemplateData['loadedCollection'] = array();
+$TemplateData['collections'] = array();
+$TemplateData['collectionFields'] = array();
+
+if(!empty($_collection)) {
+       $TemplateData['loadedCollection'] = $Trite->load($_collection);
+       if(!empty($TemplateData['loadedCollection'])) {
+               $TemplateData['collectionFields'] = $Trite->getCollectionFields();
+       }
+       else {
+               $TemplateData['message']['content'] = "Can not load given collection.";
+               $TemplateData['message']['status'] = "error";
+       }
+}
+else {
+       $TemplateData['collections'] = $Trite->getCollections();
+}
index b9f42cd3b22c43479fa764eb0a8e8fc1389a2b6d..55f82d635fa33e5f3b14a596319a53efee557ebd 100644 (file)
@@ -67,6 +67,7 @@ $_menuManage = $Gorenest->get('manage');
                        <div class="uk-drop" uk-drop="mode: click; pos: left-center; offset: 0">
                                <form class="uk-search uk-search-navbar uk-width-1-1" method="post" action="<?php echo $TemplateData['searchAction']; ?>">
                                        <input class="uk-search-input" type="search" placeholder="Search..." name="navSearch" autofocus>
+                                       <small><a href="index.php?p=advancedsearch">Advanced</a></small>
                                </form>
                        </div>
                </div>