Completed
Push — 1.11.x ( 6904fa...6a92e6 )
by José
525:44 queued 484:20
created
main/document/create_draw.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -46,59 +46,59 @@  discard block
 block discarded – undo
46 46
 // Please, do not modify this dirname formatting
47 47
 
48 48
 if (strstr($dir, '..')) {
49
-	$dir = '/';
49
+    $dir = '/';
50 50
 }
51 51
 
52 52
 if ($dir[0] == '.') {
53
-	$dir = substr($dir, 1);
53
+    $dir = substr($dir, 1);
54 54
 }
55 55
 
56 56
 if ($dir[0] != '/') {
57
-	$dir = '/'.$dir;
57
+    $dir = '/'.$dir;
58 58
 }
59 59
 
60 60
 if ($dir[strlen($dir) - 1] != '/') {
61
-	$dir .= '/';
61
+    $dir .= '/';
62 62
 }
63 63
 
64 64
 $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
65 65
 
66 66
 if (!is_dir($filepath)) {
67
-	$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
68
-	$dir = '/';
67
+    $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
68
+    $dir = '/';
69 69
 }
70 70
 
71 71
 $groupId = api_get_group_id();
72 72
 
73 73
 if (!empty($groupId)) {
74
-	$interbreadcrumb[] = array (
74
+    $interbreadcrumb[] = array (
75 75
         "url" => "../group/group_space.php?".api_get_cidreq(),
76 76
         "name" => get_lang('GroupSpace')
77 77
     );
78
-	$noPHP_SELF = true;
79
-	$group = GroupManager :: get_group_properties($groupId);
80
-	$path = explode('/', $dir);
81
-	if ('/'.$path[1] != $group['directory']) {
82
-		api_not_allowed(true);
83
-	}
78
+    $noPHP_SELF = true;
79
+    $group = GroupManager :: get_group_properties($groupId);
80
+    $path = explode('/', $dir);
81
+    if ('/'.$path[1] != $group['directory']) {
82
+        api_not_allowed(true);
83
+    }
84 84
 }
85 85
 
86 86
 $interbreadcrumb[] = array(
87
-	"url" => "./document.php?".api_get_cidreq(),
88
-	"name" => get_lang('Documents')
87
+    "url" => "./document.php?".api_get_cidreq(),
88
+    "name" => get_lang('Documents')
89 89
 );
90 90
 
91 91
 if (!$is_allowed_in_course) {
92
-	api_not_allowed(true);
92
+    api_not_allowed(true);
93 93
 }
94 94
 
95 95
 if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] ||
96
-	DocumentManager::is_my_shared_folder(
97
-		api_get_user_id(),
98
-		Security::remove_XSS($dir),
99
-		api_get_session_id()))
96
+    DocumentManager::is_my_shared_folder(
97
+        api_get_user_id(),
98
+        Security::remove_XSS($dir),
99
+        api_get_session_id()))
100 100
 ) {
101
-	api_not_allowed(true);
101
+    api_not_allowed(true);
102 102
 }
103 103
 
104 104
 
@@ -106,10 +106,10 @@  discard block
 block discarded – undo
106 106
 Event::event_access_tool(TOOL_DOCUMENT);
107 107
 $display_dir = $dir;
108 108
 if (isset ($group)) {
109
-	$display_dir = explode('/', $dir);
110
-	unset ($display_dir[0]);
111
-	unset ($display_dir[1]);
112
-	$display_dir = implode('/', $display_dir);
109
+    $display_dir = explode('/', $dir);
110
+    unset ($display_dir[0]);
111
+    unset ($display_dir[1]);
112
+    $display_dir = implode('/', $display_dir);
113 113
 }
114 114
 
115 115
 // Interbreadcrumb for the current directory root path
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 } else {
124 124
     foreach ($document_data['parents'] as $document_sub_data) {
125 125
         $interbreadcrumb[] = array(
126
-			'url' => $document_sub_data['document_url'],
127
-			'name' => $document_sub_data['title']
128
-		);
126
+            'url' => $document_sub_data['document_url'],
127
+            'name' => $document_sub_data['title']
128
+        );
129 129
     }
130 130
 }
131 131
 Display :: display_header($nameTools, 'Doc');
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
 
