OpenSencillo  2016.106
Long live the simplicity of PHP
 All Data Structures Namespaces Files Functions Pages
structure.generator.structgen.php
1 <?php
11 class structgen
12 {
13  protected $data=array();
14  protected $sql;
15  protected $baseCtr;
16  protected $subCtr;
17  protected $name;
18 
19  public function __construct($name,$mysqlObject)
20  {
21  $this->sql=$mysqlObject;
22  }
23 
28  public function createStructure($name='structgen')
29  {
30  $this->data['structure'][]=array(
31  $name=>array(
32  'id'=>array(
33  'type'=>'int',
34  'primary_key'=>true,
35  'auto_increment'=>true
36  ),
37  'base'=>array(
38  'type'=>'int'
39  ),
40  'subnav'=>array(
41  'type'=>'int'
42  ),
43  'priority'=>array(
44  'type'=>'int'
45  ),
46  'perm'=>array(
47  'type'=>'int(4)'
48  ),
49  'name'=>array(
50  'type'=>'varchar(50)'
51  ),
52  'link'=>array(
53  'type'=>'varchar(255)'
54  ),
55  )
56  );
57  $this->name=$name;
58  }
59 
64  public function uniStore($name='uniStructgen')
65  {
66  $this->data['structure'][]=array(
67  $name=>array(
68  'id'=>array(
69  'type'=>'int',
70  'primary_key'=>true,
71  'auto_increment'=>true
72  ),
73  'mainBase'=>array(
74  'type'=>'int'
75  ),
76  'subBase'=>array(
77  'type'=>'int'
78  ),
79  'priority'=>array(
80  'type'=>'int'
81  ),
82  'perm'=>array(
83  'type'=>'int(4)'
84  ),
85  'dataName'=>array(
86  'type'=>'varchar(50)'
87  ),
88  'vchVal'=>array(
89  'type'=>'varchar(255)'
90  ),
91  'floatVal'=>array(
92  'type'=>'varchar(255)'
93  ),
94  'intVal'=>array(
95  'type'=>'varchar(255)'
96  ),
97  'datetime'=>array(
98  'type'=>'datetime'
99  ),
100  )
101  );
102  $this->name=$name;
103  }
104 
109  public function switchStructure($name)
110  {
111  $this->name=$name;
112  }
113 
123  public function add($item,$base=0,$subnav=null,$perm=1000,$link=null,$priority=null)
124  {
125  $this->data['add'][]=array(
126  $this->name=>array(
127  'id'=>"''",
128  'base'=>$base,
129  'subnav'=>$subnav,
130  'priority'=>$priority,
131  'perm'=>$perm,
132  'name'=>$item,
133  'link'=>$link
134  )
135  );
136  }
137 
141  private function createQueries()
142  {
143  foreach($this->data['structure'] as $val)
144  {
145  $this->sql->dbCreateTable($val);
146  }
147  foreach($this->data['add'] as $val)
148  {
149  $this->sql->insert($val);
150  }
151  $this->sql->execute();
152  }
153 
159  public function listStructure()
160  {
161  $structure = $this->worker();
162  $arr=array();
163  $arrstrc=array();
164  foreach($structure as $key=>$val)
165  {
166  foreach($structure as $keyB=>$valB)
167  {
168  if($valB['subnav']==$val['base'])
169  {
170  $arrstrc[]=$valB;
171  unset($structure[$keyB]);
172  }
173  }
174  $arr[$val['base']]=$arrstrc;
175  }
176  }
177 
183  public function listBase($base)
184  {
185  $structure = $this->worker();
186  foreach($structure as $key=>$val)
187  {
188  if($base!=$val['base'])
189  {
190  unset($structure[$key]);
191  }
192  }
193  return $structure;
194  }
199  private function worker()
200  {
201  $allBase=array(
202  $this->name=array(
203  'condition'=>array(
204  '`id`>=0',
205  ),
206  'sort'=>array(
207  'asc'=>'`id`'
208  )
209  )
210  );
211  $this->sql->select($allBase);
212  $arr = $this->sql->execute();
213  $sizearr = sizeof($arr);
214  return array('sqlreturn'=>$arr,'recordsctr'=>$sizearr);
215  }
216 
217  public function __destruct(){}
218 }
219 
221 {
222 
223 }
224 ?>