Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.16] Update method of checking friendship humhub/humhub#6745 #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
61 changes: 30 additions & 31 deletions widgets/TaskPicker.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
Expand All @@ -8,9 +9,10 @@

namespace humhub\modules\tasks\widgets;

use humhub\modules\friendship\Module as FriendshipModule;
use Yii;
use yii\helpers\Html;
use \yii\helpers\Url;
use yii\helpers\Url;

/**
* TaskPickerWidget displays a task picker instead of an input field.
Expand Down Expand Up @@ -38,7 +40,6 @@
*/
class TaskPicker extends \yii\base\Widget
{

/**
* Id of input element which should replaced
*
Expand Down Expand Up @@ -91,10 +92,10 @@ class TaskPicker extends \yii\base\Widget
* @var string for input placeholder attribute.
*/
public $placeholderText = "";

/**
* Used to transfer additional data to the server
* @var type
* @var type
*/
public $data = null;

Expand Down Expand Up @@ -139,27 +140,27 @@ public function run()
'placeholderText' => $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
*/
Expand All @@ -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();
}
Expand All @@ -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)));
Expand All @@ -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
Expand All @@ -246,29 +247,27 @@ 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
*/
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;
$taskInfo['disabled'] = $disabled;
return $taskInfo;
}
}

?>