websiteWebsite
codingteam CodingTeam
A free forge, lightweight and extensible.

 

Browse the code

Revision log Information on the revision
Revision: 147 (differences)
Author: xbright
Log message: * Add documentation to timeline
* Bug fixes
Change revision:
<?php
# ***** BEGIN LICENSE BLOCK *****
#
#    This file is a part of CodingTeam. See <http://www.codingteam.net>.
#    Copyright (C) 2007-2008 CodingTeam (See AUTHORS and THANKS for details)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, version 3 only.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ***** END LICENSE BLOCK *****
 
class Todo {
    private $ct_db;
    public $id, $projectid, $version, $status, $task;
 
    function __construct($db)
    {
        $this->ct_db = $db;
    }
 
    function addTask($projectid, $array)
    {
        return $this->ct_db->insert('projects_todo', array('projectid' => $projectid,
                                                           'version' => $array['version'],
                                                           'status' => $array['status'],
                                                           'task' => $array['task']
                                                          ));
    }
 
    function getTasksByVersion($projectid, $version, $sql='')
    {
        return $this->ct_db->select('projects_todo', array('projectid' => $projectid, 'version' => $version), '*', $sql);
    }
 
    function countTasksByStatus($projectid, $status, $version)
    {
        return count($this->ct_db->select('projects_todo', array('projectid' => $projectid, 'status' => $status, 'version' => $version)));
    }
 
    function countTasks($projectid, $version=FALSE)
    {
        if ($version)
            $where = array('projectid' => $projectid, 'version' => $version);
        else
            $where = array('projectid' => $projectid);
 
        $req = $this->ct_db->select('projects_todo', $where);
 
        return count($req);
    }
 
    function load($task_id, $loadby='id')
    {
        if ($this->loaded)
            return TRUE;
        else
        {
            $req = $this->ct_db->select('projects_todo', array($loadby => $task_id), '*', 'LIMIT 1');
 
            if (count($req) == 1)
            {
                $this->id = $req[0]['id'];
                $this->projectid = $req[0]['projectid'];
                $this->version = $req[0]['version'];
                $this->status = $req[0]['status'];
                $this->task = $req[0]['task'];
 
                $this->loaded = TRUE;
                return TRUE;
            }
            else
                return FALSE;
        }
    }
 
    function deleteTask()
    {
        if (isset($this->id))
            $this->ct_db->delete('projects_todo', array('id' => $this->id));
    }
 
    function updateField($field, $value)
    {
        if (isset($this->id))
            $this->ct_db->update('projects_todo', array($field => $value), array('id' => $this->id));
    }
 
    function getId()
    {
        if ($this->loaded)
            return $this->id;
    }
 
    function setId($id)
    {
        $this->updateField('id', $id);
        $this->id = $id;
    }
 
    function getProjectid()
    {
        if ($this->loaded)
            return $this->projectid;
    }
 
    function setProjectid($projectid)
    {
        $this->updateField('projectid', $projectid);
        $this->projectid = $projectid;
    }
 
    function getVersion()
    {
        if ($this->loaded)
            return $this->version;
    }
 
    function setVersion($version)
    {
        $this->updateField('version', $version);
        $this->version = $version;
    }
 
    function getStatus()
    {
        if ($this->loaded)
            return $this->status;
    }
 
    function setStatus($status)
    {
        $this->updateField('status', $status);
        $this->status = $status;
    }
 
    function getTask()
    {
        if ($this->loaded)
            return $this->task;
    }
 
    function setTask($task)
    {
        $this->updateField('task', $task);
        $this->task = $task;
    }
 
}
?>