<?php
/**
 * Class represents records from table softsale_file
 * {autogenerated}
 * @property int $file_id 
 * @property string $title 
 * @property string $desc 
 * @property int $hide 
 * @see Am_Table
 */
class SoftsaleFile extends ResourceAbstract
{
    const ACCESS_TYPE = 'softsale-file';
    protected $_uploads;
    
    // do not display in "ActiveResources" list
    public function renderLink() {}
    
    /**
     * @return SoftsaleFileUpload[] 
     */
    public function getUploads($cache = false)
    {
        if ($cache && $this->_uploads)
            return $this->_uploads;
        $ret = $this->getDi()->softsaleFileUploadTable->selectObjects("
            SELECT * 
            FROM ?_softsale_file_upload 
            WHERE file_id=?d AND hide <= 0
            ORDER BY date DESC, file_upload_id DESC", $this->pk());
        if ($cache)
            $this->_uploads = $ret;
        return $ret;
    }
    
    public function getUploadsOptions(array $uploads)
    {
        $ret = array();
        foreach ($uploads as $upload)
            $ret[ $upload->version ] = $upload->version;
        return $ret;
    }
}

class SoftsaleFileTable extends ResourceAbstractTable
{
    protected $_key = 'file_id';
    protected $_table = '?_softsale_file';
    protected $_recordClass = 'SoftsaleFile';

    public function getAccessType()
    {
        return SoftsaleFile::ACCESS_TYPE;
    }
    public function getAccessTitle()
    {
        return ___('Software Download');
    }
    public function getPageId()
    {
        return 'softsalefile';
    }
    
}
