Mercurial > packages > magicforger
comparison src/Generator/Model/ModelGenerator.php @ 28:f88d2d5dee30 codex
Updated inputs and routes
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Mon, 09 Jun 2025 19:51:31 -0400 |
| parents | 555bfaa500ac |
| children | 010ace248d14 |
comparison
equal
deleted
inserted
replaced
| 27:b17f81b804ff | 28:f88d2d5dee30 |
|---|---|
| 89 protected function gatherRelations() { | 89 protected function gatherRelations() { |
| 90 $relations = RelationshipNavigator::getRelations($this->getCurrentTable()); | 90 $relations = RelationshipNavigator::getRelations($this->getCurrentTable()); |
| 91 | 91 |
| 92 return renderRelations($relations); | 92 return renderRelations($relations); |
| 93 | 93 |
| 94 } | |
| 95 | |
| 96 protected function renderFilters() { | |
| 97 $insert = ''; | |
| 98 foreach ($this->get_columns() as $column) { | |
| 99 if (in_array($column['name'], $this->columns_to_ignore)) { | |
| 100 continue; | |
| 101 } | |
| 102 $insert .= sprintf("'%s',", $column['name'])."\n"; | |
| 103 } | |
| 104 | |
| 94 } | 105 } |
| 95 | 106 |
| 96 protected function renderRelations($relations) { | 107 protected function renderRelations($relations) { |
| 97 $renders = [ | 108 $renders = [ |
| 98 'belongsTo' => [], | 109 'belongsTo' => [], |
| 173 $snippet | 184 $snippet |
| 174 ); | 185 ); |
| 175 | 186 |
| 176 return $string; | 187 return $string; |
| 177 } | 188 } |
| 189 | |
| 178 /** | 190 /** |
| 179 * Get available insertions including model relationships. | 191 * Get available insertions including model relationships. |
| 180 * | 192 * |
| 181 * @return array | 193 * @return array |
| 182 */ | 194 */ |
| 184 { | 196 { |
| 185 // Merge parent insertions (attributes, fillable, etc.) | 197 // Merge parent insertions (attributes, fillable, etc.) |
| 186 $inserts = parent::get_available_inserts(); | 198 $inserts = parent::get_available_inserts(); |
| 187 | 199 |
| 188 // Gather and render relationships for this model | 200 // Gather and render relationships for this model |
| 189 $relations = RelationshipNavigator::getRelations($this->getCurrentTable()); | 201 $relations = $this->gatherRelations(); |
| 190 $rendered = $this->renderRelations($relations); | 202 $rendered = $this->renderRelations($relations); |
| 203 $filters = $this->renderFilters(); | |
| 191 | 204 |
| 192 // Build code blocks for each relation type | 205 // Build code blocks for each relation type |
| 193 $belongs = !empty($rendered['belongsTo']) ? implode("\n ", $rendered['belongsTo']) : ''; | 206 $belongs = !empty($rendered['belongsTo']) ? implode("\n ", $rendered['belongsTo']) : ''; |
| 194 $hasMany = !empty($rendered['hasMany']) ? implode("\n ", $rendered['hasMany']) : ''; | 207 $hasMany = !empty($rendered['hasMany']) ? implode("\n ", $rendered['hasMany']) : ''; |
| 195 $belongsMany = !empty($rendered['belongsToMany']) ? implode("\n ", $rendered['belongsToMany']) : ''; | 208 $belongsMany = !empty($rendered['belongsToMany']) ? implode("\n ", $rendered['belongsToMany']) : ''; |
| 200 // Assign to stub placeholders | 213 // Assign to stub placeholders |
| 201 $inserts['# {{ belongs_to_relationships }}'] = $belongs; | 214 $inserts['# {{ belongs_to_relationships }}'] = $belongs; |
| 202 $inserts['# {{ has_many_relationships }}'] = $hasMany; | 215 $inserts['# {{ has_many_relationships }}'] = $hasMany; |
| 203 $inserts['# {{ has_many_through_relationships }}'] = $belongsMany; | 216 $inserts['# {{ has_many_through_relationships }}'] = $belongsMany; |
| 204 $inserts['# {{ defaultRelationsInsertPoint }}'] = $default_relations; | 217 $inserts['# {{ defaultRelationsInsertPoint }}'] = $default_relations; |
| 218 $inserts['# {{ defaultFiltersInsertPoint }}'] = $filters; | |
| 205 | 219 |
| 206 return $inserts; | 220 return $inserts; |
| 207 } | 221 } |
| 208 } | 222 } |
