Skip to content
Snippets Groups Projects
Commit 36400568 authored by David Siegfried's avatar David Siegfried Committed by Jan-Hendrik Willms
Browse files

remove ProfilModel, fixes #4185

Closes #4185

Merge request studip/studip!3022
parent 5e0842ce
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
- `isMetadateCorrespondingDate ($termin_id, $begin = '', $end = '', $seminar_id='')` - `isMetadateCorrespondingDate ($termin_id, $begin = '', $end = '', $seminar_id='')`
- `getPresenceTypes()` - `getPresenceTypes()`
- Die Klasse `AuxLockRules` wurde ausgebaut. ([Issue #4187](https://gitlab.studip.de/studip/studip/-/issues/4187)) - Die Klasse `AuxLockRules` wurde ausgebaut. ([Issue #4187](https://gitlab.studip.de/studip/studip/-/issues/4187))
- Die Klasse `ProfileModel` wurde gelöscht. Die darin enthaltenen Methoden wurden in den `Profile_Controller` verschoben. ([Issue #4185]https://gitlab.studip.de/studip/studip/-/issues/4185))
## Security related issues ## Security related issues
......
...@@ -106,11 +106,11 @@ class ProfileController extends AuthenticatedController ...@@ -106,11 +106,11 @@ class ProfileController extends AuthenticatedController
// Additional user information // Additional user information
$this->public_email = get_visible_email($this->current_user->user_id); $this->public_email = get_visible_email($this->current_user->user_id);
$this->motto = $this->profile->getVisibilityValue('motto'); $this->motto = $this->getVisibilityValue('motto');
$this->private_nr = $this->profile->getVisibilityValue('privatnr', 'private_phone'); $this->private_nr = $this->getVisibilityValue('privatnr', 'private_phone');
$this->private_cell = $this->profile->getVisibilityValue('privatcell', 'private_cell'); $this->private_cell = $this->getVisibilityValue('privatcell', 'private_cell');
$this->privadr = $this->profile->getVisibilityValue('privadr', 'privadr'); $this->privadr = $this->getVisibilityValue('privadr', 'privadr');
$this->homepage = $this->profile->getVisibilityValue('Home', 'homepage'); $this->homepage = $this->getVisibilityValue('Home', 'homepage');
// skype informations // skype informations
$this->skype_name = ''; $this->skype_name = '';
...@@ -119,8 +119,8 @@ class ProfileController extends AuthenticatedController ...@@ -119,8 +119,8 @@ class ProfileController extends AuthenticatedController
} }
// get generic datafield entries // get generic datafield entries
$this->shortDatafields = $this->profile->getShortDatafields(); $this->shortDatafields = $this->getShortDatafields();
$this->longDatafields = $this->profile->getLongDatafields(); $this->longDatafields = $this->getLongDatafields();
// get working station of an user (institutes) // get working station of an user (institutes)
$this->institutes = $this->getInstitutInformation(); $this->institutes = $this->getInstitutInformation();
...@@ -206,7 +206,7 @@ class ProfileController extends AuthenticatedController ...@@ -206,7 +206,7 @@ class ProfileController extends AuthenticatedController
// Anzeige der Seminare, falls User = dozent // Anzeige der Seminare, falls User = dozent
if ($this->current_user['perms'] == 'dozent') { if ($this->current_user['perms'] == 'dozent') {
$this->seminare = array_filter($this->profile->getDozentSeminars()); $this->seminare = array_filter($this->getTeacherSeminars());
} }
// Hompageplugins // Hompageplugins
...@@ -234,7 +234,7 @@ class ProfileController extends AuthenticatedController ...@@ -234,7 +234,7 @@ class ProfileController extends AuthenticatedController
foreach ($category as $cat) { foreach ($category as $cat) {
$head = $cat->name; $head = $cat->name;
$body = $cat->content; $body = $cat->content;
$vis_text = ""; $vis_text = '';
if ($this->user->user_id == $this->current_user->user_id) { if ($this->user->user_id == $this->current_user->user_id) {
$vis_text .= ' (' . Visibility::getStateDescription('kat_' . $cat->kategorie_id) . ')'; $vis_text .= ' (' . Visibility::getStateDescription('kat_' . $cat->kategorie_id) . ')';
...@@ -521,4 +521,159 @@ class ProfileController extends AuthenticatedController ...@@ -521,4 +521,159 @@ class ProfileController extends AuthenticatedController
PageLayout::setTitle(sprintf(_('Profil von %s'), $external_user['name'])); PageLayout::setTitle(sprintf(_('Profil von %s'), $external_user['name']));
$this->user = $external_user; $this->user = $external_user;
} }
/**
* Collect user datafield informations
*
* @return array
*/
private function getDatafields(): array
{
$short_datafields = [];
$long_datafields = [];
foreach (DataFieldEntry::getDataFieldEntries($this->current_user->user_id, 'user') as $entry) {
if ($entry->isVisible() && $entry->getDisplayValue()
&& Visibility::verify($entry->getID(), $this->current_user->user_id))
{
if ($entry instanceof DataFieldTextareaEntry) {
$long_datafields[] = $entry;
} else {
$short_datafields[] = $entry;
}
}
}
return [
'long' => $long_datafields,
'short' => $short_datafields,
];
}
/**
* Filter long datafiels from the datafields
*
* @return array
*/
private function getLongDatafields(): array
{
$datafields = $this->getDatafields();
$array = [];
if (!empty($datafields)) {
foreach ($datafields['long'] as $entry) {
$array[(string)$entry->getName()] = [
'content' => $entry->getDisplayValue(),
'visible' => '(' . $entry->getPermsDescription() . ')',
];
}
}
return $array;
}
/**
* Filter short datafiels from the datafields
*
* @return array
*/
private function getShortDatafields(): array
{
$shortDatafields = $this->getDatafields();
$array = [];
if (!empty($shortDatafields)) {
foreach ($shortDatafields['short'] as $entry) {
$array[(string)$entry->getName()] = [
'content' => $entry->getDisplayValue(),
'visible' => '(' . $entry->getPermsDescription() . ')',
];
}
}
return $array;
}
/**
* Creates an array with all seminars
*
* @return array
*/
private function getTeacherSeminars(): array
{
$courses = [];
$semester = [];
$next_semester = Semester::findNext();
$current_semester = Semester::findCurrent();
$previous_semester = Semester::findPrevious();
if ($next_semester) {
$semester[$next_semester->id] = $next_semester;
}
if ($current_semester) {
$semester[$current_semester->id] = $current_semester;
}
if ($previous_semester) {
$semester[$previous_semester->id] = $previous_semester;
}
$field = 'name';
if (Config::get()->IMPORTANT_SEMNUMBER) {
$field = "veranstaltungsnummer,{$field}";
}
$allcourses = new SimpleCollection(
Course::findBySQL(
"INNER JOIN seminar_user USING(Seminar_id) WHERE user_id=? AND seminar_user.status='dozent' AND seminare.visible=1",
[
$this->current_user->id
]
)
);
foreach (array_filter($semester) as $one) {
$courses[(string) $one->name] = $allcourses->filter(function ($c) use ($one) {
if (Config::get()->HIDE_STUDYGROUPS_FROM_PROFILE && $c->isStudygroup()) {
return false;
}
if (!$c->isOpenEnded()) {
return $c->isInSemester($one);
} elseif ($one->isCurrent()) {
return $c;
}
return false;
})->orderBy($field);
if (!$courses[(string) $one->name]->count()) {
unset($courses[(string) $one->name]);
}
}
return $courses;
}
/**
* Get the homepagevisibilities
*
* @return array
*/
private function getHomepageVisibilities(): array
{
$visibilities = get_local_visibility_by_id(
$this->current_user ? $this->current_user->id : null,
'homepage'
);
if (is_array(json_decode($visibilities, true))) {
return json_decode($visibilities, true);
}
return [];
}
/**
* Returns the visibility value
*
* @param string $param
* @param string $visibility
* @return string|bool
*/
private function getVisibilityValue(string $param, string $visibility = ''): string|bool
{
if (Visibility::verify($visibility ?: $param, $this->current_user->user_id)) {
return $this->current_user->$param;
}
return false;
}
} }
<?php
/**
* ProfileModel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author David Siegfried <david.siegfried@uni-oldenburg.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 2.4
*/
class ProfileModel
{
protected $perm;
/**
* Internal current selected user id
* @var String
*/
protected $current_user;
/**
* Internal current logged in user id
* @var String
*/
protected $user;
/**
* Internal user homepage visbilities
* @var array
*/
protected $visibilities;
/**
* Get informations on depending selected user
* @param String $current_user
* @param String $user
*/
public function __construct($current_user, $user)
{
$this->current_user = User::find($current_user);
$this->user = User::find($user);
$this->visibilities = $this->getHomepageVisibilities();
$this->perm = $GLOBALS['perm'];
}
/**
* Get the homepagevisibilities
*
* @return array
*/
public function getHomepageVisibilities()
{
$visibilities = get_local_visibility_by_id(
$this->current_user ? $this->current_user->id : null,
'homepage'
);
if (is_array(json_decode($visibilities, true))) {
return json_decode($visibilities, true);
}
return [];
}
/**
* Returns the visibility value
*
* @return String
*/
public function getVisibilityValue($param, $visibility = '')
{
if (Visibility::verify($visibility ?: $param, $this->current_user->user_id)) {
return $this->current_user->$param;
}
return false;
}
/**
* Returns a specific value of the visibilies
* @param String $param
* @return String
*/
public function getSpecificVisibilityValue($param)
{
if (!empty($this->visibilities[$param])) {
return $this->visibilities[$param];
}
return false;
}
/**
* Creates an array with all seminars
*
* @return array
*/
public function getDozentSeminars()
{
$courses = [];
$semester = [];
$next_semester = Semester::findNext();
$current_semester = Semester::findCurrent();
$previous_semester = Semester::findPrevious();
if ($next_semester) {
$semester[$next_semester->id] = $next_semester;
}
if ($current_semester) {
$semester[$current_semester->id] = $current_semester;
}
if ($previous_semester) {
$semester[$previous_semester->id] = $previous_semester;
}
$field = 'name';
if (Config::get()->IMPORTANT_SEMNUMBER) {
$field = "veranstaltungsnummer,{$field}";
}
$allcourses = new SimpleCollection(Course::findBySQL("INNER JOIN seminar_user USING(Seminar_id) WHERE user_id=? AND seminar_user.status='dozent' AND seminare.visible=1", [$this->current_user->id]));
foreach (array_filter($semester) as $one) {
$courses[(string) $one->name] = $allcourses->filter(function ($c) use ($one) {
if (Config::get()->HIDE_STUDYGROUPS_FROM_PROFILE && $c->isStudygroup()) {
return false;
}
if (!$c->isOpenEnded()) {
return $c->isInSemester($one);
} elseif ($one->isCurrent()) {
return $c;
}
return false;
})->orderBy($field);
if (!$courses[(string) $one->name]->count()) {
unset($courses[(string) $one->name]);
}
}
return $courses;
}
/**
* Collect user datafield informations
*
* @return array
*/
public function getDatafields()
{
// generische Datenfelder aufsammeln
$short_datafields = [];
$long_datafields = [];
foreach (DataFieldEntry::getDataFieldEntries($this->current_user->user_id, 'user') as $entry) {
if ($entry->isVisible() && $entry->getDisplayValue()
&& Visibility::verify($entry->getID(), $this->current_user->user_id))
{
if ($entry instanceof DataFieldTextareaEntry) {
$long_datafields[] = $entry;
} else {
$short_datafields[] = $entry;
}
}
}
return [
'long' => $long_datafields,
'short' => $short_datafields,
];
}
/**
* Filter long datafiels from the datafields
*
* @return array
*/
public function getLongDatafields()
{
$datafields = $this->getDatafields();
$array = [];
if (empty($datafields)) {
return null;
}
foreach ($datafields['long'] as $entry) {
$array[(string) $entry->getName()] = [
'content' => $entry->getDisplayValue(),
'visible' => '(' . $entry->getPermsDescription() . ')',
];
}
return $array;
}
/**
* Filter short datafiels from the datafields
*
* @return array
*/
public function getShortDatafields()
{
$shortDatafields = $this->getDatafields();
$array = [];
if (empty($shortDatafields)) {
return null;
}
foreach ($shortDatafields['short'] as $entry) {
$array[(string) $entry->getName()] = [
'content' => $entry->getDisplayValue(),
'visible' => '(' . $entry->getPermsDescription() . ')',
];
}
return $array;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment