Skip to content
Snippets Groups Projects
Commit 74cde461 authored by Moritz Strohm's avatar Moritz Strohm
Browse files

fix for BIESt #971

Closes #971

Merge request studip/studip!578
parent 956957c1
No related branches found
No related tags found
No related merge requests found
Showing
with 76 additions and 52 deletions
......@@ -43,7 +43,7 @@ class Admin_CoursesController extends AuthenticatedController
{
//first get the active datafields of the user:
$userSelectedElements = $this->getActiveElements();
$activeDatafields = $userSelectedElements['datafields'];
$activeDatafields = $userSelectedElements['datafields'] ?? [];
if (!$activeDatafields) {
return [];
......@@ -189,7 +189,7 @@ class Admin_CoursesController extends AuthenticatedController
}
//if there are datafields in the list, draw their input fields, too:
if ($visibleElements['datafields']) {
if (!empty($visibleElements['datafields'])) {
//The datafields entry contains an array with datafield-IDs.
//We must fetch them from the database and show an appropriate widget
//for each datafield.
......@@ -1190,7 +1190,7 @@ class Admin_CoursesController extends AuthenticatedController
$filter->where("sem_classes.studygroup_mode = '0'");
// Get only children of given course
if ($params['parent_course']) {
if (!empty($params['parent_course'])) {
$filter->where("parent_course = :parent",
[
'parent' => $params['parent_course']
......@@ -1235,10 +1235,10 @@ class Admin_CoursesController extends AuthenticatedController
return [];
}
$seminars = array_map('reset', $courses);
if (!empty($seminars)) {
foreach ($seminars as $seminar_id => $seminar) {
$seminars = [];
if (!empty($courses)) {
foreach ($courses as $seminar_id => $seminar) {
$seminars[$seminar_id] = $seminar[0];
$seminars[$seminar_id]['seminar_id'] = $seminar_id;
$seminars[$seminar_id]['obj_type'] = 'sem';
$dozenten = $this->getTeacher($seminar_id);
......@@ -1253,7 +1253,7 @@ class Admin_CoursesController extends AuthenticatedController
$seminars[$seminar_id]['navigation'] = MyRealmModel::getAdditionalNavigations(
$seminar_id,
$seminars[$seminar_id],
$seminars[$seminar_id]['sem_class'],
$seminars[$seminar_id]['sem_class'] ?? null,
$GLOBALS['user']->id,
$visit_data[$seminar_id]
);
......@@ -1264,8 +1264,8 @@ class Admin_CoursesController extends AuthenticatedController
}
if ((int)$this->selected_action === 17) {
$seminars[$seminar_id]['admission_locked'] = false;
if ($seminar['course_set']) {
$set = new CourseSet($seminar['course_set']);
if ($seminar[0]['course_set']) {
$set = new CourseSet($seminar[0]['course_set']);
if (!is_null($set) && $set->hasAdmissionRule('LockedAdmission')) {
$seminars[$seminar_id]['admission_locked'] = 'locked';
} else {
......
......@@ -122,7 +122,7 @@ class MyCoursesController extends AuthenticatedController
foreach ($_outer as $course) {
$_courses[$course['seminar_id']] = $course;
if ($course['children']) {
if (!empty($course['children']) && is_array($course['children'])) {
foreach ($course['children'] as $child) {
$_courses[$child['seminar_id']] = $child;
}
......@@ -722,12 +722,12 @@ class MyCoursesController extends AuthenticatedController
*/
public function check_course($seminar_content)
{
if ($seminar_content['visitdate'] <= $seminar_content['chdate'] || $seminar_content['last_modified'] > 0) {
$last_modified_timestamp = $seminar_content['last_modified'] ?? 0;
if ($seminar_content['visitdate'] <= $seminar_content['chdate'] || $last_modified_timestamp > 0) {
$last_modified = $seminar_content['visitdate'] <= $seminar_content['chdate']
&& $seminar_content['chdate'] > $seminar_content['last_modified']
&& $seminar_content['chdate'] > $last_modified_timestamp
? $seminar_content['chdate']
: $seminar_content['last_modified'];
: $last_modified_timestamp;
if ($last_modified) {
return true;
}
......@@ -994,7 +994,7 @@ class MyCoursesController extends AuthenticatedController
} else {
$attr = $n->getLinkAttributes();
if (empty($attr['title']) && $n->getImage()) {
$attr['title'] = (string) $n->getImage()->getAttributes()['title'];
$attr['title'] = (string) ($n->getImage()->getAttributes()['title'] ?? '');
}
if (empty($attr['title'])) {
$attr['title'] = (string) $n->getTitle();
......
......@@ -19,7 +19,6 @@ class PluginController extends StudipController
}
$this->plugin = $dispatcher->current_plugin;
if ($this->plugin && $this->plugin->hasTranslation()) {
// Localization
$this->_ = function ($string) {
......
......@@ -753,7 +753,7 @@ abstract class StudipController extends Trails_Controller
*/
protected function controller_path()
{
$class = get_class($this->parent_controller ?: $this);
$class = get_class($this->parent_controller ?? $this);
$controller = mb_substr($class, 0, -mb_strlen('Controller'));
$controller = strtosnakecase($controller);
return preg_replace('/_{2,}/', '/', $controller);
......
......@@ -204,9 +204,11 @@ if (!$values['parent_course'] || !in_array($values['parent_course'], array_keys(
<?=
\Studip\LinkButton::create(
$actions[$selected_action]['title'],
URLHelper::getURL(sprintf($actions[$selected_action]['url'], $semid),
($actions[$selected_action]['params'] ? $actions[$selected_action]['params'] : [])),
($actions[$selected_action]['attributes'] ? $actions[$selected_action]['attributes'] : [])
URLHelper::getURL(
sprintf($actions[$selected_action]['url'], $semid),
$actions[$selected_action]['params'] ?? []
),
$actions[$selected_action]['attributes'] ?? []
) ?>
<? endif ?>
<? endif ?>
......
<? $colspan = 2 ?>
<? if ($actions[$selected_action]['multimode']) : ?>
<? if (!empty($actions[$selected_action]['multimode'])) : ?>
<form action="<?= URLHelper::getLink($actions[$selected_action]['url']) ?>" method="post">
<? endif ?>
<?= CSRFProtection::tokenTag() ?>
......@@ -197,7 +197,7 @@
<?= _('Aktion') ?>
</th>
</tr>
<? if ($actions[$selected_action]['multimode']) : ?>
<? if (!empty($actions[$selected_action]['multimode'])) : ?>
<?= $this->render_partial('admin/courses/additional_inputs.php', compact('colspan')) ?>
<? if (count($courses) > 10): ?>
<tr>
......@@ -219,10 +219,20 @@
</thead>
<tbody>
<? foreach ($courses as $semid => $values) : ?>
<?= $this->render_partial('admin/courses/_course', compact('semid', 'values', 'view_filter', 'actions', 'selected_action', 'courses')) ?>
<?= $this->render_partial('admin/courses/_course',
[
'semid' => $semid,
'values' => $values,
'view_filter' => $view_filter,
'actions' => $actions,
'selected_action' => $selected_action,
'courses' => $courses,
'parent' => $parent ?? null
]
) ?>
<? endforeach ?>
</tbody>
<? if ($actions[$selected_action]['multimode']) : ?>
<? if (!empty($actions[$selected_action]['multimode'])) : ?>
<tfoot>
<tr>
<td colspan="<?= $colspan ?>" style="text-align: right">
......@@ -241,6 +251,6 @@
</tfoot>
<? endif ?>
</table>
<? if ($actions[$selected_action]['multimode']) : ?>
<? if (!empty($actions[$selected_action]['multimode'])) : ?>
</form>
<? endif ?>
<?
# Lifter010: TODO
?>
<?= $colon ? ', ' : '' ?><a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $_dozent['username']]) ?>"><?= htmlReady($_dozent["fullname"]) ?></a><? $this->colon = true; ?>
<?= !empty($colon) ? ', ' : '' ?><a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $_dozent['username']]) ?>"><?= htmlReady($_dozent['fullname']) ?></a><? $this->colon = true; ?>
......@@ -7,7 +7,7 @@
</td>
<td style="text-align: left">
<a href="<?= URLHelper::getLink('seminar_main.php', ['auswahl' => $group['seminar_id']]) ?>"
<?= $group['lastvisitdate'] >= $group['chdate'] ? 'style="color: red;"' : '' ?>>
<?= $group['last_visitdate'] >= $group['chdate'] ? 'style="color: red;"' : '' ?>>
<?= htmlReady($group['name']) ?>
</a>
<? if ($group['visible'] == 0) : ?>
......
......@@ -344,7 +344,7 @@ class AdminCourseFilter
$id = md5($where);
}
$this->settings['query']['where'][$id] = $where;
$this->settings['parameter'] = array_merge((array) $this->settings['parameter'], $parameter);
$this->settings['parameter'] = array_merge((array)($this->settings['parameter'] ?? []), $parameter);
return $this;
}
......
......@@ -171,7 +171,7 @@ class MyRealmModel
$semester_ids = [];
for ($i = $min_sem_key; $i <= $max_sem_key; $i++) {
if ($sem_data[$i]['semester_id']) {
if (!empty($sem_data[$i]['semester_id'])) {
$semester_ids[] = $sem_data[$i]['semester_id'];
}
}
......@@ -364,7 +364,7 @@ class MyRealmModel
// add the the course to the correct semester
if (!$_course['parent_course']) {
if (empty($_course['parent_course'])) {
if ($course->isOpenEnded()) {
if ($current_semester_nr >= $min_sem_key && $current_semester_nr <= $max_sem_key) {
$sem_courses[$current_semester_nr][$course->id] = $_course;
......@@ -395,7 +395,7 @@ class MyRealmModel
return null;
}
if ($params['main_navigation']) {
if (!empty($params['main_navigation'])) {
return $sem_courses;
}
......@@ -805,7 +805,7 @@ class MyRealmModel
$data['tools'] = $studygroup->tools;
$data['sem_class'] = $studygroup->getSemClass();
$data['start_semester'] = $studygroup->start_semester->name;
$data['end_semester'] = $studygroup->end_semester->name;
$data['end_semester'] = $studygroup->end_semester->name ?? '';
$data['obj_type'] = 'sem';
$data['user_status'] = $membership->status;
$data['gruppe'] = $membership->gruppe;
......
......@@ -632,7 +632,7 @@ class Request implements ArrayAccess, IteratorAggregate
*/
public static function method()
{
return mb_strtoupper($_SERVER['X_HTTP_METHOD_OVERRIDE'] ?: $_SERVER['REQUEST_METHOD']);
return mb_strtoupper($_SERVER['X_HTTP_METHOD_OVERRIDE'] ?? $_SERVER['REQUEST_METHOD']);
}
/**
......
......@@ -93,7 +93,7 @@ class SemClass implements ArrayAccess
foreach ($slots as $slot => $module) {
$data[$slot] = $module;
$modules[$module] = ['activated' => (int) $INST_MODULES[$type][$slot], 'sticky' => 0];
$modules[$module] = ['activated' => (int) ($INST_MODULES[$type][$slot] ?? 0), 'sticky' => 0];
}
$data['modules'] = json_encode($modules);
......@@ -200,7 +200,7 @@ class SemClass implements ArrayAccess
*/
public function isModuleForbidden($modulename)
{
if ($this->data['studygroup_mode']) {
if (!empty($this->data['studygroup_mode'])) {
return in_array($modulename, self::$studygroup_forbidden_modules);
} else {
return strpos($modulename, 'Studygroup') !== false;
......
......@@ -72,7 +72,7 @@ class Seminar
if ($refresh_cache) {
self::$seminar_object_pool[$id] = null;
}
if (is_object(self::$seminar_object_pool[$id]) && self::$seminar_object_pool[$id]->getId() == $id) {
if (!empty(self::$seminar_object_pool[$id]) && is_object(self::$seminar_object_pool[$id]) && self::$seminar_object_pool[$id]->getId() == $id) {
return self::$seminar_object_pool[$id];
} else {
self::$seminar_object_pool[$id] = new Seminar($id);
......@@ -316,7 +316,7 @@ class Seminar
$data = unserialize($cache->read($cache_key));
// build cache from scratch
if (!$data || !$data[$sub_key]) {
if (empty($data) || empty($data[$sub_key])) {
$cycles = $this->metadate->getCycleData();
$dates = $this->getSingleDates($filter, $filter);
$rooms = [];
......
......@@ -45,8 +45,9 @@ class SeminarCategories {
* @param String $id
* @return Array
*/
public static function Get($id){
if(is_null(self::$seminar_categories[$id])){
public static function Get($id)
{
if (empty(self::$seminar_categories[$id])) {
$cat = new SeminarCategories($id);
if ($cat->id !== false) {
self::$seminar_categories[$id] = $cat;
......
......@@ -32,7 +32,13 @@ class SkipLinks
*/
public static function isEnabled()
{
if (isset($GLOBALS['user']->id)) {
//Use the user configuration:
return UserConfig::get($GLOBALS['user']->id)->SKIPLINKS_ENABLE;
} else {
//Use the global configuration:
return Config::get()->SKIPLINKS_ENABLE;
}
}
/**
......
......@@ -24,7 +24,7 @@ abstract class WidgetContainer
public static function Get()
{
$class = get_called_class();
if (!isset(static::$instances[$class])) {
if (empty(static::$instances[$class])) {
static::$instances[$class] = new static;
}
return static::$instances[$class];
......
......@@ -138,6 +138,8 @@ class SearchWidget extends SidebarWidget
}
}
$this->template_variables['reset_search'] = '';
if ($this->hasData()) {
// Remove needles from query params for reset link
$reset_params = $query_params;
......
......@@ -126,6 +126,9 @@ class SelectWidget extends SidebarWidget
//submit-upon-select is not helpful if we have the multiple version
if (!$this->template_variables['multiple']) {
if (!array_key_exists('class', $this->template_variables)) {
$this->template_variables['class'] = '';
}
$this->template_variables['class'] .= ' submit-upon-select';
}
......
......@@ -207,7 +207,7 @@ function shrink_dates($dates) {
if (((date ("z", $dates[$i]["start_time"])-1) == date ("z", $dates[$i-1]["start_time"]))
|| ((date ("z", $dates[$i]["start_time"]) == 0) && (date ("j", $dates[$i-1]["start_time"]) == 0))) {
if ($dates[$i]["time_match"]) {
if (!empty($dates[$i]["time_match"])) {
$dates[$i]["conjuncted"] = true;
}
}
......@@ -217,23 +217,24 @@ function shrink_dates($dates) {
$return_string = '';
// create text-output
for ($i=0; $i < sizeof($dates); $i++) {
if (!$dates[$i]["conjuncted"]) {
$conjuncted = true;
if (empty($dates[$i]["conjuncted"])) {
$conjuncted = false;
}
if ((!$dates[$i]["conjuncted"]) || (!$dates[$i+1]["conjuncted"])) {
if (empty($dates[$i]["conjuncted"]) || empty($dates[$i+1]["conjuncted"])) {
$return_string .= ' ' . strftime('%A', $dates[$i]['start_time']) .'.';
$return_string .= date (" d.m.y", $dates[$i]["start_time"]);
}
if ((!$conjuncted) && ($dates[$i+1]["conjuncted"])) {
if (!$conjuncted && !empty($dates[$i+1]["conjuncted"])) {
$return_string .= ' -';
$conjuncted = true;
} else if ((!$dates[$i+1]["conjuncted"]) && ($dates[$i+1]["time_match"])) {
} else if (empty($dates[$i+1]["conjuncted"]) && !empty($dates[$i+1]["time_match"])) {
$return_string .= ',';
}
if (!$dates[$i+1]["time_match"]) {
if (empty($dates[$i+1]["time_match"])) {
// check if the current date is for a whole day
if ((($dates[$i]["end_time"] - $dates[$i]["start_time"]) / 60 / 60) > 23) {
$return_string .= ' ('. _('ganztägig') . ')';
......@@ -245,7 +246,7 @@ function shrink_dates($dates) {
}
}
if ($return_string != '' && !$dates[$i+1]['conjuncted'] && !$dates[$i+1]['time_match']) {
if ($return_string != '' && empty($dates[$i+1]['conjuncted']) && empty($dates[$i+1]['time_match'])) {
$ret[] = $return_string;
$return_string = '';
}
......
......@@ -1520,7 +1520,7 @@ function studip_default_exception_handler($exception) {
// ajax requests return JSON instead
// re-use the http status code determined above
if (!strcasecmp($_SERVER['HTTP_X_REQUESTED_WITH'], 'xmlhttprequest')) {
if (!strcasecmp($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '', 'xmlhttprequest')) {
header('Content-Type: application/json; charset=UTF-8');
$template = 'json_exception';
$layout = null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment