<?php

Doo::loadModel('itematt');

class ItemFile
{

    private $__itemfile;

    function __construct()
    {
        $this->__itemfile = new ItemAtt();
    }

    public function insertItemFileRecord($postArray)
    {
        $this->__itemfile->ownerid = $postArray['ownerid'];
        $this->__itemfile->pid = $postArray['pid'];
        $this->__itemfile->pmid = $postArray['pmid'];
        $this->__itemfile->filename = $postArray['filename'];
        $this->__itemfile->fileext = $postArray['fileext'];
        $this->__itemfile->filesize = $postArray['filesize'];
        $this->__itemfile->filepath = $postArray['filepath'];
        $this->__itemfile->intime = time();
        return $this->__itemfile->insert();
    }

    public function getItemFile($iaid)
    {
        return $iaid ? $this->__itemfile->getOne(array('where' => 'iaid=?', 'param' => array($iaid), 'asArray' => TRUE)) : FALSE;
    }

    public function getFilesAll($pmid)
    {
        return $pmid ? $this->__itemfile->find(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE)) : FALSE;
    }

    public function updateItemFields($id, $fname)
    {
        $this->__itemfile->filename = iconv('GBK', 'UTF-8', $fname);
        return $this->__itemfile->update(array('where' => 'iaid=?', 'param' => array($id)));
    }

}

?>