138 138
 if (api_browser_support('svg')) {
139 139
 
140
-	//automatic loading the course language
141
-	$svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
142
-	$langsvgedit = api_get_language_isocode();
143
-	$langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
144
-	$langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
145
-	$svg_url= api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?lang='.$langsvgedit;
146
-	?>
140
+    //automatic loading the course language
141
+    $svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
142
+    $langsvgedit = api_get_language_isocode();
143
+    $langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
144
+    $langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
145
+    $svg_url= api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?lang='.$langsvgedit;
146
+    ?>
147 147
 	<script>
148 148
 		document.write ('<iframe id="frame" frameborder="0" scrolling="no" src="<?php echo  $svg_url; ?>" width="100%" height="100%"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>');
149 149
         function resizeIframe() {
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 
162 162
     <?php
163 163
     echo '<noscript>';
164
-	echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0" src="'.$svg_url.'"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
165
-	echo '</noscript>';
164
+    echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0" src="'.$svg_url.'"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
165
+    echo '</noscript>';
166 166
 } else {
167
-	Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
167
+    Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
168 168
 }
169 169
 
170 170
 Display :: display_footer();
Please login to merge, or discard this patch.
main/inc/lib/icalcreator/iCalcreator.class.php 1 patch
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
  * @author Patrick Cool
17 17
  * @author René Haentjens, added CSV file import (October 2004)
18 18
  * @package chamilo.link
19
-
20 19
  */
21 20
 
22 21
 // Including libraries
Please login to merge, or discard this patch.
external_login/facebook-php-sdk/src/Facebook/Entities/SignedRequest.php 1 patch
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -33,99 +33,99 @@  discard block
 block discarded – undo
33 33
 class SignedRequest
34 34
 {
35 35
 
36
-  /**
37
-   * @var string
38
-   */
39
-  public $rawSignedRequest;
40
-
41
-  /**
42
-   * @var array
43
-   */
44
-  public $payload;
45
-
46
-  /**
47
-   * Instantiate a new SignedRequest entity.
48
-   *
49
-   * @param string|null $rawSignedRequest The raw signed request.
50
-   * @param string|null $state random string to prevent CSRF.
51
-   * @param string|null $appSecret
52
-   */
53
-  public function __construct($rawSignedRequest = null, $state = null, $appSecret = null)
54
-  {
36
+    /**
37
+     * @var string
38
+     */
39
+    public $rawSignedRequest;
40
+
41
+    /**
42
+     * @var array
43
+     */
44
+    public $payload;
45
+
46
+    /**
47
+     * Instantiate a new SignedRequest entity.
48
+     *
49
+     * @param string|null $rawSignedRequest The raw signed request.
50
+     * @param string|null $state random string to prevent CSRF.
51
+     * @param string|null $appSecret
52
+     */
53
+    public function __construct($rawSignedRequest = null, $state = null, $appSecret = null)
54
+    {
55 55
     if (!$rawSignedRequest) {
56
-      return;
56
+        return;
57 57
     }
58 58
 
59 59
     $this->rawSignedRequest = $rawSignedRequest;
60 60
     $this->payload = static::parse($rawSignedRequest, $state, $appSecret);
61
-  }
62
-
63
-  /**
64
-   * Returns the raw signed request data.
65
-   *
66
-   * @return string
67
-   */
68
-  public function getRawSignedRequest()
69
-  {
61
+    }
62
+
63
+    /**
64
+     * Returns the raw signed request data.
65
+     *
66
+     * @return string
67
+     */
68
+    public function getRawSignedRequest()
69
+    {
70 70
     return $this->rawSignedRequest;
71
-  }
72
-
73
-  /**
74
-   * Returns the parsed signed request data.
75
-   *
76
-   * @return array|null
77
-   */
78
-  public function getPayload()
79
-  {
71
+    }
72
+
73
+    /**
74
+     * Returns the parsed signed request data.
75
+     *
76
+     * @return array|null
77
+     */
78
+    public function getPayload()
79
+    {
80 80
     return $this->payload;
81
-  }
82
-
83
-  /**
84
-   * Returns a property from the signed request data if available.
85
-   *
86
-   * @param string $key
87
-   * @param integer $default
88
-   *
89
-   * @return mixed|null
90
-   */
91
-  public function get($key, $default = null)
92
-  {
81
+    }
82
+
83
+    /**
84
+     * Returns a property from the signed request data if available.
85
+     *
86
+     * @param string $key
87
+     * @param integer $default
88
+     *
89
+     * @return mixed|null
90
+     */
91
+    public function get($key, $default = null)
92
+    {
93 93
     if (isset($this->payload[$key])) {
94
-      return $this->payload[$key];
94
+        return $this->payload[$key];
95 95
     }
96 96
     return $default;
97
-  }
98
-
99
-  /**
100
-   * Returns user_id from signed request data if available.
101
-   *
102
-   * @return string|null
103
-   */
104
-  public function getUserId()
105
-  {
97
+    }
98
+
99
+    /**
100
+     * Returns user_id from signed request data if available.
101
+     *
102
+     * @return string|null
103
+     */
104
+    public function getUserId()
105
+    {
106 106
     return $this->get('user_id');
107
-  }
108
-
109
-  /**
110
-   * Checks for OAuth data in the payload.
111
-   *
112
-   * @return boolean
113
-   */
114
-  public function hasOAuthData()
115
-  {
107
+    }
108
+
109
+    /**
110
+     * Checks for OAuth data in the payload.
111
+     *
112
+     * @return boolean
113
+     */
114
+    public function hasOAuthData()
115
+    {
116 116
     return isset($this->payload['oauth_token']) || isset($this->payload['code']);
117
-  }
118
-
119
-  /**
120
-   * Creates a signed request from an array of data.
121
-   *
122
-   * @param array $payload
123
-   * @param string|null $appSecret
124
-   *
125
-   * @return string
126
-   */
127
-  public static function make(array $payload, $appSecret = null)
128
-  {
117
+    }
118
+
119
+    /**
120
+     * Creates a signed request from an array of data.
121
+     *
122
+     * @param array $payload
123
+     * @param string|null $appSecret
124
+     *
125
+     * @return string
126
+     */
127
+    public static function make(array $payload, $appSecret = null)
128
+    {
129 129
     $payload['algorithm'] = 'HMAC-SHA256';
130 130
     $payload['issued_at'] = time();
131 131
     $encodedPayload = static::base64UrlEncode(json_encode($payload));
@@ -134,20 +134,20 @@  discard block
 block discarded – undo
134 134
     $encodedSig = static::base64UrlEncode($hashedSig);
135 135
 
136 136
     return $encodedSig.'.'.$encodedPayload;
137
-  }
138
-
139
-  /**
140
-   * Validates and decodes a signed request and returns
141
-   * the payload as an array.
142
-   *
143
-   * @param string $signedRequest
144
-   * @param string|null $state
145
-   * @param string|null $appSecret
146
-   *
147
-   * @return array
148
-   */
149
-  public static function parse($signedRequest, $state = null, $appSecret = null)
150
-  {
137
+    }
138
+
139
+    /**
140
+     * Validates and decodes a signed request and returns
141
+     * the payload as an array.
142
+     *
143
+     * @param string $signedRequest
144
+     * @param string|null $state
145
+     * @param string|null $appSecret
146
+     *
147
+     * @return array
148
+     */
149
+    public static function parse($signedRequest, $state = null, $appSecret = null)
150
+    {
151 151
     list($encodedSig, $encodedPayload) = static::split($signedRequest);
152 152
 
153 153
     // Signature validation
@@ -159,228 +159,228 @@  discard block
 block discarded – undo
159 159
     $data = static::decodePayload($encodedPayload);
160 160
     static::validateAlgorithm($data);
161 161
     if ($state) {
162
-      static::validateCsrf($data, $state);
162
+        static::validateCsrf($data, $state);
163 163
     }
164 164
 
165 165
     return $data;
166
-  }
167
-
168
-  /**
169
-   * Validates the format of a signed request.
170
-   *
171
-   * @param string $signedRequest
172
-   *
173
-   * @throws FacebookSDKException
174
-   */
175
-  public static function validateFormat($signedRequest)
176
-  {
166
+    }
167
+
168
+    /**
169
+     * Validates the format of a signed request.
170
+     *
171
+     * @param string $signedRequest
172
+     *
173
+     * @throws FacebookSDKException
174
+     */
175
+    public static function validateFormat($signedRequest)
176
+    {
177 177
     if (strpos($signedRequest, '.') !== false) {
178
-      return;
178
+        return;
179 179
     }
180 180
 
181 181
     throw new FacebookSDKException(
182
-      'Malformed signed request.', 606
182
+        'Malformed signed request.', 606
183 183
     );
184
-  }
185
-
186
-  /**
187
-   * Decodes a raw valid signed request.
188
-   *
189
-   * @param string $signedRequest
190
-   *
191
-   * @returns array
192
-   */
193
-  public static function split($signedRequest)
194
-  {
184
+    }
185
+
186
+    /**
187
+     * Decodes a raw valid signed request.
188
+     *
189
+     * @param string $signedRequest
190
+     *
191
+     * @returns array
192
+     */
193
+    public static function split($signedRequest)
194
+    {
195 195
     static::validateFormat($signedRequest);
196 196
 
197 197
     return explode('.', $signedRequest, 2);
198
-  }
199
-
200
-  /**
201
-   * Decodes the raw signature from a signed request.
202
-   *
203
-   * @param string $encodedSig
204
-   *
205
-   * @returns string
206
-   *
207
-   * @throws FacebookSDKException
208
-   */
209
-  public static function decodeSignature($encodedSig)
210
-  {
198
+    }
199
+
200
+    /**
201
+     * Decodes the raw signature from a signed request.
202
+     *
203
+     * @param string $encodedSig
204
+     *
205
+     * @returns string
206
+     *
207
+     * @throws FacebookSDKException
208
+     */
209
+    public static function decodeSignature($encodedSig)
210
+    {
211 211
     $sig = static::base64UrlDecode($encodedSig);
212 212
 
213 213
     if ($sig) {
214
-      return $sig;
214
+        return $sig;
215 215
     }
216 216
 
217 217
     throw new FacebookSDKException(
218
-      'Signed request has malformed encoded signature data.', 607
218
+        'Signed request has malformed encoded signature data.', 607
219 219
     );
220
-  }
221
-
222
-  /**
223
-   * Decodes the raw payload from a signed request.
224
-   *
225
-   * @param string $encodedPayload
226
-   *
227
-   * @returns array
228
-   *
229
-   * @throws FacebookSDKException
230
-   */
231
-  public static function decodePayload($encodedPayload)
232
-  {
220
+    }
221
+
222
+    /**
223
+     * Decodes the raw payload from a signed request.
224
+     *
225
+     * @param string $encodedPayload
226
+     *
227
+     * @returns array
228
+     *
229
+     * @throws FacebookSDKException
230
+     */
231
+    public static function decodePayload($encodedPayload)
232
+    {
233 233
     $payload = static::base64UrlDecode($encodedPayload);
234 234
 
235 235
     if ($payload) {
236
-      $payload = json_decode($payload, true);
236
+        $payload = json_decode($payload, true);
237 237
     }
238 238
 
239 239
     if (is_array($payload)) {
240
-      return $payload;
240
+        return $payload;
241 241
     }
242 242
 
243 243
     throw new FacebookSDKException(
244
-      'Signed request has malformed encoded payload data.', 607
244
+        'Signed request has malformed encoded payload data.', 607
245 245
     );
246
-  }
247
-
248
-  /**
249
-   * Validates the algorithm used in a signed request.
250
-   *
251
-   * @param array $data
252
-   *
253
-   * @throws FacebookSDKException
254
-   */
255
-  public static function validateAlgorithm(array $data)
256
-  {
246
+    }
247
+
248
+    /**
249
+     * Validates the algorithm used in a signed request.
250
+     *
251
+     * @param array $data
252
+     *
253
+     * @throws FacebookSDKException
254
+     */
255
+    public static function validateAlgorithm(array $data)
256
+    {
257 257
     if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') {
258
-      return;
258
+        return;
259 259
     }
260 260
 
261 261
     throw new FacebookSDKException(
262
-      'Signed request is using the wrong algorithm.', 605
262
+        'Signed request is using the wrong algorithm.', 605
263 263
     );
264
-  }
265
-
266
-  /**
267
-   * Hashes the signature used in a signed request.
268
-   *
269
-   * @param string $encodedData
270
-   * @param string|null $appSecret
271
-   *
272
-   * @return string
273
-   *
274
-   * @throws FacebookSDKException
275
-   */
276
-  public static function hashSignature($encodedData, $appSecret = null)
277
-  {
264
+    }
265
+
266
+    /**
267
+     * Hashes the signature used in a signed request.
268
+     *
269
+     * @param string $encodedData
270
+     * @param string|null $appSecret
271
+     *
272
+     * @return string
273
+     *
274
+     * @throws FacebookSDKException
275
+     */
276
+    public static function hashSignature($encodedData, $appSecret = null)
277
+    {
278 278
     $hashedSig = hash_hmac(
279
-      'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true
279
+        'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true
280 280
     );
281 281
 
282 282
     if ($hashedSig) {
283
-      return $hashedSig;
283
+        return $hashedSig;
284 284
     }
285 285
 
286 286
     throw new FacebookSDKException(
287
-      'Unable to hash signature from encoded payload data.', 602
287
+        'Unable to hash signature from encoded payload data.', 602
288 288
     );
289
-  }
290
-
291
-  /**
292
-   * Validates the signature used in a signed request.
293
-   *
294
-   * @param string $hashedSig
295
-   * @param string $sig
296
-   *
297
-   * @throws FacebookSDKException
298
-   */
299
-  public static function validateSignature($hashedSig, $sig)
300
-  {
289
+    }
290
+
291
+    /**
292
+     * Validates the signature used in a signed request.
293
+     *
294
+     * @param string $hashedSig
295
+     * @param string $sig
296
+     *
297
+     * @throws FacebookSDKException
298
+     */
299
+    public static function validateSignature($hashedSig, $sig)
300
+    {
301 301
     if (mb_strlen($hashedSig) === mb_strlen($sig)) {
302
-      $validate = 0;
303
-      for ($i = 0; $i < mb_strlen($sig); $i++) {
302
+        $validate = 0;
303
+        for ($i = 0; $i < mb_strlen($sig); $i++) {
304 304
         $validate |= ord($hashedSig[$i]) ^ ord($sig[$i]);
305
-      }
306
-      if ($validate === 0) {
305
+        }
306
+        if ($validate === 0) {
307 307
         return;
308
-      }
308
+        }
309 309
     }
310 310
 
311 311
     throw new FacebookSDKException(
312
-      'Signed request has an invalid signature.', 602
312
+        'Signed request has an invalid signature.', 602
313 313
     );
314
-  }
315
-
316
-  /**
317
-   * Validates a signed request against CSRF.
318
-   *
319
-   * @param array $data
320
-   * @param string $state
321
-   *
322
-   * @throws FacebookSDKException
323
-   */
324
-  public static function validateCsrf(array $data, $state)
325
-  {
314
+    }
315
+
316
+    /**
317
+     * Validates a signed request against CSRF.
318
+     *
319
+     * @param array $data
320
+     * @param string $state
321
+     *
322
+     * @throws FacebookSDKException
323
+     */
324
+    public static function validateCsrf(array $data, $state)
325
+    {
326 326
     if (isset($data['state']) && $data['state'] === $state) {
327
-      return;
327
+        return;
328 328
     }
329 329
 
330 330
     throw new FacebookSDKException(
331
-      'Signed request did not pass CSRF validation.', 604
331
+        'Signed request did not pass CSRF validation.', 604
332 332
     );
333
-  }
334
-
335
-  /**
336
-   * Base64 decoding which replaces characters:
337
-   *   + instead of -
338
-   *   / instead of _
339
-   * @link http://en.wikipedia.org/wiki/Base64#URL_applications
340
-   *
341
-   * @param string $input base64 url encoded input
342
-   *
343
-   * @return string decoded string
344
-   */
345
-  public static function base64UrlDecode($input)
346
-  {
333
+    }
334
+
335
+    /**
336
+     * Base64 decoding which replaces characters:
337
+     *   + instead of -
338
+     *   / instead of _
339
+     * @link http://en.wikipedia.org/wiki/Base64#URL_applications
340
+     *
341
+     * @param string $input base64 url encoded input
342
+     *
343
+     * @return string decoded string
344
+     */
345
+    public static function base64UrlDecode($input)
346
+    {
347 347
     $urlDecodedBase64 = strtr($input, '-_', '+/');
348 348
     static::validateBase64($urlDecodedBase64);
349 349
     return base64_decode($urlDecodedBase64);
350
-  }
351
-
352
-  /**
353
-   * Base64 encoding which replaces characters:
354
-   *   + instead of -
355
-   *   / instead of _
356
-   * @link http://en.wikipedia.org/wiki/Base64#URL_applications
357
-   *
358
-   * @param string $input string to encode
359
-   *
360
-   * @return string base64 url encoded input
361
-   */
362
-  public static function base64UrlEncode($input)
363
-  {
350
+    }
351
+
352
+    /**
353
+     * Base64 encoding which replaces characters:
354
+     *   + instead of -
355
+     *   / instead of _
356
+     * @link http://en.wikipedia.org/wiki/Base64#URL_applications
357
+     *
358
+     * @param string $input string to encode
359
+     *
360
+     * @return string base64 url encoded input
361
+     */
362
+    public static function base64UrlEncode($input)
363
+    {
364 364
     return strtr(base64_encode($input), '+/', '-_');
365
-  }
366
-
367
-  /**
368
-   * Validates a base64 string.
369
-   *
370
-   * @param string $input base64 value to validate
371
-   *
372
-   * @throws FacebookSDKException
373
-   */
374
-  public static function validateBase64($input)
375
-  {
365
+    }
366
+
367
+    /**
368
+     * Validates a base64 string.
369
+     *
370
+     * @param string $input base64 value to validate
371
+     *
372
+     * @throws FacebookSDKException
373
+     */
374
+    public static function validateBase64($input)
375
+    {
376 376
     $pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/';
377 377
     if (preg_match($pattern, $input)) {
378
-      return;
378
+        return;
379 379
     }
380 380
 
381 381
     throw new FacebookSDKException(
382
-      'Signed request contains malformed base64 encoding.', 608
382
+        'Signed request contains malformed base64 encoding.', 608
383 383
     );
384
-  }
384
+    }
385 385
 
386 386
 }
Please login to merge, or discard this patch.
auth/external_login/facebook-php-sdk/src/Facebook/Entities/AccessToken.php 1 patch
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -35,120 +35,120 @@  discard block
 block discarded – undo
35 35
 class AccessToken
