[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [BP][FIX] Categories: Some issues related to object categories
"Adrien Mbuya Maloba \(@adrienmaloba\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68a25ff7d625_2cd6b6437328@gitlab-sidekiq-low-urgency-cpu-bound-v2-7b465d79f4-ld9vl.mail> |
Adrien Mbuya Maloba pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki
Commits:
e8e33a9b by Adrien Mbuya Maloba at 2025-08-18T01:57:50+03:00
[BP][FIX] Categories: Some issues related to object categories
---
* [BP][FIX] Categories: Some issues related to object categories
---
* [FIX] Categories: Some issues related to object categories
---
* Categories: Remove unused function list_orphan_objects
* [FIX] Categories: Category names are not shown in tiki-browse_categories.php
* Categories: Remove some keys from expected_keys array
* [REF] Categories: Move other_value_in_tab_line function
* [FIX] Categories: Removing object from category via 'icon-remove' gave Warning: Trying to access array offset on value of type null in tiki-admin_categories.php on line 196
* [FIX] Categories: Browse categories in 'browse mode' gave Deprecated: str_replace(): Passing null to parameter #3 () of type array|string is deprecated in lib\smarty_tiki\Modifier\TrIf.php on line 28
* [FIX] Categories: Warning: Undefined array key categId in tiki-browse_categories.php on line 287
* [FIX] Categories: Objects list not displayed in browse mode (tiki-browse_categories.php) or admin mode (tiki-admin_categories.php)
See merge request tikiwiki/tiki!6150
See merge request tikiwiki/tiki!7208
See merge request tikiwiki/tiki!7216
- - - - -
7 changed files:
- doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json
- lib/categories/categlib.php
- lib/smarty_tiki/Modifier/TrIf.php
- lib/tikilib.php
- templates/tiki-admin_categories.tpl
- templates/tiki-browse_categories.tpl
- tiki-browse_categories.php
Changes:
=====================================
doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json
=====================================
@@ -6878,7 +6878,6 @@
"CategLib::get_category_by_name": true,
"CategLib::list_category_objects": true,
"CategLib::filter_object_list": true,
- "CategLib::list_orphan_objects": true,
"CategLib::get_catorphan_object_type": true,
"CategLib::get_object_categories": true,
"CategLib::remove_object_from_category": true,
@@ -8561,7 +8560,6 @@
"TikiLib::get_language": true,
"TikiLib::read_raw": true,
"TikiLib::get_groups_to_user_with_permissions": true,
- "TikiLib::other_value_in_tab_line": true,
"TikiLib::get_attach_hash_file_name": true,
"TikiLib::attach_file": true,
"TikiLib::strlen_quoted": true,
=====================================
lib/categories/categlib.php
=====================================
@@ -683,7 +683,7 @@ class CategLib extends ObjectLib
}
// Fetch all results as was done before, but only do it once
- $query = "SELECT o.*, GROUP_CONCAT(c.catObjectId) as category_ids";
+ $query = "SELECT o.*, GROUP_CONCAT(c.categId) as category_ids";
$query .= " FROM `tiki_objects` o";
// I don't understand what the tiki_categorized_objects table does. It looks like just a cache of objects part of tiki_category_object. It's lone catObjectId column matches tiki_category_objects.objectId and tiki_objects.objectId, so it doesn't help the join but makes it fail if it's not present!?!?!? - benoitg- 2024-01-31
@@ -722,7 +722,7 @@ class CategLib extends ObjectLib
}
/**
- * @param array $result object list
+ * @param array $result (object list) resulting from the join of table tiki_objects that have columns objectId, type, itemId, description, name, href and tiki_category_objects having category_ids concatenation of column categId
* @param int $count size of list
* @param int $offset start of list
* @param int $maxRecords size of page - NB: -1 will check perms etc on every object and can be very slow
@@ -732,12 +732,19 @@ class CategLib extends ObjectLib
{
global $user, $prefs;
$permMap = TikiLib::lib('object')->map_object_type_to_permission();
- $groupList = $this->get_user_groups($user);
// Filter based on permissions
$contextMap = ['type' => 'type', 'object' => 'itemId'];
$contextMapMap = array_fill_keys(array_keys($permMap), $contextMap);
+ $expected_keys = ['objectId', 'type', 'itemId', 'description', 'name', 'href', 'category_ids'];
+ foreach ($result as $res) {
+ // Make sure all keys are present
+ if (count(array_intersect_key(array_flip($expected_keys), $res)) !== count($expected_keys)) {
+ throw new Exception(tr("One or more object keys missing"));
+ }
+ }
+
if ($maxRecords == -1) {
$requiredResult = $result;
} else {
@@ -799,7 +806,7 @@ class CategLib extends ObjectLib
$res['name'] = '#' . $res['itemId'];
}
$ret[] = $res;
- $objs[] = $res['catObjectId'] . '-' . $res['categId'];
+ $objs[] = $res['objectId'] . '-' . $res['category_ids'];
}
}
@@ -825,28 +832,6 @@ class CategLib extends ObjectLib
];
}
- public function list_orphan_objects($offset, $maxRecords, $sort_mode)
- {
- $orderClause = $this->convertSortMode($sort_mode);
-
- $common = "
- FROM
- tiki_objects
- LEFT JOIN tiki_category_objects ON objectId = catObjectId
- WHERE
- catObjectId IS NULL
- ORDER BY $orderClause
- ";
-
- $query = "SELECT objectId catObjectId, 0 categId, type, itemId, name, href $common";
- $queryCount = "SELECT COUNT(*) $common";
-
- $result = $this->fetchAll($query, [], $maxRecords, $offset);
- $count = $this->getOne($queryCount);
-
- return $this->filter_object_list($result, $count, $offset, $maxRecords);
- }
-
// get specific object types that are not categorised
public function get_catorphan_object_type($offset, $maxRecords, $object_type, $object_table, $object_ref, $sort_mode = null)
{
=====================================
lib/smarty_tiki/Modifier/TrIf.php
=====================================
@@ -25,7 +25,7 @@ class TrIf
},
array_keys($args)
);
- return str_replace($search, $replace, $source);
+ return str_replace($search, $replace, $source ?? '');
}
}
}
=====================================
lib/tikilib.php
=====================================
@@ -6139,22 +6139,6 @@ class TikiLib extends TikiDb_Bridge
return $this->fetchAll($query, [(int)$userid, $perm]);
}
- /**
- * @param $tab
- * @param $valField1
- * @param $field1
- * @param $field2
- * @return mixed
- */
- public function other_value_in_tab_line($tab, $valField1, $field1, $field2)
- {
- foreach ($tab as $line) {
- if ($line[$field1] == $valField1) {
- return $line[$field2];
- }
- }
- }
-
/**
* @param $file_name
* @return string
=====================================
templates/tiki-admin_categories.tpl
=====================================
@@ -214,7 +214,7 @@
</div>
</td>
<td class="icon">
- <a href="tiki-admin_categories.php?parentId={$parentId}&removeObject={$objects[ix].catObjectId}&fromCateg={$parentId}" class="tips text-danger" title=":{tr}Remove from this category{/tr}" onclick="confirmPopup('{tr}Remove object from category?{/tr}', '{ticket mode=get}')">
+ <a href="tiki-admin_categories.php?parentId={$parentId}&removeObject={$objects[ix].objectId}&fromCateg={$parentId}" class="tips text-danger" title=":{tr}Remove from this category{/tr}" onclick="confirmPopup('{tr}Remove object from category?{/tr}', '{ticket mode=get}')">
{icon name='remove'}
</a>
</td>
=====================================
templates/tiki-browse_categories.tpl
=====================================
@@ -175,7 +175,7 @@
</td>
{if $deep eq 'on'}
<td class="text">
- {$objects[ix].categName|tr_if|escape}
+ {$objects[ix].categNames|tr_if|escape}
</td>
{/if}
</tr>
=====================================
tiki-browse_categories.php
=====================================
@@ -265,7 +265,7 @@ $objects = $categlib->list_category_objects(
if ($deep == 'on') {
foreach ($objects['data'] as &$object) {
- $object['categName'] = $tikilib->other_value_in_tab_line($ctall, $object['categId'], 'categId', 'name');
+ $object['categNames'] = implode(", ", other_value_in_tab_line($ctall, $object['category_ids']));
}
}
@@ -450,3 +450,22 @@ function add_watch_icons($descendants, $usercatwatches, $requestid, $categid, $d
// return $eyes . $eyesgroup;
}
+
+/**
+ * @param $tab
+ * @param $category_ids
+ * @return array
+ */
+function other_value_in_tab_line($tab, $categoryIds): array
+{
+ $categoryIds = explode(",", $categoryIds);
+ $categoryNames = [];
+ foreach ($categoryIds as $catId) {
+ foreach ($tab as $line) {
+ if ($line['categId'] == (int) $catId) {
+ $categoryNames[] = $line['name'];
+ }
+ }
+ }
+ return $categoryNames;
+}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e8e33a9bc561f07d41f0359d964381222ce72949
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e8e33a9bc561f07d41f0359d964381222ce72949
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs