-1

I have developed a scheduling application where I have one table and dm class called "users" where i so far have stored all information about all users in the system. All users are internal users.

Now I need to implement login functionality for external users (customers) too.

My question: I would now like to use my table users and just add an enum field 'user_type' (internal/external).

I would then like to create a datamapper object called internal_user and another one called exernal_user.

when i run

$external_user = new External_user();
$external_user->get();

I only want to get the rows in my user table where user_type = external. Is that possible to achieve in a nice way using datamapper?

UPDATE:

I solved the problem by overriding the get method in the Datamapper class like this:

class Internal_user(){
    [...]
    function get()
    {
        $this->where('type', 'internal');
        return parent::get();
    }
}

Now this line:

$internal_user->get();

only returns the records with the value internal in my user_type field.

jonixj
  • 397
  • 3
  • 11
  • If External_user is extended model from CI_Model, then you can add something like this in get method `$this->db->select(array('col1', 'col2')); $this->db->where(array('type' => 'external', 'othercondn' => value)); return $this->db->get(tablename)->result();` – smitrp Mar 13 '13 at 14:42
  • In case, you want to implement this using single extended model from CI_Model, then you can have two method in extended model. 1) get_internal() - In this you change where function params like this `$this->db->where(array('type' => 'external', 'othercondn' => value));` 2) get_external() - In this you change where function params like this `$this->db->where(array('type' => 'internal', 'othercondn' => value));` – smitrp Mar 13 '13 at 14:46
  • Thanks for your comments. I was hoping to have 2 different classes/ models for external/internal where i did not need to consider the type-parameter. However given you idéa i might be able to extend the get()-method in my model like this: function get(){ $this->db->where('type' => 'internal'); parent::get(); } – jonixj Mar 13 '13 at 15:24

1 Answers1

1

In case, you want to implement this using single extended model from CI_Model, then you can have two method in extended model.

  1. get() - In Base model (which inherits CI_Model) you change where function params like this

    $this->db->select(array('col1', 'col2'));
    
    $this->db->where(array('type' => 'internal', 'othercondn' => value));    
    
    return $this->db->get(tablename)->result();
    
  2. get_external() - In this model (which inherits BaseModel) you change where function params like this

    $this->db->select(array('col1', 'col2'));
    
    $this->db->where(array('type' => 'internal', 'othercondn' => value));
    
    return $this->db->get(tablename)->result();
    
smitrp
  • 1,292
  • 1
  • 12
  • 28