<?php

Doo::loadModel('pro');

class Project
{

    private $pro;

    public function __construct()
    {
        $this->pro = new Pro();
    }

    public function insertProject($uid, $pname)
    {
        if (!isset($pname) && $pname)
            return FALSE;
        $this->pro->uid = filter_var($uid, FILTER_VALIDATE_INT);
        $this->pro->pname = filter_var($pname, FILTER_SANITIZE_STRING);
        $this->pro->intime = time();
        return $this->pro->insert();
    }

    public function getAll($uid = NULL)
    {
        if (isset($uid)) {
            return $this->pro->find(array('where' => 'uid=?', 'param' => array($uid), 'asArray' => TRUE));
        } else {
            return $this->pro->find(array('asArray' => TRUE));
        }
    }

    public function getFewRow($pidstr)
    {
        return $this->pro->find(array('where' => 'pid in(' . $pidstr . ')', 'asArray' => TRUE));
    }

    public function getRowByPid($pid)
    {
        return $this->pro->getOne(array('where' => 'pid=?', 'param' => array($pid), 'asArray' => TRUE));
    }

// for api
    public function getRowUid($uid)
    {
        return $this->pro->find(array('where' => 'uid=?', 'param' => array($uid), 'asArray' => TRUE));
    }

    public function updateProName($pid, $pname)
    {
        $this->pro->pname = filter_var($pname, FILTER_SANITIZE_STRING);
        return $this->pro->update(array('where' => 'pid=?', 'param' => array($pid)));
    }

    public function del($pid)
    {
        return $this->pro->delete(array('where' => 'pid=?', 'param' => array($pid)));
    }
}

?>