From bbd1b2f46ebdfc7fa5889fa0fc7f4dc2b43c6d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20R=C3=BCegg?= Date: Wed, 17 Jan 2024 13:24:22 +0100 Subject: [PATCH] Update method of checking friendship humhub/humhub#6745 --- module.json | 2 +- widgets/TaskPicker.php | 61 +++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/module.json b/module.json index 203dc2d4..288cad06 100644 --- a/module.json +++ b/module.json @@ -6,7 +6,7 @@ "version": "1.8.4", "homepage": "https://github.com/humhub/tasks", "humhub": { - "minVersion": "1.14" + "minVersion": "1.16" }, "screenshots": ["resources/screen1.jpg", "resources/screen2.jpg", "resources/screen3.jpg", "resources/screen4.jpg", "resources/screen5.jpg", "resources/screen6.jpg", "resources/screen7.jpg", "resources/screen8.jpg", "resources/screen9.jpg", "resources/screen10.jpg", "resources/screen11.jpg", "resources/screen12.jpg", "resources/screen13.jpg"] } diff --git a/widgets/TaskPicker.php b/widgets/TaskPicker.php index 7f976be3..4576629d 100644 --- a/widgets/TaskPicker.php +++ b/widgets/TaskPicker.php @@ -1,4 +1,5 @@ $this->placeholderText, ]); } - + /** * Creates a json task array used in the taskpicker js frontend. * The $cfg is used to specify the filter values the following values are available: - * + * * query - (ActiveQuery) The initial query which is used to append additional filters. - default = User Friends if friendship module is enabled else User::find() - * + * * active - (boolean) Specifies if only active task should be included in the result - default = true - * + * * maxResults - (int) The max number of entries returned in the array - default = 10 - * + * * keyword - (string) A keyword which filters task by title and description - * + * * permission - (BasePermission) An additional permission filter - * + * * fillQuery - (ActiveQuery) Can be used to fill the result array if the initial query does not return the maxResults, these results will have a lower priority - * + * * fillUser - (boolean) When set to true and no fillQuery is given the result is filled with User::find() results - * + * * disableFillUser - Specifies if the results of the fillQuery should be disabled in the taskpicker results - default = true - * + * * @param type $cfg filter configuration * @return type json representation used by the taskpicker */ @@ -178,8 +179,9 @@ public static function filter($cfg = null) $cfg = ($cfg == null) ? $defaultCfg : array_merge($defaultCfg, $cfg); //If no initial query is given we use getFriends if friendship module is enabled otherwise all tasks - if(!isset($cfg['query'])) { - $cfg['query'] = (Yii::$app->getModule('friendship')->getIsEnabled()) + if (!isset($cfg['query'])) { + $module = Yii::$app->getModule('friendship'); + $cfg['query'] = ($module instanceof FriendshipModule && $module->isFriendshipEnabled()) ? Yii::$app->task->getIdentity()->getFriends() : UserFilter::find(); } @@ -189,8 +191,7 @@ public static function filter($cfg = null) $jsonResult = self::asJSON($task, $cfg['permission'], 2); //Fill the result with additional tasks if it's allowed and the result count less than maxResult - if(count($task) < $cfg['maxResult'] && (isset($cfg['fillQuery']) || $cfg['fillUser']) ) { - + if (count($task) < $cfg['maxResult'] && (isset($cfg['fillQuery']) || $cfg['fillUser'])) { //Filter out tasks by means of the fillQuery or default the fillQuery $fillQuery = (isset($cfg['fillQuery'])) ? $cfg['fillQuery'] : UserFilter::find(); UserFilter::addKeywordFilter($fillQuery, $cfg['keyword'], ($cfg['maxResult'] - count($task))); @@ -204,26 +205,26 @@ public static function filter($cfg = null) return $jsonResult; } - + /** * Assambles all task Ids of the given $tasks into an array - * + * * @param array $tasks array of task models * @return array task id array */ private static function getTaskIdArray($tasks) { $result = []; - foreach($tasks as $task) { + foreach ($tasks as $task) { $result[] = $task->id; } return $result; } - + /** * Creates an json result with task information arrays. A task will be marked * as disabled, if the permission check fails on this task. - * + * * @param type $tasks * @param type $permission * @return type @@ -246,7 +247,7 @@ public static function asJSON($tasks, $permission = null, $priority = null) /** * Creates an single task-information array for a given task. A task will be marked * as disabled, if the permission check fails on this task. - * + * * @param type $task * @param type $permission * @return type @@ -254,15 +255,15 @@ public static function asJSON($tasks, $permission = null, $priority = null) private static function createJSONTaskInfo($task, $permission = null, $priority = null) { $disabled = false; - - if($permission != null && $permission instanceof \humhub\libs\BasePermission) { + + if ($permission != null && $permission instanceof \humhub\libs\BasePermission) { $disabled = !$task->getPermissionManager()->can($permission); - } else if($permission != null) { + } elseif ($permission != null) { $disabled = $permission; } - + $priority = ($priority == null) ? 0 : $priority; - + $text = Html::encode($task->title); $taskInfo = []; $taskInfo['id'] = $task->id; @@ -270,5 +271,3 @@ private static function createJSONTaskInfo($task, $permission = null, $priority return $taskInfo; } } - -?>