3 class ORMRootSetGenerator
extends class_generator
{
6 public function __construct() {
7 $this->classname
= "BaseObjectSet";
11 public function generate($skip_generated_note = false) {
12 parent
::generate($skip_generated_note);
13 $this->init_class( false, array('abstract'), array("IteratorAggregate", "Countable") );
14 $this->generate_construct();
15 $this->variable('table',null,'protected');
16 $this->variable('dbtable',null,'protected');
17 $this->variable('dbtable_expr',null,'protected');
18 $this->variable('class',null,'protected');
19 $this->variable('filter',null,'protected');
20 $this->variable('default_sort',array(),'protected');
21 $this->variable('key_columns',array(),'protected');
22 $this->generate_getter('table');
23 $this->generate_getter('class');
24 $this->generate_binary_operator('union', 'LivestatusFilterOr');
25 $this->generate_binary_operator('intersect', 'LivestatusFilterAnd');
26 $this->generate_unary_operator('complement','LivestatusFilterNot');
27 $this->generate_reduce();
28 $this->generate_convert_to_object();
29 $this->generate_stats();
30 $this->generate_getIterator();
32 $this->generate_get_auth_filter();
33 $this->generate_get_all_columns_list();
34 $this->finish_class();
37 public function generate_construct() {
38 $this->init_function('__construct', array('filter'));
39 $this->write('$this->filter = $filter;');
40 $this->finish_function();
43 public function generate_getter($var) {
44 $this->init_function('get_'.$var);
45 $this->write('return $this->'.$var.';');
46 $this->finish_function();
49 public function generate_unary_operator($operator,$filterclass) {
50 $this->init_function($operator);
52 $this->write('$filter = new '.$filterclass.'($this->filter);');
54 $this->write('return new static($filter);');
55 $this->finish_function();
58 public function generate_binary_operator($operator,$filterclass) {
59 $this->init_function($operator, array('set'));
60 $this->write('if( $this->table != $set->table ) {');
61 $this->write('return false;');
64 $this->write('$filter = new '.$filterclass.'();');
65 $this->write('$filter->add( $this->filter );');
66 $this->write('$filter->add( $set->filter );');
68 $this->write('return new static($filter);');
69 $this->finish_function();
72 public function generate_reduce() {
73 $this->init_function('reduce_by', array('column', 'value', 'op'));
74 $this->write('$filter = new LivestatusFilterAnd();');
75 $this->write('$filter->add( $this->filter );');
76 $this->write('$filter->add( new LivestatusFilterMatch( $column, $value, $op ) );');
78 $this->write('return new static($filter);');
79 $this->finish_function();
82 public function generate_convert_to_object() {
83 $this->init_function('convert_to_object', array('table','field'));
84 $this->write('$result = ObjectPool'.self
::$model_suffix.'::pool($table)->all();');
85 $this->write('$result->filter = $this->filter->prefix($field . ".");');
86 $this->write('return $result;');
87 $this->finish_function();
90 public function generate_stats() {
91 $this->abstract_function('stats',array('intersections'));
94 public function generate_getIterator() {
95 $this->init_function('getIterator');
96 $this->write('return $this->it(false,array());');
97 $this->finish_function();
100 public function generate_it() {
101 $this->abstract_function( 'it', array('columns','order','limit','offset'), array(), array('order' => array(), 'limit'=>false, 'offset'=>false) );
104 public function generate_get_auth_filter() {
105 $this->init_function('get_auth_filter',array(),array('protected'));
106 $this->write('return $this->filter;');
107 $this->finish_function();
111 * Fetch all columns possible for this class to fetch, including subobjects.
113 * This is just a stub, which is overwritten by each object set.
115 private function generate_get_all_columns_list() {
116 $this->init_function('get_all_columns_list', array(), array('static'));
117 $this->write('return array();');
118 $this->finish_function();