36 36
 {
37 37
 
38
-  /**
39
-   * The access token.
40
-   *
41
-   * @var string
42
-   */
43
-  protected $accessToken;
44
-
45
-  /**
46
-   * A unique ID to identify a client.
47
-   *
48
-   * @var string
49
-   */
50
-  protected $machineId;
51
-
52
-  /**
53
-   * Date when token expires.
54
-   *
55
-   * @var \DateTime|null
56
-   */
57
-  protected $expiresAt;
58
-
59
-  /**
60
-   * Create a new access token entity.
61
-   *
62
-   * @param string $accessToken
63
-   * @param int $expiresAt
64
-   * @param string|null machineId
65
-   * @param string $machineId
66
-   */
67
-  public function __construct($accessToken, $expiresAt = 0, $machineId = null)
68
-  {
38
+    /**
39
+     * The access token.
40
+     *
41
+     * @var string
42
+     */
43
+    protected $accessToken;
44
+
45
+    /**
46
+     * A unique ID to identify a client.
47
+     *
48
+     * @var string
49
+     */
50
+    protected $machineId;
51
+
52
+    /**
53
+     * Date when token expires.
54
+     *
55
+     * @var \DateTime|null
56
+     */
57
+    protected $expiresAt;
58
+
59
+    /**
60
+     * Create a new access token entity.
61
+     *
62
+     * @param string $accessToken
63
+     * @param int $expiresAt
64
+     * @param string|null machineId
65
+     * @param string $machineId
66
+     */
67
+    public function __construct($accessToken, $expiresAt = 0, $machineId = null)
68
+    {
69 69
     $this->accessToken = $accessToken;
70 70
     if ($expiresAt) {
71
-      $this->setExpiresAtFromTimeStamp($expiresAt);
71
+        $this->setExpiresAtFromTimeStamp($expiresAt);
72 72
     }
73 73
     $this->machineId = $machineId;
74
-  }
75
-
76
-  /**
77
-   * Setter for expires_at.
78
-   *
79
-   * @param int $timeStamp
80
-   */
81
-  protected function setExpiresAtFromTimeStamp($timeStamp)
82
-  {
74
+    }
75
+
76
+    /**
77
+     * Setter for expires_at.
78
+     *
79
+     * @param int $timeStamp
80
+     */
81
+    protected function setExpiresAtFromTimeStamp($timeStamp)
82
+    {
83 83
     $dt = new \DateTime();
84 84
     $dt->setTimestamp($timeStamp);
85 85
     $this->expiresAt = $dt;
86
-  }
87
-
88
-  /**
89
-   * Getter for expiresAt.
90
-   *
91
-   * @return \DateTime|null
92
-   */
93
-  public function getExpiresAt()
94
-  {
86
+    }
87
+
88
+    /**
89
+     * Getter for expiresAt.
90
+     *
91
+     * @return \DateTime|null
92
+     */
93
+    public function getExpiresAt()
94
+    {
95 95
     return $this->expiresAt;
96
-  }
97
-
98
-  /**
99
-   * Getter for machineId.
100
-   *
101
-   * @return string
102
-   */
103
-  public function getMachineId()
104
-  {
96
+    }
97
+
98
+    /**
99
+     * Getter for machineId.
100
+     *
101
+     * @return string
102
+     */
103
+    public function getMachineId()
104
+    {
105 105
     return $this->machineId;
106
-  }
107
-
108
-  /**
109
-   * Determines whether or not this is a long-lived token.
110
-   *
111
-   * @return bool
112
-   */
113
-  public function isLongLived()
114
-  {
106
+    }
107
+
108
+    /**
109
+     * Determines whether or not this is a long-lived token.
110
+     *
111
+     * @return bool
112
+     */
113
+    public function isLongLived()
114
+    {
115 115
     if ($this->expiresAt) {
116
-      return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2);
116
+        return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2);
117 117
     }
118 118
     return false;
119
-  }
120
-
121
-  /**
122
-   * Checks the validity of the access token.
123
-   *
124
-   * @param string|null $appId Application ID to use
125
-   * @param string|null $appSecret App secret value to use
126
-   * @param string|null $machineId
127
-   *
128
-   * @return boolean
129
-   */
130
-  public function isValid($appId = null, $appSecret = null, $machineId = null)
131
-  {
119
+    }
120
+
121
+    /**
122
+     * Checks the validity of the access token.
123
+     *
124
+     * @param string|null $appId Application ID to use
125
+     * @param string|null $appSecret App secret value to use
126
+     * @param string|null $machineId
127
+     *
128
+     * @return boolean
129
+     */
130
+    public function isValid($appId = null, $appSecret = null, $machineId = null)
131
+    {
132 132
     $accessTokenInfo = $this->getInfo($appId, $appSecret);
133 133
     $machineId = $machineId ?: $this->machineId;
134 134
     return static::validateAccessToken($accessTokenInfo, $appId, $machineId);
135
-  }
136
-
137
-  /**
138
-   * Ensures the provided GraphSessionInfo object is valid,
139
-   *   throwing an exception if not.  Ensures the appId matches,
140
-   *   that the machineId matches if it's being used,
141
-   *   that the token is valid and has not expired.
142
-   *
143
-   * @param GraphSessionInfo $tokenInfo
144
-   * @param string|null $appId Application ID to use
145
-   * @param string|null $machineId
146
-   *
147
-   * @return boolean
148
-   */
149
-  public static function validateAccessToken(GraphSessionInfo $tokenInfo,
150
-                                             $appId = null, $machineId = null)
151
-  {
135
+    }
136
+
137
+    /**
138
+     * Ensures the provided GraphSessionInfo object is valid,
139
+     *   throwing an exception if not.  Ensures the appId matches,
140
+     *   that the machineId matches if it's being used,
141
+     *   that the token is valid and has not expired.
142
+     *
143
+     * @param GraphSessionInfo $tokenInfo
144
+     * @param string|null $appId Application ID to use
145
+     * @param string|null $machineId
146
+     *
147
+     * @return boolean
148
+     */
149
+    public static function validateAccessToken(GraphSessionInfo $tokenInfo,
150
+                                                $appId = null, $machineId = null)
151
+    {
152 152
     $targetAppId = FacebookSession::_getTargetAppId($appId);
153 153
 
154 154
     $appIdIsValid = $tokenInfo->getAppId() == $targetAppId;
@@ -157,90 +157,90 @@  discard block
 block discarded – undo
157 157
 
158 158
     // Not all access tokens return an expiration. E.g. an app access token.
159 159
     if ($tokenInfo->getExpiresAt() instanceof \DateTime) {
160
-      $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time();
160
+        $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time();
161 161
     } else {
162
-      $accessTokenIsStillAlive = true;
162
+        $accessTokenIsStillAlive = true;
163 163
     }
164 164
 
165 165
     return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive;
166
-  }
167
-
168
-  /**
169
-   * Get a valid access token from a code.
170
-   *
171
-   * @param string $code
172
-   * @param string|null $appId
173
-   * @param string|null $appSecret
174
-   * @param string|null $machineId
175
-   *
176
-   * @return AccessToken
177
-   */
178
-  public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null)
179
-  {
166
+    }
167
+
168
+    /**
169
+     * Get a valid access token from a code.
170
+     *
171
+     * @param string $code
172
+     * @param string|null $appId
173
+     * @param string|null $appSecret
174
+     * @param string|null $machineId
175
+     *
176
+     * @return AccessToken
177
+     */
178
+    public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null)
179
+    {
180 180
     $params = array(
181
-      'code' => $code,
182
-      'redirect_uri' => '',
181
+        'code' => $code,
182
+        'redirect_uri' => '',
183 183
     );
184 184
 
185 185
     if ($machineId) {
186
-      $params['machine_id'] = $machineId;
186
+        $params['machine_id'] = $machineId;
187 187
     }
188 188
 
189 189
     return static::requestAccessToken($params, $appId, $appSecret);
190
-  }
191
-
192
-  /**
193
-   * Get a valid code from an access token.
194
-   *
195
-   * @param AccessToken $accessToken
196
-   * @param string|null $appId
197
-   * @param string|null $appSecret
198
-   *
199
-   * @return string
200
-   */
201
-  public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null)
202
-  {
190
+    }
191
+
192
+    /**
193
+     * Get a valid code from an access token.
194
+     *
195
+     * @param AccessToken $accessToken
196
+     * @param string|null $appId
197
+     * @param string|null $appSecret
198
+     *
199
+     * @return string
200
+     */
201
+    public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null)
202
+    {
203 203
     $accessToken = (string) $accessToken;
204 204
 
205 205
     $params = array(
206
-      'access_token' => $accessToken,
207
-      'redirect_uri' => '',
206
+        'access_token' => $accessToken,
207
+        'redirect_uri' => '',
208 208
     );
209 209
 
210 210
     return static::requestCode($params, $appId, $appSecret);
211
-  }
212
-
213
-  /**
214
-   * Exchanges a short lived access token with a long lived access token.
215
-   *
216
-   * @param string|null $appId
217
-   * @param string|null $appSecret
218
-   *
219
-   * @return AccessToken
220
-   */
221
-  public function extend($appId = null, $appSecret = null)
222
-  {
211
+    }
212
+
213
+    /**
214
+     * Exchanges a short lived access token with a long lived access token.
215
+     *
216
+     * @param string|null $appId
217
+     * @param string|null $appSecret
218
+     *
219
+     * @return AccessToken
220
+     */
221
+    public function extend($appId = null, $appSecret = null)
222
+    {
223 223
     $params = array(
224
-      'grant_type' => 'fb_exchange_token',
225
-      'fb_exchange_token' => $this->accessToken,
224
+        'grant_type' => 'fb_exchange_token',
225
+        'fb_exchange_token' => $this->accessToken,
226 226
     );
227 227
 
228 228
     return static::requestAccessToken($params, $appId, $appSecret);
229
-  }
230
-
231
-  /**
232
-   * Request an access token based on a set of params.
233
-   *
234
-   * @param array $params
235
-   * @param string|null $appId
236
-   * @param string|null $appSecret
237
-   *
238
-   * @return AccessToken
239
-   *
240
-   * @throws FacebookRequestException
241
-   */
242
-  public static function requestAccessToken(array $params, $appId = null, $appSecret = null)
243
-  {
229
+    }
230
+
231
+    /**
232
+     * Request an access token based on a set of params.
233
+     *
234
+     * @param array $params
235
+     * @param string|null $appId
236
+     * @param string|null $appSecret
237
+     *
238
+     * @return AccessToken
239
+     *
240
+     * @throws FacebookRequestException
241
+     */
242
+    public static function requestAccessToken(array $params, $appId = null, $appSecret = null)
243
+    {
244 244
     $response = static::request('/oauth/access_token', $params, $appId, $appSecret);
245 245
     $data = $response->getResponse();
246 246
 
@@ -249,133 +249,133 @@  discard block
 block discarded – undo
249 249
      * @see https://github.com/facebook/facebook-php-sdk-v4/issues/36
250 250
      */
251 251
     if (is_array($data)) {
252
-      if (isset($data['access_token'])) {
252
+        if (isset($data['access_token'])) {
253 253
         $expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0;
254 254
         return new static($data['access_token'], $expiresAt);
255
-      }
255
+        }
256 256
     } elseif($data instanceof \stdClass) {
257
-      if (isset($data->access_token)) {
257
+        if (isset($data->access_token)) {
258 258
         $expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0;
259 259
         $machineId = isset($data->machine_id) ? (string) $data->machine_id : null;
260 260
         return new static((string) $data->access_token, $expiresAt, $machineId);
261
-      }
261
+        }
262 262
     }
263 263
 
264 264
     throw FacebookRequestException::create(
265
-      $response->getRawResponse(),
266
-      $data,
267
-      401
265
+        $response->getRawResponse(),
266
+        $data,
267
+        401
268 268
     );
269
-  }
270
-
271
-  /**
272
-   * Request a code from a long lived access token.
273
-   *
274
-   * @param array $params
275
-   * @param string|null $appId
276
-   * @param string|null $appSecret
277
-   *
278
-   * @return string
279
-   *
280
-   * @throws FacebookRequestException
281
-   */
282
-  public static function requestCode(array $params, $appId = null, $appSecret = null)
283
-  {
269
+    }
270
+
271
+    /**
272
+     * Request a code from a long lived access token.
273
+     *
274
+     * @param array $params
275
+     * @param string|null $appId
276
+     * @param string|null $appSecret
277
+     *
278
+     * @return string
279
+     *
280
+     * @throws FacebookRequestException
281
+     */
282
+    public static function requestCode(array $params, $appId = null, $appSecret = null)
283
+    {
284 284
     $response = static::request('/oauth/client_code', $params, $appId, $appSecret);
285 285
     $data = $response->getResponse();
286 286
 
287 287
     if (isset($data->code)) {
288
-      return (string) $data->code;
288
+        return (string) $data->code;
289 289
     }
290 290
 
291 291
     throw FacebookRequestException::create(
292
-      $response->getRawResponse(),
293
-      $data,
294
-      401
292
+        $response->getRawResponse(),
293
+        $data,
294
+        401
295 295
     );
296
-  }
297
-
298
-  /**
299
-   * Send a request to Graph with an app access token.
300
-   *
301
-   * @param string $endpoint
302
-   * @param array $params
303
-   * @param string|null $appId
304
-   * @param string|null $appSecret
305
-   *
306
-   * @return \Facebook\FacebookResponse
307
-   *
308
-   * @throws FacebookRequestException
309
-   */
310
-  protected static function request($endpoint, array $params, $appId = null, $appSecret = null)
311
-  {
296
+    }
297
+
298
+    /**
299
+     * Send a request to Graph with an app access token.
300
+     *
301
+     * @param string $endpoint
302
+     * @param array $params
303
+     * @param string|null $appId
304
+     * @param string|null $appSecret
305
+     *
306
+     * @return \Facebook\FacebookResponse
307
+     *
308
+     * @throws FacebookRequestException
309
+     */
310
+    protected static function request($endpoint, array $params, $appId = null, $appSecret = null)
311
+    {
312 312
     $targetAppId = FacebookSession::_getTargetAppId($appId);
313 313
     $targetAppSecret = FacebookSession::_getTargetAppSecret($appSecret);
314 314
 
315 315
     if (!isset($params['client_id'])) {
316
-      $params['client_id'] = $targetAppId;
316
+        $params['client_id'] = $targetAppId;
317 317
     }
318 318
     if (!isset($params['client_secret'])) {
319
-      $params['client_secret'] = $targetAppSecret;
319
+        $params['client_secret'] = $targetAppSecret;
320 320
     }
321 321
 
322 322
     // The response for this endpoint is not JSON, so it must be handled
323 323
     //   differently, not as a GraphObject.
324 324
     $request = new FacebookRequest(
325
-      FacebookSession::newAppSession($targetAppId, $targetAppSecret),
326
-      'GET',
327
-      $endpoint,
328
-      $params
325
+        FacebookSession::newAppSession($targetAppId, $targetAppSecret),
326
+        'GET',
327
+        $endpoint,
328
+        $params
329 329
     );
330 330
     return $request->execute();
331
-  }
332
-
333
-  /**
334
-   * Get more info about an access token.
335
-   *
336
-   * @param string|null $appId
337
-   * @param string|null $appSecret
338
-   *
339
-   * @return GraphSessionInfo
340
-   */
341
-  public function getInfo($appId = null, $appSecret = null)
342
-  {
331
+    }
332
+
333
+    /**
334
+     * Get more info about an access token.
335
+     *
336
+     * @param string|null $appId
337
+     * @param string|null $appSecret
338
+     *
339
+     * @return GraphSessionInfo
340
+     */
341
+    public function getInfo($appId = null, $appSecret = null)
342
+    {
343 343
     $params = array('input_token' => $this->accessToken);
344 344
 
345 345
     $request = new FacebookRequest(
346
-      FacebookSession::newAppSession($appId, $appSecret),
347
-      'GET',
348
-      '/debug_token',
349
-      $params
346
+        FacebookSession::newAppSession($appId, $appSecret),
347
+        'GET',
348
+        '/debug_token',
349
+        $params
350 350
     );
351 351
     $response = $request->execute()->getGraphObject(GraphSessionInfo::className());
352 352
 
353 353
     // Update the data on this token
354 354
     if ($response->getExpiresAt()) {
355
-      $this->expiresAt = $response->getExpiresAt();
355
+        $this->expiresAt = $response->getExpiresAt();
356 356
     }
357 357
 
358 358
     return $response;
359
-  }
360
-
361
-  /**
362
-   * Returns the access token as a string.
363
-   *
364
-   * @return string
365
-   */
366
-  public function __toString()
367
-  {
359
+    }
360
+
361
+    /**
362
+     * Returns the access token as a string.
363
+     *
364
+     * @return string
365
+     */
366
+    public function __toString()
367
+    {
368 368
     return $this->accessToken;
369
-  }
370
-
371
-  /**
372
-   * Returns true if the access token is an app session token.
373
-   *
374
-   * @return bool
375
-   */
376
-  public function isAppSession()
377
-  {
369
+    }
370
+
371
+    /**
372
+     * Returns true if the access token is an app session token.
373
+     *
374
+     * @return bool
375
+     */
376
+    public function isAppSession()
377
+    {
378 378
     return strpos($this->accessToken, "|") !== false;
379
-  }
379
+    }
380 380
 
