Completed
Push — master ( e0a519...eabd41 )
by Julito
119:58 queued 99:23
created

main/admin/skill_create.php (2 issues)

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Create skill form.
6
 *
7
 * @author Angel Fernando Quiroz Campos <[email protected]>
8
 *
9
 * @package chamilo.admin
10
 */
11
$cidReset = true;
12
13
require_once __DIR__.'/../inc/global.inc.php';
14
15
$this_section = SECTION_PLATFORM_ADMIN;
16
17
api_protect_admin_script();
18
Skill::isAllowed();
19
20
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')];
21
$interbreadcrumb[] = ['url' => 'skill_list.php', 'name' => get_lang('ManageSkills')];
22
23
/* Process data */
24
$skillParentId = isset($_GET['parent']) ? intval($_GET['parent']) : 0;
25
$formDefaultValues = [];
26
27
$objSkill = new Skill();
28
if ($skillParentId > 0) {
29
    $skillParentInfo = $objSkill->getSkillInfo($skillParentId);
30
31
    $formDefaultValues = [
32
        'parent_id' => $skillParentInfo['id'],
33
        'gradebook_id' => [],
34
    ];
35
36
    foreach ($skillParentInfo['gradebooks'] as $gradebook) {
37
        $formDefaultValues['gradebook_id'][] = intval($gradebook['id']);
38
    }
39
}
40
41
/* Form */
42
$createForm = new FormValidator('skill_create');
43
$createForm->addHeader(get_lang('CreateSkill'));
44
$returnParams = $objSkill->setForm($createForm, []);
45
$jquery_ready_content = $returnParams['jquery_ready_content'];
46
47
// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
48
if (!empty($jquery_ready_content)) {
49
    $htmlHeadXtra[] = '<script>
50
    $(document).ready(function(){
51
        '.$jquery_ready_content.'
52
    });
53
    </script>';
54
}
55
56
$createForm->setDefaults($formDefaultValues);
57
58
if ($createForm->validate()) {
59
    $skillValues = $createForm->getSubmitValues();
60
    $created = $objSkill->add($skillValues);
0 ignored issues
show
Are you sure the assignment to $created is correct as $objSkill->add($skillValues) targeting Skill::add() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
61
62
    $skillValues['item_id'] = $created;
63
    $extraFieldValue = new ExtraFieldValue('skill');
64
    $extraFieldValue->saveFieldValues($skillValues);
65
    if ($created) {
0 ignored issues
show
$created is of type null, thus it always evaluated to false.
Loading history...
66
        $url = api_get_path(WEB_CODE_PATH).'admin/skill_edit.php?id='.$created;
67
        $link = Display::url($skillValues['name'], $url);
68
        Display::addFlash(
69
            Display::return_message(get_lang('TheSkillHasBeenCreated').': '.$link, 'success', false)
70
        );
71
    } else {
72
        Display::addFlash(
73
            Display::return_message(get_lang('CannotCreateSkill'), 'error')
74
        );
75
    }
76
77
    header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php');
78
    exit;
79
}
80
81
$toolbar = $objSkill->getToolbar();
82
83
$tpl = new Template(get_lang('CreateSkill'));
84
$tpl->assign('content', $toolbar.$createForm->returnForm());
85
$tpl->display_one_col_template();
86