Changeset 3090 for trunk/modules/auth
- Timestamp:
- 07/12/2008 10:05:34 AM (5 months ago)
- Files:
-
- 1 modified
-
trunk/modules/auth/models/user.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/auth/models/user.php
r3081 r3090 6 6 protected $has_many = array('user_tokens'); 7 7 protected $has_and_belongs_to_many = array('roles'); 8 9 // User roles 10 protected $has_roles; 8 11 9 12 public function __set($key, $value) … … 22 25 if ($object === 'role') 23 26 { 24 // Load a role model25 $role = ORM::factory('role');27 if ( ! $this->loaded) 28 return FALSE; 26 29 27 // Load JOIN info 28 $join_table = $role->join_table($this->table_name); 29 $join_col1 = $role->foreign_key(NULL, $join_table); 30 $join_col2 = $role->foreign_key(TRUE); 30 if ($this->has_roles === NULL) 31 { 32 $this->db->select('id', 'name'); 31 33 32 return (bool) $this->db 33 ->join($role->table_name, $join_col1, $join_col2) 34 ->where($role->unique_key($id), $id) 35 ->where($this->foreign_key(NULL, $join_table), $this->object[$this->primary_key]) 36 ->count_records($join_table); 34 // Load the roles 35 $this->has_roles = $this->roles->select_list('id', 'name'); 36 } 37 38 if (is_string($id) AND ! ctype_digit($id)) 39 { 40 return in_array($id, $this->has_roles); 41 } 42 else 43 { 44 return isset($this->has_roles[$id]); 45 } 37 46 } 38 47 … … 66 75 } 67 76 77 /** 78 * Resets roles when results are loaded. 79 */ 80 protected function load_result($array = FALSE) 81 { 82 parent::load_result($array); 83 84 if ($array === FALSE) 85 { 86 // Reset roles 87 $this->has_roles = NULL; 88 } 89 90 return $this; 91 } 92 68 93 } // End User_Model
