/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/application/models/user.php

  • Committer: Gustav Hatvigsson
  • Date: 2013-05-16 09:01:38 UTC
  • mfrom: (68.1.1 lenasys)
  • Revision ID: gustav.hartvigsson@gmail.com-20130516090138-3s9sf1qo9nkirmqa
Merged the addition of the Ladok user data parser.

Show diffs side-by-side

added added

removed removed

Lines of Context:
246
246
 
247
247
 
248
248
                /*
249
 
                 *      This parser a user list from ladok.
 
249
                 *      This parses a user list from ladok and returns an array with users.
250
250
                 *  RESTRICTED-LEVEL: Teacher
251
251
                 */
252
 
                public function parseLadok() {
253
 
                        //Check that a user is logged in, has the right privileges (is teacher) and not is the users own username.
254
 
                        if($this->isLoggedIn() && $this->getUserType() === 'Teacher' && $this->getUserName() != $userName) {
 
252
                public function parseLadok($string) {
 
253
                        //Check that a user is logged in and has the right privileges (is teacher).
 
254
                        if($this->isLoggedIn() && $this->getUserType() === 'Teacher') {
 
255
                                $userArray = array();
 
256
                                
 
257
                                //Populate array with users from ladok
 
258
                                $ladokUsers = preg_split( '/\r\n|\r|\n/', $string);
 
259
                                
 
260
                                //Trim lines
 
261
                                foreach ($ladokUsers as $key => $value) {
 
262
                                        $ladokUsers[$key] = trim($ladokUsers[$key]);
 
263
                                }
 
264
                                
 
265
                                //Split after last name
 
266
                                foreach ($ladokUsers as $key => $value) {
 
267
                                        $ladokUsers[$key] = explode(',', trim($ladokUsers[$key]));
 
268
                                }
 
269
                                
 
270
                                //Replace whitespaces and tabs with divider.
 
271
                                foreach ($ladokUsers as $key => $value) {
 
272
                                        foreach ($ladokUsers[$key] as $key2 => $value2) {
 
273
                                                $ladokUsers[$key][$key2] = preg_replace('/\s+/', ' ', trim($ladokUsers[$key][$key2]));
 
274
                                        }
 
275
                                }
 
276
                                
 
277
                                //Generate user array
 
278
                                foreach ($ladokUsers as $key => $value) {
 
279
                                        $temp = array(
 
280
                                                'ssn' => substr($ladokUsers[$key][0], 0, 11),
 
281
                                                'lastname' => substr($ladokUsers[$key][0], 12, strlen($ladokUsers[$key][0])),
 
282
                                                'firstname' => substr($ladokUsers[$key][1], 0, stripos($ladokUsers[$key][1], ' ')),
 
283
                                                'email' => substr($ladokUsers[$key][1], (strrpos($ladokUsers[$key][1], ' ') + 1))
 
284
                                        );
 
285
                                        array_push($userArray, $temp);
 
286
                                }
 
287
                                
 
288
                                //Return parsed user array
 
289
                                return $userArray;
255
290
                        }
 
291
                        
 
292
                        //If not authed
 
293
                        return FALSE;
256
294
                }
257
295
 
258
296