<?php

/*
 *	  CLASS:  QTGStatusList
 *    
*/
class QTGStatusList {
	
	private $all = array();
  private $select_opt = array();

		
	function __construct() {
		$this->init();
	}
	
	private function init() {
		try {
				// get the list of engines for the test plan or test
				$query = db_select('qms_qtg_test_statuses', 's')
									->fields('s', array('test_status_code', 
                                      'test_status_desc'));
				
				$results = $query->orderBy('test_status_code')
                  ->execute();
				
				$select_opt[0] = '- Select -';  // add default option

				foreach($results as $row) {
          // if requested by test_id, return just the engine code
          // if requested by test plan, return the code & desc
					$this->all[$row->test_status_code] = $row->test_status_desc;
				}
		}
		catch (Exception $e) {
			watchdog('sabreQMS', 'QTGStatusList::init() ' . $e->getMessage(), array(), WATCHDOG_ERROR);
		} 	
	}
	
	
	public function get_count() {
		return count($this->all);
	}
	
	
	public function get() {
		return ($select_opt + $this->all);
	}

	public function getName($id) {
		if ( $id && isset($this->all[$id]) ) {
			return $this->all[$id];
		}
		return '';
	}
	
	public function reload() {
		
		unset($this->all);
		$this->init();
	}
	
} // end - class QTGStatusList
