PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/application/models/staff_userdb.php

https://bitbucket.org/jrdnhannah/hnd
PHP | 274 lines | 157 code | 55 blank | 62 comment | 10 complexity | 123cecec99852672d32f617566876d60 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH') ) exit('No direct script access!');
  2. require_once('IUserDB.php');
  3. class Staff_UserDB extends CI_Model implements IUserDB
  4. {
  5. #########################################
  6. # Check if username is valid #
  7. # public #
  8. #########################################
  9. public function is_valid_id($id)
  10. {
  11. $this->db->select('staff_id')
  12. ->from('tblStaff')
  13. ->where('staff_id', $id);
  14. $query = $this->db->get();
  15. if($query->num_rows() == 0)
  16. return false;
  17. else
  18. return true;
  19. }
  20. #########################################
  21. # Check if username + pass are valid #
  22. # public #
  23. #########################################
  24. public function is_valid_account($id, $pass)
  25. {
  26. $this->db->select('staff_id')
  27. ->from('tblStaff')
  28. ->where('staff_id', $id)
  29. ->where('password', $pass);
  30. $query = $this->db->get();
  31. if($query->num_rows() == 0)
  32. return false;
  33. else
  34. return true;
  35. }
  36. #########################################
  37. # Get full name #
  38. # public #
  39. #########################################
  40. public function get_full_name($user)
  41. {
  42. $this->db->select('CONCAT(`firstName`, " ", `lastName`) AS `name`', false)
  43. ->from('tblStaff')
  44. ->where('staff_id', $user);
  45. $query = $this->db->get();
  46. $query = $query->row();
  47. return $query->name;
  48. }
  49. #########################################
  50. # Get first name #
  51. # public #
  52. #########################################
  53. public function get_first_name($user)
  54. {
  55. $this->db->select('firstName')
  56. ->from('tblStaff')
  57. ->where('staff_id', $user);
  58. $query = $this->db->get();
  59. $query = $query->row();
  60. return $query->firstName;
  61. }
  62. #########################################
  63. # Get last name #
  64. # public #
  65. #########################################
  66. public function get_last_name($user)
  67. {
  68. $this->db->select('lastName')
  69. ->from('tblStaff')
  70. ->where('staff_id', $user);
  71. $query = $this->db->get();
  72. $query = $query->row();
  73. return $query->lastName;
  74. }
  75. #########################################
  76. # Get dept ID #
  77. # public #
  78. #########################################
  79. public function get_dept($user)
  80. {
  81. $this->db->select('dept')
  82. ->from('tblStaff')
  83. ->where('staff_id', $user);
  84. $query = $this->db->get();
  85. $query = $query->row();
  86. return $query->dept;
  87. }
  88. #########################################
  89. # Get dept name #
  90. # public #
  91. #########################################
  92. public function get_dept_name($did)
  93. {
  94. $this->db->select('name')
  95. ->from('tblDepartments')
  96. ->where('ID', $did);
  97. $query = $this->db->get();
  98. $query = $query->row();
  99. return $query->name;
  100. }
  101. #########################################
  102. # Get student course type #
  103. # public #
  104. #########################################
  105. public function get_course_type($id)
  106. {
  107. $this->db->select('`c`.`type`', false)
  108. ->from('`tblCourses` `c`, `tblStudents` `s`', false)
  109. ->where('`s`.`pnumber`', "'".$id."'", false)
  110. ->where('`s`.`course_id` = `c`.`ID`');
  111. $query = $this->db->get();
  112. $query = $query->row();
  113. return $query->type;
  114. }
  115. #########################################
  116. # Get grades for course type #
  117. # public #
  118. #########################################
  119. public function get_course_marks($ctype)
  120. {
  121. $this->db->select('marks')
  122. ->from('tblCourseType')
  123. ->where('ID', $ctype);
  124. $query = $this->db->get();
  125. $query = $query->row();
  126. return $query->marks;
  127. }
  128. #########################################
  129. # Get lecturers #
  130. # public #
  131. #########################################
  132. public function get_lecturers()
  133. {
  134. $this->db->select('`staff_id`, CONCAT(`firstName`, " ", `lastName`) AS `name`', FALSE)
  135. ->from('tblStaff');
  136. $query = $this->db->get();
  137. return $query->result();
  138. }
  139. #########################################
  140. # Get lecturers all info #
  141. # public #
  142. #########################################
  143. public function get_lecturers_all_info()
  144. {
  145. $this->db->select()
  146. ->from('tblStaff');
  147. $query = $this->db->get();
  148. return $query->result();
  149. }
  150. #########################################
  151. # Get all info on a lecturer #
  152. # public #
  153. #########################################
  154. public function get_lecturer($id)
  155. {
  156. $this->db->select()
  157. ->from('tblStaff')
  158. ->where('staff_id',$id);
  159. $query = $this->db->get();
  160. $l = $query->result();
  161. return $l[0];
  162. }
  163. #########################################
  164. # Add Staff #
  165. # public #
  166. #########################################
  167. public function add_staff($id, $fname, $lname, $pass, $addr, $email, $num, $dept)
  168. {
  169. $data = array(
  170. 'staff_id' => $id,
  171. 'firstName' => $fname,
  172. 'lastName' => $lname,
  173. 'password' => md5($pass),
  174. 'address' => $addr,
  175. 'email' => $email,
  176. 'contactNumber' => $num,
  177. 'dept' => $dept
  178. );
  179. if($this->db->insert('tblStaff', $data))
  180. return true;
  181. else
  182. return false;
  183. }
  184. #########################################
  185. # Edit Staff #
  186. # public #
  187. #########################################
  188. public function edit_staff($id, $fname, $lname, $pass, $addr, $email, $num, $dept)
  189. {
  190. $data = array(
  191. 'firstName' => $fname,
  192. 'lastName' => $lname,
  193. 'address' => $addr,
  194. 'email' => $email,
  195. 'contactNumber' => $num,
  196. 'dept' => $dept
  197. );
  198. if($pass != NULL) $data['password'] = md5($pass);
  199. $this->db->where('staff_id',$id);
  200. if($this->db->update('tblStaff', $data))
  201. return true;
  202. else
  203. return false;
  204. }
  205. #########################################
  206. # Delete Staff Member #
  207. # public #
  208. #########################################
  209. public function delete_staff($id)
  210. {
  211. $this->db->where('staff_id',$id);
  212. if($this->db->delete('tblStaff'))
  213. return true;
  214. else
  215. return false;
  216. }
  217. }
  218. /* End of File */
  219. /* File Location: ./application/models/staff_userdb.php */