<?php

/*
 *	  CLASS:  UserGroupList;
 *    
*/
class UserGroupList {
	private $all = array();
	
	
	function __construct($bHideSelect = False) {
		$this->init($bHideSelect);
	}
	
	private function init($bHideSelect = False) {
		try {
			// get the list of user groups
			$sql = "SELECT user_group_id, group_name FROM {qms_user_groups} g ORDER BY group_name";	
			$results = db_query($sql);
			
			if ( !$bHideSelect ) {
				$this->all[0] = '- Select -';  // add default option
			}
		
			foreach($results as $g) {
				// this is needed for a mixed select list
				// add the 'G' suffix to the id
				// if the outside processes need it, its available
				// if the outside processes do not need it, its easily ignored when cast to an int
				$this->all[$g->user_group_id . 'G'] = '[Group] ' . $g->group_name;
			}
		}
		catch (Exception $e) {
			watchdog('sabreQMS', 'UserGroupList::init() ' . $e->getMessage(), array(), WATCHDOG_ERROR);
		} 	
	}
	
	public function get($assigned_group_list = array()) {
		
		// if an $assigned_group_list is passed as a parm, 
		// remove those groups from the groups list returned
		// returns all items in $this->all not in the $assigned_group_list
		
		return array_diff($this->all, $assigned_group_list);
	}

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

