@@ 409-477 (lines=69) @@ | ||
406 | * @param array $navigationFields Collection of entity additional fields |
|
407 | * @return string Generated entity query PHP class code |
|
408 | */ |
|
409 | protected function createCollectionClass($navigationID, $navigationName, $entityName, $navigationFields) |
|
410 | { |
|
411 | $this->generator |
|
412 | ->multiComment(array('Class for getting "'.$navigationName.'" instances from database',)) |
|
413 | ->defClass($entityName, '\samsoncms\api\renderable\Collection') |
|
414 | ; |
|
415 | ||
416 | // Iterate additional fields |
|
417 | $localizedFieldIDs = array(); |
|
418 | $notLocalizedFieldIDs = array(); |
|
419 | $allFieldIDs = array(); |
|
420 | $allFieldNames = array(); |
|
421 | $allFieldValueColumns = array(); |
|
422 | $realNames = array(); |
|
423 | foreach ($navigationFields as $fieldID => $fieldRow) { |
|
424 | $fieldName = $this->fieldName($fieldRow['Name']); |
|
425 | ||
426 | // TODO: Add different method generation depending on their field type |
|
427 | $this->generator->text($this->generateFieldConditionMethod( |
|
428 | $fieldName, |
|
429 | $fieldRow[Field::F_PRIMARY], |
|
430 | $fieldRow[Field::F_TYPE] |
|
431 | )); |
|
432 | ||
433 | // Store field metadata |
|
434 | $realNames[$fieldRow['Name']] = $fieldName; |
|
435 | $allFieldIDs[$fieldID] = $fieldName; |
|
436 | $allFieldNames[$fieldName] = $fieldID; |
|
437 | $allFieldValueColumns[$fieldID] = Field::valueColumn($fieldRow[Field::F_TYPE]); |
|
438 | if ($fieldRow[Field::F_LOCALIZED] == 1) { |
|
439 | $localizedFieldIDs[$fieldID] = $fieldName; |
|
440 | } else { |
|
441 | $notLocalizedFieldIDs[$fieldID] = $fieldName; |
|
442 | } |
|
443 | } |
|
444 | ||
445 | // TODO: Add generator method generation logic |
|
446 | $class = "\n\t".'/**'; |
|
447 | $class .= "\n\t".' * @param ViewInterface $renderer Rendering instance'; |
|
448 | $class .= "\n\t".' * @param QueryInterface $query Querying instance'; |
|
449 | $class .= "\n\t".' * @param string $locale Localization identifier'; |
|
450 | $class .= "\n\t".' */'; |
|
451 | $class .= "\n\t".'public function __construct(ViewInterface $renderer, QueryInterface $query = null, $locale = null)'; |
|
452 | $class .= "\n\t".'{'; |
|
453 | $class .= "\n\t\t".'parent::__construct($query === null ? new dbQuery() : $query, $renderer, $locale);'; |
|
454 | $class .= "\n\t".'}'."\n"; |
|
455 | ||
456 | return $this->generator |
|
457 | ->commentVar('array', 'Collection of real additional field names') |
|
458 | ->defClassVar('$fieldRealNames', 'public static', $realNames) |
|
459 | ->commentVar('array', 'Collection of navigation identifiers') |
|
460 | ->defClassVar('$navigationIDs', 'protected static', array($navigationID)) |
|
461 | ->commentVar('string', 'Not transliterated entity name') |
|
462 | ->defClassVar('$identifier', 'protected static', $this->fullEntityName($navigationName)) |
|
463 | ->commentVar('array', 'Collection of localized additional fields identifiers') |
|
464 | ->defClassVar('$localizedFieldIDs', 'protected static', $localizedFieldIDs) |
|
465 | ->commentVar('array', 'Collection of NOT localized additional fields identifiers') |
|
466 | ->defClassVar('$notLocalizedFieldIDs', 'protected static', $notLocalizedFieldIDs) |
|
467 | ->commentVar('array', 'Collection of localized additional fields identifiers') |
|
468 | ->defClassVar('$fieldIDs', 'protected static', $allFieldIDs) |
|
469 | ->commentVar('array', 'Collection of additional fields value column names') |
|
470 | ->defClassVar('$fieldValueColumns', 'protected static', $allFieldValueColumns) |
|
471 | ->commentVar('array', 'Collection of additional field names') |
|
472 | ->defClassVar('$fieldNames', 'public static', $allFieldNames) |
|
473 | ->text($class) |
|
474 | ->endClass() |
|
475 | ->flush() |
|
476 | ; |
|
477 | } |
|
478 | ||
479 | /** |
|
480 | * Create entity query PHP class code. |
|
@@ 488-555 (lines=68) @@ | ||
485 | * @param array $navigationFields Collection of entity additional fields |
|
486 | * @return string Generated entity query PHP class code |
|
487 | */ |
|
488 | protected function createQueryClass($navigationID, $navigationName, $entityName, $navigationFields) |
|
489 | { |
|
490 | $this->generator |
|
491 | ->multiComment(array('Class for getting "'.$navigationName.'" instances from database')) |
|
492 | ->defClass($entityName, '\samsoncms\api\query\Entity') |
|
493 | ; |
|
494 | ||
495 | // Iterate additional fields |
|
496 | $localizedFieldIDs = array(); |
|
497 | $notLocalizedFieldIDs = array(); |
|
498 | $allFieldIDs = array(); |
|
499 | $allFieldNames = array(); |
|
500 | $allFieldValueColumns = array(); |
|
501 | $realNames = array(); |
|
502 | foreach ($navigationFields as $fieldID => $fieldRow) { |
|
503 | $fieldName = $this->fieldName($fieldRow['Name']); |
|
504 | ||
505 | // TODO: Add different method generation depending on their field type |
|
506 | $this->generator->text($this->generateFieldConditionMethod( |
|
507 | $fieldName, |
|
508 | $fieldRow[Field::F_PRIMARY], |
|
509 | $fieldRow[Field::F_TYPE] |
|
510 | )); |
|
511 | ||
512 | // Store field metadata |
|
513 | $realNames[$fieldRow['Name']] = $fieldName; |
|
514 | $allFieldIDs[$fieldID] = $fieldName; |
|
515 | $allFieldNames[$fieldName] = $fieldID; |
|
516 | $allFieldValueColumns[$fieldID] = Field::valueColumn($fieldRow[Field::F_TYPE]); |
|
517 | if ($fieldRow[Field::F_LOCALIZED] == 1) { |
|
518 | $localizedFieldIDs[$fieldID] = $fieldName; |
|
519 | } else { |
|
520 | $notLocalizedFieldIDs[$fieldID] = $fieldName; |
|
521 | } |
|
522 | } |
|
523 | ||
524 | // TODO: Add generator method generation logic |
|
525 | $class = "\n\t".'/**'; |
|
526 | $class .= "\n\t".' * @param QueryInterface $query Rendering instance'; |
|
527 | $class .= "\n\t".' * @param string $locale Localization identifier'; |
|
528 | $class .= "\n\t".' */'; |
|
529 | $class .= "\n\t".'public function __construct(QueryInterface $query = null, $locale = null)'; |
|
530 | $class .= "\n\t".'{'; |
|
531 | $class .= "\n\t\t".'parent::__construct($query === null ? new dbQuery() : $query, $locale);'; |
|
532 | $class .= "\n\t".'}'."\n"; |
|
533 | ||
534 | return $this->generator |
|
535 | ->commentVar('array', 'Collection of real additional field names') |
|
536 | ->defClassVar('$fieldRealNames', 'public static', $realNames) |
|
537 | ->commentVar('array', 'Collection of navigation identifiers') |
|
538 | ->defClassVar('$navigationIDs', 'protected static', array($navigationID)) |
|
539 | ->commentVar('string', 'Not transliterated entity name') |
|
540 | ->defClassVar('$identifier', 'protected static', $this->fullEntityName($navigationName)) |
|
541 | ->commentVar('array', 'Collection of localized additional fields identifiers') |
|
542 | ->defClassVar('$localizedFieldIDs', 'protected static', $localizedFieldIDs) |
|
543 | ->commentVar('array', 'Collection of NOT localized additional fields identifiers') |
|
544 | ->defClassVar('$notLocalizedFieldIDs', 'protected static', $notLocalizedFieldIDs) |
|
545 | ->commentVar('array', 'Collection of localized additional fields identifiers') |
|
546 | ->defClassVar('$fieldIDs', 'protected static', $allFieldIDs) |
|
547 | ->commentVar('array', 'Collection of additional fields value column names') |
|
548 | ->defClassVar('$fieldValueColumns', 'protected static', $allFieldValueColumns) |
|
549 | ->commentVar('array', 'Collection of additional field names') |
|
550 | ->defClassVar('$fieldNames', 'public static', $allFieldNames) |
|
551 | ->text($class) |
|
552 | ->endClass() |
|
553 | ->flush() |
|
554 | ; |
|
555 | } |
|
556 | ||
557 | /** @return string Entity state hash */ |
|
558 | public function entityHash() |