Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by Triada ( 15 years ago )
<?php

/**
 * Класс модели для работы с конкретными данными отчета за месяц
 */

class HRLib_Myls_Model_MonthReportElement extends HRLib_myModel
{
    const REPORT_TYPE_RELEASE = 1;
    const REPORT_TYPE_TEST = 2;
    const REPORT_TYPE_BUG = 3;
    const REPORT_TYPE_DOCUMENTATION  = 4;
    const REPORT_TYPE_CONSULTATION = 5;
    const REPORT_TYPE_OTHER = 6;
    const REPORT_TYPE_GROUP_COMMUNICATION = 7;
    
    private static $_reportTypeNameList = array(
        self::REPORT_TYPE_RELEASE => 'Релизы',
        self::REPORT_TYPE_TEST => 'На тесте',
        self::REPORT_TYPE_BUG => 'Баги',
        self::REPORT_TYPE_DOCUMENTATION => 'Документация',
        self::REPORT_TYPE_CONSULTATION => 'Консультации',
        self::REPORT_TYPE_OTHER => 'Другое',
        self::REPORT_TYPE_GROUP_COMMUNICATION => 'Общение в группе'
    );
    //для шаблона
    private static $_reportTypeEngNameList = array(
        'release'=>self::REPORT_TYPE_RELEASE,
        'test'=>self::REPORT_TYPE_TEST,
        'bug'=>self::REPORT_TYPE_BUG,
        'documentation'=>self::REPORT_TYPE_DOCUMENTATION,
        'consultation'=>self::REPORT_TYPE_CONSULTATION,
        'other'=>self::REPORT_TYPE_OTHER,
        'group'=>self::REPORT_TYPE_GROUP_COMMUNICATION
    );
    
    protected function  __construct($isTable = true)
    {
        $this->_tableName = HRLib_Db_Router::MYLS_MONTHREPORT_ELEMENT;
        $this->_dsnName = HRLib_Db_Connection::getDSNMyls();

        parent::__construct($isTable);
    }

    public static function create($isTable = true)
    {
        return new self($isTable);
    }
    
    public static function getReportTypeEngNameList()
    {
        return self::$_reportTypeEngNameList;
    }

    public function setFilterMonthReportId($monthReportId)
    {
        try {
            HRLib_Assert::isPositiveInteger($monthReportId);

            $this->getSelectObj()->where($this->_convertFieldName('report_id'), $monthReportId);
        } catch (Exception $e) {/*boo*/}

        return $this;
    }

    public function add($data)
    {
        $insertData = array(
            'report_text' => $data['report_text'],
            'spent_time' => $data['spent_time']
            );
        if($data['update'] == ''){
            $insertData['report_id'] = (int)$data['report_id'];
            $insertData['report_type'] = $data['report_type'];
            
            return $this->_getTableObj()->insert($insertData);
        }else{
            $where = array(
                'report_id' => (int)$data['report_id'],
                'report_type' => $data['report_type']
            );
            return $this->_getTableObj()->update($insertData,$where);
        }
    }

    public function getByMonthReportId($monthReportId)
    {
        try {
            HRLib_Assert::isPositiveInteger($monthReportId);
        } catch (Exception $e) {
            return array();
        }

        return $this->reCreateTableObj()
            ->setFilterMonthReportId($monthReportId)
            ->setOrder('id')
            ->getList();
    }

    public function deleteByMonthReportId($monthReportId)
    {
        if ( $this->getByMonthReportId($monthReportId) ) {
            return $this->_getTableObj()->delete(array('report_id' => $monthReportId));
        }

        return false;
    }
    protected function _getBaseFieldList()
    {
        return
            array(
                $this->_convertFieldName($this->_idFieldName),
                $this->_convertFieldName('report_id'),
                $this->_convertFieldName('report_type'),
                $this->_convertFieldName('report_text'),
                $this->_convertFieldName('spent_time')
            );
    }
}
?>

 

Revise this Paste

Parent: 39337
Children: 39339
Your Name: Code Language: