public function importLiteral($pPhpObjectLiteral) { if (is_null($this->mLeftJoins)) { $this->_buildModelTree(array($pPhpObjectLiteral->model => null)); } $this->setLiteral(Literal::phpObjectToLiteral($pPhpObjectLiteral, $this->mLeftJoins, $this->mLiteralCollection)); }
/** * @param stdClass $pPhpObject * @param array $pLeftJoins * @throws \Exception * @return Literal */ public static function phpObjectToLiteral($pPhpObject, &$pLeftJoins, $pLiteralCollection = null) { if (isset($pPhpObject->id) && !is_null($pLiteralCollection)) { if (!array_key_exists($pPhpObject->id, $pLiteralCollection)) { throw new \Exception("literal id '{$pPhpObject->id}' is not defined in literal collection"); } return $pLiteralCollection[$pPhpObject->id]; } self::_verifPhpObject($pPhpObject); if (!array_key_exists($pPhpObject->node, $pLeftJoins)) { throw new \Exception("node doesn't exist in join tree : " . json_encode($pPhpObject)); } $lLeftJoin = $pLeftJoins[$pPhpObject->node]; $lLeftModel = $lLeftJoin['left_model']; $lRightodel = $lLeftJoin['right_model']; $lTable = $pPhpObject->node; if (isset($pPhpObject->queue)) { $lSubQueryTables = self::_queuetoLeftJoins($lLeftModel, $lTable, $pPhpObject->queue); $lLeftJoin = $pLeftJoins[$pPhpObject->node]; $lLeftColumn = $lLeftJoin['left_model']->getProperty($lLeftJoin['left_model']->getFirstIdPropertyName())->getSerializationName(); $lLeftTable = array_key_exists('right_table_alias', $lLeftJoin) && !is_null($lLeftJoin['right_table_alias']) ? $lLeftJoin['right_table_alias'] : $lLeftJoin['right_table']; $lColumnIdSubQuery = $lSubQueryTables[0]['right_column'][0]; $lSelectQuery = self::_setSubSelectQuery($lSubQueryTables, $pPhpObject); $lRigthTableAlias = 't_' . self::$sIndex++; while (array_key_exists($lRigthTableAlias, $pLeftJoins)) { $lRigthTableAlias = 't_' . self::$sIndex++; } $lJoinTable = array('left_table' => $lLeftTable, 'left_column' => $lLeftColumn, 'right_table' => $lSelectQuery, 'right_table_alias' => $lRigthTableAlias, 'right_column' => $lColumnIdSubQuery); $pLeftJoins[$lJoinTable['right_table_alias']] = $lJoinTable; $lLiteral = new Literal($lJoinTable['right_table_alias'], $lColumnIdSubQuery, Literal::DIFF, null); } else { $lProperty = $lRightodel->getProperty($pPhpObject->property, true); if ($lProperty->isComposition()) { throw new \Exception("literal cannot contain foreign porperty '{$pPhpObject->property}'"); } $lLiteral = new Literal($lTable, $lProperty->getSerializationName(), $pPhpObject->operator, $pPhpObject->value); } if (isset($pPhpObject->id)) { $lLiteral->setId($pPhpObject->id); } return $lLiteral; }