<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class sectionType 
{

    var $_db;
    var $_sectionTypes;
    
    function __construct($hostname, $dbname, $user, $pass) 
    {
        $this->_db = mysqli_connect($hostname, $user, $pass, $dbname) or die("Could not connect database");
        $result = mysqli_query($this->_db, 'SELECT * FROM `section_type` ORDER BY `id`') or die(mysqli_error());
        $this->_sectionTypes = array();
        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) 
        {
            $this->_sectionTypes[$row['id']] = array(
                'code' => $row['code'],
                'name' => $row['name']
            );
        }
    }
    
    function getSectionTypeAll () 
    {
        return $this->_sectionTypes;
    }
    
    function getSectionTypeIdFromCode ($code) 
    {
        foreach ($this->_sectionTypes as $key => $sectionType)
        {
            if ($sectionType['code'] == $code) {
                return $key;
            }
        }
        return null;
    }
    
    function getInfoFromId ($id) 
    {
        if (array_key_exists($id, $this->_sectionTypes)) {
            return $this->_sectionTypes[$id];
        }
        return null;
    }
    
}

?>