Esempio n. 1
0
 protected static function _generateProxyMethodForOneToOneAssociation(SimDAL_Mapper_Association $association, SimDAL_Mapper_Entity $mapping)
 {
     $method = ucfirst($association->getMethod());
     $getter = 'get' . $method;
     $setter = 'set' . $method;
     $output = '';
     $output .= '	public function ' . $getter . '($load=true) {' . PHP_EOL;
     $output .= '		if ($load && !$this->_isSimDALAssociationLoaded(\'' . $association->getMethod() . '\')) {' . PHP_EOL;
     $output .= '			$session = $this->_getSession();' . PHP_EOL;
     if ($association->isDependent()) {
         $output .= '			$foreign_key = $this->get' . ucfirst($association->getForeignKey()) . '();' . PHP_EOL;
         $output .= '			if (!is_null($foreign_key)) {' . PHP_EOL;
         $output .= '                    $this->' . $setter . '(' . PHP_EOL;
         $output .= '                            $session->load(\'' . $association->getClass() . '\')' . PHP_EOL;
         $output .= '                            ->whereColumn(\'' . $association->getParentKey() . '\')' . PHP_EOL;
         $output .= '                            ->equals($foreign_key)' . PHP_EOL;
         $output .= '                            ->fetch()' . PHP_EOL;
         $output .= '                    );' . PHP_EOL;
         $output .= '			}' . PHP_EOL;
     } else {
         if ($association->isParent()) {
             $output .= '			$parent_key = $this->get' . ucfirst($association->getParentKey()) . '();' . PHP_EOL;
             $output .= '			if (!is_null($parent_key)) {' . PHP_EOL;
             $output .= '                    $this->' . $setter . '(' . PHP_EOL;
             $output .= '                            $session->load(\'' . $association->getClass() . '\')' . PHP_EOL;
             $output .= '                            ->whereColumn(\'' . $association->getForeignKey() . '\')' . PHP_EOL;
             $output .= '                            ->equals($parent_key)' . PHP_EOL;
             $output .= '                            ->fetch()' . PHP_EOL;
             $output .= '                    );' . PHP_EOL;
             $output .= '			}' . PHP_EOL;
         }
     }
     $output .= '			$this->_SimDALAssociationIsLoaded(\'' . $association->getMethod() . '\');' . PHP_EOL;
     $output .= '		}' . PHP_EOL;
     $output .= '		return parent::' . $getter . '();' . PHP_EOL;
     $output .= '	}' . PHP_EOL . PHP_EOL;
     $output .= '	public function ' . $setter . '(' . $association->getClass() . ' $value=null, $set_circlic_ref=true) {' . PHP_EOL;
     $output .= '		if (!is_null($value)) {' . PHP_EOL;
     if ($association->isDependent()) {
         $output .= '			$this->' . $association->getForeignKey() . ' = $value->get' . ucfirst($association->getParentKey()) . '();' . PHP_EOL;
     }
     $output .= '			if (!$this->_getSession()->isLoaded($value) && !$this->_getSession()->isAdded($value)) {' . PHP_EOL;
     $output .= '				$this->_getSession()->addEntity($value);' . PHP_EOL;
     $output .= '			}' . PHP_EOL;
     $output .= '		}' . PHP_EOL;
     $output .= '		$this->_SimDALAssociationIsLoaded(\'' . $association->getMethod() . '\');' . PHP_EOL;
     $output .= '		parent::' . $setter . '($value);' . PHP_EOL . PHP_EOL;
     $output .= '		if (!is_null($value) && $set_circlic_ref) {' . PHP_EOL;
     $output .= '			$value->_SimDAL_SetReference($this, $this->_SimDAL_GetAssociation(\'' . $association->getIdentifier() . '\'));' . PHP_EOL;
     $output .= '		}' . PHP_EOL;
     $output .= '	}' . PHP_EOL . PHP_EOL;
     return $output;
 }