<?php

class ModelCommonDocument extends HModel {

    protected function getTable() {
        return 'document';
    }

    protected function getView() {
        return 'vw_document';
    }

    protected function getPrimaryKey() {
        return 'document_id';
    }

    public function getOutstandingDocuments($filter, $sort_order) {
        $sql = "SELECT *";
        $sql .= " FROM " . DB_PREFIX . "vw_outstanding_document";
        if($filter) {
            if(is_array($filter)) {
                $implode = array();
                foreach($filter as $column => $value) {
                    $implode[] = "`$column`='$value'";
                }
                if($implode)
                    $sql .= " WHERE " . implode(" AND ", $implode);
            } else {
                $sql .= " WHERE " . $filter;
            }
        }

        if($sort_order) {
            $sql .= " ORDER BY " . implode(',',$sort_order);
        }

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

        return $query->rows;

    }
}

?>