public static function getObjects($pParams) { try { $lObjects = ComplexLoadRequest::buildObjectLoadRequest($pParams)->execute(); return self::_setSuccessReturn($lObjects->toObject(false)); } catch (\Exception $e) { return self::_setErrorReturn($e); } }
/** * * @param stdClass $pPhpObject * @return ComplexLoadRequest */ public static function buildObjectLoadRequest($pPhpObject) { if (isset($pPhpObject->model)) { $lObjectLoadRequest = new ComplexLoadRequest($pPhpObject->model); } else { if (isset($pPhpObject->tree) && isset($pPhpObject->tree->model)) { $lObjectLoadRequest = new ComplexLoadRequest($pPhpObject->tree->model); $lObjectLoadRequest->importModelTree($pPhpObject->tree); } else { throw new Exception("request doesn't have model"); } } if (isset($pPhpObject->logicalJunction) && isset($pPhpObject->literal)) { throw new Exception('can\'t have logicalJunction and literal properties in same time'); } if (isset($pPhpObject->literalCollection)) { $lObjectLoadRequest->importLiteralCollection($pPhpObject->literalCollection); } if (isset($pPhpObject->logicalJunction)) { $lObjectLoadRequest->importLogicalJunction($pPhpObject->logicalJunction); } else { if (isset($pPhpObject->literal)) { $lObjectLoadRequest->importLiteral($pPhpObject->literal); } } if (isset($pPhpObject->maxLength)) { $lObjectLoadRequest->setMaxLength($pPhpObject->maxLength); } if (isset($pPhpObject->offset)) { $lObjectLoadRequest->setOffset($pPhpObject->offset); } if (isset($pPhpObject->order)) { if (!is_array($pPhpObject->order)) { throw new Exception("order parameter must be an array"); } foreach ($pPhpObject->order as $lOrder) { if (!isset($lOrder->property)) { throw new Exception("an order element doesn't have property"); } $lObjectLoadRequest->addOrder($lOrder->property, isset($lOrder->type) ? $lOrder->type : SelectQuery::ASC); } } if (isset($pPhpObject->requestChildren)) { $lObjectLoadRequest->requestChildren($pPhpObject->requestChildren); } if (isset($pPhpObject->loadForeignProperties)) { $lObjectLoadRequest->loadForeignProperties($pPhpObject->loadForeignProperties); } return $lObjectLoadRequest; }
private static function _queuetoLeftJoins($pModel, $pAlias, $pQueue, $pTableNameUsed = array()) { $lLeftModel = $pModel; $lLeftTable = $pModel->getSqlTableUnit(); $lLeftAliasTable = self::_getAlias($lLeftTable->getValue("name"), $pTableNameUsed); $lLeftJoins = array(array('left_model' => $pModel, 'right_model' => $pModel, 'right_table' => $lLeftTable->getValue("name"), 'right_table_alias' => $lLeftAliasTable, 'right_column' => $pModel->getSerializationIds())); $lCurrentNode = $pQueue; while (!is_null($lCurrentNode)) { if (!is_object($lCurrentNode) || !isset($lCurrentNode->property)) { throw new \Exception("malformed phpObject literal : " . json_encode($pPhpObject)); } $lLeftTableName = is_null($lLeftAliasTable) ? $lLeftTable->getValue("name") : $lLeftAliasTable; $lProperty = $lLeftModel->getProperty($lCurrentNode->property, true); $lLeftJoin = ComplexLoadRequest::prepareLeftJoin($lLeftTable, $lLeftModel, $lProperty); $lLeftJoin["left_table"] = $lLeftTableName; $lLeftJoin["right_table_alias"] = self::_getAlias($lLeftJoin["right_table"], $pTableNameUsed); $lLeftJoins[] = $lLeftJoin; $lLeftModel = $lProperty->getUniqueModel(); $lLeftTable = $lProperty->getSqlTableUnit(); $lLeftAliasTable = $lLeftJoin["right_table_alias"]; $lCurrentNode = isset($lCurrentNode->child) ? $lCurrentNode->child : null; } // if first left join has only one join column, first table is redundant so we can remove it. if (count($lLeftJoins[1]['right_column']) == 1) { array_shift($lLeftJoins); } return $lLeftJoins; }