381 381
 }
Please login to merge, or discard this patch.
main/document/edit_draw.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 //path for svg-edit save
44 44
 $_SESSION['draw_dir'] = Security::remove_XSS($dir);
45 45
 if ($_SESSION['draw_dir'] == '/') {
46
-	$_SESSION['draw_dir'] = '';
46
+    $_SESSION['draw_dir'] = '';
47 47
 }
48 48
 $_SESSION['draw_file'] = basename(Security::remove_XSS($file_path));
49 49
 $get_file = Security::remove_XSS($file_path);
@@ -59,26 +59,26 @@  discard block
 block discarded – undo
59 59
 /* Please, do not modify this dirname formatting */
60 60
 
61 61
 if (strstr($dir, '..')) {
62
-	$dir = '/';
62
+    $dir = '/';
63 63
 }
64 64
 
65 65
 if ($dir[0] == '.') {
66
-	$dir = substr($dir, 1);
66
+    $dir = substr($dir, 1);
67 67
 }
68 68
 
69 69
 if ($dir[0] != '/') {
70
-	$dir = '/'.$dir;
70
+    $dir = '/'.$dir;
71 71
 }
72 72
 
73 73
 if ($dir[strlen($dir) - 1] != '/') {
74
-	$dir .= '/';
74
+    $dir .= '/';
75 75
 }
76 76
 
77 77
 $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
78 78
 
79 79
 if (!is_dir($filepath)) {
80
-	$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
81
-	$dir = '/';
80
+    $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
81
+    $dir = '/';
82 82
 }
83 83
 
84 84
 //groups //TODO:clean
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
         'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
88 88
         'name' => get_lang('GroupSpace'),
89 89
     );
90
-	$group_document = true;
91
-	$noPHP_SELF = true;
90
+    $group_document = true;
91
+    $noPHP_SELF = true;
92 92
 }
93 93
 
94 94
 $is_certificate_mode = DocumentManager::is_certificate_mode($dir);
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
 }
115 115
 
116 116
 $is_allowedToEdit = api_is_allowed_to_edit(null, true) || $_SESSION['group_member_with_upload_rights'] ||
117
-	DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $current_session_id);
117
+    DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $current_session_id);
118 118
 
119 119
 if (!$is_allowedToEdit) {
120
-	api_not_allowed(true);
120
+    api_not_allowed(true);
121 121
 }
122 122
 
123 123
 Event::event_access_tool(TOOL_DOCUMENT);
@@ -131,13 +131,13 @@  discard block
 block discarded – undo
131 131
 echo '</div>';
132 132
 
133 133
 if (api_browser_support('svg')) {
134
-	//automatic loading the course language
135
-	$svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
136
-	$langsvgedit  = api_get_language_isocode();
137
-	$langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
138
-	$langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
139
-	$svg_url = api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?url=../../../../../courses/'.$courseDir.$dir.$file.'&lang='.$langsvgedit;
140
-	?>
134
+    //automatic loading the course language
135
+    $svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
136
+    $langsvgedit  = api_get_language_isocode();
137
+    $langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
138
+    $langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
139
+    $svg_url = api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?url=../../../../../courses/'.$courseDir.$dir.$file.'&lang='.$langsvgedit;
140
+    ?>
141 141
 	<script>
142 142
 	document.write ('<iframe id="frame" frameborder="0" scrolling="no" src="<?php echo  $svg_url; ?>" width="100%" height="100%"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>');
143 143
 	function resizeIframe() {
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 
156 156
     <?php
157 157
     echo '<noscript>';
158
-	echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0\' src="'.$svg_url.'"<noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
159
-	echo '</noscript>';
158
+    echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0\' src="'.$svg_url.'"<noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
159
+    echo '</noscript>';
160 160
 } else {
161
-	Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
161
+    Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
162 162
 }
163 163
 Display::display_footer();
Please login to merge, or discard this patch.
main/inc/lib/exercise_show_functions.lib.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -17,25 +17,25 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class ExerciseShowFunctions
19 19
 {
20
-	/**
21
-	 * Shows the answer to a fill-in-the-blanks question, as HTML
20
+    /**
21
+     * Shows the answer to a fill-in-the-blanks question, as HTML
22 22
      * @param int $feedbackType
23
-	 * @param string    $answer
24
-	 * @param int $id       Exercise ID
25
-	 * @param int $questionId      Question ID
23
+     * @param string    $answer
24
+     * @param int $id       Exercise ID
25
+     * @param int $questionId      Question ID
26 26
      * @param int $resultsDisabled
27 27
      * @param string $originalStudentAnswer
28 28
      *
29
-	 * @return void
30
-	 */
31
-	public static function display_fill_in_blanks_answer(
32
-	    $feedbackType,
33
-	    $answer,
34
-	    $id,
35
-	    $questionId,
36
-	    $resultsDisabled,
37
-	    $originalStudentAnswer = '',
38
-	    $showTotalScoreAndUserChoices
29
+     * @return void
30
+     */
31
+    public static function display_fill_in_blanks_answer(
32
+        $feedbackType,
33
+        $answer,
34
+        $id,
35
+        $questionId,
36
+        $resultsDisabled,
37
+        $originalStudentAnswer = '',
38
+        $showTotalScoreAndUserChoices
39 39
     ) {
40 40
         $answerHTML = FillBlanks::getHtmlDisplayForAnswer($answer, $resultsDisabled, $showTotalScoreAndUserChoices);
41 41
         if (strpos($originalStudentAnswer, 'font color') !== false) {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
             </tr>
65 65
         <?php
66 66
         }
67
-	}
67
+    }
68 68
 
69 69
     /**
70 70
      * Shows the answer to a calculated question, as HTML
@@ -105,20 +105,20 @@  discard block
 block discarded – undo
105 105
         }
106 106
     }
107 107
 
108
-	/**
109
-	 * Shows the answer to a free-answer question, as HTML
110
-	 * @param string    Answer text
111
-	 * @param int       Exercise ID
112
-	 * @param int       Question ID
113
-	 * @return void
114
-	 */
115
-	public static function display_free_answer(
116
-	    $feedback_type,
117
-	    $answer,
118
-	    $exe_id,
119
-	    $questionId,
120
-	    $questionScore = null,
121
-	    $results_disabled = 0
108
+    /**
109
+     * Shows the answer to a free-answer question, as HTML
110
+     * @param string    Answer text
111
+     * @param int       Exercise ID
112
+     * @param int       Question ID
113
+     * @return void
114
+     */
115
+    public static function display_free_answer(
116
+        $feedback_type,
117
+        $answer,
118
+        $exe_id,
119
+        $questionId,
120
+        $questionScore = null,
121
+        $results_disabled = 0
122 122
     ) {
123 123
         $comments = Event::get_comments($exe_id, $questionId);
124 124
 
@@ -136,17 +136,17 @@  discard block
 block discarded – undo
136 136
                 echo '</tr>';
137 137
             }
138 138
         }
139
-	}
139
+    }
140 140
 
141 141
     /**
142
-    * @param $feedback_type
143
-    * @param $answer
144
-    * @param $id
145
-    * @param $questionId
146
-    * @param null $nano
147
-    * @param int $results_disabled
142
+     * @param $feedback_type
143
+     * @param $answer
144
+     * @param $id
145
+     * @param $questionId
146
+     * @param null $nano
147
+     * @param int $results_disabled
148 148
      */
149
-	public static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $fileUrl = null, $results_disabled = 0)
149
+    public static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $fileUrl = null, $results_disabled = 0)
150 150
     {
151 151
         if (isset($fileUrl)) {
152 152
             echo '
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
         }
185 185
     }
186 186
 
187
-	/**
188
-	 * Displays the answer to a hotspot question
187
+    /**
188
+     * Displays the answer to a hotspot question
189 189
      * @param int $feedback_type
190 190
      * @param int $answerId
191 191
      * @param string $answer
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      * @param int $resultsDisabled
195 195
      * @param int $orderColor
196 196
      */
197
-	public static function display_hotspot_answer(
197
+    public static function display_hotspot_answer(
198 198
         $feedback_type,
199 199
         $answerId,
200 200
         $answer,
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
             }
218 218
         }
219 219
 
220
-		$hotspot_colors = array(
220
+        $hotspot_colors = array(
221 221
             "", // $i starts from 1 on next loop (ugly fix)
222 222
             "#4271B5",
223 223
             "#FE8E16",
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             "#F7BDE2"
235 235
         );
236 236
 
237
-		?>
237
+        ?>
238 238
 		<table class="data_table">
239 239
 		<tr>
240 240
             <td class="text-center" width="5%">
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 			<td class="text-left" width="10%">
247 247
 				<?php
248 248
                 if (!$hide_expected_answer) {
249
-    				$my_choice = $studentChoice ? get_lang('Correct') : get_lang('Fault');
250
-    				echo $my_choice;
249
+                    $my_choice = $studentChoice ? get_lang('Correct') : get_lang('Fault');
250
+                    echo $my_choice;
251 251
                 }
252
-				?>
252
+                ?>
253 253
 			</td>
254 254
 			<?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
255 255
 			<td class="text-left" width="60%">
@@ -257,29 +257,29 @@  discard block
 block discarded – undo
257 257
                 if ($studentChoice) {
258 258
                     echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
259 259
                 }
260
-				?>
260
+                ?>
261 261
 			</td>
262 262
 			<?php } else { ?>
263 263
 				<td class="text-left" width="60%">&nbsp;</td>
264 264
 			<?php } ?>
265 265
 		</tr>
266 266
 		<?php
267
-	}
268
-
269
-	/**
270
-	 * Display the answers to a multiple choice question
271
-	 * @param int $feedback_type Feedback type
272
-	 * @param integer Answer type
273
-	 * @param integer Student choice
274
-	 * @param string  Textual answer
275
-	 * @param string  Comment on answer
276
-	 * @param string  Correct answer comment
277
-	 * @param integer Exercise ID
278
-	 * @param integer Question ID
279
-	 * @param boolean Whether to show the answer comment or not
280
-	 * @return void
281
-	 */
282
-	public static function display_unique_or_multiple_answer(
267
+    }
268
+
269
+    /**
270
+     * Display the answers to a multiple choice question
271
+     * @param int $feedback_type Feedback type
272
+     * @param integer Answer type
273
+     * @param integer Student choice
274
+     * @param string  Textual answer
275
+     * @param string  Comment on answer
276
+     * @param string  Correct answer comment
277
+     * @param integer Exercise ID
278
+     * @param integer Question ID
279
+     * @param boolean Whether to show the answer comment or not
280
+     * @return void
281
+     */
282
+    public static function display_unique_or_multiple_answer(
283 283
         $feedback_type,
284 284
         $answerType,
285 285
         $studentChoice,
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
         }
308 308
 
309 309
         $icon = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
310
-		$icon .= $studentChoice?'_on':'_off';
311
-		$icon .= '.gif';
310
+        $icon .= $studentChoice?'_on':'_off';
311
+        $icon .= '.gif';
312 312
 
313
-		$iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
314
-		$iconAnswer .= $answerCorrect?'_on':'_off';
315
-		$iconAnswer .= '.gif';
313
+        $iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox';
314
+        $iconAnswer .= $answerCorrect?'_on':'_off';
315
+        $iconAnswer .= '.gif';
316 316
 
317
-		?>
317
+        ?>
318 318
 		<tr>
319 319
 		<td width="5%">
320 320
 			<?php echo Display::return_icon($icon); ?>
