Location: PHPKode > projects > Todo Manager > todo/controllers/user_description.class.php
<?php
require_once $_SERVER["DOCUMENT_ROOT"]."/".FOLDER."/classes/controller.class.php";
require_once $_SERVER["DOCUMENT_ROOT"]."/".FOLDER."/classes/database.class.php";
require_once $_SERVER["DOCUMENT_ROOT"]."/".FOLDER."/classes/activerecord.class.php";
require_once $_SERVER["DOCUMENT_ROOT"]."/".FOLDER."/classes/authentication.class.php";

class UserDescription extends Controller {
	var $db;
	var $auth;
	var $user;
	var $user_id;

	function init() {
		// database connection
		$this->db = new Database(DATABASE_NAME, USER_NAME, PASSWORD);
		
		// authentication
		$this->auth = new Authentication($this->db);
		if (!$this->auth->isLogged())
			$this->redirect("login.php");
		
		// messages
		$this->loadMessages("messages/generic", "es");
		
		// default parameters
		$this->loadParams("user_id");
		$this->user_id = $this->getParam("user_id");
	}
	
	function onGet() {
		// parameters
		$this->user = new ActiveRecord($this->db, "user", $this->user_id);
	}
	
	function getUsername() {
		return $this->user->get("username");
	}
	
	function getFullName() {
		return $this->user->get("full_name");
	}
	
	function getEmail() {
		return $this->user->get("email");
	}
	
	function getReceiveNotifications() {
		return $this->user->get("receive_notifications");
	}
	
	function getAdmin() {
		return $this->user->get("admin");
	}
	
	function getDescription() {
		return $this->user->get("description");
	}
	
	function getLoginName() {
		$user_id = $this->auth->getUserId();
		$t = new ActiveRecord($this->db, "user", $user_id);
		return $t->get("username");
	}
	
	function getProjects() {
		$ret = array();
		
		$sql = "
		select
			p.title
		from project p
		inner join project_vs_user pu
			on pu.user_id = ".$this->db->quote($this->user_id)."
			and pu.project_id = p.id
		order by p.title";
		$result = $this->db->getResult($sql);
		while ($row = $this->db->getRow($result))
			array_push($ret, $row["title"]);
			
		if (sizeof($ret) > 0)
			return implode(", ", $ret);
		return "(este usuario no está participando en ningún proyecto)";
	}
}
?>
Return current item: Todo Manager