PageRenderTime 42ms CodeModel.GetById 32ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/request/domain/Person.php

http://zoop.googlecode.com/
PHP | 35 lines | 30 code | 5 blank | 0 comment | 6 complexity | 6d43d269c19d4857d2f858ce63905ddc MD5 | raw file
 1<?php
 2class Person extends DbObject
 3{
 4	const rootId = 1;
 5	
 6	protected function init()
 7	{
 8		$this->hasMany('request', array('remote_field' => 'owner_id'));
 9		$this->addGetter('name');
10	}
11	
12	public function getName()
13	{
14		return $this->firstname . ' ' . $this->lastname;
15	}
16		
17	public function getPermittedRequests()
18	{
19		if($this->id == self::rootId)
20			$requests = DbObject::_find('Request', NULL, array('orderby' => 'id'));
21		else
22			$requests = $this->request;
23		return $requests;
24	}
25	
26	public function RequestIsAllowed($request)
27	{
28		if(is_numeric($request))
29			$request = new Request($request);
30		else if(!($request instanceof Request))
31			trigger_error("request not valid: $request");
32		
33		return $request->owner_id == $this->id;
34	}
35}