@@ -328,39 +328,39 @@  discard block
 block discarded – undo
328 328
 		</td>
329 329
 		<td width="40%">
330 330
 			<?php
331
-			echo $answer;
332
-			?>
331
+            echo $answer;
332
+            ?>
333 333
 		</td>
334 334
 
335 335
 		<?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
336 336
 		<td width="20%">
337 337
 			<?php
338 338
             if ($studentChoice) {
339
-				if ($answerCorrect) {
339
+                if ($answerCorrect) {
340 340
                     $color = 'green';
341
-					//echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
342
-				} else {
341
+                    //echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
342
+                } else {
343 343
                     $color = 'black';
344 344
                     //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
345
-				}
346
-				if ($hide_expected_answer) {
347
-				    $color = '';
348
-				}
345
+                }
346
+                if ($hide_expected_answer) {
347
+                    $color = '';
348
+                }
349 349
                 echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
350
-			}
351
-			?>
350
+            }
351
+            ?>
352 352
 		</td>
353 353
 			<?php
354
-		    if ($ans==1) {
355
-		        $comm = Event::get_comments($id,$questionId);
356
-			}
357
-		    ?>
354
+            if ($ans==1) {
355
+                $comm = Event::get_comments($id,$questionId);
356
+            }
357
+            ?>
358 358
 		 <?php } else { ?>
359 359
 			<td>&nbsp;</td>
360 360
 		<?php } ?>
361 361
 		</tr>
362 362
 		<?php
363
-	}
363
+    }
364 364
 
