| @@ 276-304 (lines=29) @@ | ||
| 273 | * | |
| 274 | * @return $this | |
| 275 | */ | |
| 276 | 	public function replaceReverseRelationships(){ | |
| 277 | ||
| 278 | $functions = ''; | |
| 279 | ||
| 280 | $method = File::get($this->stubsDirectory . '/Controller/ControllerReverseRelationship.php'); | |
| 281 | ||
| 282 | foreach ($this->modelData->reverseRelationships as $relationship) | |
| 283 | 		{ | |
| 284 | $functionName = ''; | |
| 285 | if ($relationship->type == "hasOne") | |
| 286 | $functionName = strtolower($relationship->modelName); | |
| 287 | elseif ($relationship->type == "belongsToMany") | |
| 288 | $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); | |
| 289 | else | |
| 290 | $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); | |
| 291 | ||
| 292 | $replacedMethod = ''; | |
| 293 | 			$replacedMethod = str_replace('{{function_name}}', $functionName, $method); | |
| 294 | 			$replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); | |
| 295 | 			$replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod); | |
| 296 | ||
| 297 | $functions .= $replacedMethod; | |
| 298 | } | |
| 299 | ||
| 300 | 		$this->stub = str_replace('{{reverseRelationships}}', $functions, $this->stub); | |
| 301 | ||
| 302 | return $this; | |
| 303 | ||
| 304 | } | |
| 305 | ||
| 306 | /** | |
| 307 | * replace enum fields | |
| @@ 592-620 (lines=29) @@ | ||
| 589 | * | |
| 590 | * @return $this | |
| 591 | */ | |
| 592 | 	public function replaceReverseRelationshipsFunctions(){ | |
| 593 | ||
| 594 | $functions = ''; | |
| 595 | ||
| 596 | $method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php'); | |
| 597 | ||
| 598 | foreach ($this->modelData->reverseRelationships as $relationship) | |
| 599 | 		{ | |
| 600 | $functionName = ''; | |
| 601 | if ($relationship->type == "hasOne") | |
| 602 | $functionName = strtolower($relationship->modelName); | |
| 603 | elseif ($relationship->type == "belongsToMany") | |
| 604 | $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable)); | |
| 605 | else | |
| 606 | $functionName = CamelCase::pluralize(strtolower($relationship->modelName)); | |
| 607 | ||
| 608 | $replacedMethod = ''; | |
| 609 | 			$replacedMethod = str_replace('{{function_name}}', $functionName, $method); | |
| 610 | 			$replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod); | |
| 611 | 			$replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod); | |
| 612 | ||
| 613 | $functions .= $replacedMethod; | |
| 614 | } | |
| 615 | ||
| 616 | 		$this->stub = str_replace('{{reverseRelationshipFunctions}}', $functions, $this->stub); | |
| 617 | ||
| 618 | return $this; | |
| 619 | ||
| 620 | } | |
| 621 | ||
| 622 | ||
| 623 | /** | |