<?php
class Module {
	var $data = array();
	 
	function __construct(&$locator) {
		$this->config   =& $locator->get('config');
		$this->database =& $locator->get('database');
	
    	$results = $this->database->getRows("select * from extension where type = 'module' group by code");
	
		foreach ($results as $result) {
			$file  = DIR_EXTENSION . $result['directory'] . '/' . $result['filename'];
			$class = 'Module' . str_replace('_', '', $result['code']);

			if (file_exists($file)) {
				require_once($file);

				$this->data[$result['code']] = new $class($locator);
			}
		}
  	}
	
  	function fetch() {
		$module_data = array();
		
		foreach (array_keys($this->data) as $key) {
			$module = $this->data[$key]->fetch();
			
			if ($module) {
				$module_data[$key] = $module;
			}
		}

		return $module_data;
  	}
}
?>