Skip to content
Snippets Groups Projects
Commit 5d085f7c authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

fix errors and warnings, fixes #2803

Closes #2803

Merge request studip/studip!1890
parent 188d9a67
No related branches found
No related tags found
No related merge requests found
......@@ -891,16 +891,14 @@ class Admin_UserController extends AuthenticatedController
}
if ($GLOBALS['perm']->have_perm('root')) {
$sql
= "SELECT Institut_id, Name, 1 AS is_fak
$sql = "SELECT Institut_id, Name, 1 AS is_fak
FROM Institute
WHERE Institut_id=fakultaets_id
ORDER BY Name";
$faks = DBManager::get()->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$domains = UserDomain::getUserDomains();
} else {
$sql
= "SELECT a.Institut_id, Name, b.Institut_id = b.fakultaets_id AS is_fak
$sql = "SELECT a.Institut_id, Name, b.Institut_id = b.fakultaets_id AS is_fak
FROM user_inst a
LEFT JOIN Institute b USING (Institut_id)
WHERE a.user_id = ? AND a.inst_perms = 'admin'
......@@ -911,8 +909,7 @@ class Admin_UserController extends AuthenticatedController
$domains = UserDomain::getUserDomainsForUser(User::findCurrent()->id);
}
$query
= "SELECT Institut_id, Name
$query = "SELECT Institut_id, Name
FROM Institute
WHERE fakultaets_id = ? AND institut_id != fakultaets_id
ORDER BY Name";
......
......@@ -11,7 +11,9 @@ class Course_MessengerController extends AuthenticatedController
public function course_action($thread_id = null)
{
if (Context::get()) {
PageLayout::setTitle(Context::get()->getFullname() . ' - ' . _('Blubber'));
}
if (Navigation::hasItem('/course/blubber')) {
Navigation::activateItem('/course/blubber');
......
......@@ -28,19 +28,41 @@ class ProfileController extends AuthenticatedController
URLHelper::addLinkParam('username', Request::username('username'));
PageLayout::setHelpKeyword('Basis.Homepage');
$this->user = User::findCurrent(); // current logged in user
$this->perm = $GLOBALS['perm']; // perms of current logged in user
$this->current_user = User::findByUsername(Request::username('username', $this->user->username)); // current selected user
// current logged in user
$this->user = User::findCurrent();
// perms of current logged in user
$this->perm = $GLOBALS['perm'];
// current selected user
$this->current_user = User::findByUsername(Request::username(
'username',
$this->user ? $this->user->username : null
));
// get additional informations to selected user
$this->profile = new ProfileModel($this->current_user->user_id, $this->user->user_id);
$this->profile = new ProfileModel(
$this->current_user ? $this->current_user->id : null,
$this->user ? $this->user->id : null
);
// set the page title depending on user selection
if ($this->current_user['user_id'] == $this->user->id && !$this->current_user['locked']) {
if (
$this->user
&& $this->current_user->id === $this->user->id
&& !$this->current_user->locked
) {
PageLayout::setTitle(_('Mein Profil'));
UserConfig::get($this->user->id)->store('PROFILE_LAST_VISIT', time());
} elseif ($this->current_user['user_id'] && ($this->perm->have_perm('root') || (!$this->current_user['locked'] && get_visibility_by_id($this->current_user['user_id'])))) {
} elseif (
$this->current_user->id
&& (
$this->perm->have_perm('root')
|| (
!$this->current_user->locked
&& get_visibility_by_id($this->current_user->id)
)
)
) {
PageLayout::setTitle(_('Profil von') . ' ' . $this->current_user->getFullname());
object_add_view($this->current_user->user_id);
object_add_view($this->current_user->id);
} else {
PageLayout::setTitle(_('Profil'));
$action = 'not_available';
......
......@@ -175,7 +175,7 @@ use Studip\Button, Studip\LinkButton;
<option value="<?= $fak['Institut_id'] ?>" <?= ($user['institute'] == $fak['Institut_id']) ? 'selected' : '' ?> class="<?= $fak['is_fak'] ? 'nested-item-header' : 'nested-item'; ?>">
<?= htmlReady($fak['Name']) ?>
</option>
<? foreach ($fak['institutes'] as $institute) : ?>
<? foreach ($fak['institutes'] ?? [] as $institute) : ?>
<option value="<?= $institute['Institut_id'] ?>" <?= ($user['institute'] == $institute['Institut_id']) ? 'selected' : '' ?> class="nested-item">
<?= htmlReady($institute['Name']) ?>
</option>
......
......@@ -122,7 +122,7 @@
</table>
<? endif ?>
<footer data-dialog-button>
<? if ($ilias->isActive() && $submit_text) : ?>
<? if ($ilias && $ilias->isActive() && $submit_text) : ?>
<?= Studip\Button::create($submit_text, 'submit', ($dialog && $keep_dialog) ? ['data-dialog' => 'size=auto;reload-on-close'] : []) ?>
<? endif ?>
<?= Studip\Button::createCancel(_('Schließen'), 'cancel', $dialog ? ['data-dialog' => 'close'] : []) ?>
......
......@@ -54,7 +54,10 @@ class ProfileModel
*/
public function getHomepageVisibilities()
{
$visibilities = get_local_visibility_by_id($this->current_user->user_id, 'homepage');
$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);
}
......
......@@ -302,21 +302,22 @@ function my_substr($what, $start, $end)
*/
function get_fullname($user_id = "", $format = "full" , $htmlready = false)
{
static $cache;
global $user, $_fullname_sql;
static $cache = [];
$current_user = User::findCurrent();
if (!$user_id) {
$user_id = $user->id;
$user_id = $current_user ? $current_user->id : null;
}
if (User::findCurrent()->id === $user_id) {
$fullname = User::findCurrent()->getFullName($format);
if ($current_user && $current_user->id === $user_id) {
$fullname = $current_user->getFullName($format);
return $htmlready ? htmlReady($fullname) : $fullname;
}
$hash = md5($user_id . $format);
if (!isset($cache[$hash])) {
$query = "SELECT {$_fullname_sql[$format]}
$query = "SELECT {$GLOBALS['_fullname_sql'][$format]}
FROM auth_user_md5
LEFT JOIN user_info USING (user_id)
WHERE user_id = ?";
......
......@@ -109,8 +109,12 @@ class UserDomain extends SimpleORMap
*/
public static function getUserDomainsForUser($user_id)
{
$domains = User::find($user_id)->domains;
return $domains ? $domains->getArrayCopy() : [];
$user = User::find($user_id);
if (!$user) {
return [];
}
return $user->domains ? $user->domains->getArrayCopy() : [];
}
/**
......
......@@ -82,14 +82,15 @@ function get_visibility_by_state ($state, $user_id) {
return true;
}
$user = User::findCurrent();
$other_user = User::find($user_id);
if (!$other_user) {
if (!$user || !$other_user) {
return false;
}
$same_domain = UserDomain::checkUserVisibility(
$other_user->domains,
User::findCurrent()->domains
$user->domains
);
switch ($state) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment