* delete of a collection
* sort by filter for collection display
* responsive and breakpoints
-* DB query log and optimization
*/
private $_queryOptions;
+ /**
+ * Store the all the values for an entry from lookup table
+ *
+ * @var array
+ */
+ private $_cacheLookupValuesForEntry = array();
+
+ /**
+ * Store entryFields for run time
+ *
+ * @var array
+ */
+ private $_cacheEntryFields = array();
+
/**
* Mancubus constructor.
*
public function getEntriesByFieldValue($fieldId, $fieldValue) {
$ret = array();
- $fieldData = array();
- $queryStr = "SELECT `identifier`, `type`, `id`, `searchtype` FROM `".DB_PREFIX."_sys_fields`
- WHERE `id` = '".$this->_DB->real_escape_string($fieldId)."'";
- 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) {
- if(($result = $query->fetch_assoc()) != false) {
- $fieldData = $result;
- }
- }
- }
- catch (Exception $e) {
- error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
+ $_entryFields = $this->_getEntryFields();
+ if(isset($_entryFields[$fieldId])) {
+ $fieldData = $_entryFields[$fieldId];
}
if(empty($fieldData)) return $ret;
* @return array
*/
private function _getEntryFields() {
- $ret = array();
+
+ if(!empty($this->_cacheEntryFields)) {
+ return $this->_cacheEntryFields;
+ }
if(!empty($this->_collectionId)) {
$queryStr = "SELECT `cf`.`fk_field_id` AS id, `sf`.`type`, `sf`.`displayname`, `sf`.`identifier`,
- `sf`.`value` AS preValue, `sf`.`apiinfo`
+ `sf`.`value` AS preValue, `sf`.`apiinfo` , `sf`.`searchtype`
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`
ORDER BY `cf`.`sort`";
$query = $this->_DB->query($queryStr);
if($query !== false && $query->num_rows > 0) {
while(($result = $query->fetch_assoc()) != false) {
- $ret[$result['id']] = $result;
+ $this->_cacheEntryFields[$result['id']] = $result;
}
}
}
}
}
- return $ret;
+ return $this->_cacheEntryFields;
}
/**
$ret = array();
if(!empty($entryId) && !empty($fieldData) && !empty($this->_collectionId)) {
- $queryStr = "SELECT `value`
- FROM `".DB_PREFIX."_collection_entry2lookup_".$this->_DB->real_escape_string($this->_collectionId)."`
- WHERE `fk_field` = '".$this->_DB->real_escape_string($fieldData['id'])."'
- AND `fk_entry` = '".$this->_DB->real_escape_string($entryId)."'";
- 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'];
- }
+
+ // avoid db query for each wanted value
+ if(isset($this->_cacheLookupValuesForEntry[$this->_collectionId])) {
+ if(isset($this->_cacheLookupValuesForEntry[$this->_collectionId][$entryId][$fieldData['id']])) {
+ $ret = $this->_cacheLookupValuesForEntry[$this->_collectionId][$entryId][$fieldData['id']];
}
}
- catch (Exception $e) {
- error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
+ else {
+ $queryStr = "SELECT `fk_field`, `value`, `fk_entry`
+ FROM `".DB_PREFIX."_collection_entry2lookup_".$this->_DB->real_escape_string($this->_collectionId)."`";
+ 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) {
+ $this->_cacheLookupValuesForEntry[$this->_collectionId][$result['fk_entry']][$result['fk_field']][$result['value']] = $result['value'];
+ }
+ }
+ }
+ catch (Exception $e) {
+ error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
+ }
}
}
FROM `".DB_PREFIX."_tool`
WHERE ".$this->_User->getSQLRightsString()."
AND `action` = '".$this->_DB->real_escape_string($identifier)."'";
+ 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) {
LEFT JOIN `".DB_PREFIX."_group` AS g ON `c`.`group` = `g`.`id`
WHERE ".$this->_User->getSQLRightsString($right, "c")."
AND `c`.`id` = '".$this->_DB->real_escape_string($id)."'";
+ 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) {
$this->_id = $this->_collectionData['id'];
}
} catch (Exception $e) {
- if(DEBUG) error_log("[DEBUG] ".__METHOD__." mysql query: ".$queryStr);
error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
}
}
LEFT JOIN `".DB_PREFIX."_group` AS g ON `c`.`group` = `g`.`id`
WHERE ".$this->_User->getSQLRightsString("read", "c")."
ORDER BY `c`.`name`";
+ if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
try {
$query = $this->_DB->query($queryStr);
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`";
+ 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) {
}
}
} catch (Exception $e) {
- if(DEBUG) error_log("[DEBUG] ".__METHOD__." mysql query: ".$queryStr);
error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
}
$_ms = count($_matches[0]);
for($i=0;$i<$_ms;$i++) {
$_cn = trim(str_replace(':','',$_matches[1][$i]));
- $_sData[$i]['colName'] = $_cn;
- $_sData[$i]['colValue'] = trim(str_replace($_matches[1][$i],'',$_matches[0][$i]));
- $_sData[$i]['fieldData'] = $TemplateData['collectionFields'][$_cn];
+ if(isset($TemplateData['collectionFields'][$_cn])) {
+ $_sData[$i]['colName'] = $_cn;
+ $_sData[$i]['colValue'] = trim(str_replace($_matches[1][$i],'',$_matches[0][$i]));
+ $_sData[$i]['fieldData'] = $TemplateData['collectionFields'][$_cn];
+ }
}
$TemplateData['entries'] = $Mancubus->getEntries($_sData);
$_collection = Summoner::validate($_collection,'digit') ? $_collection : false;
}
-// field id to search within
+// field identifier to search within
$_fid = false;
if(isset($_GET['fid']) && !empty($_GET['fid'])) {
$_fid = trim($_GET['fid']);
- $_fid = Summoner::validate($_fid,'digit') ? $_fid : false;
+ $_fid = Summoner::validate($_fid,'nospace') ? $_fid : false;
}
// field value to look up
$_fv = false;
if(isset($_GET['fv']) && !empty($_GET['fv'])) {
$_fv = trim($_GET['fv']);
- $_fv = Summoner::validate($_fv,'text') ? $_fv : false;
+ $_fv = Summoner::validate($_fv) ? $_fv : false;
}
$_search = false;
if(isset($_POST['navSearch'])) {
$_search = trim($_POST['navSearch']);
- $_search = Summoner::validate($_search,'text') ? $_search : false;
+ $_search = Summoner::validate($_search) ? $_search : false;
}
require_once(Summoner::themefile('system/pagination_before.php',UI_THEME));
$TemplateData['entryLinkPrefix'] = "index.php?p=entry&collection=".$Trite->param('id');
$TemplateData['searchAction'] = 'index.php?p=collections&collection='.$Trite->param('id');
- if (!empty($_fv) && !empty($_fid)) {
- $TemplateData['entries'] = $Mancubus->getEntriesByFieldValue($_fid, $_fv);
- $TemplateData['search'] = $_fv;
+ $_fd = $Trite->getCollectionFields();
+ $_sdata = array();
+ if (!empty($_fv) && !empty($_fid)) {
+ $_sdata[0] = array(
+ 'colName' => $_fd[$_fid]['identifier'],
+ 'colValue' => $_fv,
+ 'fieldData' => $_fd[$_fid]
+ );
+ $_search = $_fv;
$TemplateData['pagination']['currentGetParameters']['fid'] = $_fid;
$TemplateData['pagination']['currentGetParameters']['fv'] = $_fv;
- } else {
- $_fd = $Trite->getCollectionFields();
- $TemplateData['entries'] = $Mancubus->getEntries(
- array(
- 0 => array(
- 'colName' => $Trite->param('defaultSearchField'),
- 'colValue' => $_search,
- 'fieldData' =>$_fd[$Trite->param('defaultSearchField')]
- )
- )
+ }
+ else {
+ $_sdata[0] = array(
+ 'colName' => $Trite->param('defaultSearchField'),
+ 'colValue' => $_search,
+ 'fieldData' =>$_fd[$Trite->param('defaultSearchField')]
);
- if (!empty($_search)) {
- $TemplateData['search'] = $_search;
- }
+ }
+
+ $TemplateData['entries'] = $Mancubus->getEntries($_sdata);
+ if (!empty($_search)) {
+ $TemplateData['search'] = $_search;
}
}
else {
<p data-field-name="date" data-field-id="<?php echo $field['identifier']; ?>">
<span class="uk-text-muted"><?php echo $field['displayname']; ?>:</span>
- <a href="index.php?p=collections&collection='.$TemplateData['loadedCollection']['id'].'&fid='.$field['id'].'&fv='.urlencode(Summoner::ifset($field, 'value')).'"><?php echo Summoner::ifset($field, 'value'); ?></a>
+ <a href="index.php?p=collections&collection='.$TemplateData['loadedCollection']['id'].'&fid='.$field['identifier'].'&fv='.urlencode(Summoner::ifset($field, 'value')).'"><?php echo Summoner::ifset($field, 'value'); ?></a>
</p>
<span class="uk-text-muted"><?php echo $field['displayname']; ?>:</span>
<?php
foreach($field['value'] as $_fv) {
- echo '<a href="index.php?p=collections&collection='.$TemplateData['loadedCollection']['id'].'&fid='.$field['id'].'&fv='.urlencode($_fv).'">'.$_fv.'</a>, ';
+ echo '<a href="index.php?p=collections&collection='.$TemplateData['loadedCollection']['id'].'&fid='.$field['identifier'].'&fv='.urlencode($_fv).'">'.$_fv.'</a>, ';
}
?>
</p>
<p data-field-name="number" data-field-id="<?php echo $field['identifier']; ?>">
<span class="uk-text-muted"><?php echo $field['displayname']; ?>:</span>
- <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&fid=<?php echo $field['id']; ?>&fv=<?php echo urlencode(Summoner::ifset($field, 'value')); ?>"><?php echo Summoner::ifset($field, 'value'); ?></a>
+ <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&fid=<?php echo $field['identifier']; ?>&fv=<?php echo urlencode(Summoner::ifset($field, 'value')); ?>"><?php echo Summoner::ifset($field, 'value'); ?></a>
</p>
<p data-field-name="selection" data-field-id="<?php echo $field['identifier']; ?>">
<span class="uk-text-muted"><?php echo $field['displayname']; ?>:</span>
- <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&fid=<?php echo $field['id']; ?>&fv=<?php echo urlencode(Summoner::ifset($field, 'value')); ?>"><?php echo Summoner::ifset($field, 'value'); ?></a>
+ <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&fid=<?php echo $field['identifier']; ?>&fv=<?php echo urlencode(Summoner::ifset($field, 'value')); ?>"><?php echo Summoner::ifset($field, 'value'); ?></a>
</p>
<p data-field-name="year" data-field-id="<?php echo $field['identifier']; ?>">
<span class="uk-text-muted"><?php echo $field['displayname']; ?>:</span>
- <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&fid=<?php echo $field['id']; ?>&fv=<?php echo urlencode(Summoner::ifset($field, 'value')); ?>"><?php echo Summoner::ifset($field, 'value'); ?></a>
+ <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&fid=<?php echo $field['identifier']; ?>&fv=<?php echo urlencode(Summoner::ifset($field, 'value')); ?>"><?php echo Summoner::ifset($field, 'value'); ?></a>
</p>
Just use drag and drop below to add, remove or order your fields.<br />
<span class="" uk-icon="icon: warning"></span> Removing a field will remove
the stored data from the collection.<br />
- <span class="" uk-icon="icon: warning"></span> Make sure at least the <b>title</b>
- field is available.
+ <span class="" uk-icon="icon: warning"></span> Make sure at least the <b>title</b>, <b>cover image</b>
+ and <b>description</b> fields are available.
</p>
<div id="collectionFields" uk-sortable="group: sortable-group">
<?php foreach($TemplateData['existingFields'] as $k=>$v) { ?>
<h4 class="uk-heading-line"><span><a uk-toggle="target: #toggle-<?php echo $k; ?>"><?php echo $v['displayname']; ?></a></span></h4>
<div id="toggle-<?php echo $k; ?>">
<?php foreach($v['entries'] as $ek=>$ev) { ?>
- <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&fid=<?php echo $k; ?>&fv=<?php echo urlencode($ev); ?>"><?php echo $ev; ?></a>,
+ <a href="index.php?p=collections&collection=<?php echo $TemplateData['loadedCollection']['id']; ?>&fid=<?php echo $v['identifier']; ?>&fv=<?php echo urlencode($ev); ?>"><?php echo $ev; ?></a>,
<?php } ?>
</div>
<?php } ?>