365 365
     /**
366 366
      * Display the answers to a multiple choice question
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
         if (isset($new_options[$studentChoice])) {
414 414
             echo get_lang($new_options[$studentChoice]['name']);
415 415
         } else {
416
-        	echo '-';
416
+            echo '-';
417 417
         }
418 418
 
419 419
         ?>
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
         <td width="5%">
422 422
         <?php
423 423
 
424
-		//Expected choice
424
+        //Expected choice
425 425
         if (!$hide_expected_answer) {
426 426
             if (isset($new_options[$answerCorrect])) {
427 427
                 echo get_lang($new_options[$answerCorrect]['name']);
@@ -447,8 +447,8 @@  discard block
 block discarded – undo
447 447
                 }
448 448
 
449 449
                 if ($hide_expected_answer) {
450
-				    $color = '';
451
-				}
450
+                    $color = '';
451
+                }
452 452
 
453 453
                 echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
454 454
             }
@@ -466,19 +466,19 @@  discard block
 block discarded – undo
466 466
         <?php
467 467
     }
468 468
 
469
-     /**
470
-     * Display the answers to a multiple choice question
471
-     *
472
-     * @param integer Answer type
473
-     * @param integer Student choice
474
-     * @param string  Textual answer
475
-     * @param string  Comment on answer
476
-     * @param string  Correct answer comment
477
-     * @param integer Exercise ID
478
-     * @param integer Question ID
479
-     * @param boolean Whether to show the answer comment or not
480
-     * @return void
481
-     */
469
+        /**
470
+         * Display the answers to a multiple choice question
471
+         *
472
+         * @param integer Answer type
473
+         * @param integer Student choice
474
+         * @param string  Textual answer
475
+         * @param string  Comment on answer
476
+         * @param string  Correct answer comment
477
+         * @param integer Exercise ID
478
+         * @param integer Question ID
479
+         * @param boolean Whether to show the answer comment or not
480
+         * @return void
481
+         */
482 482
     public static function display_multiple_answer_combination_true_false(
483 483
         $feedback_type,
484 484
         $answerType,
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
         <tr>
510 510
         <td width="5%">
511 511
         <?php
512
-		//Your choice
512
+        //Your choice
513 513
         $question = new MultipleAnswerCombinationTrueFalse();
514 514
         if (isset($question->options[$studentChoice])) {
515 515
             echo $question->options[$studentChoice];
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
         </td>
521 521
         <td width="5%">
522 522
         <?php
523
-		//Expected choice
523
+        //Expected choice
524 524
         if (!$hide_expected_answer) {
525 525
             if (isset($question->options[$answerCorrect])) {
526 526
                 echo $question->options[$answerCorrect];
@@ -545,14 +545,14 @@  discard block
 block discarded – undo
545 545
             <?php
546 546
             //@todo replace this harcoded value
547 547
             if ($studentChoice) {
548
-                 $color = "black";
548
+                    $color = "black";
549 549
                 if ($studentChoice == $answerCorrect) {
550 550
                     $color = "green";
551 551
                 }
552
-            	//echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
552
+                //echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
553 553
                 if ($hide_expected_answer) {
554 554
                     $color = '';
555
-				}
555
+                }
556 556
                 echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
557 557
             }
558 558
             ?>
Please login to merge, or discard this patch.
plugin/vchamilo/lib.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -582,7 +582,7 @@
 block discarded – undo
582 582
             false
583 583
         );
584 584
 
585
-          Display::addFlash(
585
+            Display::addFlash(
586 586
             Display::return_message("Copying {$absolute_template_datadir}/data/archive => $archivePath")
587 587
         );
588 588
         copyDirTo(
Please login to merge, or discard this patch.
main/gradebook/lib/be/evaluation.class.php 1 patch
Indentation   +748 added lines, -748 removed lines patch added patch discarded remove patch
@@ -9,367 +9,367 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class Evaluation implements GradebookItem
11 11
 {
12
-	private $id;
13
-	private $name;
14
-	private $description;
15
-	private $user_id;
16
-	private $course_code;
17
-	/** @var Category */
18
-	private $category;
19
-	private $created_at;
20
-	private $weight;
21
-	private $eval_max;
22
-	private $visible;
23
-	private $sessionId;
24
-	public $studentList;
25
-
26
-	/**
27
-	 * Construct
28
-	 */
29
-	public function __construct()
30
-	{
31
-	}
32
-
33
-	/**
34
-	 * @return Category
35
-	 */
36
-	public function getCategory()
37
-	{
38
-		return $this->category;
39
-	}
40
-
41
-	/**
42
-	 * @param Category $category
43
-	 */
44
-	public function setCategory($category)
45
-	{
46
-		$this->category = $category;
47
-	}
48
-
49
-	/**
50
-	 * @return int
51
-	 */
52
-	public function get_category_id()
53
-	{
54
-		return $this->category->get_id();
55
-	}
56
-
57
-	/**
58
-	 * @param int $category_id
59
-	 */
60
-	public function set_category_id($category_id)
61
-	{
62
-		$categories = Category::load($category_id);
63
-		if (isset($categories[0])) {
64
-			$this->setCategory($categories[0]);
65
-		}
66
-	}
67
-
68
-	/**
69
-	 * @return int
70
-	 */
71
-	public function get_id()
72
-	{
73
-		return $this->id;
74
-	}
75
-
76
-	/**
77
-	 * @return string
78
-	 */
79
-	public function get_name()
80
-	{
81
-		return $this->name;
82
-	}
83
-
84
-	/**
85
-	 * @return string
86
-	 */
87
-	public function get_description()
88
-	{
89
-		return $this->description;
90
-	}
91
-
92
-	public function get_user_id()
93
-	{
94
-		return $this->user_id;
95
-	}
96
-
97
-	public function get_course_code()
98
-	{
99
-		return $this->course_code;
100
-	}
101
-
102
-	/**
103
-	 * @return int
104
-	 */
105
-	public function getSessionId()
106
-	{
107
-		return $this->sessionId;
108
-	}
109
-
110
-	/**
111
-	 * @param int $sessionId
112
-	 */
113
-	public function setSessionId($sessionId)
114
-	{
115
-		$this->sessionId = intval($sessionId);
116
-	}
117
-
118
-	public function get_date()
119
-	{
120
-		return $this->created_at;
121
-	}
122
-
123
-	public function get_weight()
124
-	{
125
-		return $this->weight;
126
-	}
127
-
128
-	public function get_max()
129
-	{
130
-		return $this->eval_max;
131
-	}
132
-
133
-	public function get_type()
134
-	{
135
-		return $this->type;
136
-	}
137
-
138
-	public function is_visible()
139
-	{
140
-		return $this->visible;
141
-	}
142
-
143
-	public function get_locked()
144
-	{
145
-		return $this->locked;
146
-	}
147
-
148
-	public function is_locked()
149
-	{
150
-		return isset($this->locked) && $this->locked == 1 ? true : false;
151
-	}
152
-
153
-	public function set_id($id)
154
-	{
155
-		$this->id = $id;
156
-	}
157
-
158
-	public function set_name($name)
159
-	{
160
-		$this->name = $name;
161
-	}
162
-
163
-	public function set_description($description)
164
-	{
165
-		$this->description = $description;
166
-	}
167
-
168
-	public function set_user_id($user_id)
169
-	{
170
-		$this->user_id = $user_id;
171
-	}
172
-
173
-	public function set_course_code($course_code)
174
-	{
175
-		$this->course_code = $course_code;
176
-	}
177
-
178
-	public function set_date($date)
179
-	{
180
-		$this->created_at = $date;
181
-	}
182
-
183
-	public function set_weight($weight)
184
-	{
185
-		$this->weight = $weight;
186
-	}
187
-
188
-	public function set_max($max)
189
-	{
190
-		$this->eval_max = $max;
191
-	}
192
-
193
-	public function set_visible($visible)
194
-	{
195
-		$this->visible = $visible;
196
-	}
197
-
198
-	public function set_type($type)
199
-	{
200
-		$this->type = $type;
201
-	}
202
-
203
-	public function set_locked($locked)
204
-	{
205
-		$this->locked = $locked;
206
-	}
207
-
208
-	/**
209
-	 * Retrieve evaluations and return them as an array of Evaluation objects
210
-	 * @param int $id evaluation id
211
-	 * @param int $user_id user id (evaluation owner)
212
-	 * @param string $course_code course code
213
-	 * @param int $category_id parent category
214
-	 * @param integer $visible visible
215
-	 */
216
-	public static function load(
217
-		$id = null,
218
-		$user_id = null,
219
-		$course_code = null,
220
-		$category_id = null,
221
-		$visible = null,
222
-		$locked = null
223
-	) {
224
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
225
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations;
226
-		$paramcount = 0;
227
-
228
-		if (isset ($id)) {
229
-			$sql.= ' WHERE id = '.intval($id);
230
-			$paramcount ++;
231
-		}
232
-
233
-		if (isset ($user_id)) {
234
-			if ($paramcount != 0) $sql .= ' AND';
235
-			else $sql .= ' WHERE';
236
-			$sql .= ' user_id = '.intval($user_id);
237
-			$paramcount ++;
238
-		}
239
-
240
-		if (isset ($course_code) && $course_code <> '-1') {
241
-			if ($paramcount != 0) $sql .= ' AND';
242
-			else $sql .= ' WHERE';
243
-			$sql .= " course_code = '".Database::escape_string($course_code)."'";
244
-			$paramcount ++;
245
-		}
246
-
247
-		if (isset ($category_id)) {
248
-			if ($paramcount != 0) $sql .= ' AND';
249
-			else $sql .= ' WHERE';
250
-			$sql .= ' category_id = '.intval($category_id);
251
-			$paramcount ++;
252
-		}
253
-
254
-		if (isset ($visible)) {
255
-			if ($paramcount != 0) $sql .= ' AND';
256
-			else $sql .= ' WHERE';
257
-			$sql .= ' visible = '.intval($visible);
258
-			$paramcount ++;
259
-		}
260
-
261
-		if (isset ($locked)) {
262
-			if ($paramcount != 0) $sql .= ' AND';
263
-			else $sql .= ' WHERE';
264
-			$sql .= ' locked = '.intval($locked);
265
-		}
266
-
267
-		$result = Database::query($sql);
268
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
269
-
270
-		return $alleval;
271
-	}
272
-
273
-
274
-
275
-	/**
276
-	 * @param array $result
277
-	 * @return array
278
-	 */
279
-	private static function create_evaluation_objects_from_sql_result($result)
280
-	{
281
-		$alleval = array();
282
-		if (Database::num_rows($result)) {
283
-			while ($data = Database::fetch_array($result)) {
284
-				$eval= new Evaluation();
285
-				$eval->set_id($data['id']);
286
-				$eval->set_name($data['name']);
287
-				$eval->set_description($data['description']);
288
-				$eval->set_user_id($data['user_id']);
289
-				$eval->set_course_code($data['course_code']);
290
-				$eval->set_category_id($data['category_id']);
291
-				$eval->set_date(api_get_local_time($data['created_at']));
292
-				$eval->set_weight($data['weight']);
293
-				$eval->set_max($data['max']);
294
-				$eval->set_visible($data['visible']);
295
-				$eval->set_type($data['type']);
296
-				$eval->set_locked($data['locked']);
297
-				$eval->setSessionId(api_get_session_id());
298
-
299
-				$alleval[] = $eval;
300
-			}
301
-		}
302
-
303
-		return $alleval;
304
-	}
305
-
306
-	/**
307
-	 * Insert this evaluation into the database
308
-	 */
309
-	public function add()
310
-	{
311
-		if (isset($this->name) &&
312
-			isset($this->user_id) &&
313
-			isset($this->weight) &&
314
-			isset ($this->eval_max) &&
315
-			isset($this->visible)
316
-		) {
317
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
318
-
319
-			$sql = 'INSERT INTO '.$tbl_grade_evaluations
320
-				.' (name, user_id, weight, max, visible';
321
-			if (isset($this->description)) {
322
-				$sql .= ',description';
323
-			}
324
-			if (isset($this->course_code)) {
325
-				$sql .= ', course_code';
326
-			}
327
-			if (isset($this->category)) {
328
-				$sql .= ', category_id';
329
-			}
330
-			$sql .= ', created_at';
331
-			$sql .= ',type';
332
-			$sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
333
-				.','.intval($this->get_user_id())
334
-				.','.floatval($this->get_weight())
335
-				.','.intval($this->get_max())
336
-				.','.intval($this->is_visible());
337
-			if (isset($this->description)) {
338
-				$sql .= ",'".Database::escape_string($this->get_description())."'";
339
-			}
340
-			if (isset($this->course_code)) {
341
-				$sql .= ",'".Database::escape_string($this->get_course_code())."'";
342
-			}
343
-			if (isset($this->category)) {
344
-				$sql .= ','.intval($this->get_category_id());
345
-			}
346
-			if (empty($this->type)) {
347
-				$this->type = 'evaluation';
348
-			}
349
-			$sql .= ", '".api_get_utc_datetime()."'";
350
-			$sql .= ',\''.Database::escape_string($this->type).'\'';
351
-			$sql .= ")";
352
-
353
-			Database::query($sql);
354
-			$this->set_id(Database::insert_id());
355
-		} else {
356
-			die('Error in Evaluation add: required field empty');
357
-		}
358
-	}
359
-
360
-	/**
361
-	 * @param int $idevaluation
362
-	 */
363
-	public function add_evaluation_log($idevaluation)
364
-	{
365
-		if (!empty($idevaluation)) {
366
-			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
367
-			$tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
368
-			$eval = new Evaluation();
369
-			$dateobject = $eval->load($idevaluation,null,null,null,null);
370
-			$arreval = get_object_vars($dateobject[0]);
371
-			if (!empty($arreval['id'])) {
372
-				$sql = 'SELECT weight from '.$tbl_grade_evaluations.'
12
+    private $id;
13
+    private $name;
14
+    private $description;
15
+    private $user_id;
16
+    private $course_code;
17
+    /** @var Category */
18
+    private $category;
19
+    private $created_at;
20
+    private $weight;
21
+    private $eval_max;
22
+    private $visible;
23
+    private $sessionId;
24
+    public $studentList;
25
+
26
+    /**
27
+     * Construct
28
+     */
29
+    public function __construct()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * @return Category
35
+     */
36
+    public function getCategory()
37
+    {
38
+        return $this->category;
39
+    }
40
+
41
+    /**
42
+     * @param Category $category
43
+     */
44
+    public function setCategory($category)
45
+    {
46
+        $this->category = $category;
47
+    }
48
+
49
+    /**
50
+     * @return int
51
+     */
52
+    public function get_category_id()
53
+    {
54
+        return $this->category->get_id();
55
+    }
56
+
57
+    /**
58
+     * @param int $category_id
59
+     */
60
+    public function set_category_id($category_id)
61
+    {
62
+        $categories = Category::load($category_id);
63
+        if (isset($categories[0])) {
64
+            $this->setCategory($categories[0]);
65
+        }
66
+    }
67
+
68
+    /**
69
+     * @return int
70
+     */
71
+    public function get_id()
72
+    {
73
+        return $this->id;
74
+    }
75
+
76
+    /**
77
+     * @return string
78
+     */
79
+    public function get_name()
80
+    {
81
+        return $this->name;
82
+    }
83
+
84
+    /**
85
+     * @return string
86
+     */
87
+    public function get_description()
88
+    {
89
+        return $this->description;
90
+    }
91
+
92
+    public function get_user_id()
93
+    {
94
+        return $this->user_id;
95
+    }
96
+
97
+    public function get_course_code()
98
+    {
99
+        return $this->course_code;
100
+    }
101
+
102
+    /**
103
+     * @return int
104
+     */
105
+    public function getSessionId()
106
+    {
107
+        return $this->sessionId;
108
+    }
109
+
110
+    /**
111
+     * @param int $sessionId
112
+     */
113
+    public function setSessionId($sessionId)
114
+    {
115
+        $this->sessionId = intval($sessionId);
116
+    }
117
+
118
+    public function get_date()
119
+    {
120
+        return $this->created_at;
121
+    }
122
+
123
+    public function get_weight()
124
+    {
125
+        return $this->weight;
126
+    }
127
+
128
+    public function get_max()
129
+    {
130
+        return $this->eval_max;
131
+    }
132
+
133
+    public function get_type()
134
+    {
135
+        return $this->type;
136
+    }
137
+
138
+    public function is_visible()
139
+    {
140
+        return $this->visible;
141
+    }
142
+
143
+    public function get_locked()
144
+    {
145
+        return $this->locked;
146
+    }
147
+
148
+    public function is_locked()
149
+    {
150
+        return isset($this->locked) && $this->locked == 1 ? true : false;
151
+    }
152
+
153
+    public function set_id($id)
154
+    {
155
+        $this->id = $id;
156
+    }
157
+
158
+    public function set_name($name)
159
+    {
160
+        $this->name = $name;
161
+    }
162
+
163
+    public function set_description($description)
164
+    {
165
+        $this->description = $description;
166
+    }
167
+
168
+    public function set_user_id($user_id)
169
+    {
170
+        $this->user_id = $user_id;
171
+    }
172
+
173
+    public function set_course_code($course_code)
174
+    {
175
+        $this->course_code = $course_code;
176
+    }
177
+
178
+    public function set_date($date)
179
+    {
180
+        $this->created_at = $date;
181
+    }
182
+
183
+    public function set_weight($weight)
184
+    {
185
+        $this->weight = $weight;
186
+    }
187
+
188
+    public function set_max($max)
189
+    {
190
+        $this->eval_max = $max;
191
+    }
192
+
193
+    public function set_visible($visible)
194
+    {
195
+        $this->visible = $visible;
196
+    }
197
+
198
+    public function set_type($type)
199
+    {
200
+        $this->type = $type;
201
+    }
202
+
203
+    public function set_locked($locked)
204
+    {
205
+        $this->locked = $locked;
206
+    }
207
+
208
+    /**
209
+     * Retrieve evaluations and return them as an array of Evaluation objects
210
+     * @param int $id evaluation id
211
+     * @param int $user_id user id (evaluation owner)
212
+     * @param string $course_code course code
213
+     * @param int $category_id parent category
214
+     * @param integer $visible visible
215
+     */
216
+    public static function load(
217
+        $id = null,
218
+        $user_id = null,
219
+        $course_code = null,
220
+        $category_id = null,
221
+        $visible = null,
222
+        $locked = null
223
+    ) {
224
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
225
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations;
226
+        $paramcount = 0;
227
+
228
+        if (isset ($id)) {
229
+            $sql.= ' WHERE id = '.intval($id);
230
+            $paramcount ++;
231
+        }
232
+
233
+        if (isset ($user_id)) {
234
+            if ($paramcount != 0) $sql .= ' AND';
235
+            else $sql .= ' WHERE';
236
+            $sql .= ' user_id = '.intval($user_id);
237
+            $paramcount ++;
238
+        }
239
+
240
+        if (isset ($course_code) && $course_code <> '-1') {
241
+            if ($paramcount != 0) $sql .= ' AND';
242
+            else $sql .= ' WHERE';
243
+            $sql .= " course_code = '".Database::escape_string($course_code)."'";
244
+            $paramcount ++;
245
+        }
246
+
247
+        if (isset ($category_id)) {
248
+            if ($paramcount != 0) $sql .= ' AND';
249
+            else $sql .= ' WHERE';
250
+            $sql .= ' category_id = '.intval($category_id);
251
+            $paramcount ++;
252
+        }
253
+
254
+        if (isset ($visible)) {
255
+            if ($paramcount != 0) $sql .= ' AND';
256
+            else $sql .= ' WHERE';
257
+            $sql .= ' visible = '.intval($visible);
258
+            $paramcount ++;
259
+        }
260
+
261
+        if (isset ($locked)) {
262
+            if ($paramcount != 0) $sql .= ' AND';
263
+            else $sql .= ' WHERE';
264
+            $sql .= ' locked = '.intval($locked);
265
+        }
266
+
267
+        $result = Database::query($sql);
268
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
269
+
270
+        return $alleval;
271
+    }
272
+
273
+
274
+
275
+    /**
276
+     * @param array $result
277
+     * @return array
278
+     */
279
+    private static function create_evaluation_objects_from_sql_result($result)
280
+    {
281
+        $alleval = array();
282
+        if (Database::num_rows($result)) {
283
+            while ($data = Database::fetch_array($result)) {
284
+                $eval= new Evaluation();
285
+                $eval->set_id($data['id']);
286
+                $eval->set_name($data['name']);
287
+                $eval->set_description($data['description']);
288
+                $eval->set_user_id($data['user_id']);
289
+                $eval->set_course_code($data['course_code']);
290
+                $eval->set_category_id($data['category_id']);
291
+                $eval->set_date(api_get_local_time($data['created_at']));
292
+                $eval->set_weight($data['weight']);
293
+                $eval->set_max($data['max']);
294
+                $eval->set_visible($data['visible']);
295
+                $eval->set_type($data['type']);
296
+                $eval->set_locked($data['locked']);
297
+                $eval->setSessionId(api_get_session_id());
298
+
299
+                $alleval[] = $eval;
300
+            }
301
+        }
302
+
303
+        return $alleval;
304
+    }
305
+
306
+    /**
307
+     * Insert this evaluation into the database
308
+     */
309
+    public function add()
310
+    {
311
+        if (isset($this->name) &&
312
+            isset($this->user_id) &&
313
+            isset($this->weight) &&
314
+            isset ($this->eval_max) &&
315
+            isset($this->visible)
316
+        ) {
317
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
318
+
319
+            $sql = 'INSERT INTO '.$tbl_grade_evaluations
320
+                .' (name, user_id, weight, max, visible';
321
+            if (isset($this->description)) {
322
+                $sql .= ',description';
323
+            }
324
+            if (isset($this->course_code)) {
325
+                $sql .= ', course_code';
326
+            }
327
+            if (isset($this->category)) {
328
+                $sql .= ', category_id';
329
+            }
330
+            $sql .= ', created_at';
331
+            $sql .= ',type';
332
+            $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
333
+                .','.intval($this->get_user_id())
334
+                .','.floatval($this->get_weight())
335
+                .','.intval($this->get_max())
336
+                .','.intval($this->is_visible());
337
+            if (isset($this->description)) {
338
+                $sql .= ",'".Database::escape_string($this->get_description())."'";
339
+            }
340
+            if (isset($this->course_code)) {
341
+                $sql .= ",'".Database::escape_string($this->get_course_code())."'";
342
+            }
343
+            if (isset($this->category)) {
344
+                $sql .= ','.intval($this->get_category_id());
345
+            }
346
+            if (empty($this->type)) {
347
+                $this->type = 'evaluation';
348
+            }
349
+            $sql .= ", '".api_get_utc_datetime()."'";
350
+            $sql .= ',\''.Database::escape_string($this->type).'\'';
351
+            $sql .= ")";
352
+
353
+            Database::query($sql);
354
+            $this->set_id(Database::insert_id());
355
+        } else {
356
+            die('Error in Evaluation add: required field empty');
357
+        }
358
+    }
359
+
360
+    /**
361
+     * @param int $idevaluation
362
+     */
363
+    public function add_evaluation_log($idevaluation)
364
+    {
365
+        if (!empty($idevaluation)) {
366
+            $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
367
+            $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
368
+            $eval = new Evaluation();
369
+            $dateobject = $eval->load($idevaluation,null,null,null,null);
370
+            $arreval = get_object_vars($dateobject[0]);
371
+            if (!empty($arreval['id'])) {
372
+                $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
373 373
                         WHERE id='.$arreval['id'];
374 374
                 $rs = Database::query($sql);
375 375
                 $row_old_weight = Database::fetch_array($rs, 'ASSOC');
@@ -385,426 +385,426 @@  discard block
 block discarded – undo
385 385
                     'user_id_log' => api_get_user_id()
386 386
                 ];
387 387
                 Database::insert($tbl_grade_linkeval_log, $params);
388
-			}
389
-		}
390
-	}
391
-
392
-	/**
393
-	 * Update the properties of this evaluation in the database
394
-	 */
395
-	public function save()
396
-	{
397
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
398
-		$sql = 'UPDATE '.$tbl_grade_evaluations
399
-			." SET name = '".Database::escape_string($this->get_name())."'"
400
-			.', description = ';
401
-		if (isset($this->description)) {
402
-			$sql .= "'".Database::escape_string($this->get_description())."'";
403
-		}else {
404
-			$sql .= 'null';
405
-		}
406
-		$sql .= ', user_id = '.intval($this->get_user_id())
407
-			.', course_code = ';
408
-		if (isset($this->course_code)) {
409
-			$sql .= "'".Database::escape_string($this->get_course_code())."'";
410
-		} else {
411
-			$sql .= 'null';
412
-		}
413
-		$sql .= ', category_id = ';
414
-		if (isset($this->category)) {
415
-			$sql .= intval($this->get_category_id());
416
-		} else {
417
-			$sql .= 'null';
418
-		}
419
-		$sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
420
-			.', max = '.intval($this->get_max())
421
-			.', visible = '.intval($this->is_visible())
422
-			.' WHERE id = '.intval($this->id);
423
-		//recorded history
424
-
425
-		$eval_log = new Evaluation();
426
-		$eval_log->add_evaluation_log($this->id);
427
-		Database::query($sql);
428
-	}
429
-
430
-	/**
431
-	 * Delete this evaluation from the database
432
-	 */
433
-	public function delete()
434
-	{
435
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
436
-		$sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
437
-		Database::query($sql);
438
-	}
439
-
440
-	/**
441
-	 * Check if an evaluation name (with the same parent category) already exists
442
-	 * @param $name name to check (if not given, the name property of this object will be checked)
443
-	 * @param $parent parent category
444
-	 */
445
-	public function does_name_exist($name, $parent)
446
-	{
447
-		if (!isset ($name)) {
448
-			$name = $this->name;
449
-			$parent = $this->category;
450
-		}
451
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
452
-		$sql = 'SELECT count(id) AS number'
453
-			.' FROM '.$tbl_grade_evaluations
454
-			." WHERE name = '".Database::escape_string($name)."'";
455
-
456
-		if (api_is_allowed_to_edit()) {
457
-			$parent = Category::load($parent);
458
-			$code = $parent[0]->get_course_code();
459
-			$courseInfo = api_get_course_info($code);
460
-			$courseId = $courseInfo['real_id'];
461
-
462
-			if (isset($code) && $code != '0') {
463
-				$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
464
-				$sql .= ' AND user_id IN (
388
+            }
389
+        }
390
+    }
391
+
392
+    /**
393
+     * Update the properties of this evaluation in the database
394
+     */
395
+    public function save()
396
+    {
397
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
398
+        $sql = 'UPDATE '.$tbl_grade_evaluations
399
+            ." SET name = '".Database::escape_string($this->get_name())."'"
400
+            .', description = ';
401
+        if (isset($this->description)) {
402
+            $sql .= "'".Database::escape_string($this->get_description())."'";
403
+        }else {
404
+            $sql .= 'null';
405
+        }
406
+        $sql .= ', user_id = '.intval($this->get_user_id())
407
+            .', course_code = ';
408
+        if (isset($this->course_code)) {
409
+            $sql .= "'".Database::escape_string($this->get_course_code())."'";
410
+        } else {
411
+            $sql .= 'null';
412
+        }
413
+        $sql .= ', category_id = ';
414
+        if (isset($this->category)) {
415
+            $sql .= intval($this->get_category_id());
416
+        } else {
417
+            $sql .= 'null';
418
+        }
419
+        $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" '
420
+            .', max = '.intval($this->get_max())
421
+            .', visible = '.intval($this->is_visible())
422
+            .' WHERE id = '.intval($this->id);
423
+        //recorded history
424
+
425
+        $eval_log = new Evaluation();
426
+        $eval_log->add_evaluation_log($this->id);
427
+        Database::query($sql);
428
+    }
429
+
430
+    /**
431
+     * Delete this evaluation from the database
432
+     */
433
+    public function delete()
434
+    {
435
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
436
+        $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id);
437
+        Database::query($sql);
438
+    }
439
+
440
+    /**
441
+     * Check if an evaluation name (with the same parent category) already exists
442
+     * @param $name name to check (if not given, the name property of this object will be checked)
443
+     * @param $parent parent category
444
+     */
445
+    public function does_name_exist($name, $parent)
446
+    {
447
+        if (!isset ($name)) {
448
+            $name = $this->name;
449
+            $parent = $this->category;
450
+        }
451
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
452
+        $sql = 'SELECT count(id) AS number'
453
+            .' FROM '.$tbl_grade_evaluations
454
+            ." WHERE name = '".Database::escape_string($name)."'";
455
+
456
+        if (api_is_allowed_to_edit()) {
457
+            $parent = Category::load($parent);
458
+            $code = $parent[0]->get_course_code();
459
+            $courseInfo = api_get_course_info($code);
460
+            $courseId = $courseInfo['real_id'];
461
+
462
+            if (isset($code) && $code != '0') {
463
+                $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
464
+                $sql .= ' AND user_id IN (
465 465
 					 SELECT user_id FROM '.$main_course_user_table.'
466 466
 					 WHERE
467 467
 						c_id = '.$courseId.' AND
468 468
 						status = '.COURSEMANAGER.'
469 469
 					)';
470
-			} else {
471
-				$sql .= ' AND user_id = '.api_get_user_id();
472
-			}
473
-
474
-		}else {
475
-			$sql .= ' AND user_id = '.api_get_user_id();
476
-		}
477
-
478
-		if (!isset ($parent)) {
479
-			$sql.= ' AND category_id is null';
480
-		} else {
481
-			$sql.= ' AND category_id = '.intval($parent);
482
-		}
483
-		$result = Database::query($sql);
484
-		$number=Database::fetch_row($result);
485
-
486
-		return $number[0] != 0;
487
-	}
488
-
489
-	/**
490
-	 * Are there any results for this evaluation yet ?
491
-	 * The 'max' property should not be changed then.
492
-	 */
493
-	public function has_results()
494
-	{
495
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
496
-		$sql = 'SELECT count(id) AS number
470
+            } else {
471
+                $sql .= ' AND user_id = '.api_get_user_id();
472
+            }
473
+
474
+        }else {
475
+            $sql .= ' AND user_id = '.api_get_user_id();
476
+        }
477
+
478
+        if (!isset ($parent)) {
479
+            $sql.= ' AND category_id is null';
480
+        } else {
481
+            $sql.= ' AND category_id = '.intval($parent);
482
+        }
483
+        $result = Database::query($sql);
484
+        $number=Database::fetch_row($result);
485
+
486
+        return $number[0] != 0;
487
+    }
488
+
489
+    /**
490
+     * Are there any results for this evaluation yet ?
491
+     * The 'max' property should not be changed then.
492
+     */
493
+    public function has_results()
494
+    {
495
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
496
+        $sql = 'SELECT count(id) AS number
497 497
 				FROM '.$tbl_grade_results.'
498 498
 				WHERE evaluation_id = '.intval($this->id);
499
-		$result = Database::query($sql);
500
-		$number=Database::fetch_row($result);
501
-
502
-		return ($number[0] != 0);
503
-	}
504
-
505
-	/**
506
-	 * Delete all results for this evaluation
507
-	 */
508
-	public function delete_results()
509
-	{
510
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
511
-		$sql = 'DELETE FROM '.$tbl_grade_results.'
499
+        $result = Database::query($sql);
500
+        $number=Database::fetch_row($result);
501
+
502
+        return ($number[0] != 0);
503
+    }
504
+
505
+    /**
506
+     * Delete all results for this evaluation
507
+     */
508
+    public function delete_results()
509
+    {
510
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
511
+        $sql = 'DELETE FROM '.$tbl_grade_results.'
512 512
 				WHERE evaluation_id = '.intval($this->id);
513
-		Database::query($sql);
514
-	}
515
-
516
-	/**
517
-	 * Delete this evaluation and all underlying results.
518
-	 */
519
-	public function delete_with_results()
520
-	{
521
-		$this->delete_results();
522
-		$this->delete();
523
-	}
524
-
525
-	/**
526
-	 * Check if the given score is possible for this evaluation
527
-	 */
528
-	public function is_valid_score($score)
529
-	{
530
-		return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
531
-	}
532
-
533
-	/**
534
-	 * Calculate the score of this evaluation
535
-	 * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
536
-	 * @param string $type (best, average, ranking)
537
-	 * @return	array (score, max) if student is given
538
-	 * 			array (sum of scores, number of scores) otherwise
539
-	 * 			or null if no scores available
540
-	 */
541
-	public function calc_score($stud_id = null, $type = null)
542
-	{
513
+        Database::query($sql);
514
+    }
515
+
516
+    /**
517
+     * Delete this evaluation and all underlying results.
518
+     */
519
+    public function delete_with_results()
520
+    {
521
+        $this->delete_results();
522
+        $this->delete();
523
+    }
524
+
525
+    /**
526
+     * Check if the given score is possible for this evaluation
527
+     */
528
+    public function is_valid_score($score)
529
+    {
530
+        return is_numeric($score) && $score >= 0 && $score <= $this->eval_max;
531
+    }
532
+
533
+    /**
534
+     * Calculate the score of this evaluation
535
+     * @param int $stud_id (default: all students who have results for this eval - then the average is returned)
536
+     * @param string $type (best, average, ranking)
537
+     * @return	array (score, max) if student is given
538
+     * 			array (sum of scores, number of scores) otherwise
539
+     * 			or null if no scores available
540
+     */
541
+    public function calc_score($stud_id = null, $type = null)
542
+    {
543 543
         $useSession = true;
544
-		if (isset($stud_id) && empty($type)) {
545
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
546
-			$data = Session::read('calc_score');
544
+        if (isset($stud_id) && empty($type)) {
545
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
546
+            $data = Session::read('calc_score');
547 547
             $results = isset($data[$key]) ? $data[$key] : null;
548 548
 
549 549
             if ($useSession == false) {
550 550
                 $results  = null;
551 551
             }
552
-			if (empty($results)) {
553
-				$results = Result::load(null, $stud_id, $this->id);
554
-				Session::write('calc_score', array($key => $results));
555
-			}
556
-
557
-			$score = 0;
558
-			/** @var Result $res */
559
-			foreach ($results as $res) {
560
-				$score = $res->get_score();
561
-			}
562
-
563
-			return array($score, $this->get_max());
564
-		} else {
565
-
566
-			$count = 0;
567
-			$sum = 0;
568
-			$bestResult = 0;
569
-			$weight = 0;
570
-			$sumResult = 0;
571
-
572
-			$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
552
+            if (empty($results)) {
553
+                $results = Result::load(null, $stud_id, $this->id);
554
+                Session::write('calc_score', array($key => $results));
555
+            }
556
+
557
+            $score = 0;
558
+            /** @var Result $res */
559
+            foreach ($results as $res) {
560
+                $score = $res->get_score();
561
+            }
562
+
563
+            return array($score, $this->get_max());
564
+        } else {
565
+
566
+            $count = 0;
567
+            $sum = 0;
568
+            $bestResult = 0;
569
+            $weight = 0;
570
+            $sumResult = 0;
571
+
572
+            $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
573 573
             $data = Session::read('calc_score');
574 574
             $allResults = isset($data[$key]) ? $data[$key] : null;
575 575
             if ($useSession == false) {
576 576
                 $allResults  = null;
577 577
             }
578
-			if (empty($allResults)) {
579
-				$allResults = Result::load(null, null, $this->id);
580
-				Session::write($key, $allResults);
581
-			}
582
-
583
-			$students = array();
584
-			/** @var Result $res */
585
-			foreach ($allResults as $res) {
586
-				$score = $res->get_score();
587
-				if (!empty($score) || $score == '0') {
588
-					$count++;
589
-					$sum += $score / $this->get_max();
590
-					$sumResult += $score;
591
-					if ($score > $bestResult) {
592
-						$bestResult = $score;
593
-					}
594
-					$weight = $this->get_max();
595
-				}
596
-				$students[$res->get_user_id()] = $score;
597
-			}
598
-
599
-			if (empty($count)) {
600
-				return null;
601
-			}
602
-
603
-			switch ($type) {
604
-				case 'best':
605
-					return array($bestResult, $weight);
606
-					break;
607
-				case 'average':
608
-					return array($sumResult/$count, $weight);
609
-					break;
610
-				case 'ranking':
578
+            if (empty($allResults)) {
579
+                $allResults = Result::load(null, null, $this->id);
580
+                Session::write($key, $allResults);
581
+            }
582
+
583
+            $students = array();
584
+            /** @var Result $res */
585
+            foreach ($allResults as $res) {
586
+                $score = $res->get_score();
587
+                if (!empty($score) || $score == '0') {
588
+                    $count++;
589
+                    $sum += $score / $this->get_max();
590
+                    $sumResult += $score;
591
+                    if ($score > $bestResult) {
592
+                        $bestResult = $score;
593
+                    }
594
+                    $weight = $this->get_max();
595
+                }
596
+                $students[$res->get_user_id()] = $score;
597
+            }
598
+
599
+            if (empty($count)) {
600
+                return null;
601
+            }
602
+
603
+            switch ($type) {
604
+                case 'best':
605
+                    return array($bestResult, $weight);
606
+                    break;
607
+                case 'average':
608
+                    return array($sumResult/$count, $weight);
609
+                    break;
610
+                case 'ranking':
611 611
                     $students = array();
612 612
                     /** @var Result $res */
613 613
                     foreach ($allResults as $res) {
614 614
                         $score = $res->get_score();
615 615
                         $students[$res->get_user_id()] = $score;
616 616
                     }
617
-					return AbstractLink::getCurrentUserRanking($stud_id, $students);
618
-					break;
619
-				default:
620
-					return array($sum, $count);
621
-					break;
622
-			}
623
-		}
624
-	}
625
-
626
-	/**
627
-	 * Generate an array of possible categories where this evaluation can be moved to.
628
-	 * Notice: its own parent will be included in the list: it's up to the frontend
629
-	 * to disable this element.
630
-	 * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
631
-	 */
632
-	public function get_target_categories()
633
-	{
634
-		// - course independent evaluation
635
-		//   -> movable to root or other course independent categories
636
-		// - evaluation inside a course
637
-		//   -> movable to root, independent categories or categories inside the course
638
-		$user = (api_is_platform_admin() ? null : api_get_user_id());
639
-		$targets = array();
640
-		$level = 0;
641
-
642
-		$root = array(0, get_lang('RootCat'), $level);
643
-		$targets[] = $root;
644
-
645
-		if (isset($this->course_code) && !empty($this->course_code)) {
646
-			$crscats = Category::load(null,null,$this->course_code,0);
647
-			foreach ($crscats as $cat) {
648
-				$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
649
-				$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
650
-			}
651
-		}
652
-
653
-		$indcats = Category::load(null,$user,0,0);
654
-		foreach ($indcats as $cat) {
655
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
656
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
657
-		}
658
-
659
-		return $targets;
660
-	}
661
-
662
-	/**
663
-	 * Internal function used by get_target_categories()
664
-	 * @param integer $level
665
-	 */
666
-	private function add_target_subcategories($targets, $level, $catid)
667
-	{
668
-		$subcats = Category::load(null,null,null,$catid);
669
-		foreach ($subcats as $cat) {
670
-			$targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
671
-			$targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
672
-		}
673
-		return $targets;
674
-	}
675
-
676
-	/**
677
-	 * Move this evaluation to the given category.
678
-	 * If this evaluation moves from inside a course to outside,
679
-	 * its course code is also changed.
680
-	 */
681
-	public function move_to_cat($cat)
682
-	{
683
-		$this->set_category_id($cat->get_id());
684
-		if ($this->get_course_code() != $cat->get_course_code()) {
685
-			$this->set_course_code($cat->get_course_code());
686
-		}
687
-		$this->save();
688
-	}
689
-
690
-	/**
691
-	 * Retrieve evaluations where a student has results for
692
-	 * and return them as an array of Evaluation objects
693
-	 * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
694
-	 * @param int $stud_id student id
695
-	 */
696
-	public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
697
-	{
698
-		$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
699
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
700
-
701
-		$sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
617
+                    return AbstractLink::getCurrentUserRanking($stud_id, $students);
618
+                    break;
619
+                default:
620
+                    return array($sum, $count);
621
+                    break;
622
+            }
623
+        }
624
+    }
625
+
626
+    /**
627
+     * Generate an array of possible categories where this evaluation can be moved to.
628
+     * Notice: its own parent will be included in the list: it's up to the frontend
629
+     * to disable this element.
630
+     * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
631
+     */
632
+    public function get_target_categories()
633
+    {
634
+        // - course independent evaluation
635
+        //   -> movable to root or other course independent categories
636
+        // - evaluation inside a course
637
+        //   -> movable to root, independent categories or categories inside the course
638
+        $user = (api_is_platform_admin() ? null : api_get_user_id());
639
+        $targets = array();
640
+        $level = 0;
641
+
642
+        $root = array(0, get_lang('RootCat'), $level);
643
+        $targets[] = $root;
644
+
645
+        if (isset($this->course_code) && !empty($this->course_code)) {
646
+            $crscats = Category::load(null,null,$this->course_code,0);
647
+            foreach ($crscats as $cat) {
648
+                $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
649
+                $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
650
+            }
651
+        }
652
+
653
+        $indcats = Category::load(null,$user,0,0);
654
+        foreach ($indcats as $cat) {
655
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
656
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
657
+        }
658
+
659
+        return $targets;
660
+    }
661
+
662
+    /**
663
+     * Internal function used by get_target_categories()
664
+     * @param integer $level
665
+     */
666
+    private function add_target_subcategories($targets, $level, $catid)
667
+    {
668
+        $subcats = Category::load(null,null,null,$catid);
669
+        foreach ($subcats as $cat) {
670
+            $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1);
671
+            $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id());
672
+        }
673
+        return $targets;
674
+    }
675
+
676
+    /**
677
+     * Move this evaluation to the given category.
678
+     * If this evaluation moves from inside a course to outside,
679
+     * its course code is also changed.
680
+     */
681
+    public function move_to_cat($cat)
682
+    {
683
+        $this->set_category_id($cat->get_id());
684
+        if ($this->get_course_code() != $cat->get_course_code()) {
685
+            $this->set_course_code($cat->get_course_code());
686
+        }
687
+        $this->save();
688
+    }
689
+
690
+    /**
691
+     * Retrieve evaluations where a student has results for
692
+     * and return them as an array of Evaluation objects
693
+     * @param int $cat_id parent category (use 'null' to retrieve them in all categories)
694
+     * @param int $stud_id student id
695
+     */
696
+    public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id)
697
+    {
698
+        $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
699
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
700
+
701
+        $sql = 'SELECT * FROM '.$tbl_grade_evaluations.'
702 702
 				WHERE id IN (
703 703
 					SELECT evaluation_id FROM '.$tbl_grade_results.'
704 704
 					WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL
705 705
 				)';
706
-		if (!api_is_allowed_to_edit()) {
707
-			$sql .= ' AND visible = 1';
708
-		}
709
-		if (isset($cat_id)) {
710
-			$sql .= ' AND category_id = '.intval($cat_id);
711
-		} else {
712
-			$sql .= ' AND category_id >= 0';
713
-		}
714
-
715
-		$result = Database::query($sql);
716
-		$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
717
-
718
-		return $alleval;
719
-	}
720
-
721
-	/**
722
-	 * Get a list of students that do not have a result record for this evaluation
723
-	 */
724
-	public function get_not_subscribed_students($first_letter_user = '')
725
-	{
726
-		$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
727
-		$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
728
-
729
-		$sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
730
-			." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
731
-			.' AND status = '.STUDENT
732
-			.' AND user_id NOT IN'
733
-			.' (SELECT user_id FROM '.$tbl_grade_results
734
-			.' WHERE evaluation_id = '.intval($this->id)
735
-			.' )'
736
-			.' ORDER BY lastname';
737
-
738
-		$result = Database::query($sql);
739
-		$users = Database::store_result($result);
740
-
741
-		return $users;
742
-	}
743
-
744
-	/**
745
-	 * Find evaluations by name
746
-	 * @param string $name_mask search string
747
-	 * @return array evaluation objects matching the search criterium
748
-	 * @todo can be written more efficiently using a new (but very complex) sql query
749
-	 */
750
-	public function find_evaluations($name_mask,$selectcat)
751
-	{
752
-		$rootcat = Category::load($selectcat);
753
-		$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
754
-		$foundevals = array();
755
-		foreach ($evals as $eval) {
756
-			if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
757
-				$foundevals[] = $eval;
758
-			}
759
-		}
760
-		return $foundevals;
761
-	}
762
-
763
-	public function get_item_type()
764
-	{
765
-		return 'E';
766
-	}
767
-
768
-	public function get_icon_name()
769
-	{
770
-		return $this->has_results() ? 'evalnotempty' : 'evalempty';
771
-	}
772
-
773
-	/**
774
-	 * Locks an evaluation, only one who can unlock it is the platform administrator.
775
-	 * @param int locked 1 or unlocked 0
776
-	 *
777
-	 **/
778
-	function lock($locked)
779
-	{
780
-		$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
781
-		$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
782
-		Database::query($sql);
783
-	}
784
-
785
-	function check_lock_permissions()
786
-	{
787
-		if (api_is_platform_admin()) {
788
-			return true;
789
-		} else {
790
-			if ($this->is_locked()) {
791
-				api_not_allowed();
792
-			}
793
-		}
794
-	}
795
-
796
-	function delete_linked_data()
797
-	{
798
-
799
-	}
706
+        if (!api_is_allowed_to_edit()) {
707
+            $sql .= ' AND visible = 1';
708
+        }
709
+        if (isset($cat_id)) {
710
+            $sql .= ' AND category_id = '.intval($cat_id);
711
+        } else {
712
+            $sql .= ' AND category_id >= 0';
713
+        }
714
+
715
+        $result = Database::query($sql);
716
+        $alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
717
+
718
+        return $alleval;
719
+    }
720
+
721
+    /**
722
+     * Get a list of students that do not have a result record for this evaluation
723
+     */
724
+    public function get_not_subscribed_students($first_letter_user = '')
725
+    {
726
+        $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
727
+        $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
728
+
729
+        $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
730
+            ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
731
+            .' AND status = '.STUDENT
732
+            .' AND user_id NOT IN'
733
+            .' (SELECT user_id FROM '.$tbl_grade_results
734
+            .' WHERE evaluation_id = '.intval($this->id)
735
+            .' )'
736
+            .' ORDER BY lastname';
737
+
738
+        $result = Database::query($sql);
739
+        $users = Database::store_result($result);
740
+
741
+        return $users;
742
+    }
743
+
744
+    /**
745
+     * Find evaluations by name
746
+     * @param string $name_mask search string
747
+     * @return array evaluation objects matching the search criterium
748
+     * @todo can be written more efficiently using a new (but very complex) sql query
749
+     */
750
+    public function find_evaluations($name_mask,$selectcat)
751
+    {
752
+        $rootcat = Category::load($selectcat);
753
+        $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
754
+        $foundevals = array();
755
+        foreach ($evals as $eval) {
756
+            if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
757
+                $foundevals[] = $eval;
758
+            }
759
+        }
760
+        return $foundevals;
761
+    }
762
+
763
+    public function get_item_type()
764
+    {
765
+        return 'E';
766
+    }
767
+
768
+    public function get_icon_name()
769
+    {
770
+        return $this->has_results() ? 'evalnotempty' : 'evalempty';
771
+    }
772
+
773
+    /**
774
+     * Locks an evaluation, only one who can unlock it is the platform administrator.
775
+     * @param int locked 1 or unlocked 0
776
+     *
777
+     **/
778
+    function lock($locked)
779
+    {
780
+        $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
781
+        $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
782
+        Database::query($sql);
783
+    }
784
+
785
+    function check_lock_permissions()
786
+    {
787
+        if (api_is_platform_admin()) {
788
+            return true;
789
+        } else {
790
+            if ($this->is_locked()) {
791
+                api_not_allowed();
792
+            }
793
+        }
794
+    }
795
+
796
+    function delete_linked_data()
797
+    {
798
+
799
+    }
800 800
 
