]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
simplified tag overview and moved to the trite class
authorBanana <mail@bananas-playground.net>
Mon, 4 Jan 2021 10:39:32 +0000 (11:39 +0100)
committerBanana <mail@bananas-playground.net>
Mon, 4 Jan 2021 10:39:32 +0000 (11:39 +0100)
documentation/setup/bibliotheca.sql
webclient/lib/managecollections.class.php
webclient/lib/mancubus.class.php
webclient/lib/trite.class.php
webclient/view/default/manageentry/manageentry.html
webclient/view/default/managetags/managetags.html
webclient/view/default/tags/tags.php

index 750e442f4593d4ac816d65c3024ba3bee0e726af..6bd188b22d95a2943b23ac587dac14c874156e27 100644 (file)
@@ -141,13 +141,13 @@ INSERT INTO `#REPLACEME#_sys_fields` (`id`, `identifier`, `displayname`, `type`,
 (6, 'category', 'Category', 'lookupmultiple', 'tag', NULL, NULL, 'string 64', '2019-09-01 19:11:18', 0, 1, 1, 'rw-r--r--'),
 (7, 'publisher', 'Publisher', 'lookupmultiple', 'tag', NULL, NULL, 'string 64', '2019-09-01 19:17:51', 0, 1, 1, 'rw-r--r--'),
 (8, 'developer', 'Developer', 'lookupmultiple', 'tag', NULL, NULL, 'string 64', '2019-09-01 19:17:51', 0, 1, 1, 'rw-r--r--'),
-(9, 'platform', 'Platform', 'selection', 'tag', '`platform` varchar(32) NULL DEFAULT NULL', 'PC,Xbox,Playstation,Nintendo,Nintendo Switch', 'One of PC,Xbox,Playstation,Nintendo,Nintendo Switch', '2019-09-01 19:18:33', 0, 1, 1, 'rw-r--r--'),
+(9, 'platform', 'Platform', 'selection', 'entrySingleText', '`platform` varchar(32) NULL DEFAULT NULL', 'PC,Xbox,Playstation,Nintendo,Nintendo Switch', 'One of PC,Xbox,Playstation,Nintendo,Nintendo Switch', '2019-09-01 19:18:33', 0, 1, 1, 'rw-r--r--'),
 (10, 'storage', 'Storage', 'lookupmultiple', 'tag', NULL, NULL, 'string 64', '2019-09-01 19:18:33', 0, 1, 1, 'rw-r--r--'),
 (13, 'rating', 'Rating', 'selection', 'entrySingleText', '`rating` varchar(16) NULL DEFAULT NULL', '0/10,2/10,3/10,4/10,5/10,6/10,7/10,8/10,9/10,10/10', 'One of 0/10,2/10,3/10,4/10,5/10,6/10,7/10,8/10,9/10,10/10', '2019-09-01 19:25:35', 0, 1, 1, 'rw-r--r--'),
 (14, 'year', 'Year', 'number', 'entrySingleNum', '`year` int(10) NULL, ADD INDEX (`year`)', NULL, 'int 10', '2019-09-01 19:30:11', 0, 1, 1, 'rw-r--r--'),
 (15, 'coverimage', 'Cover image', 'upload', NULL, NULL, NULL, 'One file in $_FILES[uploads] of post', '2019-09-01 19:48:44', 0, 1, 1, 'rw-r--r--'),
 (16, 'attachment', 'Attachments', 'upload_multiple', NULL, NULL, NULL, 'Multiple in $_FILES[uploads] of post', '2019-09-01 19:48:44', 0, 1, 1, 'rw-r--r--'),
-(17, 'os', 'Operating system and version', 'selection', 'tag', '`os` varchar(32) NULL DEFAULT NULL', 'Windows 10,Windows 95, Windows 99,Windows XP, Windows ME, Windows 2000,Windows Vista,Windows 8', 'One of Windows 10,Windows 95, Windows 99,Windows XP, Windows ME, Windows 2000,Windows Vista,Windows 8', '2019-09-01 19:55:13', 0, 1, 1, 'rw-r--r--'),
+(17, 'os', 'Operating system and version', 'selection', 'entrySingleNum', '`os` varchar(32) NULL DEFAULT NULL', 'Windows 10,Windows 95, Windows 99,Windows XP, Windows ME, Windows 2000,Windows Vista,Windows 8', 'One of Windows 10,Windows 95, Windows 99,Windows XP, Windows ME, Windows 2000,Windows Vista,Windows 8', '2019-09-01 19:55:13', 0, 1, 1, 'rw-r--r--'),
 (18, 'actors', 'Actors', 'lookupmultiple', 'tag', NULL, NULL, 'string 64', '2020-07-26 07:12:48', NULL, 1, 1, 'rw-r--r--'),
 (19, 'countries', 'Countries', 'lookupmultiple', 'tag', NULL, NULL, 'string 64', '2020-07-26 07:16:08', NULL, 1, 1, 'rw-r--r--'),
 (20, 'directors', 'Directors', 'lookupmultiple', 'tag', NULL, NULL, 'string 64', '2020-07-26 07:17:59', NULL, 1, 1, 'rw-r--r--'),
index 410900fa640c40a3536d796d94515fd52b4051ee..91d09281e07682ecc9d29b19bc6d617ff4170821 100644 (file)
@@ -221,6 +221,8 @@ class ManageCollections {
                                                                                `fk_field` int NOT NULL,
                                                                                `fk_entry` int NOT NULL,
                                                                                `value` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+                                                                               KEY `fk_entry` (`fk_entry`),
+                                                                               KEY `fk_field` (`fk_field`),
                                                                                FULLTEXT KEY `value` (`value`)
                                                                                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
                                if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryEntry2lookup,true));
