Removed dep on API
[ninja.git] / src / op5 / ninja_sdk / orm / ORMRootGenerator.php
blob8c5ab86d5abce32650fc62ad791ec8978a901365
1 <?php
3 class ORMRootGenerator extends class_generator {
5 private $structure;
7 public function __construct() {
8 $this->classname = 'BaseObject';
9 $this->set_model();
12 public function generate($skip_generated_note = false) {
13 parent::generate($skip_generated_note);
14 $this->init_class();
15 $this->variable( '_table', null, 'protected' );
16 $this->variable( 'export', array('key'), 'protected' );
17 $this->variable( 'rewrite_columns', array(), 'static public' );
18 $this->generate_export();
19 $this->generate_construct();
20 $this->finish_class();
23 private function generate_construct() {
24 $this->init_function( "__construct", array( 'values', 'prefix', 'export' ) );
25 $this->finish_function();
28 private function generate_export() {
29 $this->init_function('export');
30 $this->write( '$result=array();');
31 $this->write( 'foreach( $this->export as $field) {' );
32 $this->write( 'if(is_callable(array($this, "get_$field"))) {');
33 $this->write( '$value = $this->{"get_$field"}();');
34 $this->write( 'if( $value instanceof Object'.self::$model_suffix.' ) {');
35 $this->write( '$value = $value->export();');
36 $this->write( '}');
37 $this->write( '$result[$field] = $value;');
38 $this->write( '}');
39 $this->write( '}');
40 $this->write( 'return $result;');
41 $this->finish_function();