<?php
class Projet{
	protected $ID;
	protected $name;
	protected $dateCreation;
	protected $owner;
	protected $secondaryOwners;
	
	protected $valid;
	
	public function __construct($ID){
		$this->ID = $ID;
		$req = $GLOBALS['bdd']->prepare('SELECT * FROM projets WHERE ID=?');
		$req->execute(array($ID));
		if($rep = $req->fetch()){
			$this->valid = TRUE;
			$this->name = $rep['name'];
			$this->owner = new Membre($rep['ownerID']);
			$this->dateCreation = $rep['dateCreation'];
			$this->secondaryOwners = array();
			foreach (explode(';',$rep['secondaryOwners']) AS $secondaryOwner)
				$this->secondaryOwners[] = new Membre($secondaryOwner);
		}else{
			$this->valid = FALSE;
		}
	}
	
	public function exists(){
		return $this->valid;
	}
	
	public function __toString(){
		$out = 'Projet\n';
		$out .= '\tID:' . $this->ID . '\n';
		$out .= '\tName:' . $this->name . '\n';
		$out .= '\tOwner:{' . substr(str_replace('\n\t',';',$this->owner->__toString()),0,-1) . '}\n';
		foreach($this->secondaryOwners AS $secondaryOwner)
			$out .= '\tSecondary owner:{' . substr(str_replace('\n\t',';',$secondaryOwner->__toString()),0,-1) . '}\n';
		$out .= '\tDate of creation:' . $this->dateCreation . '\n';
		return out;
	}
	
	//Getters
	public function getID(){
		return $this->ID;
	}
	
	public function getName(){
		return $this->name;
	}
	
	public function getOwner(){
		return $this->owner;
	}
	
	public function getSecondaryOwners(){
		return $this->secondaryOwners;
	}
	
	public function getDateCreation(){
		return $this->dateCreation;
	}
	
}