示例#1
0
 function update_user_role($user_id, $role_ids)
 {
     $this->_db()->delete('user_role', array('user_id' => $user_id));
     if (!empty($role_ids)) {
         if (!is_array($role_ids)) {
             $role_ids = array($role_ids);
         }
         foreach ($role_ids as $role_id) {
             if (!empty($role_id)) {
                 $role_id = empty($role_id) ? 0 : $role_id;
                 $user_role = array('user_id' => $user_id, 'role_id' => $role_id);
                 Base_Model::before_save($user_role);
                 $this->_db()->insert('user_role', $user_role);
             }
         }
     }
 }
示例#2
0
 function update_tag($tags, $id)
 {
     $CI =& get_instance();
     if (!is_array($tags)) {
         $tags = array($tags);
     }
     $this->db->where(array($this->_name . '_id' => $id));
     $this->db->delete('tag_' . $this->_name);
     foreach ($tags as $tag) {
         if (!empty($tag)) {
             $tag_id = $CI->_model('tag')->add($tag);
             if (!empty($tag_id)) {
                 $obj_tag = array('tag_id' => $tag_id, $this->_name . '_id' => $id);
                 Base_Model::before_save($obj_tag);
                 $this->db->insert('tag_' . $this->_name, $obj_tag);
             }
         }
     }
 }