private static function _setFinalLogicalJunction($pEssentialPrimeImplicants, $pFlattenedLiterals, $pLiteralsToFactoryze, $pLiteralKeys)
 {
     $lLiteralsToFactoryzeByKey = array();
     $lFirstConjunction = new LogicalJunction(LogicalJunction::CONJUNCTION);
     if (!empty($pLiteralsToFactoryze)) {
         foreach ($pLiteralsToFactoryze as $pLiteralIndex) {
             $lFirstConjunction->addLiteral($pFlattenedLiterals[$pLiteralKeys[$pLiteralIndex]]);
             $lLiteralsToFactoryzeByKey[$pLiteralIndex] = null;
         }
     }
     $lDisjunction = new LogicalJunction(LogicalJunction::DISJUNCTION);
     $lFirstConjunction->addLogicalJunction($lDisjunction);
     foreach ($pEssentialPrimeImplicants as $lEssentialPrimeImplicantValues) {
         $lConjunction = new LogicalJunction(LogicalJunction::CONJUNCTION);
         foreach ($lEssentialPrimeImplicantValues as $lIndex => $lValue) {
             // if literal hasn't been factorised
             if (!array_key_exists($lIndex, $lLiteralsToFactoryzeByKey)) {
                 if ($lValue === true) {
                     $lConjunction->addLiteral($pFlattenedLiterals[$pLiteralKeys[$lIndex]]);
                 } else {
                     if ($lValue === false) {
                         $lLiteral = $pFlattenedLiterals[$pLiteralKeys[$lIndex]];
                         $lOppositeLiteral = clone $lLiteral;
                         $lOppositeLiteral->reverseOperator();
                         $lConjunction->addLiteral($lOppositeLiteral);
                     }
                 }
             }
         }
         $lDisjunction->addLogicalJunction($lConjunction);
     }
     return $lFirstConjunction;
 }
 public function importLogicalJunction($pPhpObjectLogicalJunction)
 {
     if (is_null($this->mLeftJoins)) {
         $lMainTableName = $this->mModel->getSqlTableUnit()->getValue("name");
         $this->mSelectQuery = new SelectQuery($lMainTableName);
         $this->mLeftJoins = array();
         $this->mLeftJoins[$lMainTableName] = array('left_model' => $this->mModel, 'right_model' => $this->mModel, "right_table" => $lMainTableName, "right_table_alias" => null);
         $lModels = array();
         $this->_getModelLiterals($pPhpObjectLogicalJunction, $lMainTableName, $lModels);
         $this->_buildModelTree($lModels);
     }
     $this->setLogicalJunction(LogicalJunction::phpObjectToLogicalJunction($pPhpObjectLogicalJunction, $this->mLeftJoins, $this->mLiteralCollection));
     array_shift($this->mLeftJoins);
     foreach ($this->mLeftJoins as $lLeftJoin) {
         $lAlias = array_key_exists('right_table_alias', $lLeftJoin) ? $lLeftJoin['right_table_alias'] : null;
         $this->mSelectQuery->addTable($lLeftJoin["right_table"], $lAlias, SelectQuery::LEFT_JOIN, $lLeftJoin["right_column"], $lLeftJoin["left_column"], $lLeftJoin["left_table"]);
     }
 }
 private function _loadObjectFromDatabase($pObject, $pSelectColumns, $pWhereColumns, $lLogicalJunctionType)
 {
     $lSuccess = false;
     if (!array_key_exists($this->getValue("database")->getValue("id"), self::$sDbObjectById)) {
         $this->_initDbObject();
     }
     if (!$this->mInitialized) {
         $this->_initColumnsProperties($pObject->getModel());
     }
     $lLinkedLiteral = new LogicalJunction($lLogicalJunctionType);
     foreach ($pWhereColumns as $lColumn => $lValue) {
         $lLinkedLiteral->addLiteral(new Literal($this->getValue("name"), $lColumn, "=", $lValue));
     }
     $lSelectQuery = new SelectQuery($this->getValue("name"));
     $lSelectQuery->setWhereLogicalJunction($lLinkedLiteral);
     foreach ($pSelectColumns as $lColumn) {
         $lSelectQuery->addSelectColumn($lColumn);
     }
     $lResult = self::$sDbObjectById[$this->getValue("database")->getValue("id")]->executeQuery($lSelectQuery);
     $lIsModelArray = $pObject->getModel() instanceof ModelArray;
     if (is_array($lResult) && ($lIsModelArray || count($lResult) == 1)) {
         if (!$lIsModelArray) {
             $lResult = $lResult[0];
         }
         if (empty($pSelectColumns)) {
             $pObject->fromSqlDataBase($lResult, self::getDatabaseConnectionTimeZone());
         } else {
             $pObject->fromSqlDataBaseId($lResult, self::getDatabaseConnectionTimeZone());
         }
         $lSuccess = true;
     }
     return $lSuccess;
 }