<?php

class ModelSetupDocumentType extends HModel {

    protected function getTable() {
        return 'document_type';
    }
    
    public function getDocumentType($primary_key) {
        $query = $this->conn->query("SELECT * FROM `" . DB_PREFIX . "document_type` WHERE document_type_id = '" . $primary_key . "'");
        return $query->row;
    }

    public function getDocumentTypes($data = array()) {
        $sql = "SELECT * FROM `" . DB_PREFIX . "document_type`";
        if(!empty($data)) {
            $sql .= " WHERE";
            foreach($data as $column => $value) {
                $sql .= " `" . $column . "` = '" . $value . "' AND";
            }
            
            $sql = substr($sql, 0, strlen($sql) - 3);
        }

        $query = $this->conn->query($sql);

        return $query->rows;
    }
    
    public function getDocumentTypesArray($data = array()) {
        $rows = $this->getDocumentTypes($data);
        $arrDocumentTypes = array();
        foreach($rows as $row) {
            $arrDocumentTypes[$row['document_type_code']] = $row['name'];
        }

        return $arrDocumentTypes;
    }
    
}

?>