2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/UsersDAO.class.php');
27 var $userID; // set by setUserID
28 var $userDAO; // DAO for this user
37 function User($user_id)
39 $this->userID = $user_id;
41 $this->userDAO = new UsersDAO();
45 * Based on this->userID, return (first name, last name), if first name, last name not exists, return login name
48 * @return first name, last name. if not exists, return login name
51 public function getUserName()
53 return $this->userDAO->getUserName($this->userID);
57 * Return all info of this->userID
63 public function getInfo()
65 return $this->userDAO->getUserByID($this->userID);
69 * Check if user is an author
71 * @param $course_id: optional.
72 * if > 0, check whether the user is the author of the course with $course_id
73 * else if = 0 or is not given, check whether the user has author privilege
74 * @return true : if is an author
75 * false : if not an author
78 public function isAuthor($course_id = 0)
82 $row = $this->userDAO->getUserByID($this->userID);
83 return $row['is_author'];
87 include_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
88 $coursesDAO = new CoursesDAO();
89 $course_row = $coursesDAO->get($course_id);
91 return ($course_row['user_id'] == $this->userID);
96 * Check if user is admin
99 * @return true : if is an admin
100 * false : if not an admin
101 * @author Cindy Qi Li
103 public function isAdmin()
105 $row = $this->userDAO->getUserByID($this->userID);
107 if ($row['user_group_id'] == TR_USER_GROUP_ADMIN)
114 * Update user's first, last name
116 * @param $firstName : first name
117 * $lastName : last name
118 * @return true if update successfully
119 * false if update unsuccessful
120 * @author Cindy Qi Li
122 public function setName($firstName, $lastName)
124 return $this->userDAO->setName($this->userID, $firstName, $lastName);
128 * Update user's password
131 * @return true if update successfully
132 * false if update unsuccessful
133 * @author Cindy Qi Li
135 public function setPassword($password)
137 return $this->userDAO->setPassword($this->userID, $password);
141 * Update user's email
144 * @return true if update successfully
145 * false if update unsuccessful
146 * @author Cindy Qi Li
148 public function setEmail($email)
150 return $this->userDAO->setEmail($this->userID, $email);