Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2

[eluser]WanWizard[/eluser]
As documented, you can use all supported query clauses in advanced queries, so that works fine.

See http://datamapper.wanwizard.eu/pages/get...ry.Clauses

[eluser]CI-Newb[/eluser]
Hello, I'm using the following login function

Code:
function login() {
        $username = $this->username;
        $u = new User();
        $u->where('username', $username);
        $u->where('account_status =', 'active')->get();
        $this->salt = $u->salt;
        $this->validate()->get();
        if ($this->exists()) {
            return TRUE;
        } else {
            $this->error_message('login', $this->lang->line('error_invalid_login'));
            $this->username = $username;
            return FALSE;
        }
    }

I have different type's of account status like "expired", "suspended" etc. What would be the most efficent way to show a different error message for each?

[eluser]PoetaWD[/eluser]
Thanks Man ! I see now !

[eluser]Maglok[/eluser]
@CI-Newb: You could try to select a different lang line for each?

Code:
$this->error_message('login', $this->lang->line('error_' . $u->status));

[eluser]CI-Newb[/eluser]
I don't think that would work because it's only getting a user if their status is active .. otherwise the user object is blank I believe

[eluser]Maglok[/eluser]
Wouldnt you need a User/Account object to see what the status of it is?

If not you can always do it if it is an empty object on the default value.

Lets say $user = 'inactive' by default, then you can use that? And for all others you need to get the account first?

[eluser]CI-Newb[/eluser]
edit: Although the suggested solution did work I've reworked the code here is my new login logic should anyone find it useful at some point in time. Inactive = can't log in, Suspended = can't log in, expired = can log in sets flash data asking to renew

Code:
function login() {
        $username = $this->username;
        $u = new User();
        $u->where('username', $username)->where('account_status !=', 'inactive')->get();
        $this->salt = $u->salt;
        $this->validate()->get();
        if ($this->exists()) {
            if ($u->account_status == 'suspended') {
                $this->error_message('login', $this->lang->line('error_invalid_login_suspended'));
                $this->username = $username;
                return FALSE;
            } else if ($u->account_status == 'expired') {
                $CI = & get_instance();
                $CI->session->set_flashdata('login_message', $this->lang->line('error_account_expired'));
                return TRUE;
            } else {
                return TRUE;
            }
        } else {
            $this->error_message('login', $this->lang->line('error_invalid_login'));
            $this->username = $username;
            return FALSE;
        }
    }

[eluser]Maglok[/eluser]
Great Smile

And on the flipside, it is quite quite early. Smile

[eluser]Maglok[/eluser]
Alrighty self relationships 101. I go from this page on this: http://datamapper.wanwizard.eu/pages/adv...tions.html

I have a very 'simple' self relationship. Never done those before in Datamapper and thus, issues.

It is simple. I have a class ACCategory and it should have a has_many with more categories who are children of it, kinda like directories. Then it should also know its parent.

Code:
class ACCategory extends DataMapper {
var $auto_populate_has_many = TRUE;
var $table = 'ac_categories';

var $has_many = array(
   'parentcategory' => array(
     'class' => 'accategory',
     'other_field' => 'category',
     'join_self_as' => 'category',
     'join_other_as' => 'parentcategory',
     'join_table' => 'ccj_ac_category_parentcategory'    
   ),  
   'categories' => array(
     'class' => 'accategory',
     'other_field' => 'parentcategory',
     'join_self_as' => 'parentcategory',
     'join_other_as' => 'category',
     'join_table' => 'ccj_ac_category_parentcategory'    
   ),
  );

That is where I am at the moment.

The database is like this:
Code:
TABLE: ccj_ac_category_parentcategory = id|category_id|parentcategory_id

I am kind of stuck with the tablenaming conventions so that is a given.

I get the usual 'category is not a valid parent relationship for ACCategory' error.

EDIT: Now that I think about it, the parent_category should probably be only one, you can only have one parent in this case.

[eluser]WanWizard[/eluser]
'other_field' has to point to the relation from the other side, so in your first definition that should be 'categories', not 'category'.




Theme © iAndrew 2016 - Forum software by © MyBB