Commit 928fe0b9 authored by Christian Walgenbach's avatar Christian Walgenbach
Browse files

Profile: Show the membership for workgroups

parent 097fb603
Pipeline #323402429 passed with stages
in 5 minutes and 44 seconds
......@@ -9,6 +9,7 @@
- Introduces Push Notifications for the Android App !1647 !1976 @dthulke
- Improve wording in German texts, to make the language more consistent, clear, and inclusive in some places. !1959 @blinry @Claraaa @alex.simm @fs_k
- Display same-day pickups when confirming to sign into a pickup slot !1827 @ChrisOelmueller
- Show membership in profile for workgroups !1988 @chriswalg
## Changes
- Profile storelist now shows store cooperation status !1828 !1935 @ChrisOelmueller @chriswalg
......
......@@ -16,9 +16,6 @@
font-weight: bolder;
margin-top: 5px;
}
.profile-infos dt::after {
content: ':';
}
.profile-infos dd {
padding-bottom: 5px;
}
......
......@@ -5,6 +5,7 @@ namespace Foodsharing\Modules\Profile;
use Foodsharing\Lib\WebSocketConnection;
use Foodsharing\Modules\Core\BaseGateway;
use Foodsharing\Modules\Core\Database;
use Foodsharing\Modules\Core\DBConstants\Region\Type;
final class ProfileGateway extends BaseGateway
{
......@@ -115,18 +116,40 @@ final class ProfileGateway extends BaseGateway
$stm = '
SELECT bz.`name`,
bz.`id`
bz.`id`,
bz.type
FROM `fs_bezirk` bz,
fs_foodsaver_has_bezirk b
WHERE b.`bezirk_id` = bz.`id`
AND b.foodsaver_id = :fs_id
AND bz.type != 7
AND bz.type != :type
';
if ($fs = $this->db->fetchAll($stm, [':fs_id' => $fsId])
if ($fs = $this->db->fetchAll($stm, [':fs_id' => $fsId, ':type' => Type::WORKING_GROUP])
) {
$data['foodsaver'] = $fs;
}
// find all working groups in which both the foodsaver and the viewer of the profile are members
$stm = '
SELECT bz.name,
bz.id
FROM fs_bezirk bz
JOIN fs_foodsaver_has_bezirk b1
ON b1.bezirk_id = bz.id
LEFT JOIN fs_foodsaver_has_bezirk b2
ON b1.bezirk_id = b2.bezirk_id
WHERE b1.foodsaver_id = :fs_id
AND b2.foodsaver_id = :viewerId
AND bz.type = :type
';
if ($fs = $this->db->fetchAll($stm, [
':fs_id' => $fsId,
':viewerId' => $viewerId,
':type' => Type::WORKING_GROUP
])) {
$data['working_groups'] = $fs;
}
$stm = '
SELECT bz.`name`,
bz.`id`
......
......@@ -370,7 +370,7 @@ class ProfileView extends View
$out = '<dl class="profile-infos profile-side">';
foreach ($infos as $info) {
$out .= '<dt>' . $info['name'] . '</dt>';
$out .= '<dt>' . $info['name'] . ':</dt>';
$out .= '<dd>' . $info['val'] . '</dd>';
}
$out .= '</dl>';
......@@ -628,13 +628,23 @@ class ProfileView extends View
[$ambassador, $infos] = $this->renderAmbassadorInformation($infos);
$infos = $this->renderFoodsaverInformation($ambassador, $infos);
$infos = $this->renderOrgaTeamMemberInformation($infos);
if ($this->foodsaver['id'] != $this->session->id()) {
$infos = $this->renderFoodsaverTeamMemberInformation($infos);
}
$infos = $this->renderSleepingHatInformation($infos);
$infos = $this->renderAboutMeInternalInformation($infos);
$out = '<dl class="profile-infos profile-main">';
foreach ($infos as $info) {
$out .= '<dt>' . $info['name'] . '</dt>';
$out .= '<dd>' . $info['val'] . '</dd>';
$out .= '<dt>' . $info['name'];
if (!empty($info['val'])) {
$out .= ':';
}
$out .= '</dt>';
if (!empty($info['val'])) {
$out .= '<dd>' . $info['val'] . '</dd>';
}
}
$out .= '</dl>';
......@@ -723,7 +733,7 @@ class ProfileView extends View
}
}
$infos[] = [
'name' => $this->translator->trans('profile.workgroups', ['{name}' => $this->foodsaver['name']]),
'name' => $this->translator->trans('profile.workgroups_admin', ['{name}' => $this->foodsaver['name']]),
'val' => implode(', ', $ambassador),
];
}
......@@ -731,6 +741,30 @@ class ProfileView extends View
return $infos;
}
private function renderFoodsaverTeamMemberInformation(array $infos): array
{
// only display groups in which the user is not an admin
if (!empty($this->foodsaver['working_groups'])) {
$groups = $this->foodsaver['working_groups'];
$groupInfos = [];
foreach ($groups as $group) {
$groupInfos[$group['id']] = $group['name'];
}
$infos[] = [
'name' => $this->translator->trans('profile.workgroups_member', ['{name}' => $this->foodsaver['name']]),
'val' => implode(', ', $groupInfos),
];
} else {
$infos[] = [
'name' => $this->translator->trans('profile.no_common_workgroups', ['{name}' => $this->foodsaver['name']]),
'val' => null,
];
}
return $infos;
}
private function renderSleepingHatInformation(array $infos): array
{
switch ($this->foodsaver['sleep_status']) {
......
......@@ -1533,7 +1533,9 @@ profile:
regions: "{name} ist Foodsaver in"
ambRegions: "{name} ist {role} für"
homeRegion: "Stammbezirk von {name}"
workgroups: "{name} engagiert sich als Ansprechperson für die Gruppen"
workgroups_admin: "{name} engagiert sich als Ansprechperson für die Gruppen"
workgroups_member: "Du bist mit {name} gemeinsam in folgenden Arbeitsgruppen"
no_common_workgroups: "Du bist mit {name} in keiner gemeinsamen Arbeitsgruppe"
sleeping: "{name} hat eine Schlafmütze auf unbestimmte Zeit"
sleepinfo: "{name} hat eine Schlafmütze auf vom {from} bis {until}"
about_me_intern: "Über sich selbst"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment