Code Duplication    Length = 34-41 lines in 2 locations

main/gradebook/lib/GradebookUtils.php 2 locations

@@ 293-326 (lines=34) @@
290
     * @param  Evaluation $eval evaluation object
291
     * @param int $selectcat id of selected category
292
     */
293
    public static function build_edit_icons_eval($eval, $selectcat)
294
    {
295
        $is_locked = $eval->is_locked();
296
        $eval->get_course_code();
297
        $cat = new Category();
298
        $message_eval = $cat->show_message_resource_delete($eval->getCourseId());
299
        $courseParams = api_get_cidreq_params($eval->get_course_code(), $eval->getSessionId());
300
301
        if ($message_eval === false && api_is_allowed_to_edit(null, true)) {
302
            $visibility_icon = ($eval->is_visible() == 0) ? 'invisible' : 'visible';
303
            $visibility_command = ($eval->is_visible() == 0) ? 'set_visible' : 'set_invisible';
304
            if ($is_locked && !api_is_platform_admin()) {
305
                $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL);
306
            } else {
307
                $modify_icons = '<a href="gradebook_edit_eval.php?editeval=' . $eval->get_id() . '&' . $courseParams. '">' .
308
                    Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL) . '</a>';
309
            }
310
311
            $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visibleeval=' . $eval->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '&'.$courseParams. ' ">' .
312
                Display::return_icon($visibility_icon . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>';
313
            if (api_is_allowed_to_edit(null, true)) {
314
                $modify_icons .= '&nbsp;<a href="gradebook_showlog_eval.php?visiblelog=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &' . $courseParams. '">' .
315
                    Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL) . '</a>';
316
            }
317
318
            if ($is_locked && !api_is_platform_admin()) {
319
                $modify_icons .= '&nbsp;' . Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
320
            } else {
321
                $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &' . $courseParams. '" onclick="return confirmation();">' .
322
                    Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
323
            }
324
            return $modify_icons;
325
        }
326
    }
327
328
    /**
329
     * Builds the course or platform admin icons to edit a link
@@ 333-373 (lines=41) @@
330
     * @param AbstractLink $link
331
     * @param int $selectcat id of selected category
332
     */
333
    public static function build_edit_icons_link($link, $selectcat)
334
    {
335
        $cat = new Category();
336
        $message_link = $cat->show_message_resource_delete($link->getCourseId());
337
        $is_locked = $link->is_locked();
338
339
        $modify_icons = null;
340
341
        if (!api_is_allowed_to_edit(null, true)) {
342
            return null;
343
        }
344
345
        $courseParams = api_get_cidreq_params($link->get_course_code(), $link->get_session_id());
346
347
        if ($message_link === false) {
348
            $visibility_icon = ($link->is_visible() == 0) ? 'invisible' : 'visible';
349
            $visibility_command = ($link->is_visible() == 0) ? 'set_visible' : 'set_invisible';
350
351
            if ($is_locked && !api_is_platform_admin()) {
352
                $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL);
353
            } else {
354
                $modify_icons = '<a href="gradebook_edit_link.php?editlink=' . $link->get_id() . '&' . $courseParams.'">' .
355
                    Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL) . '</a>';
356
            }
357
            $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visiblelink=' . $link->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '&'.$courseParams. ' ">' .
358
                Display::return_icon($visibility_icon . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>';
359
            $modify_icons .= '&nbsp;<a href="gradebook_showlog_link.php?visiblelink=' . $link->get_id() . '&selectcat=' . $selectcat . '&' . $courseParams. '">' .
360
                Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL) . '</a>';
361
362
            //If a work is added in a gradebook you can only delete the link in the work tool
363
364
            if ($is_locked && !api_is_platform_admin()) {
365
                $modify_icons .= '&nbsp;' . Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
366
            } else {
367
                $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletelink=' . $link->get_id() . '&selectcat=' . $selectcat . ' &' . $courseParams. '" onclick="return confirmation();">' .
368
                    Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
369
            }
370
371
            return $modify_icons;
372
        }
373
    }
374
375
    /**
376
     * Checks if a resource is in the unique gradebook of a given course