801 801
     public function getStudentList()
802 802
     {
803 803
         return $this->studentList;
804 804
     }
805 805
 
806
-	public function setStudentList($list)
807
-	{
808
-		$this->studentList = $list;
809
-	}
806
+    public function setStudentList($list)
807
+    {
808
+        $this->studentList = $list;
809
+    }
810 810
 }
Please login to merge, or discard this patch.
main/inc/lib/chat.lib.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
     }
40 40
 
41 41
     /**
42
-    * Set user chat status
43
-    * @param int 0 if disconnected, 1 if connected
44
-    * @param integer $status
42
+     * Set user chat status
43
+     * @param int 0 if disconnected, 1 if connected
44
+     * @param integer $status
45 45
      *
46
-    * @return void
47
-    */
46
+     * @return void
47
+     */
48 48
     public function setUserStatus($status)
49 49
     {
50 50
         UserManager::update_extra_field_value(api_get_user_id(), 'user_chat_status', $status);
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
     }
149 149
 
150 150
     /**
151
-    * Returns an array of messages inside a chat session with a specific user
152
-    * @param int The ID of the user with whom the current user is chatting
153
-    * @return array Messages list
154
-    */
151
+     * Returns an array of messages inside a chat session with a specific user
152
+     * @param int The ID of the user with whom the current user is chatting
153
+     * @return array Messages list
154
+     */
155 155
     public function box_session($user_id)
156 156
     {
157 157
         $items = array();
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             }
300 300
         }
301 301
          
302
-         return false;
302
+            return false;
303 303
     }
304 304
     
305 305
     public function is_chat_blocked_by_exercises()
Please login to merge, or discard this patch.