Avail feature updated
[ninja.git] / modules / orm / models / objectpool.php
blob900c62de3fb7011066855f82f872012ba9062185
1 <?php
3 require_once( dirname(__FILE__).'/base/baseobjectpool.php' );
5 /**
6 * The univese of a objects of a given type in livestatus
7 */
8 abstract class ObjectPool_Model extends BaseObjectPool_Model {
10 /**
11 * List which places this object is available for.
13 * It is (for now) always available within ninja. Other places are: api
15 protected static $available_for = array(
16 'api' => true
19 /**
20 * Check if a table is available to read and export from a given interface.
22 * This can be used to hide tables from the HTTP-API that isn't API-stable
23 * enough yet.
26 public function available_for($where) {
27 if(isset(static::$available_for[$where])) {
28 return static::$available_for[$where];
31 * Everything has traditionally been available everywhere. This is to limit
32 * access if we can't guarantee integrety of the API in upcoming releases
34 return true;
38 /**
39 * Parse a query and return the related set
41 public static function get_by_query( $query, $disabled_saved_queries = array() ) {
42 $preprocessor = new LSFilterPP();
44 $parser = new LSFilter($preprocessor, new LSFilterMetadataVisitor());
45 $metadata = $parser->parse( $query );
47 $parser = new LSFilter($preprocessor, new LSFilterSetBuilderVisitor($metadata, $disabled_saved_queries));
48 return $parser->parse( $query );
51 /**
52 * Get a set of object, given a named query. Can be overridden to handle groups (in HostPool/ServicePool)
54 public function get_by_name( $name, $disabled_saved_queries = array() ) {
55 if( in_array($name, $disabled_saved_queries) ) {
56 throw new ORMException( 'Circular depencencies of saved filters detected');
58 $query = LSFilter_Saved_Queries_Model::get_query($name,$this->table);
59 if( $query === false ) return false;
61 $disabled_saved_queries[] = $name;
62 return self::get_by_query($query, $disabled_saved_queries);
65 /**
66 * Get classes for tables in the system
68 static public function load_table_classes() {
69 return Module_Manifest_Model::get('orm_table_classes');
72 /**
73 * Get JS-files to render the orm...
75 * @todo move from this class... should be somewhere else, but not here...
77 static public function get_js_files() {
78 $js_files = array();
79 foreach( scandir(MODPATH) as $module ) {
80 $path = MODPATH . $module . '/js/orm_structure.js';
81 if( is_file($path) ) {
82 $js_files[] = 'modules/'.$module.'/js/orm_structure.js';
85 return $js_files;