@@ -10,128 +10,128 @@ |
||
10 | 10 | */ |
11 | 11 | class UserTable extends SortableTable |
12 | 12 | { |
13 | - private $userid; |
|
14 | - private $datagen; |
|
13 | + private $userid; |
|
14 | + private $datagen; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function UserTable($userid, $evals = array(), $links = array(), $addparams = null) |
|
20 | - { |
|
21 | - parent :: __construct ('userlist', null, null, 0); |
|
22 | - $this->userid = $userid; |
|
23 | - $this->datagen = new UserDataGenerator($userid, $evals, $links); |
|
24 | - if (isset($addparams)) { |
|
25 | - $this->set_additional_parameters($addparams); |
|
26 | - } |
|
27 | - $column = 0; |
|
28 | - $this->set_header($column++, get_lang('Type')); |
|
29 | - $this->set_header($column++, get_lang('Evaluation')); |
|
30 | - $this->set_header($column++, get_lang('Course')); |
|
31 | - $this->set_header($column++, get_lang('Category')); |
|
32 | - $this->set_header($column++, get_lang('EvaluationAverage')); |
|
33 | - $this->set_header($column++, get_lang('Result')); |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function UserTable($userid, $evals = array(), $links = array(), $addparams = null) |
|
20 | + { |
|
21 | + parent :: __construct ('userlist', null, null, 0); |
|
22 | + $this->userid = $userid; |
|
23 | + $this->datagen = new UserDataGenerator($userid, $evals, $links); |
|
24 | + if (isset($addparams)) { |
|
25 | + $this->set_additional_parameters($addparams); |
|
26 | + } |
|
27 | + $column = 0; |
|
28 | + $this->set_header($column++, get_lang('Type')); |
|
29 | + $this->set_header($column++, get_lang('Evaluation')); |
|
30 | + $this->set_header($column++, get_lang('Course')); |
|
31 | + $this->set_header($column++, get_lang('Category')); |
|
32 | + $this->set_header($column++, get_lang('EvaluationAverage')); |
|
33 | + $this->set_header($column++, get_lang('Result')); |
|
34 | 34 | |
35 | - $scoredisplay = ScoreDisplay :: instance(); |
|
36 | - if ($scoredisplay->is_custom()) { |
|
37 | - $this->set_header($column++, get_lang('Display')); |
|
38 | - } |
|
39 | - } |
|
35 | + $scoredisplay = ScoreDisplay :: instance(); |
|
36 | + if ($scoredisplay->is_custom()) { |
|
37 | + $this->set_header($column++, get_lang('Display')); |
|
38 | + } |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Function used by SortableTable to get total number of items in the table |
|
43 | - */ |
|
44 | - function get_total_number_of_items() |
|
45 | - { |
|
46 | - return $this->datagen->get_total_items_count(); |
|
47 | - } |
|
41 | + /** |
|
42 | + * Function used by SortableTable to get total number of items in the table |
|
43 | + */ |
|
44 | + function get_total_number_of_items() |
|
45 | + { |
|
46 | + return $this->datagen->get_total_items_count(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Function used by SortableTable to generate the data to display |
|
51 | - */ |
|
52 | - public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) |
|
53 | - { |
|
54 | - $scoredisplay = ScoreDisplay :: instance(); |
|
49 | + /** |
|
50 | + * Function used by SortableTable to generate the data to display |
|
51 | + */ |
|
52 | + public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) |
|
53 | + { |
|
54 | + $scoredisplay = ScoreDisplay :: instance(); |
|
55 | 55 | |
56 | - // determine sorting type |
|
57 | - switch ($this->column) { |
|
58 | - // Type |
|
59 | - case 0: |
|
60 | - $sorting = UserDataGenerator :: UDG_SORT_TYPE; |
|
61 | - break; |
|
62 | - case 1: |
|
63 | - $sorting = UserDataGenerator :: UDG_SORT_NAME; |
|
64 | - break; |
|
65 | - case 2: |
|
66 | - $sorting = UserDataGenerator :: UDG_SORT_COURSE; |
|
67 | - break; |
|
68 | - case 3: |
|
69 | - $sorting = UserDataGenerator :: UDG_SORT_CATEGORY; |
|
70 | - break; |
|
71 | - case 4: |
|
72 | - $sorting = UserDataGenerator :: UDG_SORT_AVERAGE; |
|
73 | - break; |
|
74 | - case 5: |
|
75 | - $sorting = UserDataGenerator :: UDG_SORT_SCORE; |
|
76 | - break; |
|
77 | - case 6: |
|
78 | - $sorting = UserDataGenerator :: UDG_SORT_MASK; |
|
79 | - break; |
|
80 | - } |
|
81 | - if ($this->direction == 'DESC') { |
|
82 | - $sorting |= UserDataGenerator :: UDG_SORT_DESC; |
|
83 | - } else { |
|
84 | - $sorting |= UserDataGenerator :: UDG_SORT_ASC; |
|
85 | - } |
|
86 | - $data_array = $this->datagen->get_data($sorting, $from, $this->per_page); |
|
87 | - // generate the data to display |
|
88 | - $sortable_data = array(); |
|
89 | - foreach ($data_array as $data) { |
|
90 | - if ($data[2]!="") {//filter by course removed |
|
91 | - $row = array (); |
|
92 | - $row[] = $this->build_type_column($data[0]); |
|
93 | - $row[] = $this->build_name_link($data[0]); |
|
94 | - $row[] = $data[2]; |
|
95 | - $row[] = $data[3]; |
|
96 | - $row[] = $data[4]; |
|
97 | - $row[] = $data[5]; |
|
98 | - if ($scoredisplay->is_custom()) |
|
99 | - $row[] = $data[6]; |
|
100 | - $sortable_data[] = $row; |
|
101 | - } |
|
102 | - } |
|
56 | + // determine sorting type |
|
57 | + switch ($this->column) { |
|
58 | + // Type |
|
59 | + case 0: |
|
60 | + $sorting = UserDataGenerator :: UDG_SORT_TYPE; |
|
61 | + break; |
|
62 | + case 1: |
|
63 | + $sorting = UserDataGenerator :: UDG_SORT_NAME; |
|
64 | + break; |
|
65 | + case 2: |
|
66 | + $sorting = UserDataGenerator :: UDG_SORT_COURSE; |
|
67 | + break; |
|
68 | + case 3: |
|
69 | + $sorting = UserDataGenerator :: UDG_SORT_CATEGORY; |
|
70 | + break; |
|
71 | + case 4: |
|
72 | + $sorting = UserDataGenerator :: UDG_SORT_AVERAGE; |
|
73 | + break; |
|
74 | + case 5: |
|
75 | + $sorting = UserDataGenerator :: UDG_SORT_SCORE; |
|
76 | + break; |
|
77 | + case 6: |
|
78 | + $sorting = UserDataGenerator :: UDG_SORT_MASK; |
|
79 | + break; |
|
80 | + } |
|
81 | + if ($this->direction == 'DESC') { |
|
82 | + $sorting |= UserDataGenerator :: UDG_SORT_DESC; |
|
83 | + } else { |
|
84 | + $sorting |= UserDataGenerator :: UDG_SORT_ASC; |
|
85 | + } |
|
86 | + $data_array = $this->datagen->get_data($sorting, $from, $this->per_page); |
|
87 | + // generate the data to display |
|
88 | + $sortable_data = array(); |
|
89 | + foreach ($data_array as $data) { |
|
90 | + if ($data[2]!="") {//filter by course removed |
|
91 | + $row = array (); |
|
92 | + $row[] = $this->build_type_column($data[0]); |
|
93 | + $row[] = $this->build_name_link($data[0]); |
|
94 | + $row[] = $data[2]; |
|
95 | + $row[] = $data[3]; |
|
96 | + $row[] = $data[4]; |
|
97 | + $row[] = $data[5]; |
|
98 | + if ($scoredisplay->is_custom()) |
|
99 | + $row[] = $data[6]; |
|
100 | + $sortable_data[] = $row; |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - return $sortable_data; |
|
105 | - } |
|
104 | + return $sortable_data; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @param $item |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - private function build_type_column($item) |
|
112 | - { |
|
113 | - return GradebookUtils::build_type_icon_tag($item->get_icon_name()); |
|
114 | - } |
|
107 | + /** |
|
108 | + * @param $item |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + private function build_type_column($item) |
|
112 | + { |
|
113 | + return GradebookUtils::build_type_icon_tag($item->get_icon_name()); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @param $item |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - private function build_name_link($item) |
|
121 | - { |
|
122 | - switch ($item->get_item_type()) { |
|
123 | - // evaluation |
|
124 | - case 'E' : |
|
125 | - return ' ' |
|
126 | - . '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">' |
|
127 | - . $item->get_name() |
|
128 | - . '</a>'; |
|
129 | - // link |
|
130 | - case 'L' : |
|
131 | - return ' <a href="' . $item->get_link() . '">' |
|
132 | - . $item->get_name() |
|
133 | - . '</a>' |
|
134 | - . ' [' . $item->get_type_name() . ']'; |
|
135 | - } |
|
136 | - } |
|
116 | + /** |
|
117 | + * @param $item |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + private function build_name_link($item) |
|
121 | + { |
|
122 | + switch ($item->get_item_type()) { |
|
123 | + // evaluation |
|
124 | + case 'E' : |
|
125 | + return ' ' |
|
126 | + . '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">' |
|
127 | + . $item->get_name() |
|
128 | + . '</a>'; |
|
129 | + // link |
|
130 | + case 'L' : |
|
131 | + return ' <a href="' . $item->get_link() . '">' |
|
132 | + . $item->get_name() |
|
133 | + . '</a>' |
|
134 | + . ' [' . $item->get_type_name() . ']'; |
|
135 | + } |
|
136 | + } |
|
137 | 137 | } |
@@ -10,47 +10,47 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ScoreDisplayForm extends FormValidator |
12 | 12 | { |
13 | - /** |
|
14 | - * @param $form_name |
|
15 | - * @param null $action |
|
16 | - */ |
|
17 | - public function ScoreDisplayForm($form_name, $action= null) |
|
18 | - { |
|
19 | - parent :: __construct($form_name, 'post', $action); |
|
20 | - $displayscore = ScoreDisplay :: instance(); |
|
21 | - $customdisplays = $displayscore->get_custom_score_display_settings(); |
|
22 | - |
|
23 | - $nr_items = (count($customdisplays)!='0') ? count($customdisplays) : '1'; |
|
24 | - $this->setDefaults(array ( |
|
13 | + /** |
|
14 | + * @param $form_name |
|
15 | + * @param null $action |
|
16 | + */ |
|
17 | + public function ScoreDisplayForm($form_name, $action= null) |
|
18 | + { |
|
19 | + parent :: __construct($form_name, 'post', $action); |
|
20 | + $displayscore = ScoreDisplay :: instance(); |
|
21 | + $customdisplays = $displayscore->get_custom_score_display_settings(); |
|
22 | + |
|
23 | + $nr_items = (count($customdisplays)!='0') ? count($customdisplays) : '1'; |
|
24 | + $this->setDefaults(array ( |
|
25 | 25 | 'scorecolpercent' => $displayscore->get_color_split_value() |
26 | - )); |
|
26 | + )); |
|
27 | 27 | |
28 | - $this->addElement('hidden', 'maxvalue', '100'); |
|
29 | - $this->addElement('hidden', 'minvalue', '0'); |
|
30 | - $counter= 1; |
|
28 | + $this->addElement('hidden', 'maxvalue', '100'); |
|
29 | + $this->addElement('hidden', 'minvalue', '0'); |
|
30 | + $counter= 1; |
|
31 | 31 | |
32 | - //setting the default values |
|
32 | + //setting the default values |
|
33 | 33 | |
34 | - if(is_array($customdisplays)) { |
|
35 | - foreach ($customdisplays as $customdisplay) { |
|
36 | - $this->setDefaults(array ( |
|
37 | - 'endscore[' . $counter . ']' => $customdisplay['score'], |
|
38 | - 'displaytext[' . $counter . ']' => $customdisplay['display'] |
|
39 | - )); |
|
40 | - $counter++; |
|
41 | - } |
|
42 | - } |
|
43 | - $scorecol = array(); |
|
34 | + if(is_array($customdisplays)) { |
|
35 | + foreach ($customdisplays as $customdisplay) { |
|
36 | + $this->setDefaults(array ( |
|
37 | + 'endscore[' . $counter . ']' => $customdisplay['score'], |
|
38 | + 'displaytext[' . $counter . ']' => $customdisplay['display'] |
|
39 | + )); |
|
40 | + $counter++; |
|
41 | + } |
|
42 | + } |
|
43 | + $scorecol = array(); |
|
44 | 44 | |
45 | - //settings for the colored score |
|
46 | - $this->addElement('header', get_lang('ScoreEdit')); |
|
45 | + //settings for the colored score |
|
46 | + $this->addElement('header', get_lang('ScoreEdit')); |
|
47 | 47 | |
48 | 48 | if ($displayscore->is_coloring_enabled()) { |
49 | 49 | $this->addElement('html', '<b>' . get_lang('ScoreColor') . '</b>'); |
50 | 50 | $this->addElement('text', 'scorecolpercent', array(get_lang('Below'), get_lang('WillColorRed'), '%'), array( |
51 | 51 | 'size' => 5, |
52 | 52 | 'maxlength' => 5, |
53 | - 'input-size' => 2 |
|
53 | + 'input-size' => 2 |
|
54 | 54 | )); |
55 | 55 | |
56 | 56 | if (api_get_setting('teachers_can_change_score_settings') != 'true') { |
@@ -62,25 +62,25 @@ discard block |
||
62 | 62 | $this->addRule(array('scorecolpercent','minvalue'), get_lang('UnderMin'), 'compare', '>'); |
63 | 63 | } |
64 | 64 | |
65 | - //Settings for the scoring system |
|
65 | + //Settings for the scoring system |
|
66 | 66 | |
67 | - if ($displayscore->is_custom()) { |
|
67 | + if ($displayscore->is_custom()) { |
|
68 | 68 | $this->addElement('html', '<br /><b>' . get_lang('ScoringSystem') . '</b>'); |
69 | - $this->addElement('static', null, null, get_lang('ScoreInfo')); |
|
70 | - $this->setDefaults(array( |
|
71 | - 'beginscore' => '0' |
|
72 | - )); |
|
73 | - $this->addElement('text', 'beginscore', array(get_lang('Between'), null, '%'), array( |
|
74 | - 'size' => 5, |
|
75 | - 'maxlength' => 5, |
|
76 | - 'disabled' => 'disabled', |
|
77 | - 'input-size' => 2 |
|
78 | - )); |
|
79 | - |
|
80 | - for ($counter= 1; $counter <= 20; $counter++) { |
|
81 | - $renderer =& $this->defaultRenderer(); |
|
82 | - $elementTemplateTwoLabel = |
|
83 | - '<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';"> |
|
69 | + $this->addElement('static', null, null, get_lang('ScoreInfo')); |
|
70 | + $this->setDefaults(array( |
|
71 | + 'beginscore' => '0' |
|
72 | + )); |
|
73 | + $this->addElement('text', 'beginscore', array(get_lang('Between'), null, '%'), array( |
|
74 | + 'size' => 5, |
|
75 | + 'maxlength' => 5, |
|
76 | + 'disabled' => 'disabled', |
|
77 | + 'input-size' => 2 |
|
78 | + )); |
|
79 | + |
|
80 | + for ($counter= 1; $counter <= 20; $counter++) { |
|
81 | + $renderer =& $this->defaultRenderer(); |
|
82 | + $elementTemplateTwoLabel = |
|
83 | + '<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';"> |
|
84 | 84 | |
85 | 85 | <!-- BEGIN required --><span class="form_required">*</span> <!-- END required --> |
86 | 86 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | '; |
107 | 107 | |
108 | - $elementTemplateTwoLabel2 =' |
|
108 | + $elementTemplateTwoLabel2 =' |
|
109 | 109 | <div class="col-sm-2"> |
110 | 110 | <!-- BEGIN error --><span class="form_error">{error}</span> |
111 | 111 | <!-- END error --> |
@@ -118,33 +118,33 @@ discard block |
||
118 | 118 | </div> |
119 | 119 | </div>'; |
120 | 120 | |
121 | - $scorebetw = array(); |
|
122 | - $this->addElement('text', 'endscore[' . $counter . ']', null, array ( |
|
123 | - 'size' => 5, |
|
124 | - 'maxlength' => 5, |
|
125 | - 'id' => 'txta-'.$counter, |
|
126 | - 'input-size' => 2 |
|
127 | - )); |
|
128 | - |
|
129 | - $this->addElement('text', 'displaytext[' . $counter . ']', null,array ( |
|
130 | - 'size' => 40, |
|
131 | - 'maxlength' => 40, |
|
132 | - 'id' => 'txtb-'.$counter |
|
133 | - )); |
|
134 | - $renderer->setElementTemplate($elementTemplateTwoLabel, 'endscore[' . $counter . ']'); |
|
135 | - $renderer->setElementTemplate($elementTemplateTwoLabel2, 'displaytext[' . $counter . ']'); |
|
136 | - $this->addRule('endscore[' . $counter . ']', get_lang('OnlyNumbers'), 'numeric'); |
|
137 | - $this->addRule(array ('endscore[' . $counter . ']', 'maxvalue'), get_lang('Over100'), 'compare', '<='); |
|
138 | - $this->addRule(array ('endscore[' . $counter . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>'); |
|
139 | - } |
|
140 | - } |
|
121 | + $scorebetw = array(); |
|
122 | + $this->addElement('text', 'endscore[' . $counter . ']', null, array ( |
|
123 | + 'size' => 5, |
|
124 | + 'maxlength' => 5, |
|
125 | + 'id' => 'txta-'.$counter, |
|
126 | + 'input-size' => 2 |
|
127 | + )); |
|
128 | + |
|
129 | + $this->addElement('text', 'displaytext[' . $counter . ']', null,array ( |
|
130 | + 'size' => 40, |
|
131 | + 'maxlength' => 40, |
|
132 | + 'id' => 'txtb-'.$counter |
|
133 | + )); |
|
134 | + $renderer->setElementTemplate($elementTemplateTwoLabel, 'endscore[' . $counter . ']'); |
|
135 | + $renderer->setElementTemplate($elementTemplateTwoLabel2, 'displaytext[' . $counter . ']'); |
|
136 | + $this->addRule('endscore[' . $counter . ']', get_lang('OnlyNumbers'), 'numeric'); |
|
137 | + $this->addRule(array ('endscore[' . $counter . ']', 'maxvalue'), get_lang('Over100'), 'compare', '<='); |
|
138 | + $this->addRule(array ('endscore[' . $counter . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>'); |
|
139 | + } |
|
140 | + } |
|
141 | 141 | |
142 | 142 | if ($displayscore->is_custom()) { |
143 | - $this->addButtonSave(get_lang('Ok')); |
|
144 | - } |
|
145 | - } |
|
143 | + $this->addButtonSave(get_lang('Ok')); |
|
144 | + } |
|
145 | + } |
|
146 | 146 | |
147 | - function validate() { |
|
148 | - return parent :: validate(); |
|
149 | - } |
|
147 | + function validate() { |
|
148 | + return parent :: validate(); |
|
149 | + } |
|
150 | 150 | } |
@@ -194,13 +194,13 @@ discard block |
||
194 | 194 | in exercice/exercice.php, look for note-query-exe-results marker*/ |
195 | 195 | $session_id = api_get_session_id(); |
196 | 196 | $courseId = $this->getCourseId(); |
197 | - $exercise = new Exercise($courseId); |
|
197 | + $exercise = new Exercise($courseId); |
|
198 | 198 | $exercise->read($this->get_ref_id()); |
199 | 199 | |
200 | 200 | if (!$this->is_hp) { |
201 | 201 | |
202 | - if ($exercise->exercise_was_added_in_lp == false) { |
|
203 | - $sql = "SELECT * FROM $tblStats |
|
202 | + if ($exercise->exercise_was_added_in_lp == false) { |
|
203 | + $sql = "SELECT * FROM $tblStats |
|
204 | 204 | WHERE |
205 | 205 | exe_exo_id = ".intval($this->get_ref_id())." AND |
206 | 206 | orig_lp_id = 0 AND |
@@ -209,15 +209,15 @@ discard block |
||
209 | 209 | session_id = $session_id AND |
210 | 210 | c_id = $courseId |
211 | 211 | "; |
212 | - } else { |
|
213 | - $lpId = null; |
|
214 | - if (!empty($exercise->lpList)) { |
|
215 | - // Taking only the first LP |
|
216 | - $lpId = current($exercise->lpList); |
|
217 | - $lpId = $lpId['lp_id']; |
|
218 | - } |
|
219 | - |
|
220 | - $sql = "SELECT * FROM $tblStats |
|
212 | + } else { |
|
213 | + $lpId = null; |
|
214 | + if (!empty($exercise->lpList)) { |
|
215 | + // Taking only the first LP |
|
216 | + $lpId = current($exercise->lpList); |
|
217 | + $lpId = $lpId['lp_id']; |
|
218 | + } |
|
219 | + |
|
220 | + $sql = "SELECT * FROM $tblStats |
|
221 | 221 | WHERE |
222 | 222 | exe_exo_id = ".intval($this->get_ref_id())." AND |
223 | 223 | orig_lp_id = $lpId AND |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | session_id = $session_id AND |
226 | 226 | c_id = $courseId |
227 | 227 | "; |
228 | - } |
|
228 | + } |
|
229 | 229 | |
230 | 230 | if (!empty($stud_id) && $type != 'ranking') { |
231 | 231 | $sql .= " AND exe_user_id = $stud_id "; |
@@ -8,16 +8,16 @@ |
||
8 | 8 | */ |
9 | 9 | interface GradebookItem |
10 | 10 | { |
11 | - public function get_item_type(); |
|
12 | - public function get_id(); |
|
13 | - public function get_name(); |
|
14 | - public function get_description(); |
|
15 | - public function get_course_code(); |
|
16 | - public function get_weight(); |
|
17 | - public function get_date(); |
|
18 | - public function is_visible(); |
|
19 | - public function get_icon_name(); |
|
20 | - public function getStudentList(); |
|
21 | - public function setStudentList($list); |
|
22 | - public function calc_score($stud_id = null, $type = null); |
|
11 | + public function get_item_type(); |
|
12 | + public function get_id(); |
|
13 | + public function get_name(); |
|
14 | + public function get_description(); |
|
15 | + public function get_course_code(); |
|
16 | + public function get_weight(); |
|
17 | + public function get_date(); |
|
18 | + public function is_visible(); |
|
19 | + public function get_icon_name(); |
|
20 | + public function getStudentList(); |
|
21 | + public function setStudentList($list); |
|
22 | + public function calc_score($stud_id = null, $type = null); |
|
23 | 23 | } |
@@ -1571,7 +1571,6 @@ discard block |
||
1571 | 1571 | * @param string $course_code Course code (optional) |
1572 | 1572 | * @param int $session_id Session ID (optional) |
1573 | 1573 | * @param bool $order |
1574 | - |
|
1575 | 1574 | * @return array Array of subcategories |
1576 | 1575 | */ |
1577 | 1576 | public function get_subcategories($stud_id = null, $course_code = null, $session_id = null, $order = null) |
@@ -1850,7 +1849,6 @@ discard block |
||
1850 | 1849 | * This function, locks a category , only one who can unlock it is |
1851 | 1850 | * the platform administrator. |
1852 | 1851 | * @param int locked 1 or unlocked 0 |
1853 | - |
|
1854 | 1852 | * @return bool |
1855 | 1853 | * */ |
1856 | 1854 | public function lock($locked) |
@@ -8,48 +8,48 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class AttendanceLink extends AbstractLink |
10 | 10 | { |
11 | - private $attendance_table = null; |
|
12 | - private $itemprop_table = null; |
|
11 | + private $attendance_table = null; |
|
12 | + private $itemprop_table = null; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Constructor |
|
16 | - */ |
|
17 | - public function __construct() |
|
18 | - { |
|
19 | - parent::__construct(); |
|
20 | - $this->set_type(LINK_ATTENDANCE); |
|
21 | - } |
|
14 | + /** |
|
15 | + * Constructor |
|
16 | + */ |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + parent::__construct(); |
|
20 | + $this->set_type(LINK_ATTENDANCE); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function get_type_name() |
|
27 | - { |
|
28 | - return get_lang('Attendance'); |
|
29 | - } |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function get_type_name() |
|
27 | + { |
|
28 | + return get_lang('Attendance'); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public function is_allowed_to_change_name() |
|
35 | - { |
|
36 | - return false; |
|
37 | - } |
|
31 | + /** |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public function is_allowed_to_change_name() |
|
35 | + { |
|
36 | + return false; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Generate an array of attendances that a teacher hasn't created a link for. |
|
41 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
42 | - * @todo seems to be depracated |
|
43 | - */ |
|
44 | - public function get_not_created_links() |
|
45 | - { |
|
46 | - return false; |
|
47 | - if (empty($this->course_code)) { |
|
48 | - die('Error in get_not_created_links() : course code not set'); |
|
49 | - } |
|
50 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
39 | + /** |
|
40 | + * Generate an array of attendances that a teacher hasn't created a link for. |
|
41 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
42 | + * @todo seems to be depracated |
|
43 | + */ |
|
44 | + public function get_not_created_links() |
|
45 | + { |
|
46 | + return false; |
|
47 | + if (empty($this->course_code)) { |
|
48 | + die('Error in get_not_created_links() : course code not set'); |
|
49 | + } |
|
50 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
51 | 51 | |
52 | - $sql = 'SELECT att.id, att.name, att.attendance_qualify_title |
|
52 | + $sql = 'SELECT att.id, att.name, att.attendance_qualify_title |
|
53 | 53 | FROM '.$this->get_attendance_table().' att |
54 | 54 | WHERE |
55 | 55 | att.c_id = '.$this->course_id.' AND |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | course_code = "'.Database::escape_string($this->get_course_code()).'" |
61 | 61 | ) |
62 | 62 | AND att.session_id='.api_get_session_id().''; |
63 | - $result = Database::query($sql); |
|
63 | + $result = Database::query($sql); |
|
64 | 64 | |
65 | 65 | $cats = array(); |
66 | 66 | while ($data = Database::fetch_array($result)) { |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - return $cats; |
|
75 | - } |
|
74 | + return $cats; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Generate an array of all attendances available. |
|
79 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | - */ |
|
77 | + /** |
|
78 | + * Generate an array of all attendances available. |
|
79 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | + */ |
|
81 | 81 | public function get_all_links() |
82 | 82 | { |
83 | 83 | if (empty($this->course_code)) { |
@@ -104,55 +104,55 @@ discard block |
||
104 | 104 | $my_cats = isset($cats) ? $cats : null; |
105 | 105 | |
106 | 106 | return $my_cats; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Has anyone done this exercise yet ? |
|
111 | - */ |
|
112 | - public function has_results() |
|
113 | - { |
|
114 | - $tbl_attendance_result = Database :: get_course_table(TABLE_ATTENDANCE_RESULT); |
|
115 | - $session_id = api_get_session_id(); |
|
116 | - $sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result." |
|
109 | + /** |
|
110 | + * Has anyone done this exercise yet ? |
|
111 | + */ |
|
112 | + public function has_results() |
|
113 | + { |
|
114 | + $tbl_attendance_result = Database :: get_course_table(TABLE_ATTENDANCE_RESULT); |
|
115 | + $session_id = api_get_session_id(); |
|
116 | + $sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result." |
|
117 | 117 | WHERE |
118 | 118 | session_id = $session_id AND |
119 | 119 | c_id = '.$this->course_id.' AND |
120 | 120 | attendance_id = '".intval($this->get_ref_id())."'"; |
121 | - $result = Database::query($sql); |
|
122 | - $number = Database::fetch_row($result); |
|
121 | + $result = Database::query($sql); |
|
122 | + $number = Database::fetch_row($result); |
|
123 | 123 | |
124 | - return $number[0] != 0; |
|
125 | - } |
|
124 | + return $number[0] != 0; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @param int $stud_id |
|
129 | - * @return array|null |
|
130 | - */ |
|
131 | - public function calc_score($stud_id = null, $type = null) |
|
132 | - { |
|
133 | - $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
134 | - $session_id = api_get_session_id(); |
|
127 | + /** |
|
128 | + * @param int $stud_id |
|
129 | + * @return array|null |
|
130 | + */ |
|
131 | + public function calc_score($stud_id = null, $type = null) |
|
132 | + { |
|
133 | + $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT); |
|
134 | + $session_id = api_get_session_id(); |
|
135 | 135 | |
136 | - // get attendance qualify max |
|
137 | - $sql = 'SELECT att.attendance_qualify_max |
|
136 | + // get attendance qualify max |
|
137 | + $sql = 'SELECT att.attendance_qualify_max |
|
138 | 138 | FROM '.$this->get_attendance_table().' att |
139 | 139 | WHERE |
140 | 140 | att.c_id = '.$this->course_id.' AND |
141 | 141 | att.id = '.intval($this->get_ref_id()).' AND |
142 | 142 | att.session_id='.intval($session_id).''; |
143 | - $query = Database::query($sql); |
|
144 | - $attendance = Database::fetch_array($query, 'ASSOC'); |
|
143 | + $query = Database::query($sql); |
|
144 | + $attendance = Database::fetch_array($query, 'ASSOC'); |
|
145 | 145 | |
146 | - // Get results |
|
147 | - $sql = 'SELECT * |
|
146 | + // Get results |
|
147 | + $sql = 'SELECT * |
|
148 | 148 | FROM '.$tbl_attendance_result.' |
149 | 149 | WHERE c_id = '.$this->course_id.' AND attendance_id = '.intval($this->get_ref_id()); |
150 | - if (isset($stud_id)) { |
|
151 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
152 | - } |
|
153 | - $scores = Database::query($sql); |
|
154 | - // for 1 student |
|
155 | - if (isset($stud_id)) { |
|
150 | + if (isset($stud_id)) { |
|
151 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
152 | + } |
|
153 | + $scores = Database::query($sql); |
|
154 | + // for 1 student |
|
155 | + if (isset($stud_id)) { |
|
156 | 156 | if ($data = Database::fetch_array($scores, 'ASSOC')) { |
157 | 157 | return array( |
158 | 158 | $data['score'], |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | //We sent the 0/attendance_qualify_max instead of null for correct calculations |
163 | 163 | return array(0, $attendance['attendance_qualify_max']); |
164 | 164 | } |
165 | - } else { |
|
165 | + } else { |
|
166 | 166 | // all students -> get average |
167 | 167 | $students = array(); // user list, needed to make sure we only |
168 | 168 | // take first attempts into account |
@@ -171,144 +171,144 @@ discard block |
||
171 | 171 | $sumResult = 0; |
172 | 172 | $bestResult = 0; |
173 | 173 | |
174 | - while ($data = Database::fetch_array($scores)) { |
|
175 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
176 | - if ($attendance['attendance_qualify_max'] != 0) { |
|
177 | - $students[$data['user_id']] = $data['score']; |
|
178 | - $rescount++; |
|
179 | - $sum += $data['score'] / $attendance['attendance_qualify_max']; |
|
180 | - $sumResult += $data['score']; |
|
181 | - if ($data['score'] > $bestResult) { |
|
182 | - $bestResult = $data['score']; |
|
183 | - } |
|
184 | - $weight = $attendance['attendance_qualify_max']; |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
174 | + while ($data = Database::fetch_array($scores)) { |
|
175 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
176 | + if ($attendance['attendance_qualify_max'] != 0) { |
|
177 | + $students[$data['user_id']] = $data['score']; |
|
178 | + $rescount++; |
|
179 | + $sum += $data['score'] / $attendance['attendance_qualify_max']; |
|
180 | + $sumResult += $data['score']; |
|
181 | + if ($data['score'] > $bestResult) { |
|
182 | + $bestResult = $data['score']; |
|
183 | + } |
|
184 | + $weight = $attendance['attendance_qualify_max']; |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | 188 | |
189 | - if ($rescount == 0) { |
|
190 | - return null; |
|
191 | - } else { |
|
192 | - switch ($type) { |
|
193 | - case 'best': |
|
194 | - return array($bestResult, $weight); |
|
195 | - break; |
|
196 | - case 'average': |
|
197 | - return array($sumResult / $rescount, $weight); |
|
198 | - break; |
|
199 | - case 'ranking': |
|
200 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
201 | - break; |
|
202 | - default: |
|
203 | - return array($sum, $rescount); |
|
204 | - break; |
|
205 | - } |
|
206 | - } |
|
207 | - } |
|
208 | - } |
|
189 | + if ($rescount == 0) { |
|
190 | + return null; |
|
191 | + } else { |
|
192 | + switch ($type) { |
|
193 | + case 'best': |
|
194 | + return array($bestResult, $weight); |
|
195 | + break; |
|
196 | + case 'average': |
|
197 | + return array($sumResult / $rescount, $weight); |
|
198 | + break; |
|
199 | + case 'ranking': |
|
200 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
201 | + break; |
|
202 | + default: |
|
203 | + return array($sum, $rescount); |
|
204 | + break; |
|
205 | + } |
|
206 | + } |
|
207 | + } |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * Lazy load function to get the database table of the student publications |
|
212 | - */ |
|
213 | - private function get_attendance_table() |
|
214 | - { |
|
215 | - $this->attendance_table = Database::get_course_table(TABLE_ATTENDANCE); |
|
216 | - return $this->attendance_table; |
|
217 | - } |
|
210 | + /** |
|
211 | + * Lazy load function to get the database table of the student publications |
|
212 | + */ |
|
213 | + private function get_attendance_table() |
|
214 | + { |
|
215 | + $this->attendance_table = Database::get_course_table(TABLE_ATTENDANCE); |
|
216 | + return $this->attendance_table; |
|
217 | + } |
|
218 | 218 | |
219 | - public function needs_name_and_description() |
|
220 | - { |
|
221 | - return false; |
|
222 | - } |
|
219 | + public function needs_name_and_description() |
|
220 | + { |
|
221 | + return false; |
|
222 | + } |
|
223 | 223 | |
224 | - public function needs_max() |
|
225 | - { |
|
226 | - return false; |
|
227 | - } |
|
224 | + public function needs_max() |
|
225 | + { |
|
226 | + return false; |
|
227 | + } |
|
228 | 228 | |
229 | - public function needs_results() |
|
230 | - { |
|
231 | - return false; |
|
232 | - } |
|
229 | + public function needs_results() |
|
230 | + { |
|
231 | + return false; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @return string |
|
236 | - */ |
|
237 | - public function get_name() |
|
238 | - { |
|
239 | - $this->get_attendance_data(); |
|
240 | - $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : ''; |
|
241 | - $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : ''; |
|
242 | - if ( isset($attendance_qualify_title) && $attendance_qualify_title != '') { |
|
243 | - return $this->attendance_data['attendance_qualify_title']; |
|
244 | - } else { |
|
245 | - return $attendance_title; |
|
246 | - } |
|
247 | - } |
|
234 | + /** |
|
235 | + * @return string |
|
236 | + */ |
|
237 | + public function get_name() |
|
238 | + { |
|
239 | + $this->get_attendance_data(); |
|
240 | + $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : ''; |
|
241 | + $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : ''; |
|
242 | + if ( isset($attendance_qualify_title) && $attendance_qualify_title != '') { |
|
243 | + return $this->attendance_data['attendance_qualify_title']; |
|
244 | + } else { |
|
245 | + return $attendance_title; |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * @return string |
|
251 | - */ |
|
252 | - public function get_description() |
|
253 | - { |
|
254 | - return ''; |
|
255 | - } |
|
249 | + /** |
|
250 | + * @return string |
|
251 | + */ |
|
252 | + public function get_description() |
|
253 | + { |
|
254 | + return ''; |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Check if this still links to an exercise |
|
259 | - */ |
|
260 | - public function is_valid_link() |
|
261 | - { |
|
262 | - $session_id = api_get_session_id(); |
|
263 | - $sql = 'SELECT count(att.id) FROM '.$this->get_attendance_table().' att |
|
257 | + /** |
|
258 | + * Check if this still links to an exercise |
|
259 | + */ |
|
260 | + public function is_valid_link() |
|
261 | + { |
|
262 | + $session_id = api_get_session_id(); |
|
263 | + $sql = 'SELECT count(att.id) FROM '.$this->get_attendance_table().' att |
|
264 | 264 | WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' '; |
265 | - $result = Database::query($sql); |
|
266 | - $number = Database::fetch_row($result); |
|
267 | - return ($number[0] != 0); |
|
268 | - } |
|
265 | + $result = Database::query($sql); |
|
266 | + $number = Database::fetch_row($result); |
|
267 | + return ($number[0] != 0); |
|
268 | + } |
|
269 | 269 | |
270 | - public function get_test_id() |
|
271 | - { |
|
272 | - return 'DEBUG:ID'; |
|
273 | - } |
|
270 | + public function get_test_id() |
|
271 | + { |
|
272 | + return 'DEBUG:ID'; |
|
273 | + } |
|
274 | 274 | |
275 | - public function get_link() |
|
276 | - { |
|
277 | - //it was extracts the attendance id |
|
278 | - $session_id = api_get_session_id(); |
|
279 | - $sql = 'SELECT * FROM '.$this->get_attendance_table().' att |
|
275 | + public function get_link() |
|
276 | + { |
|
277 | + //it was extracts the attendance id |
|
278 | + $session_id = api_get_session_id(); |
|
279 | + $sql = 'SELECT * FROM '.$this->get_attendance_table().' att |
|
280 | 280 | WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' '; |
281 | - $result = Database::query($sql); |
|
282 | - $row = Database::fetch_array($result,'ASSOC'); |
|
283 | - $attendance_id = $row['id']; |
|
284 | - $url = api_get_path(WEB_PATH).'main/attendance/index.php?action=attendance_sheet_list&gradebook=view&attendance_id='.$attendance_id.'&session_id='.$session_id.'&cidReq='.$this->get_course_code(); |
|
281 | + $result = Database::query($sql); |
|
282 | + $row = Database::fetch_array($result,'ASSOC'); |
|
283 | + $attendance_id = $row['id']; |
|
284 | + $url = api_get_path(WEB_PATH).'main/attendance/index.php?action=attendance_sheet_list&gradebook=view&attendance_id='.$attendance_id.'&session_id='.$session_id.'&cidReq='.$this->get_course_code(); |
|
285 | 285 | |
286 | - return $url; |
|
287 | - } |
|
286 | + return $url; |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * @return array|bool |
|
291 | - */ |
|
292 | - private function get_attendance_data() |
|
293 | - { |
|
294 | - $tbl_name = $this->get_attendance_table(); |
|
295 | - $session_id = api_get_session_id(); |
|
296 | - if ($tbl_name == '') { |
|
297 | - return false; |
|
298 | - } elseif (!isset($this->attendance_data)) { |
|
299 | - $sql = 'SELECT * FROM '.$this->get_attendance_table().' att |
|
289 | + /** |
|
290 | + * @return array|bool |
|
291 | + */ |
|
292 | + private function get_attendance_data() |
|
293 | + { |
|
294 | + $tbl_name = $this->get_attendance_table(); |
|
295 | + $session_id = api_get_session_id(); |
|
296 | + if ($tbl_name == '') { |
|
297 | + return false; |
|
298 | + } elseif (!isset($this->attendance_data)) { |
|
299 | + $sql = 'SELECT * FROM '.$this->get_attendance_table().' att |
|
300 | 300 | WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' '; |
301 | - $query = Database::query($sql); |
|
302 | - $this->attendance_data = Database::fetch_array($query); |
|
303 | - } |
|
304 | - return $this->attendance_data; |
|
305 | - } |
|
301 | + $query = Database::query($sql); |
|
302 | + $this->attendance_data = Database::fetch_array($query); |
|
303 | + } |
|
304 | + return $this->attendance_data; |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - public function get_icon_name() |
|
311 | - { |
|
312 | - return 'attendance'; |
|
313 | - } |
|
307 | + /** |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + public function get_icon_name() |
|
311 | + { |
|
312 | + return 'attendance'; |
|
313 | + } |
|
314 | 314 | } |
@@ -8,94 +8,94 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class SurveyLink extends AbstractLink |
10 | 10 | { |
11 | - private $survey_table = null; |
|
12 | - |
|
13 | - /** |
|
14 | - * Constructor |
|
15 | - */ |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - parent::__construct(); |
|
19 | - $this->set_type(LINK_SURVEY); |
|
20 | - } |
|
21 | - |
|
22 | - public function get_name() |
|
23 | - { |
|
24 | - $this->get_survey_data(); |
|
25 | - return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']); |
|
26 | - } |
|
27 | - |
|
28 | - public function get_description() |
|
29 | - { |
|
30 | - $this->get_survey_data(); |
|
31 | - return $this->survey_data['subtitle']; |
|
32 | - } |
|
33 | - |
|
34 | - public function get_type_name() |
|
35 | - { |
|
36 | - return get_lang('Survey'); |
|
37 | - } |
|
38 | - |
|
39 | - public function is_allowed_to_change_name() |
|
40 | - { |
|
41 | - return false; |
|
42 | - } |
|
43 | - |
|
44 | - public function needs_name_and_description() |
|
45 | - { |
|
46 | - return false; |
|
47 | - } |
|
48 | - |
|
49 | - public function needs_max() |
|
50 | - { |
|
51 | - return false; |
|
52 | - } |
|
53 | - |
|
54 | - public function needs_results() |
|
55 | - { |
|
56 | - return false; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Generates an array of all surveys available. |
|
61 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
62 | - */ |
|
63 | - public function get_all_links() |
|
64 | - { |
|
65 | - if (empty($this->course_code)) { |
|
66 | - die('Error in get_all_links() : course code not set'); |
|
67 | - } |
|
68 | - $tbl_survey = $this->get_survey_table(); |
|
69 | - $session_id = api_get_session_id(); |
|
70 | - $course_id = api_get_course_int_id(); |
|
71 | - $sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.' |
|
11 | + private $survey_table = null; |
|
12 | + |
|
13 | + /** |
|
14 | + * Constructor |
|
15 | + */ |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + parent::__construct(); |
|
19 | + $this->set_type(LINK_SURVEY); |
|
20 | + } |
|
21 | + |
|
22 | + public function get_name() |
|
23 | + { |
|
24 | + $this->get_survey_data(); |
|
25 | + return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']); |
|
26 | + } |
|
27 | + |
|
28 | + public function get_description() |
|
29 | + { |
|
30 | + $this->get_survey_data(); |
|
31 | + return $this->survey_data['subtitle']; |
|
32 | + } |
|
33 | + |
|
34 | + public function get_type_name() |
|
35 | + { |
|
36 | + return get_lang('Survey'); |
|
37 | + } |
|
38 | + |
|
39 | + public function is_allowed_to_change_name() |
|
40 | + { |
|
41 | + return false; |
|
42 | + } |
|
43 | + |
|
44 | + public function needs_name_and_description() |
|
45 | + { |
|
46 | + return false; |
|
47 | + } |
|
48 | + |
|
49 | + public function needs_max() |
|
50 | + { |
|
51 | + return false; |
|
52 | + } |
|
53 | + |
|
54 | + public function needs_results() |
|
55 | + { |
|
56 | + return false; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Generates an array of all surveys available. |
|
61 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
62 | + */ |
|
63 | + public function get_all_links() |
|
64 | + { |
|
65 | + if (empty($this->course_code)) { |
|
66 | + die('Error in get_all_links() : course code not set'); |
|
67 | + } |
|
68 | + $tbl_survey = $this->get_survey_table(); |
|
69 | + $session_id = api_get_session_id(); |
|
70 | + $course_id = api_get_course_int_id(); |
|
71 | + $sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.' |
|
72 | 72 | WHERE c_id = '.$course_id.' AND session_id = '.intval($session_id).''; |
73 | - $result = Database::query($sql); |
|
74 | - while ($data = Database::fetch_array($result)) { |
|
75 | - $links[] = array( |
|
76 | - $data['survey_id'], |
|
77 | - api_trunc_str( |
|
78 | - $data['code'] . ': ' . self::html_to_text($data['title']), |
|
79 | - 80 |
|
80 | - ) |
|
81 | - ); |
|
82 | - } |
|
83 | - |
|
84 | - return isset($links) ? $links : null; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates an array of surveys that a teacher hasn't created a link for. |
|
89 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
90 | - */ |
|
91 | - public function get_not_created_links() |
|
92 | - { |
|
93 | - if (empty($this->course_code)) { |
|
94 | - die('Error in get_not_created_links() : course code not set'); |
|
95 | - } |
|
96 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
97 | - |
|
98 | - $sql = 'SELECT survey_id, title, code |
|
73 | + $result = Database::query($sql); |
|
74 | + while ($data = Database::fetch_array($result)) { |
|
75 | + $links[] = array( |
|
76 | + $data['survey_id'], |
|
77 | + api_trunc_str( |
|
78 | + $data['code'] . ': ' . self::html_to_text($data['title']), |
|
79 | + 80 |
|
80 | + ) |
|
81 | + ); |
|
82 | + } |
|
83 | + |
|
84 | + return isset($links) ? $links : null; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Generates an array of surveys that a teacher hasn't created a link for. |
|
89 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
90 | + */ |
|
91 | + public function get_not_created_links() |
|
92 | + { |
|
93 | + if (empty($this->course_code)) { |
|
94 | + die('Error in get_not_created_links() : course code not set'); |
|
95 | + } |
|
96 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
97 | + |
|
98 | + $sql = 'SELECT survey_id, title, code |
|
99 | 99 | FROM '.$this->get_survey_table().' AS srv |
100 | 100 | WHERE survey_id NOT IN |
101 | 101 | ( |
@@ -106,28 +106,28 @@ discard block |
||
106 | 106 | ) |
107 | 107 | AND srv.session_id = '.api_get_session_id(); |
108 | 108 | |
109 | - $result = Database::query($sql); |
|
110 | - |
|
111 | - $links = array(); |
|
112 | - while ($data = Database::fetch_array($result)) { |
|
113 | - $links[] = array( |
|
114 | - $data['survey_id'], |
|
115 | - api_trunc_str($data['code'].': '.self::html_to_text($data['title']), 80) |
|
116 | - ); |
|
117 | - } |
|
118 | - return $links; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Has anyone done this survey yet? |
|
123 | - */ |
|
124 | - public function has_results($stud_id=null) |
|
125 | - { |
|
126 | - $ref_id = intval($this->get_ref_id()); |
|
127 | - $session_id = api_get_session_id(); |
|
128 | - $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
129 | - $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
130 | - $sql = "SELECT |
|
109 | + $result = Database::query($sql); |
|
110 | + |
|
111 | + $links = array(); |
|
112 | + while ($data = Database::fetch_array($result)) { |
|
113 | + $links[] = array( |
|
114 | + $data['survey_id'], |
|
115 | + api_trunc_str($data['code'].': '.self::html_to_text($data['title']), 80) |
|
116 | + ); |
|
117 | + } |
|
118 | + return $links; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Has anyone done this survey yet? |
|
123 | + */ |
|
124 | + public function has_results($stud_id=null) |
|
125 | + { |
|
126 | + $ref_id = intval($this->get_ref_id()); |
|
127 | + $session_id = api_get_session_id(); |
|
128 | + $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
129 | + $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
130 | + $sql = "SELECT |
|
131 | 131 | COUNT(i.answered) |
132 | 132 | FROM $tbl_survey AS s |
133 | 133 | JOIN $tbl_survey_invitation AS i ON s.code = i.survey_code |
@@ -137,30 +137,30 @@ discard block |
||
137 | 137 | s.survey_id = $ref_id AND |
138 | 138 | i.session_id = $session_id"; |
139 | 139 | |
140 | - $sql_result = Database::query($sql); |
|
141 | - $data = Database::fetch_array($sql_result); |
|
140 | + $sql_result = Database::query($sql); |
|
141 | + $data = Database::fetch_array($sql_result); |
|
142 | 142 | |
143 | - return ($data[0] != 0); |
|
144 | - } |
|
143 | + return ($data[0] != 0); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @param int $stud_id |
|
148 | - * @return array|null |
|
149 | - */ |
|
150 | - public function calc_score($stud_id = null, $type = null) |
|
151 | - { |
|
152 | - // Note: Max score is assumed to be always 1 for surveys, |
|
153 | - // only student's participation is to be taken into account. |
|
154 | - $max_score = 1; |
|
146 | + /** |
|
147 | + * @param int $stud_id |
|
148 | + * @return array|null |
|
149 | + */ |
|
150 | + public function calc_score($stud_id = null, $type = null) |
|
151 | + { |
|
152 | + // Note: Max score is assumed to be always 1 for surveys, |
|
153 | + // only student's participation is to be taken into account. |
|
154 | + $max_score = 1; |
|
155 | 155 | |
156 | - $ref_id = intval($this->get_ref_id()); |
|
157 | - $session_id = api_get_session_id(); |
|
158 | - $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
159 | - $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
156 | + $ref_id = intval($this->get_ref_id()); |
|
157 | + $session_id = api_get_session_id(); |
|
158 | + $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
159 | + $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
160 | 160 | |
161 | - $get_individual_score = !is_null($stud_id); |
|
161 | + $get_individual_score = !is_null($stud_id); |
|
162 | 162 | |
163 | - $sql = "SELECT i.answered |
|
163 | + $sql = "SELECT i.answered |
|
164 | 164 | FROM $tbl_survey AS s |
165 | 165 | JOIN $tbl_survey_invitation AS i |
166 | 166 | ON s.code = i.survey_code |
@@ -171,131 +171,131 @@ discard block |
||
171 | 171 | i.session_id = $session_id |
172 | 172 | "; |
173 | 173 | |
174 | - if ($get_individual_score) { |
|
175 | - $sql .= ' AND i.user = '.intval($stud_id); |
|
176 | - } |
|
177 | - |
|
178 | - $sql_result = Database::query($sql); |
|
179 | - |
|
180 | - if ($get_individual_score) { |
|
181 | - // for 1 student |
|
182 | - if ($data = Database::fetch_array($sql_result)) { |
|
183 | - return array($data['answered'] ? $max_score : 0, $max_score); |
|
184 | - } |
|
185 | - return array(0, $max_score); |
|
186 | - } else { |
|
187 | - // for all the students -> get average |
|
188 | - $rescount = 0; |
|
189 | - $sum = 0; |
|
190 | - $bestResult = 0; |
|
191 | - $weight = 0; |
|
192 | - while ($data = Database::fetch_array($sql_result)) { |
|
193 | - $sum += $data['answered'] ? $max_score : 0; |
|
194 | - $rescount++; |
|
195 | - if ($data['answered'] > $bestResult) { |
|
196 | - $bestResult = $data['answered']; |
|
197 | - $weight = $assignment['qualification']; |
|
198 | - } |
|
199 | - } |
|
200 | - $sum = $sum / $max_score; |
|
201 | - |
|
202 | - if ($rescount == 0) { |
|
203 | - return null; |
|
204 | - } |
|
205 | - |
|
206 | - switch ($type) { |
|
207 | - case 'best': |
|
208 | - return array($bestResult, $rescount); |
|
209 | - break; |
|
210 | - case 'average': |
|
211 | - return array($sum, $rescount); |
|
212 | - break; |
|
213 | - case 'ranking': |
|
214 | - return null; |
|
215 | - break; |
|
216 | - default: |
|
217 | - return array($sum, $rescount); |
|
218 | - break; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Lazy load function to get the database table of the surveys |
|
225 | - */ |
|
226 | - private function get_survey_table() |
|
227 | - { |
|
228 | - $this->survey_table = Database :: get_course_table(TABLE_SURVEY); |
|
229 | - return $this->survey_table; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Check if this still links to a survey |
|
234 | - */ |
|
235 | - public function is_valid_link() |
|
236 | - { |
|
237 | - $session_id = api_get_session_id(); |
|
238 | - $sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().' |
|
174 | + if ($get_individual_score) { |
|
175 | + $sql .= ' AND i.user = '.intval($stud_id); |
|
176 | + } |
|
177 | + |
|
178 | + $sql_result = Database::query($sql); |
|
179 | + |
|
180 | + if ($get_individual_score) { |
|
181 | + // for 1 student |
|
182 | + if ($data = Database::fetch_array($sql_result)) { |
|
183 | + return array($data['answered'] ? $max_score : 0, $max_score); |
|
184 | + } |
|
185 | + return array(0, $max_score); |
|
186 | + } else { |
|
187 | + // for all the students -> get average |
|
188 | + $rescount = 0; |
|
189 | + $sum = 0; |
|
190 | + $bestResult = 0; |
|
191 | + $weight = 0; |
|
192 | + while ($data = Database::fetch_array($sql_result)) { |
|
193 | + $sum += $data['answered'] ? $max_score : 0; |
|
194 | + $rescount++; |
|
195 | + if ($data['answered'] > $bestResult) { |
|
196 | + $bestResult = $data['answered']; |
|
197 | + $weight = $assignment['qualification']; |
|
198 | + } |
|
199 | + } |
|
200 | + $sum = $sum / $max_score; |
|
201 | + |
|
202 | + if ($rescount == 0) { |
|
203 | + return null; |
|
204 | + } |
|
205 | + |
|
206 | + switch ($type) { |
|
207 | + case 'best': |
|
208 | + return array($bestResult, $rescount); |
|
209 | + break; |
|
210 | + case 'average': |
|
211 | + return array($sum, $rescount); |
|
212 | + break; |
|
213 | + case 'ranking': |
|
214 | + return null; |
|
215 | + break; |
|
216 | + default: |
|
217 | + return array($sum, $rescount); |
|
218 | + break; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Lazy load function to get the database table of the surveys |
|
225 | + */ |
|
226 | + private function get_survey_table() |
|
227 | + { |
|
228 | + $this->survey_table = Database :: get_course_table(TABLE_SURVEY); |
|
229 | + return $this->survey_table; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Check if this still links to a survey |
|
234 | + */ |
|
235 | + public function is_valid_link() |
|
236 | + { |
|
237 | + $session_id = api_get_session_id(); |
|
238 | + $sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().' |
|
239 | 239 | WHERE |
240 | 240 | c_id = '.$this->course_id.' AND |
241 | 241 | survey_id = '.intval($this->get_ref_id()).' AND |
242 | 242 | session_id='.intval($session_id).''; |
243 | - $result = Database::query($sql); |
|
244 | - $number = Database::fetch_row($result); |
|
245 | - return ($number[0] != 0); |
|
246 | - } |
|
247 | - |
|
248 | - public function get_test_id() |
|
249 | - { |
|
250 | - return 'DEBUG:ID'; |
|
251 | - } |
|
252 | - |
|
253 | - public function get_link() |
|
254 | - { |
|
255 | - if (api_is_allowed_to_edit()) { // Let students make access only through "Surveys" tool. |
|
256 | - $tbl_name = $this->get_survey_table(); |
|
257 | - $session_id = api_get_session_id(); |
|
258 | - if ($tbl_name != '') { |
|
259 | - $sql = 'SELECT survey_id FROM '.$this->get_survey_table().' |
|
243 | + $result = Database::query($sql); |
|
244 | + $number = Database::fetch_row($result); |
|
245 | + return ($number[0] != 0); |
|
246 | + } |
|
247 | + |
|
248 | + public function get_test_id() |
|
249 | + { |
|
250 | + return 'DEBUG:ID'; |
|
251 | + } |
|
252 | + |
|
253 | + public function get_link() |
|
254 | + { |
|
255 | + if (api_is_allowed_to_edit()) { // Let students make access only through "Surveys" tool. |
|
256 | + $tbl_name = $this->get_survey_table(); |
|
257 | + $session_id = api_get_session_id(); |
|
258 | + if ($tbl_name != '') { |
|
259 | + $sql = 'SELECT survey_id FROM '.$this->get_survey_table().' |
|
260 | 260 | WHERE |
261 | 261 | c_id = '.$this->course_id.' AND |
262 | 262 | survey_id = '.intval($this->get_ref_id()).' AND |
263 | 263 | session_id = '.intval($session_id).' '; |
264 | - $result = Database::query($sql); |
|
265 | - $row = Database::fetch_array($result, 'ASSOC'); |
|
266 | - $survey_id = $row['survey_id']; |
|
267 | - return api_get_path(WEB_PATH).'main/survey/reporting.php?cidReq='.$this->get_course_code().'&survey_id='.$survey_id; |
|
268 | - } |
|
269 | - } |
|
270 | - return null; |
|
271 | - } |
|
272 | - |
|
273 | - private function get_survey_data() |
|
274 | - { |
|
275 | - $tbl_name = $this->get_survey_table(); |
|
276 | - $session_id = api_get_session_id(); |
|
277 | - if ($tbl_name == '') { |
|
278 | - return false; |
|
279 | - } elseif (!isset($this->survey_data)) { |
|
280 | - $sql = 'SELECT * FROM '.$tbl_name.' |
|
264 | + $result = Database::query($sql); |
|
265 | + $row = Database::fetch_array($result, 'ASSOC'); |
|
266 | + $survey_id = $row['survey_id']; |
|
267 | + return api_get_path(WEB_PATH).'main/survey/reporting.php?cidReq='.$this->get_course_code().'&survey_id='.$survey_id; |
|
268 | + } |
|
269 | + } |
|
270 | + return null; |
|
271 | + } |
|
272 | + |
|
273 | + private function get_survey_data() |
|
274 | + { |
|
275 | + $tbl_name = $this->get_survey_table(); |
|
276 | + $session_id = api_get_session_id(); |
|
277 | + if ($tbl_name == '') { |
|
278 | + return false; |
|
279 | + } elseif (!isset($this->survey_data)) { |
|
280 | + $sql = 'SELECT * FROM '.$tbl_name.' |
|
281 | 281 | WHERE |
282 | 282 | c_id = '.$this->course_id.' AND |
283 | 283 | survey_id = '.intval($this->get_ref_id()).' AND |
284 | 284 | session_id='.intval($session_id).''; |
285 | - $query = Database::query($sql); |
|
286 | - $this->survey_data = Database::fetch_array($query); |
|
287 | - } |
|
288 | - return $this->survey_data; |
|
289 | - } |
|
290 | - |
|
291 | - public function get_icon_name() |
|
292 | - { |
|
293 | - return 'survey'; |
|
294 | - } |
|
295 | - |
|
296 | - private static function html_to_text($string) |
|
297 | - { |
|
298 | - return strip_tags($string); |
|
299 | - //return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES)); |
|
300 | - } |
|
285 | + $query = Database::query($sql); |
|
286 | + $this->survey_data = Database::fetch_array($query); |
|
287 | + } |
|
288 | + return $this->survey_data; |
|
289 | + } |
|
290 | + |
|
291 | + public function get_icon_name() |
|
292 | + { |
|
293 | + return 'survey'; |
|
294 | + } |
|
295 | + |
|
296 | + private static function html_to_text($string) |
|
297 | + { |
|
298 | + return strip_tags($string); |
|
299 | + //return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES)); |
|
300 | + } |
|
301 | 301 | } |
@@ -9,260 +9,260 @@ |
||
9 | 9 | */ |
10 | 10 | class LearnpathLink extends AbstractLink |
11 | 11 | { |
12 | - private $course_info = null; |
|
13 | - private $learnpath_table = null; |
|
14 | - private $learnpath_data = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_LEARNPATH); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Generate an array of learnpaths that a teacher hasn't created a link for. |
|
27 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
28 | - */ |
|
29 | - public function get_not_created_links() |
|
30 | - { |
|
31 | - return false; |
|
32 | - if (empty($this->course_code)) |
|
33 | - die('Error in get_not_created_links() : course code not set'); |
|
34 | - |
|
35 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
36 | - |
|
37 | - $sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp |
|
12 | + private $course_info = null; |
|
13 | + private $learnpath_table = null; |
|
14 | + private $learnpath_data = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_LEARNPATH); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Generate an array of learnpaths that a teacher hasn't created a link for. |
|
27 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
28 | + */ |
|
29 | + public function get_not_created_links() |
|
30 | + { |
|
31 | + return false; |
|
32 | + if (empty($this->course_code)) |
|
33 | + die('Error in get_not_created_links() : course code not set'); |
|
34 | + |
|
35 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
36 | + |
|
37 | + $sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp |
|
38 | 38 | WHERE c_id = '.$this->course_id.' AND id NOT IN ' |
39 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
40 | - .' WHERE type = '.LINK_LEARNPATH |
|
41 | - ." AND course_code = '".$this->get_course_code()."'" |
|
42 | - .') AND lp.session_id='.api_get_session_id().''; |
|
43 | - |
|
44 | - $result = Database::query($sql); |
|
45 | - |
|
46 | - $cats=array(); |
|
47 | - while ($data=Database::fetch_array($result)) { |
|
48 | - $cats[] = array ($data['id'], $data['name']); |
|
49 | - } |
|
50 | - |
|
51 | - return $cats; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Generate an array of all learnpaths available. |
|
56 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
57 | - */ |
|
58 | - public function get_all_links() |
|
59 | - { |
|
60 | - if (empty($this->course_code)) |
|
61 | - die('Error in get_not_created_links() : course code not set'); |
|
62 | - |
|
63 | - $session_id = api_get_session_id(); |
|
64 | - if (empty($session_id)) { |
|
65 | - $session_condition = api_get_session_condition(0, true); |
|
66 | - } else { |
|
67 | - $session_condition = api_get_session_condition($session_id, true, true); |
|
68 | - } |
|
69 | - |
|
70 | - $sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' |
|
39 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
40 | + .' WHERE type = '.LINK_LEARNPATH |
|
41 | + ." AND course_code = '".$this->get_course_code()."'" |
|
42 | + .') AND lp.session_id='.api_get_session_id().''; |
|
43 | + |
|
44 | + $result = Database::query($sql); |
|
45 | + |
|
46 | + $cats=array(); |
|
47 | + while ($data=Database::fetch_array($result)) { |
|
48 | + $cats[] = array ($data['id'], $data['name']); |
|
49 | + } |
|
50 | + |
|
51 | + return $cats; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Generate an array of all learnpaths available. |
|
56 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
57 | + */ |
|
58 | + public function get_all_links() |
|
59 | + { |
|
60 | + if (empty($this->course_code)) |
|
61 | + die('Error in get_not_created_links() : course code not set'); |
|
62 | + |
|
63 | + $session_id = api_get_session_id(); |
|
64 | + if (empty($session_id)) { |
|
65 | + $session_condition = api_get_session_condition(0, true); |
|
66 | + } else { |
|
67 | + $session_condition = api_get_session_condition($session_id, true, true); |
|
68 | + } |
|
69 | + |
|
70 | + $sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' |
|
71 | 71 | WHERE c_id = '.$this->course_id.' '.$session_condition.' '; |
72 | - $result = Database::query($sql); |
|
72 | + $result = Database::query($sql); |
|
73 | 73 | |
74 | - $cats = array(); |
|
75 | - while ($data=Database::fetch_array($result)) { |
|
76 | - $cats[] = array ($data['id'], $data['name']); |
|
77 | - } |
|
74 | + $cats = array(); |
|
75 | + while ($data=Database::fetch_array($result)) { |
|
76 | + $cats[] = array ($data['id'], $data['name']); |
|
77 | + } |
|
78 | 78 | |
79 | - return $cats; |
|
80 | - } |
|
79 | + return $cats; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Has anyone used this learnpath yet ? |
|
85 | - */ |
|
86 | - public function has_results() |
|
87 | - { |
|
88 | - $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
89 | - $sql = "SELECT count(id) AS number FROM $tbl_stats |
|
83 | + /** |
|
84 | + * Has anyone used this learnpath yet ? |
|
85 | + */ |
|
86 | + public function has_results() |
|
87 | + { |
|
88 | + $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
89 | + $sql = "SELECT count(id) AS number FROM $tbl_stats |
|
90 | 90 | WHERE c_id = ".$this->course_id." AND lp_id = ".$this->get_ref_id(); |
91 | - $result = Database::query($sql); |
|
92 | - $number = Database::fetch_array($result,'NUM'); |
|
93 | - return ($number[0] != 0); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the progress of this learnpath. Only the last attempt are taken into account. |
|
98 | - * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | - * @return array (score, max) if student is given |
|
100 | - * array (sum of scores, number of scores) otherwise |
|
101 | - * or null if no scores available |
|
102 | - */ |
|
103 | - public function calc_score($stud_id = null, $type = null) |
|
104 | - { |
|
105 | - $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
106 | - $session_id = api_get_session_id(); |
|
107 | - |
|
108 | - $sql = "SELECT * FROM $tbl_stats |
|
91 | + $result = Database::query($sql); |
|
92 | + $number = Database::fetch_array($result,'NUM'); |
|
93 | + return ($number[0] != 0); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the progress of this learnpath. Only the last attempt are taken into account. |
|
98 | + * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | + * @return array (score, max) if student is given |
|
100 | + * array (sum of scores, number of scores) otherwise |
|
101 | + * or null if no scores available |
|
102 | + */ |
|
103 | + public function calc_score($stud_id = null, $type = null) |
|
104 | + { |
|
105 | + $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
106 | + $session_id = api_get_session_id(); |
|
107 | + |
|
108 | + $sql = "SELECT * FROM $tbl_stats |
|
109 | 109 | WHERE |
110 | 110 | c_id = ".$this->course_id." AND |
111 | 111 | lp_id = ".$this->get_ref_id()." AND |
112 | 112 | session_id = $session_id "; |
113 | 113 | |
114 | - if (isset($stud_id)) |
|
115 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | - |
|
117 | - // order by id, that way the student's first attempt is accessed first |
|
118 | - $sql .= ' ORDER BY view_count DESC'; |
|
119 | - |
|
120 | - $scores = Database::query($sql); |
|
121 | - // for 1 student |
|
122 | - if (isset($stud_id)) { |
|
123 | - if ($data = Database::fetch_array($scores)) { |
|
124 | - return array ($data['progress'], 100); |
|
125 | - } else |
|
126 | - return null; |
|
127 | - } else { |
|
128 | - // all students -> get average |
|
129 | - $students = array(); // user list, needed to make sure we only |
|
130 | - // take first attempts into account |
|
131 | - $rescount = 0; |
|
132 | - $sum = 0; |
|
133 | - $bestResult = 0; |
|
134 | - $sumResult = 0; |
|
135 | - while ($data = Database::fetch_array($scores)) { |
|
136 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
137 | - $students[$data['user_id']] = $data['progress']; |
|
138 | - $rescount++; |
|
139 | - $sum += $data['progress'] / 100; |
|
140 | - $sumResult += $data['progress']; |
|
141 | - |
|
142 | - if ($data['progress'] > $bestResult) { |
|
143 | - $bestResult = $data['progress']; |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if ($rescount == 0) { |
|
149 | - return null; |
|
150 | - } else { |
|
151 | - |
|
152 | - switch ($type) { |
|
153 | - case 'best': |
|
154 | - return array($bestResult, 100); |
|
155 | - break; |
|
156 | - case 'average': |
|
157 | - return array($sumResult/$rescount, 100); |
|
158 | - break; |
|
159 | - case 'ranking': |
|
160 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
161 | - break; |
|
162 | - default: |
|
163 | - return array($sum, $rescount); |
|
164 | - break; |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Get URL where to go to if the user clicks on the link. |
|
172 | - */ |
|
173 | - public function get_link() |
|
174 | - { |
|
175 | - $url = api_get_path(WEB_PATH).'main/newscorm/lp_controller.php?cidReq='.$this->get_course_code().'&gradebook=view'; |
|
176 | - $session_id = api_get_session_id(); |
|
177 | - if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
178 | - $url .= '&action=view&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
179 | - } else { |
|
180 | - $url .= '&action=build&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
181 | - } |
|
182 | - return $url; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Get name to display: same as learnpath title |
|
187 | - */ |
|
188 | - public function get_name() |
|
189 | - { |
|
190 | - $data = $this->get_learnpath_data(); |
|
191 | - return $data['name']; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Get description to display: same as learnpath description |
|
196 | - */ |
|
197 | - public function get_description() |
|
198 | - { |
|
199 | - $data = $this->get_learnpath_data(); |
|
200 | - return $data['description']; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Check if this still links to a learnpath |
|
205 | - */ |
|
206 | - public function is_valid_link() { |
|
207 | - $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
114 | + if (isset($stud_id)) |
|
115 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | + |
|
117 | + // order by id, that way the student's first attempt is accessed first |
|
118 | + $sql .= ' ORDER BY view_count DESC'; |
|
119 | + |
|
120 | + $scores = Database::query($sql); |
|
121 | + // for 1 student |
|
122 | + if (isset($stud_id)) { |
|
123 | + if ($data = Database::fetch_array($scores)) { |
|
124 | + return array ($data['progress'], 100); |
|
125 | + } else |
|
126 | + return null; |
|
127 | + } else { |
|
128 | + // all students -> get average |
|
129 | + $students = array(); // user list, needed to make sure we only |
|
130 | + // take first attempts into account |
|
131 | + $rescount = 0; |
|
132 | + $sum = 0; |
|
133 | + $bestResult = 0; |
|
134 | + $sumResult = 0; |
|
135 | + while ($data = Database::fetch_array($scores)) { |
|
136 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
137 | + $students[$data['user_id']] = $data['progress']; |
|
138 | + $rescount++; |
|
139 | + $sum += $data['progress'] / 100; |
|
140 | + $sumResult += $data['progress']; |
|
141 | + |
|
142 | + if ($data['progress'] > $bestResult) { |
|
143 | + $bestResult = $data['progress']; |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if ($rescount == 0) { |
|
149 | + return null; |
|
150 | + } else { |
|
151 | + |
|
152 | + switch ($type) { |
|
153 | + case 'best': |
|
154 | + return array($bestResult, 100); |
|
155 | + break; |
|
156 | + case 'average': |
|
157 | + return array($sumResult/$rescount, 100); |
|
158 | + break; |
|
159 | + case 'ranking': |
|
160 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
161 | + break; |
|
162 | + default: |
|
163 | + return array($sum, $rescount); |
|
164 | + break; |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Get URL where to go to if the user clicks on the link. |
|
172 | + */ |
|
173 | + public function get_link() |
|
174 | + { |
|
175 | + $url = api_get_path(WEB_PATH).'main/newscorm/lp_controller.php?cidReq='.$this->get_course_code().'&gradebook=view'; |
|
176 | + $session_id = api_get_session_id(); |
|
177 | + if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
178 | + $url .= '&action=view&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
179 | + } else { |
|
180 | + $url .= '&action=build&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
181 | + } |
|
182 | + return $url; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Get name to display: same as learnpath title |
|
187 | + */ |
|
188 | + public function get_name() |
|
189 | + { |
|
190 | + $data = $this->get_learnpath_data(); |
|
191 | + return $data['name']; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Get description to display: same as learnpath description |
|
196 | + */ |
|
197 | + public function get_description() |
|
198 | + { |
|
199 | + $data = $this->get_learnpath_data(); |
|
200 | + return $data['description']; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Check if this still links to a learnpath |
|
205 | + */ |
|
206 | + public function is_valid_link() { |
|
207 | + $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
208 | 208 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
209 | - $result = Database::query($sql); |
|
210 | - $number = Database::fetch_row($result,'NUM'); |
|
211 | - return ($number[0] != 0); |
|
212 | - } |
|
213 | - |
|
214 | - public function get_type_name() |
|
215 | - { |
|
216 | - return get_lang('LearningPaths'); |
|
217 | - } |
|
218 | - |
|
219 | - public function needs_name_and_description() |
|
220 | - { |
|
221 | - return false; |
|
222 | - } |
|
223 | - |
|
224 | - public function needs_max() |
|
225 | - { |
|
226 | - return false; |
|
227 | - } |
|
228 | - |
|
229 | - public function needs_results() |
|
230 | - { |
|
231 | - return false; |
|
232 | - } |
|
233 | - |
|
234 | - public function is_allowed_to_change_name() |
|
235 | - { |
|
236 | - return false; |
|
237 | - } |
|
238 | - |
|
239 | - // INTERNAL FUNCTIONS |
|
240 | - |
|
241 | - /** |
|
242 | - * Lazy load function to get the database table of the learnpath |
|
243 | - */ |
|
244 | - private function get_learnpath_table() |
|
245 | - { |
|
246 | - $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
247 | - return $this->learnpath_table; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Lazy load function to get the database contents of this learnpath |
|
252 | - */ |
|
253 | - private function get_learnpath_data() |
|
254 | - { |
|
255 | - if (!isset($this->learnpath_data)) { |
|
256 | - $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
209 | + $result = Database::query($sql); |
|
210 | + $number = Database::fetch_row($result,'NUM'); |
|
211 | + return ($number[0] != 0); |
|
212 | + } |
|
213 | + |
|
214 | + public function get_type_name() |
|
215 | + { |
|
216 | + return get_lang('LearningPaths'); |
|
217 | + } |
|
218 | + |
|
219 | + public function needs_name_and_description() |
|
220 | + { |
|
221 | + return false; |
|
222 | + } |
|
223 | + |
|
224 | + public function needs_max() |
|
225 | + { |
|
226 | + return false; |
|
227 | + } |
|
228 | + |
|
229 | + public function needs_results() |
|
230 | + { |
|
231 | + return false; |
|
232 | + } |
|
233 | + |
|
234 | + public function is_allowed_to_change_name() |
|
235 | + { |
|
236 | + return false; |
|
237 | + } |
|
238 | + |
|
239 | + // INTERNAL FUNCTIONS |
|
240 | + |
|
241 | + /** |
|
242 | + * Lazy load function to get the database table of the learnpath |
|
243 | + */ |
|
244 | + private function get_learnpath_table() |
|
245 | + { |
|
246 | + $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
247 | + return $this->learnpath_table; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Lazy load function to get the database contents of this learnpath |
|
252 | + */ |
|
253 | + private function get_learnpath_data() |
|
254 | + { |
|
255 | + if (!isset($this->learnpath_data)) { |
|
256 | + $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
257 | 257 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
258 | - $result = Database::query($sql); |
|
259 | - $this->learnpath_data = Database::fetch_array($result); |
|
260 | - } |
|
261 | - return $this->learnpath_data; |
|
262 | - } |
|
263 | - |
|
264 | - public function get_icon_name() |
|
265 | - { |
|
266 | - return 'learnpath'; |
|
267 | - } |
|
258 | + $result = Database::query($sql); |
|
259 | + $this->learnpath_data = Database::fetch_array($result); |
|
260 | + } |
|
261 | + return $this->learnpath_data; |
|
262 | + } |
|
263 | + |
|
264 | + public function get_icon_name() |
|
265 | + { |
|
266 | + return 'learnpath'; |
|
267 | + } |
|
268 | 268 | } |
@@ -10,54 +10,54 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ForumThreadLink extends AbstractLink |
12 | 12 | { |
13 | - private $forum_thread_table = null; |
|
14 | - private $itemprop_table = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_FORUM_THREAD); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function get_type_name() |
|
29 | - { |
|
30 | - return get_lang('ForumThreads'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function is_allowed_to_change_name() |
|
37 | - { |
|
38 | - return false; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | - */ |
|
45 | - public function get_not_created_links() |
|
46 | - { |
|
47 | - if (empty($this->course_code)) { |
|
48 | - die('Error in get_not_created_links() : course code not set'); |
|
49 | - } |
|
50 | - |
|
51 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | - |
|
53 | - $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table() |
|
54 | - .' forum_thread WHERE thread_id NOT IN' |
|
55 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
56 | - .' WHERE type = '.LINK_FORUM_THREAD |
|
57 | - ." AND c_id = ".intval($this->course_id) |
|
58 | - .') AND forum_thread.session_id='.api_get_session_id().''; |
|
59 | - |
|
60 | - $result = Database::query($sql); |
|
13 | + private $forum_thread_table = null; |
|
14 | + private $itemprop_table = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_FORUM_THREAD); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function get_type_name() |
|
29 | + { |
|
30 | + return get_lang('ForumThreads'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function is_allowed_to_change_name() |
|
37 | + { |
|
38 | + return false; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | + */ |
|
45 | + public function get_not_created_links() |
|
46 | + { |
|
47 | + if (empty($this->course_code)) { |
|
48 | + die('Error in get_not_created_links() : course code not set'); |
|
49 | + } |
|
50 | + |
|
51 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | + |
|
53 | + $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table() |
|
54 | + .' forum_thread WHERE thread_id NOT IN' |
|
55 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
56 | + .' WHERE type = '.LINK_FORUM_THREAD |
|
57 | + ." AND c_id = ".intval($this->course_id) |
|
58 | + .') AND forum_thread.session_id='.api_get_session_id().''; |
|
59 | + |
|
60 | + $result = Database::query($sql); |
|
61 | 61 | |
62 | 62 | $cats = array(); |
63 | 63 | while ($data = Database::fetch_array($result)) { |
@@ -72,29 +72,29 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | return $cats; |
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Generate an array of all exercises available. |
|
79 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | - */ |
|
81 | - public function get_all_links() |
|
82 | - { |
|
83 | - if (empty($this->course_code)) { |
|
84 | - die('Error in get_not_created_links() : course code not set'); |
|
85 | - } |
|
86 | - |
|
87 | - $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | - $session_id = api_get_session_id(); |
|
90 | - |
|
91 | - if ($session_id) { |
|
92 | - $session_condition = 'tl.session_id='.api_get_session_id(); |
|
93 | - } else { |
|
94 | - $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
95 | - } |
|
96 | - |
|
97 | - $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Generate an array of all exercises available. |
|
79 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | + */ |
|
81 | + public function get_all_links() |
|
82 | + { |
|
83 | + if (empty($this->course_code)) { |
|
84 | + die('Error in get_not_created_links() : course code not set'); |
|
85 | + } |
|
86 | + |
|
87 | + $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | + $session_id = api_get_session_id(); |
|
90 | + |
|
91 | + if ($session_id) { |
|
92 | + $session_condition = 'tl.session_id='.api_get_session_id(); |
|
93 | + } else { |
|
94 | + $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
95 | + } |
|
96 | + |
|
97 | + $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
98 | 98 | FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip |
99 | 99 | ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id ) |
100 | 100 | WHERE |
@@ -105,24 +105,24 @@ discard block |
||
105 | 105 | '.$session_condition.' |
106 | 106 | '; |
107 | 107 | |
108 | - $result = Database::query($sql); |
|
108 | + $result = Database::query($sql); |
|
109 | 109 | |
110 | - while ($data = Database::fetch_array($result)) { |
|
111 | - if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | - $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
113 | - } else { |
|
114 | - $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
115 | - } |
|
116 | - } |
|
117 | - $my_cats = isset($cats) ? $cats : null; |
|
110 | + while ($data = Database::fetch_array($result)) { |
|
111 | + if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | + $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
113 | + } else { |
|
114 | + $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
115 | + } |
|
116 | + } |
|
117 | + $my_cats = isset($cats) ? $cats : null; |
|
118 | 118 | |
119 | - return $my_cats; |
|
120 | - } |
|
119 | + return $my_cats; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | /** |
123 | - * Has anyone done this exercise yet ? |
|
124 | - * @return int |
|
125 | - */ |
|
123 | + * Has anyone done this exercise yet ? |
|
124 | + * @return int |
|
125 | + */ |
|
126 | 126 | public function has_results() |
127 | 127 | { |
128 | 128 | $table = Database :: get_course_table(TABLE_FORUM_POST); |
@@ -134,40 +134,40 @@ discard block |
||
134 | 134 | $number = Database::fetch_row($result); |
135 | 135 | |
136 | 136 | return $number[0] != 0; |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param int $stud_id |
|
139 | + /** |
|
140 | + * @param int $stud_id |
|
141 | 141 | * @param string $type |
142 | 142 | * |
143 | - * @return array|null |
|
144 | - */ |
|
145 | - public function calc_score($stud_id = null, $type = null) |
|
146 | - { |
|
143 | + * @return array|null |
|
144 | + */ |
|
145 | + public function calc_score($stud_id = null, $type = null) |
|
146 | + { |
|
147 | 147 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
148 | 148 | $threadInfo = get_thread_information($this->get_ref_id()); |
149 | 149 | |
150 | - $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
150 | + $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
151 | 151 | |
152 | - $sql = 'SELECT thread_qualify_max |
|
152 | + $sql = 'SELECT thread_qualify_max |
|
153 | 153 | FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)." |
154 | 154 | WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'"; |
155 | - $query = Database::query($sql); |
|
156 | - $assignment = Database::fetch_array($query); |
|
155 | + $query = Database::query($sql); |
|
156 | + $assignment = Database::fetch_array($query); |
|
157 | 157 | |
158 | - $sql = "SELECT * FROM $thread_qualify |
|
158 | + $sql = "SELECT * FROM $thread_qualify |
|
159 | 159 | WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id(); |
160 | - if (isset($stud_id)) { |
|
161 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
162 | - } |
|
160 | + if (isset($stud_id)) { |
|
161 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
162 | + } |
|
163 | 163 | |
164 | - // order by id, that way the student's first attempt is accessed first |
|
165 | - $sql .= ' ORDER BY qualify_time DESC'; |
|
164 | + // order by id, that way the student's first attempt is accessed first |
|
165 | + $sql .= ' ORDER BY qualify_time DESC'; |
|
166 | 166 | |
167 | - $scores = Database::query($sql); |
|
167 | + $scores = Database::query($sql); |
|
168 | 168 | |
169 | - // for 1 student |
|
170 | - if (isset($stud_id)) { |
|
169 | + // for 1 student |
|
170 | + if (isset($stud_id)) { |
|
171 | 171 | if ($threadInfo['thread_peer_qualify'] == 0) { |
172 | 172 | // Classic way of calculate score |
173 | 173 | if ($data = Database::fetch_array($scores)) { |
@@ -195,174 +195,174 @@ discard block |
||
195 | 195 | } |
196 | 196 | return [$score/$counter, $assignment['thread_qualify_max']]; |
197 | 197 | } |
198 | - } else { |
|
199 | - // All students -> get average |
|
200 | - $students = array(); // user list, needed to make sure we only |
|
201 | - // take first attempts into account |
|
202 | - $counter = 0; |
|
203 | - $sum = 0; |
|
204 | - $bestResult = 0; |
|
205 | - $weight = 0; |
|
206 | - $sumResult = 0; |
|
207 | - |
|
208 | - while ($data = Database::fetch_array($scores)) { |
|
209 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
210 | - if ($assignment['thread_qualify_max'] != 0) { |
|
211 | - $students[$data['user_id']] = $data['qualify']; |
|
212 | - $counter++; |
|
213 | - $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
214 | - $sumResult += $data['qualify']; |
|
215 | - if ($data['qualify'] > $bestResult) { |
|
216 | - $bestResult = $data['qualify']; |
|
217 | - } |
|
218 | - $weight = $assignment['thread_qualify_max']; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - if ($counter == 0) { |
|
224 | - return null; |
|
225 | - } else { |
|
226 | - switch ($type) { |
|
227 | - case 'best': |
|
228 | - return array($bestResult, $weight); |
|
229 | - break; |
|
230 | - case 'average': |
|
231 | - return array($sumResult/$counter, $weight); |
|
232 | - break; |
|
233 | - case 'ranking': |
|
234 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
235 | - break; |
|
236 | - default: |
|
237 | - return array($sum, $counter); |
|
238 | - break; |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Lazy load function to get the database table of the student publications |
|
246 | - */ |
|
247 | - private function get_forum_thread_table() |
|
248 | - { |
|
249 | - return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
250 | - } |
|
251 | - |
|
252 | - public function needs_name_and_description() |
|
253 | - { |
|
254 | - return false; |
|
255 | - } |
|
256 | - |
|
257 | - public function needs_max() |
|
258 | - { |
|
259 | - return false; |
|
260 | - } |
|
261 | - |
|
262 | - public function needs_results() |
|
263 | - { |
|
264 | - return false; |
|
265 | - } |
|
198 | + } else { |
|
199 | + // All students -> get average |
|
200 | + $students = array(); // user list, needed to make sure we only |
|
201 | + // take first attempts into account |
|
202 | + $counter = 0; |
|
203 | + $sum = 0; |
|
204 | + $bestResult = 0; |
|
205 | + $weight = 0; |
|
206 | + $sumResult = 0; |
|
207 | + |
|
208 | + while ($data = Database::fetch_array($scores)) { |
|
209 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
210 | + if ($assignment['thread_qualify_max'] != 0) { |
|
211 | + $students[$data['user_id']] = $data['qualify']; |
|
212 | + $counter++; |
|
213 | + $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
214 | + $sumResult += $data['qualify']; |
|
215 | + if ($data['qualify'] > $bestResult) { |
|
216 | + $bestResult = $data['qualify']; |
|
217 | + } |
|
218 | + $weight = $assignment['thread_qualify_max']; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + if ($counter == 0) { |
|
224 | + return null; |
|
225 | + } else { |
|
226 | + switch ($type) { |
|
227 | + case 'best': |
|
228 | + return array($bestResult, $weight); |
|
229 | + break; |
|
230 | + case 'average': |
|
231 | + return array($sumResult/$counter, $weight); |
|
232 | + break; |
|
233 | + case 'ranking': |
|
234 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
235 | + break; |
|
236 | + default: |
|
237 | + return array($sum, $counter); |
|
238 | + break; |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Lazy load function to get the database table of the student publications |
|
246 | + */ |
|
247 | + private function get_forum_thread_table() |
|
248 | + { |
|
249 | + return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
250 | + } |
|
251 | + |
|
252 | + public function needs_name_and_description() |
|
253 | + { |
|
254 | + return false; |
|
255 | + } |
|
256 | + |
|
257 | + public function needs_max() |
|
258 | + { |
|
259 | + return false; |
|
260 | + } |
|
261 | + |
|
262 | + public function needs_results() |
|
263 | + { |
|
264 | + return false; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | 268 | * @return string |
269 | 269 | */ |
270 | - public function get_name() |
|
271 | - { |
|
272 | - $this->get_exercise_data(); |
|
273 | - $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | - $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | - if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
276 | - return $this->exercise_data['thread_title_qualify']; |
|
277 | - } else { |
|
278 | - return $thread_title; |
|
279 | - } |
|
280 | - } |
|
270 | + public function get_name() |
|
271 | + { |
|
272 | + $this->get_exercise_data(); |
|
273 | + $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | + $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | + if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
276 | + return $this->exercise_data['thread_title_qualify']; |
|
277 | + } else { |
|
278 | + return $thread_title; |
|
279 | + } |
|
280 | + } |
|
281 | 281 | |
282 | 282 | /** |
283 | 283 | * @return string |
284 | 284 | */ |
285 | - public function get_description() |
|
286 | - { |
|
287 | - return '';//$this->exercise_data['description']; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Check if this still links to an exercise |
|
292 | - */ |
|
293 | - public function is_valid_link() |
|
294 | - { |
|
295 | - $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
285 | + public function get_description() |
|
286 | + { |
|
287 | + return '';//$this->exercise_data['description']; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Check if this still links to an exercise |
|
292 | + */ |
|
293 | + public function is_valid_link() |
|
294 | + { |
|
295 | + $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
296 | 296 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().''; |
297 | - $result = Database::query($sql); |
|
298 | - $number = Database::fetch_row($result); |
|
299 | - return ($number[0] != 0); |
|
300 | - } |
|
301 | - |
|
302 | - public function get_test_id() |
|
303 | - { |
|
304 | - return 'DEBUG:ID'; |
|
305 | - } |
|
306 | - |
|
307 | - public function get_link() |
|
308 | - { |
|
309 | - //it was extracts the forum id |
|
310 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
297 | + $result = Database::query($sql); |
|
298 | + $number = Database::fetch_row($result); |
|
299 | + return ($number[0] != 0); |
|
300 | + } |
|
301 | + |
|
302 | + public function get_test_id() |
|
303 | + { |
|
304 | + return 'DEBUG:ID'; |
|
305 | + } |
|
306 | + |
|
307 | + public function get_link() |
|
308 | + { |
|
309 | + //it was extracts the forum id |
|
310 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
311 | 311 | WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id().""; |
312 | - $result = Database::query($sql); |
|
313 | - $row = Database::fetch_array($result,'ASSOC'); |
|
314 | - $forum_id=$row['forum_id']; |
|
315 | - |
|
316 | - $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
317 | - return $url; |
|
318 | - } |
|
319 | - |
|
320 | - private function get_exercise_data() |
|
321 | - { |
|
322 | - $session_id = api_get_session_id(); |
|
323 | - if ($session_id) { |
|
324 | - $session_condition = 'session_id='.api_get_session_id(); |
|
325 | - } else { |
|
326 | - $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
327 | - } |
|
328 | - |
|
329 | - if (!isset($this->exercise_data)) { |
|
330 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
312 | + $result = Database::query($sql); |
|
313 | + $row = Database::fetch_array($result,'ASSOC'); |
|
314 | + $forum_id=$row['forum_id']; |
|
315 | + |
|
316 | + $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
317 | + return $url; |
|
318 | + } |
|
319 | + |
|
320 | + private function get_exercise_data() |
|
321 | + { |
|
322 | + $session_id = api_get_session_id(); |
|
323 | + if ($session_id) { |
|
324 | + $session_condition = 'session_id='.api_get_session_id(); |
|
325 | + } else { |
|
326 | + $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
327 | + } |
|
328 | + |
|
329 | + if (!isset($this->exercise_data)) { |
|
330 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
331 | 331 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND '.$session_condition; |
332 | - $query = Database::query($sql); |
|
333 | - $this->exercise_data = Database::fetch_array($query); |
|
334 | - } |
|
335 | - return $this->exercise_data; |
|
336 | - } |
|
337 | - |
|
338 | - public function get_icon_name() |
|
339 | - { |
|
340 | - return 'forum'; |
|
341 | - } |
|
342 | - |
|
343 | - function save_linked_data() |
|
344 | - { |
|
345 | - $weight = (float)$this->get_weight(); |
|
346 | - $ref_id = $this->get_ref_id(); |
|
347 | - |
|
348 | - if (!empty($ref_id)) { |
|
349 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
332 | + $query = Database::query($sql); |
|
333 | + $this->exercise_data = Database::fetch_array($query); |
|
334 | + } |
|
335 | + return $this->exercise_data; |
|
336 | + } |
|
337 | + |
|
338 | + public function get_icon_name() |
|
339 | + { |
|
340 | + return 'forum'; |
|
341 | + } |
|
342 | + |
|
343 | + function save_linked_data() |
|
344 | + { |
|
345 | + $weight = (float)$this->get_weight(); |
|
346 | + $ref_id = $this->get_ref_id(); |
|
347 | + |
|
348 | + if (!empty($ref_id)) { |
|
349 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
350 | 350 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
351 | - Database::query($sql); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - function delete_linked_data() |
|
356 | - { |
|
357 | - $ref_id = $this->get_ref_id(); |
|
358 | - if (!empty($ref_id)) { |
|
359 | - //Cleans forum |
|
360 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
351 | + Database::query($sql); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + function delete_linked_data() |
|
356 | + { |
|
357 | + $ref_id = $this->get_ref_id(); |
|
358 | + if (!empty($ref_id)) { |
|
359 | + //Cleans forum |
|
360 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
361 | 361 | thread_qualify_max = 0, |
362 | 362 | thread_weight = 0, |
363 | 363 | thread_title_qualify = "" |
364 | 364 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
365 | - Database::query($sql); |
|
366 | - } |
|
367 | - } |
|
365 | + Database::query($sql); |
|
366 | + } |
|
367 | + } |
|
368 | 368 | } |