index c2b7a10e511a8692b43ed23f8a9c257c27f5183f..67eac8b80a312438c79cf13dc114d20606be0f02 100644 (file)
@@ -400,46 +400,6 @@ class Mancubus {
                return $ret;
        }
 
-       /**
-        * Get tags for loaded collection. Provide search term to use match against db search
-        *
-        * @todo Replace with trite class
-        *
-        * @param mixed $search Search term
-        * @return array
-        */
-       public function getTags($search=false) {
-               $ret = array();
-
-               if(!empty($this->_collectionId)) {
-                       $queryStr = "SELECT `cf`.`fk_field_id` AS id, `sf`.`type`, `sf`.`displayname`, `sf`.`identifier`
-                                               FROM `".DB_PREFIX."_collection_fields_".$this->_DB->real_escape_string($this->_collectionId)."` AS cf
-                                               LEFT JOIN `".DB_PREFIX."_sys_fields` AS sf ON `cf`.`fk_field_id` = `sf`.`id`
-                                               WHERE `sf`.`searchtype` = 'tag' 
-                                               ORDER BY `sf`.`displayname`";
-                       if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
-                       try {
-                               $query = $this->_DB->query($queryStr);
-                               if($query !== false && $query->num_rows > 0) {
-                                       while(($result = $query->fetch_assoc()) != false) {
-                                               $ret[$result['id']] = $result;
-                                               $ret[$result['id']]['entries'] = array();
-
-                                               $_mn = '_loadTagDistinct_'.$result['type'];
-                                               if(method_exists($this, $_mn)) {
-                                                       $ret[$result['id']]['entries'] = $this->$_mn($result,$search);
-                                               }
-                                       }
-                               }
-                       }
-                       catch (Exception $e) {
-                               error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
-                       }
-               }
-
-               return $ret;
-       }
-
        /**
         * Return the storage info for loaded collection
         * Used by API
@@ -627,110 +587,6 @@ class Mancubus {
                return $ret;
        }
 
-       /**
-        * Load the selection as tag.
-        * Search is a 1:1 match
-        *
-        * @param array $fieldData The sys field data
-        * @param mixed $search Searchterm
-        * @return array
-        */
-       private function _loadTagDistinct_selection($fieldData,$search=false) {
-               return $this->_loadColAsTagFromEntryTable($fieldData['identifier'],$search);
-       }
-
-       /**
-        * Load the data for lookupmultiple field. Provide field id and optional searchterm.
-        * Uses currently loaded collection
-        *
-        * @param array $fieldData The field data to use
-        * @param mixed $search Searchterm to run a match against DB search
-        * @return array
-        */
-       private function _loadTagDistinct_lookupmultiple($fieldData,$search=false) {
-               $ret = array();
-
-               if(!empty($fieldData) && !empty($this->_collectionId)) {
-                       $queryStr = "SELECT DISTINCT(`value`) 
-                                               FROM `".DB_PREFIX."_collection_entry2lookup_".$this->_DB->real_escape_string($this->_collectionId)."`
-                                               WHERE `fk_field` = '".$this->_DB->real_escape_string($fieldData['id'])."'";
-                       if(!empty($search)) {
-                               $queryStr .= " AND MATCH (`value`) AGAINST ('" . $this->_DB->real_escape_string($search) . "' IN BOOLEAN MODE)";
-                       }
-
-                       if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
-                       try {
-                               $query = $this->_DB->query($queryStr);
-                               if ($query !== false && $query->num_rows > 0) {
-                                       while (($result = $query->fetch_assoc()) != false) {
-                                               $ret[] = $result['value'];
-                                       }
-                               }
-                       }
-                       catch (Exception $e) {
-                               error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
-
-                       }
-               }
-
-               return $ret;
-       }
-
-       /**
-        * Load the data from lookupmultiple field. In this case $fieldata is overwritten
-        * and year is used.
-        *
-        * @param array $fieldData
-        * @param bool $search
-        * @return array
-        */
-       private function _loadTagDistinct_year($fieldData,$search=false) {
-               return $this->_loadColAsTagFromEntryTable("year",$search);
-       }
-
-       /**
-        * Get the distinct data from a col and optional search term
-        *
-        * @param string $colname
-        * @param string $search
-        * @return array
-        */
-       private function _loadColAsTagFromEntryTable($colname,$search) {
-               $ret = array();
-
-               if(!empty($colname) && !empty($this->_collectionId)) {
-                       if(!empty($search)) {
-                               $queryStr = "SELECT `".$this->_DB->real_escape_string($colname)."` 
-                                               FROM `".DB_PREFIX."_collection_entry_".$this->_DB->real_escape_string($this->_collectionId)."`";
-                               $queryStr .= " WHERE `".$colname."` = '".$this->_DB->real_escape_string($search)."'";
-                       }
-                       else {
-                               $queryStr = "SELECT DISTINCT(`".$this->_DB->real_escape_string($colname)."`) 
-                                               FROM `".DB_PREFIX."_collection_entry_".$this->_DB->real_escape_string($this->_collectionId)."`";
-                       }
-
-                       $queryStr .= " ORDER BY `".$this->_DB->real_escape_string($colname)."` DESC";
-
-                       if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
-                       try {
-                               $query = $this->_DB->query($queryStr);
-                               if($query !== false && $query->num_rows > 0) {
-                                       while(($result = $query->fetch_assoc()) != false) {
-                                               if(!empty($result[$colname])) {
-                                                       $ret[] = $result[$colname];
-                                               }
-                                       }
-                               }
-                       }
-                       catch (Exception $e) {
-                               error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
-                       }
-               }
-
-
-               return $ret;
-       }
-
        /**
         * set some defaults by init of the class
         *
index 31f304656b4075bcdeec561a687728313138d5e8..a61af9b19c5ea0bf6cf39057d477b3e2371ebb43 100644 (file)
@@ -210,6 +210,51 @@ class Trite {
                return $ret;
        }
 
+       /**
+        * Get the tag fields (searchtype = tag) and their values.
+        * Possible optimization can be done here: Do not load everything at once, but per field
+        * Needs also change in frontend to separate those calls
+        *
+        * @param string $search String value to search value against
+        * @return array
+        */
+       public function getTags($search='') {
+               $ret = array();
+
+               $queryStr = "SELECT `cf`.`fk_field_id` AS id,
+                                                       `sf`.`type`,
+                                                       `sf`.`displayname`,
+                                                       `sf`.`identifier`,
+                                                       `e2l`.`value`
+                                               FROM `".DB_PREFIX."_collection_fields_".$this->_DB->real_escape_string($this->_id)."` AS cf
+                                               LEFT JOIN `".DB_PREFIX."_sys_fields` AS sf ON `cf`.`fk_field_id` = `sf`.`id`
+                                               LEFT JOIN `".DB_PREFIX."_collection_entry2lookup_".$this->_DB->real_escape_string($this->_id)."` AS e2l ON `e2l`.`fk_field` = `sf`.`id`
+                                               WHERE `sf`.`searchtype` = 'tag'";
+               if(!empty($search)) {
+                       $queryStr .= " AND MATCH (`e2l`.`value`) AGAINST ('".$this->_DB->real_escape_string($search)."' IN BOOLEAN MODE)";
+               }
+               else {
+                       $queryStr .= " ORDER BY `sf`.`displayname`, `e2l`.`value`";
+               }
+               if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
+               $query = $this->_DB->query($queryStr);
+               try {
+                       if($query !== false && $query->num_rows > 0) {
+                               while(($result = $query->fetch_assoc()) != false) {
+                                       $ret[$result['id']]['id'] = $result['id'];
+                                       $ret[$result['id']]['displayname'] = $result['displayname'];
+                                       $ret[$result['id']]['identifier'] = $result['identifier'];
+                                       $ret[$result['id']]['type'] = $result['type'];
+                                       $ret[$result['id']]['entries'][$result['value']] = $result['value'];
+                               }
+                       }
+               } catch (Exception $e) {
+                       error_log("[ERROR] ".__METHOD__."  mysql catch: ".$e->getMessage());
+               }
+
+               return $ret;
+       }
+
        /**
         * set some defaults by init of the class
         *
index 8fef73c9556bbcc40e920bcb92a30843df56e1f9..f57e59d5f3c548272fd2633709fc59db1834f64a 100644 (file)
@@ -6,7 +6,7 @@ if(!empty($TemplateData['editFields'])) {
 ?>
                <h3 class="uk-h3">Update an entry in: <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>"><?php echo $TemplateData['loadedCollection']['name']; ?></a></h3>
                <p><span uk-icon="arrow-left"></span>
-                       <a href="index.php?p=manageentry&collection=<?php echo $TemplateData['collection']['id']; ?>&id=<?php echo $TemplateData['editData']['id']; ?>">View entry</a>
+                       <a href="index.php?p=entry&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&id=<?php echo $TemplateData['editData']['id']; ?>">View entry</a>
                </p>
 <?php } else { ?>
                <h3 class="uk-h3">Add an entry to: <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>"><?php echo $TemplateData['loadedCollection']['name']; ?></a></h3>
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a97a96199850cfdcdb4e7c4bec18d9ef74c199ea 100644 (file)
@@ -0,0 +1,15 @@
+<?php if(!empty($TemplateData['loadedCollection'])) { ?>
+
+<?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=managetags&collection=<?php echo $k; ?>"><?php echo $v['name']; ?></a></dt>
+                       <dd><?php echo $v['description']; ?></dd>
+                       <?php } ?>
+               </dl>
+       </div>
+</div>
+<?php } ?>
index 7db18b1be714a5c1715a5e40730dfa01c12f0c2b..d8df8b3c4966dd8591eec7bf38ff1ff25bf07119 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * Bibliotheca webclient
  *
- * Copyright 2018-2020 Johannes Keßler
+ * 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.
@@ -49,10 +49,13 @@ if(!empty($_collection)) {
        if(!empty($TemplateData['loadedCollection'])) {
                $TemplateData['searchAction'] = 'index.php?p=tags&collection='.$Trite->param('id');
                $Mancubus->setCollection($Trite->param('id'));
-               $TemplateData['tags'] = $Mancubus->getTags($_search);
+               //$TemplateData['tags'] = $Mancubus->getTags($_search);
+               $TemplateData['tags'] = $Trite->getTags($_search);
                if(!empty($_search)) {
                        $TemplateData['search'] = $_search;
                }
+
+               $Trite->getTags();
        }
        else {
                $TemplateData['message']['content'] = "Can not load given collection.";