vendor/propel/propel/src/Propel/Runtime/ActiveQuery/ModelWith.php line 19

Open in your IDE?
  1. <?php
  2. /**
  3.  * MIT License. This file is part of the Propel package.
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Propel\Runtime\ActiveQuery;
  8. use Propel\Runtime\Map\RelationMap;
  9. /**
  10.  * Data object to describe a joined hydration in a Model Query
  11.  * ModelWith objects are used by formatters to hydrate related objects
  12.  *
  13.  * @author Francois Zaninotto (Propel)
  14.  */
  15. class ModelWith
  16. {
  17.     /**
  18.      * @var string
  19.      */
  20.     protected $modelName;
  21.     /**
  22.      * @var \Propel\Runtime\Map\TableMap
  23.      */
  24.     protected $getTableMap;
  25.     /**
  26.      * @var bool
  27.      */
  28.     protected $isSingleTableInheritance false;
  29.     /**
  30.      * @var bool
  31.      */
  32.     protected $isAdd false;
  33.     /**
  34.      * @var bool
  35.      */
  36.     protected $isWithOneToMany false;
  37.     /**
  38.      * @var string
  39.      */
  40.     protected $relationName;
  41.     /**
  42.      * @var string
  43.      */
  44.     protected $relationMethod;
  45.     /**
  46.      * @var string
  47.      */
  48.     protected $initMethod;
  49.     /**
  50.      * @var string
  51.      */
  52.     protected $resetPartialMethod '';
  53.     /**
  54.      * @var string
  55.      */
  56.     protected $leftPhpName;
  57.     /**
  58.      * @var string
  59.      */
  60.     protected $rightPhpName;
  61.     /**
  62.      * @param \Propel\Runtime\ActiveQuery\ModelJoin|null $join
  63.      */
  64.     public function __construct(?ModelJoin $join null)
  65.     {
  66.         if ($join !== null) {
  67.             $this->init($join);
  68.         }
  69.     }
  70.     /**
  71.      * Define the joined hydration schema based on a join object.
  72.      * Fills the ModelWith properties using a ModelJoin as source
  73.      *
  74.      * @param \Propel\Runtime\ActiveQuery\ModelJoin $join
  75.      *
  76.      * @return void
  77.      */
  78.     public function init(ModelJoin $join)
  79.     {
  80.         $tableMap $join->getTableMap();
  81.         $this->setModelName($tableMap->getClassName());
  82.         $this->getTableMap $tableMap;
  83.         $this->isSingleTableInheritance $tableMap->isSingleTableInheritance();
  84.         $relation $join->getRelationMap();
  85.         $relationName $relation->getName();
  86.         if ($relation->getType() == RelationMap::ONE_TO_MANY) {
  87.             $this->isAdd $this->isWithOneToMany true;
  88.             $this->relationName $relation->getPluralName();
  89.             $this->relationMethod 'add' $relationName;
  90.             $this->initMethod 'init' $this->relationName;
  91.             $this->resetPartialMethod 'resetPartial' $this->relationName;
  92.         } else {
  93.             $this->relationName $relationName;
  94.             $this->relationMethod 'set' $relationName;
  95.         }
  96.         $this->rightPhpName $join->hasRelationAlias() ? $join->getRelationAlias() : $relationName;
  97.         if (!$join->isPrimary()) {
  98.             $this->leftPhpName $join->hasLeftTableAlias() ? $join->getLeftTableAlias() : $join->getPreviousJoin()->getRelationMap()->getName();
  99.         }
  100.     }
  101.     // DataObject getters & setters
  102.     /**
  103.      * @param string $modelName
  104.      *
  105.      * @return void
  106.      */
  107.     public function setModelName($modelName)
  108.     {
  109.         if (strpos($modelName'\\') === 0) {
  110.             $this->modelName substr($modelName1);
  111.         } else {
  112.             $this->modelName $modelName;
  113.         }
  114.     }
  115.     /**
  116.      * @return \Propel\Runtime\Map\TableMap
  117.      */
  118.     public function getTableMap()
  119.     {
  120.         return $this->getTableMap;
  121.     }
  122.     /**
  123.      * @return string
  124.      */
  125.     public function getModelName()
  126.     {
  127.         return $this->modelName;
  128.     }
  129.     /**
  130.      * @param bool $isSingleTableInheritance
  131.      *
  132.      * @return void
  133.      */
  134.     public function setIsSingleTableInheritance($isSingleTableInheritance)
  135.     {
  136.         $this->isSingleTableInheritance $isSingleTableInheritance;
  137.     }
  138.     /**
  139.      * @return bool
  140.      */
  141.     public function isSingleTableInheritance()
  142.     {
  143.         return $this->isSingleTableInheritance;
  144.     }
  145.     /**
  146.      * @param bool $isAdd
  147.      *
  148.      * @return void
  149.      */
  150.     public function setIsAdd($isAdd)
  151.     {
  152.         $this->isAdd $isAdd;
  153.     }
  154.     /**
  155.      * @return bool
  156.      */
  157.     public function isAdd()
  158.     {
  159.         return $this->isAdd;
  160.     }
  161.     /**
  162.      * @param bool $isWithOneToMany
  163.      *
  164.      * @return void
  165.      */
  166.     public function setIsWithOneToMany($isWithOneToMany)
  167.     {
  168.         $this->isWithOneToMany $isWithOneToMany;
  169.     }
  170.     /**
  171.      * @return bool
  172.      */
  173.     public function isWithOneToMany()
  174.     {
  175.         return $this->isWithOneToMany;
  176.     }
  177.     /**
  178.      * @param string $relationName
  179.      *
  180.      * @return void
  181.      */
  182.     public function setRelationName($relationName)
  183.     {
  184.         $this->relationName $relationName;
  185.     }
  186.     /**
  187.      * @return string
  188.      */
  189.     public function getRelationName()
  190.     {
  191.         return $this->relationName;
  192.     }
  193.     /**
  194.      * @param string $relationMethod
  195.      *
  196.      * @return void
  197.      */
  198.     public function setRelationMethod($relationMethod)
  199.     {
  200.         $this->relationMethod $relationMethod;
  201.     }
  202.     /**
  203.      * @return string
  204.      */
  205.     public function getRelationMethod()
  206.     {
  207.         return $this->relationMethod;
  208.     }
  209.     /**
  210.      * @param string $initMethod
  211.      *
  212.      * @return void
  213.      */
  214.     public function setInitMethod($initMethod)
  215.     {
  216.         $this->initMethod $initMethod;
  217.     }
  218.     /**
  219.      * @return string
  220.      */
  221.     public function getInitMethod()
  222.     {
  223.         return $this->initMethod;
  224.     }
  225.     /**
  226.      * @param string $resetPartialMethod
  227.      *
  228.      * @return void
  229.      */
  230.     public function setResetPartialMethod($resetPartialMethod)
  231.     {
  232.         $this->resetPartialMethod $resetPartialMethod;
  233.     }
  234.     /**
  235.      * @return string
  236.      */
  237.     public function getResetPartialMethod()
  238.     {
  239.         return $this->resetPartialMethod;
  240.     }
  241.     /**
  242.      * @param string $leftPhpName
  243.      *
  244.      * @return void
  245.      */
  246.     public function setLeftPhpName($leftPhpName)
  247.     {
  248.         $this->leftPhpName $leftPhpName;
  249.     }
  250.     /**
  251.      * @return string
  252.      */
  253.     public function getLeftPhpName()
  254.     {
  255.         return $this->leftPhpName;
  256.     }
  257.     /**
  258.      * @param string $rightPhpName
  259.      *
  260.      * @return void
  261.      */
  262.     public function setRightPhpName($rightPhpName)
  263.     {
  264.         $this->rightPhpName $rightPhpName;
  265.     }
  266.     /**
  267.      * @return string
  268.      */
  269.     public function getRightPhpName()
  270.     {
  271.         return $this->rightPhpName;
  272.     }
  273.     // Utility methods
  274.     /**
  275.      * @return bool
  276.      */
  277.     public function isPrimary()
  278.     {
  279.         return $this->leftPhpName === null;
  280.     }
  281.     /**
  282.      * @return string
  283.      */
  284.     public function __toString()
  285.     {
  286.         return sprintf('modelName: %s, relationName: %s, relationMethod: %s, leftPhpName: %s, rightPhpName: %s'$this->modelName$this->relationName$this->relationMethod$this->leftPhpName$this->rightPhpName);
  287.     }
  288. }