array('model'=>'user_token'), 'email_log'=>array('far_key'=>'id'), 'group'=>array('through'=>'account_group'), ); public function rules() { return Arr::merge(parent::rules(),array( 'id'=>array( array('ORM::get_next_id',array(':model',':field')), ), 'site_id'=>array( array('ORM::set_site_id',array(':model',':field')), ), )); } public function activated() { return $this->has_any('group',ORM::factory('Group',array('name'=>'Registered Users'))->list_childgrps(TRUE)); } /** * This function will extract the available methods for this account * This is used both for menu options and method security */ public function methods() { static $result = array(); // @todo We may want to optimise this with some session caching. if ($result) return $result; foreach ($this->groups() as $go) foreach ($go->module_method->find_all() as $mmo) if (empty($result[$mmo->id])) $result[$mmo->id] = $mmo; Sort::MAsort($result,'module->name,menu_display'); return $result; } /** * Return a token valid for this user */ public function token($token_expire,$module,$method,$uses) { return ORM::factory('Module_Method_Token') ->method(array($module,$method)) ->account($this) ->uses($uses) ->expire(time()+$token_expire) ->generate(); } } ?>