root/trunk/midcom/build/midcom_schema_factory.php

Revision 5030, 2.8 kB (checked in by tarjei, 2 years ago)

The start of a createCrud phing command

Line 
1 <?php
2
3 class midcom_schema_factory {
4
5     protected $schema;
6     protected $moduleRoot;
7     protected $type;
8
9     public function __construct $schema, $moduleRoot,$type   )
10     {
11         $this->schema = $schema;
12         $this->moduleRoot = $moduleRoot;
13         $this->type = $type;
14         $this->load_schemaapi(  );
15         $this->dms = new midcom_helper_schemaapi_schema(  );
16     }
17
18     public function write(  ) {
19
20         $this->dms->set_description( "Autogenerated schema for " . $this->type );
21
22         foreach ( $this->schema->getProperties(  )  as $property) {
23             $field = new midcom_helper_schemaapi_field( $property->getAttribute( 'name' ),
24                                                         $property->getAttribute( 'name' ),
25                                                         ucfirst$property->getAttribute( 'name' ) )
26                                                         );
27             $type $property->getAttribute( 'type' ) ;
28             $link = $property->getAttribute( 'link' );
29             $parentfield = $property->getAttribute( 'parentfield' );
30
31             if ( $type )
32             {
33                 $this->set_type( $field, $type );
34             }
35
36             if ( $link || $parentfield )
37             {
38                 echo "todo: handle up and link fields.\n";
39                 return;
40             }
41
42             $this->dms->add_field( $field );
43         }
44
45         $storage = $this->dms->asString( );
46         
47         file_put_contents( $this->moduleRoot . "/config/schemadb_{$this->type}.inc", $storage);
48
49     }
50
51     protected function set_type( $field , $mgdType)
52     {
53         $type = "midcom_helper_schemaapi_type_" $this->typeMap[$mgdType];
54         $widget = "midcom_helper_schemaapi_widget_" . $this->widgetMap[$mgdType];
55         $field->set_type( new $type  );
56         $field->set_widget( new $widget );
57
58
59     }
60     
61     protected $typeMap = array(
62             'string' => 'text',
63             'longtext' => 'text',
64             'datetime' => 'date',
65             'integer' => 'number',
66             'unsigned integer' => 'number',
67             'password' => 'password',
68             );
69     protected $widgetMap = array (
70             'string' => 'text',
71             'longtext' => 'tinymce',
72             'datetime' => 'jsdate',
73             'integer' => 'text',
74             'unsigned integer' => 'text',
75             'password' => 'password',
76
77             );
78     protected function load_schemaapi (  )
79     {
80         require_once dirname( __FILE__ ) . '/../midcom.helper.schemaapi/schema.php';
81         foreach ( $this->widgetMap as $mgdType => $widget )
82         {
83             midcom_helper_schemaapi_schema::load_widget( $widget );
84         }
85         foreach ( $this->typeMap as $mgdType => $type )
86         {
87             midcom_helper_schemaapi_schema::load_type( $type );
88         }
89     }
90 }
91
Note: See TracBrowser for help on using the browser.