Ejemplo n.º 1
0
 public function fetchTreeByQueryParams($rootSearchRule, $depth)
 {
     $queryRules = array();
     foreach ($rootSearchRule as $fieldName => $value) {
         $queryRules[] = queryParamToRule($fieldName, $value, $this);
     }
     $searchRule = implode(' AND ', $queryRules);
     return $this->fetchTreeBySearchRule($searchRule, $depth);
 }
Ejemplo n.º 2
0
 /**
  * Build the Select SQL statement based on the fields and search/sort rule
  *
  * @param BizDataObj $dataObj
  * @return void
  */
 public function buildQuerySQL($dataObj)
 {
     //echo "buildQuerySQL ".$dataObj->m_Name."\n";
     // TODO: the same dataobj re-uses the same datasqlobj ...
     // build the SQL statement based on the fields and search rule
     $dataSqlObj = $this->getNewDataSqlObj($dataObj);
     if ($dataSqlObj->isfresh()) {
         // add table
         $dataSqlObj->addMainTable($dataObj->m_MainTable);
         // add join table
         if ($dataObj->m_TableJoins) {
             foreach ($dataObj->m_TableJoins as $tableJoin) {
                 $tbl_col = $dataSqlObj->addJoinTable($tableJoin, $this);
             }
         }
         // add columns
         foreach ($dataObj->m_BizRecord as $bizFld) {
             if ($bizFld->m_IgnoreInQuery) {
                 // field to be ignore in query - save memory
                 continue;
             }
             if ($bizFld->m_Column && $bizFld->m_Type == "Blob") {
                 // ignore blob column
                 continue;
             }
             if ($bizFld->m_Column && !$bizFld->m_SqlExpression && strpos($bizFld->m_Column, ',') == 0) {
                 $dataSqlObj->addTableColumn($bizFld->m_Join, $bizFld->m_Column, $bizFld->m_Alias);
             }
             if ($bizFld->m_SqlExpression) {
                 $dataSqlObj->addSqlExpression($this->_convertSqlExpression($dataObj, $bizFld->m_SqlExpression), $bizFld->m_Alias);
             }
         }
     }
     $dataSqlObj->resetSQL();
     // append DataPerm in the WHERE clause
     if ($dataObj->m_DataPermControl == 'Y') {
         $svcObj = BizSystem::GetService(DATAPERM_SERVICE);
         $hasOwnerField = $this->_hasOwnerField($dataObj);
         $dataPermSQLRule = $svcObj->buildSqlRule($dataObj, 'select', $hasOwnerField);
         $sqlSearchRule = $this->_ruleToSql($dataObj, $dataPermSQLRule);
         $dataSqlObj->addSqlWhere($sqlSearchRule);
     }
     // append QueryPameters in the WHERE clause
     foreach ($dataObj->getQueryParameters() as $fieldName => $value) {
         $queryRule = queryParamToRule($fieldName, $value, $dataObj);
         $sqlSearchRule = $this->_ruleToSql($dataObj, $queryRule);
         $dataSqlObj->addSqlWhere($sqlSearchRule);
     }
     // append SearchRule in the WHERE clause
     $sqlSearchRule = $this->_ruleToSql($dataObj, $dataObj->m_SearchRule);
     $dataSqlObj->addSqlWhere($sqlSearchRule);
     // append SearchRule in the ORDER BY clause
     $sqlSortRule = $this->_ruleToSql($dataObj, $dataObj->m_SortRule);
     $dataSqlObj->addOrderBy($sqlSortRule);
     // append SearchRule in the other SQL clause
     $sqlOtherSQLRule = $this->_ruleToSql($dataObj, $dataObj->m_OtherSQLRule);
     $dataSqlObj->addOtherSQL($sqlOtherSQLRule);
     // append SearchRule in the AccessRule clause
     $sqlAccessSQLRule = $this->_ruleToSql($dataObj, $dataObj->m_AccessRule);
     $dataSqlObj->addSqlWhere($sqlAccessSQLRule);
     // add association to SQL
     if ($dataObj->m_Association["AsscObjName"] != "" && $dataObj->m_Association["FieldRefVal"] == "") {
         $asscObj = BizSystem::getObject($dataObj->m_Association["AsscObjName"]);
         $dataObj->m_Association["FieldRefVal"] = $asscObj->getFieldValue($dataObj->m_Association["FieldRef"]);
     }
     if ($dataObj->m_Association["AsscObjName"] != "" && $dataObj->m_Association["FieldRefVal2"] == "") {
         $asscObj = BizSystem::getObject($dataObj->m_Association["AsscObjName"]);
         $dataObj->m_Association["FieldRefVal2"] = $asscObj->getFieldValue($dataObj->m_Association["FieldRef2"]);
     }
     if ($dataObj->m_Association["Relationship"] == "Self-Self") {
         $dataObj->m_Association["ParentRecordIdColumn"] = $dataObj->getField("Id")->m_Column;
     }
     $dataSqlObj->addAssociation($dataObj->m_Association);
     // apply _ruleToSql to JoinCondition if any
     if ($dataSqlObj->hasJoinCondition) {
         $dataSqlObj->setTableJoinStm($this->_ruleToSql($dataObj, $dataSqlObj->getTableJoinStm()));
     }
     $querySQL = $dataSqlObj->getSqlStatement() . " ";
     //echo $querySQL."###\n";
     return $querySQL;
 }