Documentation is available at class_core.php
- <?php
- class core extends base {
- var $module_registry; //an array containing information about modules
- var $settings; //core settings
- var $object_types; //contains the names of all object types defined by the active modules
- var $relationship_types;
- function core() {
- //retrieve simple arrays from db
- global $db;
- $db->hide_errors();
- $modules = $db->get_results( "SELECT * FROM module_registry", ARRAY_A );
- $db->show_errors();
- if( $modules ) {
- foreach( $modules as $key => $module ) {
- $modules[$key]['module_object_types'] = unserialize( $module['module_object_types'] );
- }
- }
- $this->module_registry = $modules;
- $this->settings = $db->get_results( "SELECT * FROM core_settings", ARRAY_A );
- //initialize the containers
- $this->object_types = new container;
- $this->relationship_types = new container;
- //and fill them
- $this->object_types->set_attribute('objects', $this->get_keys( "object_types" ) );
- $this->relationship_types->set_attribute('objects', $this->get_keys( "relationship_types" ) );
- }
- function preload() {
- global $db;
- $object_data = $db->get_results( "SELECT * FROM object_types", ARRAY_A );
- $relationship_data = $db->get_results( "SELECT * FROM relationship_types", ARRAY_A );
- //$relationships = $db->get_results( "SELECT * FROM relationships", ARRAY_A );
- foreach( $object_data as $value ) {
- $this->object_types->objects[$value['id']] = true;
- $this->object_types->retrievedObjects[$value['id']] = new object_type( $value['id'], $value );
- }
- foreach( $relationship_data as $value ) {
- $this->relationship_types->objects[$value['id']] = true;
- $this->relationship_types->retrievedObjects[$value['id']] = new relationship_type( $value['id'], $value );
- $this->relationship_types->retrievedObjects[$value['id']]->retrieve_all();
- }
- }
- function get_keys( $table ) {
- global $db;
- if( $array = $db->get_results( "SELECT id FROM ".$table, ARRAY_A ) ) {
- foreach( $array as $value ) {
- $return[ $value['id'] ] = false;
- }
- return $return;
- } else {
- return array();
- }
- }
- function register_object_type( &$type ) {
- $this->object_types->register_object( $type, $type->get_attribute( 'type_id' ) );
- }
- function &retrieve_installed_modules() {
- return $this->module_registry;
- }
- function retrieve_available_modules() {
- //returns a list of modules in the modules folder
- $root = get_root();
- // scan the modules folder for subfolders, return a list of such folders
- $return_array = array();
- if ($handle = opendir($root.'Modules')) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != ".." && is_dir( $root.'Modules/'.$file ) ) {
- array_push( $return_array, $file );
- }
- }
- closedir($handle);
- }
- return $return_array;
- }
- function core_get_active_modules( $field = NULL ) {
- //returns a list of active modules (modules being executed by the script)
- foreach( $this->module_registry as $key => $module ) {
- if( $module['module_activated'] ) {
- $array[] =& $this->module_registry[$key];
- }
- }
- return $array;
- }
- function &get_object_type( $typeID ) {
- //retrieve all the defined object types
- if( $to_retrieve = array_diff_key( $this->object_types->objects, $this->object_types->retrievedObjects ) ) {
- foreach( $to_retrieve as $key => $value ) {
- $object =& new object_type( $key );
- $this->object_types->register_object( $object, $key );
- }
- }
- if( $type =& $this->get_type( $this->object_types, $typeID ) ) {
- return $type;
- } else {
- return $this->get_relationship_type( $this->relationship_types, $typeID );
- }
- }
- function &get_relationship_type( $typeID ) {
- //retrieve all the defined relationship types
- if( count($this->relationship_types->objects) != count($this->relationship_types->retrievedObjects) ) {
- foreach($this->relationship_types->objects as $key => $value ) {
- if( !$value ) {
- $relationship =& new relationship_type( $key );
- $this->relationship_types->register_object( $relationship, $key );
- }
- }
- }
- /*
- if( $to_retrieve = array_diff_key( $this->relationship_types->objects, $this->relationship_types->retrievedObjects ) ) {
- foreach( $to_retrieve as $key => $value ) {
- $relationship =& new relationship_type( $key );
- $this->relationship_types->register_object( $relationship, $key );
- }
- }
- */
- //find and return the requested type
- $token = strtok( $typeID, '-' );
- if( $foreward = strtok( '-' ) ) {
- return $this->get_type( $this->relationship_types, trim($foreward), trim($token) );
- } else {
- return $this->get_type( $this->relationship_types, $typeID );
- }
- //NOTE: add code for parsing text relationship type names into foreward and reverse names
- }
- function &get_type( &$type_type, $value1, $value2 = NULL ) {
- if( $retrieved_types =& $type_type->get_attribute( "retrievedObjects" ) ) {
- foreach( $retrieved_types as $key => $type ) {
- if( $type->get_attribute( "type_id" ) == $value1 ) { return $retrieved_types[$key]; }
- if( $value2 ) {
- if( $type->get_attribute( "type_name_foreward" ) == $value1 && $type->get_attribute( "type_name_reverse" ) == $value2 ) { return $retrieved_types[$key]; }
- } else {
- if( $type->get_attribute( "type_name" ) == $value1 ) { return $retrieved_types[$key]; }
- }
- }
- }
- return false;
- }
- function &get_module( $moduleName ) {
- if( $modules =& $this->core_get_active_modules() ) {
- foreach( $modules as $key => $module ) {
- if( $module['module_name'] == $moduleName ) {
- return $modules[$key];
- }
- }
- }
- return false;
- }
- function &get_constraints() {
- //NOTE: this doesn't need to be here...
- }
- function output() {
- echo "objects: ";
- print_r( $this->object_types->objects );
- echo "retrieved objects: ";
- foreach( $this->object_types->retrievedObjects as $object ) { print_r($object); }
- }
- }
- ?>
Documentation generated on Tue, 24 May 2005 03:57:30 -0400 by phpDocumentor 1.3.0RC3