<?php

namespace FAAPI;

$path_to_root = "../..";
include_once ($path_to_root . "/dimensions/includes/dimensions_db.inc");

class Dimensions {

    //Get Items
    public function get($rest) {
        $req = $rest->request();

        $page = $req->get("page");

        if ($page == null) {
            $this->dimensions_all();
        } else {
            // If page = 1 the value will be 0, if page = 2 the value will be 1, ...
            $from = --$page * RESULTS_PER_PAGE;
            $this->dimensions_all($from);
        }
    }

    public function getById($rest, $id) {
        $info = get_dimension($id);
        api_success_response(json_encode($info));
    }

    private function dimensions_all($from = null) {
        if ($from == null)
            $from = 0;

        $sql = "SELECT * FROM " . TB_PREF . "dimensions WHERE closed='0' LIMIT " . $from . ", " . RESULTS_PER_PAGE;

        $query = db_query($sql, "error");

        $info = array();

        while ($data = db_fetch_assoc($query, "error")) {
            $info[] = $data;
        }

        $response['items'] = $info;
        $response['incomplete_results'] = FALSE;
        $response['total_count'] = count($info);
        api_success_response(json_encode($response));
    }


}
