1 | <?php |
||||||||||||||||||||||
2 | |||||||||||||||||||||||
3 | /* For licensing terms, see /license.txt */ |
||||||||||||||||||||||
4 | |||||||||||||||||||||||
5 | /** |
||||||||||||||||||||||
6 | * Class LinkForm |
||||||||||||||||||||||
7 | * Forms related to links. |
||||||||||||||||||||||
8 | * |
||||||||||||||||||||||
9 | * @author Stijn Konings |
||||||||||||||||||||||
10 | * @author Bert Steppé (made more generic) |
||||||||||||||||||||||
11 | */ |
||||||||||||||||||||||
12 | class LinkForm extends FormValidator |
||||||||||||||||||||||
13 | { |
||||||||||||||||||||||
14 | public const TYPE_CREATE = 1; |
||||||||||||||||||||||
15 | public const TYPE_MOVE = 2; |
||||||||||||||||||||||
16 | /** @var Category */ |
||||||||||||||||||||||
17 | private $category_object; |
||||||||||||||||||||||
18 | private $link_object; |
||||||||||||||||||||||
19 | private $extra; |
||||||||||||||||||||||
20 | |||||||||||||||||||||||
21 | /** |
||||||||||||||||||||||
22 | * Builds a form containing form items based on a given parameter. |
||||||||||||||||||||||
23 | * |
||||||||||||||||||||||
24 | * @param int $form_type 1=choose link |
||||||||||||||||||||||
25 | * @param Category $category_object the category object |
||||||||||||||||||||||
26 | * @param AbstractLink $link_object |
||||||||||||||||||||||
27 | * @param string $form_name name |
||||||||||||||||||||||
28 | * @param string $method |
||||||||||||||||||||||
29 | * @param string $action |
||||||||||||||||||||||
30 | */ |
||||||||||||||||||||||
31 | public function __construct( |
||||||||||||||||||||||
32 | $form_type, |
||||||||||||||||||||||
33 | $category_object, |
||||||||||||||||||||||
34 | $link_object, |
||||||||||||||||||||||
35 | $form_name, |
||||||||||||||||||||||
36 | $method = 'post', |
||||||||||||||||||||||
37 | $action = null, |
||||||||||||||||||||||
38 | $extra = null |
||||||||||||||||||||||
39 | ) { |
||||||||||||||||||||||
40 | parent::__construct($form_name, $method, $action); |
||||||||||||||||||||||
41 | |||||||||||||||||||||||
42 | if (isset($category_object)) { |
||||||||||||||||||||||
43 | $this->category_object = $category_object; |
||||||||||||||||||||||
44 | } else { |
||||||||||||||||||||||
45 | if (isset($link_object)) { |
||||||||||||||||||||||
46 | $this->link_object = $link_object; |
||||||||||||||||||||||
47 | } |
||||||||||||||||||||||
48 | } |
||||||||||||||||||||||
49 | |||||||||||||||||||||||
50 | if (isset($extra)) { |
||||||||||||||||||||||
51 | $this->extra = $extra; |
||||||||||||||||||||||
52 | } |
||||||||||||||||||||||
53 | if (self::TYPE_CREATE == $form_type) { |
||||||||||||||||||||||
54 | $this->build_create(); |
||||||||||||||||||||||
55 | } elseif (self::TYPE_MOVE == $form_type) { |
||||||||||||||||||||||
56 | $this->build_move(); |
||||||||||||||||||||||
57 | } |
||||||||||||||||||||||
58 | } |
||||||||||||||||||||||
59 | |||||||||||||||||||||||
60 | protected function build_move() |
||||||||||||||||||||||
61 | { |
||||||||||||||||||||||
62 | $renderer = &$this->defaultRenderer(); |
||||||||||||||||||||||
63 | $renderer->setCustomElementTemplate('<span>{element}</span> '); |
||||||||||||||||||||||
64 | $this->addElement( |
||||||||||||||||||||||
65 | 'static', |
||||||||||||||||||||||
66 | null, |
||||||||||||||||||||||
67 | null, |
||||||||||||||||||||||
68 | '"'.$this->link_object->get_name().'" ' |
||||||||||||||||||||||
69 | ); |
||||||||||||||||||||||
70 | $this->addElement('static', null, null, get_lang('MoveTo').' : '); |
||||||||||||||||||||||
71 | $select = $this->addElement('select', 'move_cat', null, null); |
||||||||||||||||||||||
72 | $line = ''; |
||||||||||||||||||||||
73 | foreach ($this->link_object->get_target_categories() as $cat) { |
||||||||||||||||||||||
74 | for ($i = 0; $i < $cat[2]; $i++) { |
||||||||||||||||||||||
75 | $line .= '—'; |
||||||||||||||||||||||
76 | } |
||||||||||||||||||||||
77 | $select->addOption($line.' '.$cat[1], $cat[0]); |
||||||||||||||||||||||
78 | $line = ''; |
||||||||||||||||||||||
79 | } |
||||||||||||||||||||||
80 | $this->addElement('submit', null, get_lang('Ok')); |
||||||||||||||||||||||
81 | } |
||||||||||||||||||||||
82 | |||||||||||||||||||||||
83 | /** |
||||||||||||||||||||||
84 | * Builds the form. |
||||||||||||||||||||||
85 | */ |
||||||||||||||||||||||
86 | protected function build_create() |
||||||||||||||||||||||
87 | { |
||||||||||||||||||||||
88 | $this->addHeader(get_lang('MakeLink')); |
||||||||||||||||||||||
89 | $select = $this->addElement( |
||||||||||||||||||||||
90 | 'select', |
||||||||||||||||||||||
91 | 'select_link', |
||||||||||||||||||||||
92 | get_lang('ChooseLink'), |
||||||||||||||||||||||
93 | null, |
||||||||||||||||||||||
94 | ['onchange' => 'document.create_link.submit()'] |
||||||||||||||||||||||
95 | ); |
||||||||||||||||||||||
96 | |||||||||||||||||||||||
97 | $select->addOption('['.get_lang('ChooseLink').']', 0); |
||||||||||||||||||||||
98 | $courseCode = $this->category_object->get_course_code(); |
||||||||||||||||||||||
99 | |||||||||||||||||||||||
100 | $linkTypes = LinkFactory::get_all_types(); |
||||||||||||||||||||||
101 | foreach ($linkTypes as $linkType) { |
||||||||||||||||||||||
102 | // The hot potatoe link will be added "inside" the exercise option. |
||||||||||||||||||||||
103 | if ($linkType == LINK_HOTPOTATOES) { |
||||||||||||||||||||||
104 | continue; |
||||||||||||||||||||||
105 | } |
||||||||||||||||||||||
106 | $link = $this->createLink($linkType, $courseCode); |
||||||||||||||||||||||
107 | /* configure the session id within the gradebook evaluation*/ |
||||||||||||||||||||||
108 | $link->set_session_id(api_get_session_id()); |
||||||||||||||||||||||
109 | // disable this element if the link works with a dropdownlist |
||||||||||||||||||||||
110 | // and if there are no links left |
||||||||||||||||||||||
111 | if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') { |
||||||||||||||||||||||
112 | $select->addOption($link->get_type_name(), $linkType, 'disabled'); |
||||||||||||||||||||||
113 | } else { |
||||||||||||||||||||||
114 | $select->addOption($link->get_type_name(), $linkType); |
||||||||||||||||||||||
115 | } |
||||||||||||||||||||||
116 | |||||||||||||||||||||||
117 | if ($link->get_type() == LINK_EXERCISE) { |
||||||||||||||||||||||
118 | // Adding hot potatoes |
||||||||||||||||||||||
119 | $linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode); |
||||||||||||||||||||||
120 | $linkHot->setHp(true); |
||||||||||||||||||||||
0 ignored issues
–
show
The method
setHp() does not exist on ForumThreadLink .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
The method
setHp() does not exist on DropboxLink .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
The method
setHp() does not exist on StudentPublicationLink .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
The method
setHp() does not exist on SurveyLink .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
The method
setHp() does not exist on AttendanceLink .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||||||||||||||||||
121 | if ($linkHot->get_all_links(true)) { |
||||||||||||||||||||||
122 | $select->addOption( |
||||||||||||||||||||||
123 | ' '.$linkHot->get_type_name(), |
||||||||||||||||||||||
124 | LINK_HOTPOTATOES |
||||||||||||||||||||||
125 | ); |
||||||||||||||||||||||
126 | } else { |
||||||||||||||||||||||
127 | $select->addOption( |
||||||||||||||||||||||
128 | ' '.$linkHot->get_type_name(), |
||||||||||||||||||||||
129 | LINK_HOTPOTATOES, |
||||||||||||||||||||||
130 | 'disabled' |
||||||||||||||||||||||
131 | ); |
||||||||||||||||||||||
132 | } |
||||||||||||||||||||||
133 | } |
||||||||||||||||||||||
134 | } |
||||||||||||||||||||||
135 | |||||||||||||||||||||||
136 | if (isset($this->extra)) { |
||||||||||||||||||||||
137 | $this->setDefaults(['select_link' => $this->extra]); |
||||||||||||||||||||||
138 | } |
||||||||||||||||||||||
139 | } |
||||||||||||||||||||||
140 | |||||||||||||||||||||||
141 | /** |
||||||||||||||||||||||
142 | * @param int $link |
||||||||||||||||||||||
143 | * @param string|null $courseCode |
||||||||||||||||||||||
144 | * |
||||||||||||||||||||||
145 | * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|StudentPublicationLink|SurveyLink|null |
||||||||||||||||||||||
146 | */ |
||||||||||||||||||||||
147 | private function createLink($link, $courseCode) |
||||||||||||||||||||||
148 | { |
||||||||||||||||||||||
149 | $link = LinkFactory::create($link); |
||||||||||||||||||||||
150 | if (!empty($courseCode)) { |
||||||||||||||||||||||
151 | $link->set_course_code($courseCode); |
||||||||||||||||||||||
152 | } elseif (!empty($_GET['course_code'])) { |
||||||||||||||||||||||
153 | $link->set_course_code(Database::escape_string($_GET['course_code'], null, false)); |
||||||||||||||||||||||
154 | } |
||||||||||||||||||||||
155 | |||||||||||||||||||||||
156 | return $link; |
||||||||||||||||||||||
157 | } |
||||||||||||||||||||||
158 | } |
||||||||||||||||||||||
159 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.