00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 # streber - a php5 based project management system (c) 2005-2007 / www.streber-pm.org
00003 # Distributed under the terms and conditions of the GPL as stated in lang/license.html
00004
00013 class ProjectPerson extends DbProjectItem {
00014 public $name;
00015 public $project;
00016
00020 function __construct ($id_or_array=NULL)
00021 {
00022 global $projectperson_fields;
00023 $this->fields= &$projectperson_fields;
00024
00025 parent::__construct($id_or_array);
00026 $this->type=ITEM_PROJECTPERSON;
00027 }
00028
00032 static function initFields()
00033 {
00034 global $projectperson_fields;
00035 $$projectperson_fields=array();
00036 addProjectItemFields(&$projectperson_fields);
00037
00038 foreach(array(
00039 new FieldInternal(array( 'name'=>'id',
00040 'default'=>0,
00041 'in_db_object'=>1,
00042 'in_db_item'=>1,
00043 )),
00044 new FieldInternal(array( 'name'=>'state',
00045 'default'=>1,
00046 'in_db_object'=>1,
00047 'in_db_item'=>1,
00048 )),
00049 new FieldInternal(array( 'name'=>'person',
00050 )),
00051 new FieldInternal(array( 'name'=>'project',
00052 'default'=>0,
00053 'in_db_object'=>1,
00054 'in_db_item'=>1,
00055 )),
00056 new FieldString(array( 'name'=>'name',
00057 'default'=>'member',
00058 'title'=>__('job'),
00059 )),
00060
00061 new FieldInternal(array( 'name'=>'proj_rights',
00062 )),
00063 new FieldInternal(array( 'name'=>'level_create',
00064 'default'=>PUB_LEVEL_OPEN,
00065 )),
00066 new FieldInternal(array( 'name'=>'level_view',
00067 'default'=>PUB_LEVEL_OPEN,
00068 )),
00069 new FieldInternal(array( 'name'=>'level_edit',
00070 'default'=>PUB_LEVEL_OPEN,
00071 )),
00072 new FieldInternal(array( 'name'=>'level_reduce',
00073 'default'=>PUB_LEVEL_OPEN,
00074 )),
00075 new FieldInternal(array( 'name'=>'level_delete',
00076 'default'=>PUB_LEVEL_OPEN,
00077 )),
00082 new FieldInternal(array( 'name'=>'adjust_effort_style',
00083 'default'=>EFFORT_STYLE_DURATION,
00084 )),
00085
00086 new FieldInternal(array( 'name'=>'role', # this is only a cache for string-output
00087 'title'=>__('role'),
00088 'default'=>PROFILE_USER,
00089 )),
00090 ) as $f) {
00091 $projectperson_fields[$f->name]=$f;
00092 }
00093 }
00094
00095
00101 static function getById($id)
00102 {
00103 $pp= new ProjectPerson($id);
00104 if($pp->id) {
00105 return $pp;
00106 }
00107 return NULL;
00108 }
00109
00110
00118 static function getVisibleById($id)
00119 {
00120 if($pp= ProjectPerson::getById($id)) {
00121 if($p= Project::getById($pp->project)) {
00122 if($p->validateViewItem($pp)) {
00123 return $pp;
00124 }
00125 }
00126 }
00127 return NULL;
00128 }
00129
00133 static function getEditableById($id)
00134 {
00135 if($pp= ProjectPerson::getById($id)) {
00136 if($p= Project::getById($pp->project)) {
00137 if($p->validateEditItem($pp)) {
00138 return $pp;
00139 }
00140 }
00141 }
00142 return NULL;
00143 }
00144
00145
00146
00150 public function getPerson()
00151 {
00152 return Person::getById($this->person);
00153 }
00154
00155
00159 public function initWithUserProfile($profile_num= NULL)
00160 {
00161 global $g_user_profile_names;
00162 global $g_user_profiles;
00163
00164 if(is_null($profile_num)) {
00165 trigger_error("initWithProfile() needes profile",E_USER_ERROR);
00166 }
00167
00168 if(!isset($g_user_profiles[$profile_num])) {
00169 trigger_error("undefined profile '$profile_num'",E_USER_ERROR);
00170 return NULL;
00171 }
00172 $profile= $g_user_profiles[$profile_num];
00173
00174 ### try to initialize standard values ###
00175 if(isset($profile['job_name'])) {
00176 $this->name= $profile['job_name'];
00177 }
00178 else {
00179 $this->name= $g_user_profile_names[$profile_num];
00180 }
00181 $this->role= $profile_num;
00182
00183
00184 ### build assoc array of defined class members ###
00185 $data=array();
00186 foreach(get_object_vars($this) as $key=>$value) {
00187 $data[$key]=true;
00188 }
00189
00190 ### try to initialize other values if profile-attribute-name matches with pp-member ###
00191 foreach($profile as $key=>$value) {
00192 if(isset($data[$key])) {
00193 $this->$key= $value;
00194 }
00195 }
00196 }
00197 }
00198
00199 ProjectPerson::initFields();
00200
00201
00202 ?>