当前位置: 首页>>代码示例>>PHP>>正文


PHP DBObjectSet::FetchAssoc方法代码示例

本文整理汇总了PHP中DBObjectSet::FetchAssoc方法的典型用法代码示例。如果您正苦于以下问题:PHP DBObjectSet::FetchAssoc方法的具体用法?PHP DBObjectSet::FetchAssoc怎么用?PHP DBObjectSet::FetchAssoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBObjectSet的用法示例。


在下文中一共展示了DBObjectSet::FetchAssoc方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: IsPartOfContext

 /**
  * Determines if the given DBObject is part of a 'context'
  * @param DBObject $oObj
  * @return boolean
  */
 public function IsPartOfContext(DBObject $oObj, &$aRootCauses)
 {
     $bRet = false;
     $sFinalClass = get_class($oObj);
     $aParentClasses = MetaModel::EnumParentClasses($sFinalClass, ENUM_PARENT_CLASSES_ALL);
     foreach ($aParentClasses as $sClass) {
         if (array_key_exists($sClass, $this->aContextSearches)) {
             foreach ($this->aContextSearches[$sClass] as $aContextQuery) {
                 $aAliases = $aContextQuery['search']->GetSelectedClasses();
                 $aAliasNames = array_keys($aAliases);
                 $sRootCauseAlias = $aAliasNames[1];
                 // 1st column (=0) = object, second column = root cause
                 $oSet = new DBObjectSet($aContextQuery['search'], array(), array('id' => $oObj->GetKey()));
                 while ($aRow = $oSet->FetchAssoc()) {
                     if (!is_null($aRow[$sRootCauseAlias])) {
                         if (!array_key_exists($aContextQuery['key'], $aRootCauses)) {
                             $aRootCauses[$aContextQuery['key']] = array();
                         }
                         $aRootCauses[$aContextQuery['key']][] = $aRow[$sRootCauseAlias];
                         $bRet = true;
                     }
                 }
             }
         }
     }
     return $bRet;
 }
开发者ID:henryavila,项目名称:itop,代码行数:32,代码来源:relationgraph.class.inc.php

示例2: GetUserOrgs

 /**
  * Read and cache organizations allowed to the given user
  * 
  * @param oUser
  * @param sClass -not used here but can be used in overloads
  */
 protected function GetUserOrgs($oUser, $sClass)
 {
     $iUser = $oUser->GetKey();
     if (!array_key_exists($iUser, $this->m_aUserOrgs)) {
         $this->m_aUserOrgs[$iUser] = array();
         $sHierarchicalKeyCode = MetaModel::IsHierarchicalClass('Organization');
         if ($sHierarchicalKeyCode !== false) {
             $sUserOrgQuery = 'SELECT UserOrg, Org FROM Organization AS Org JOIN Organization AS Root ON Org.' . $sHierarchicalKeyCode . ' BELOW Root.id JOIN URP_UserOrg AS UserOrg ON UserOrg.allowed_org_id = Root.id WHERE UserOrg.userid = :userid';
             $oUserOrgSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData($sUserOrgQuery), array(), array('userid' => $iUser));
             while ($aRow = $oUserOrgSet->FetchAssoc()) {
                 $oUserOrg = $aRow['UserOrg'];
                 $oOrg = $aRow['Org'];
                 $this->m_aUserOrgs[$iUser][] = $oOrg->GetKey();
             }
         } else {
             $oSearch = new DBObjectSearch('URP_UserOrg');
             $oSearch->AllowAllData();
             $oCondition = new BinaryExpression(new FieldExpression('userid'), '=', new VariableExpression('userid'));
             $oSearch->AddConditionExpression($oCondition);
             $oUserOrgSet = new DBObjectSet($oSearch, array(), array('userid' => $iUser));
             while ($oUserOrg = $oUserOrgSet->Fetch()) {
                 $this->m_aUserOrgs[$iUser][] = $oUserOrg->Get('allowed_org_id');
             }
         }
     }
     return $this->m_aUserOrgs[$iUser];
 }
开发者ID:kira8565,项目名称:ITOP203-ZHCN,代码行数:33,代码来源:userrightsprofile.class.inc.php

示例3: GetNextChunk

 public function GetNextChunk(&$aStatus)
 {
     $sRetCode = 'run';
     $iPercentage = 0;
     $oSet = new DBObjectSet($this->oSearch);
     $aSelectedClasses = $this->oSearch->GetSelectedClasses();
     $aAliases = array_keys($aSelectedClasses);
     $oSet->SetLimit($this->iChunkSize, $this->aStatusInfo['position']);
     $aAliasByField = array();
     $aColumnsToLoad = array();
     // Prepare the list of aliases / columns to load
     foreach ($this->aStatusInfo['fields'] as $sExtendedAttCode) {
         if (preg_match('/^([^\\.]+)\\.(.+)$/', $sExtendedAttCode, $aMatches)) {
             $sAlias = $aMatches[1];
             $sAttCode = $aMatches[2];
         } else {
             $sAlias = reset($aAliases);
             $sAttCode = $sExtendedAttCode;
         }
         if (!in_array($sAlias, $aAliases)) {
             throw new Exception("Invalid alias '{$sAlias}' for the column '{$sExtendedAttCode}'. Availables aliases: '" . implode("', '", $aAliases) . "'");
         }
         if (!array_key_exists($sAlias, $aColumnsToLoad)) {
             $aColumnsToLoad[$sAlias] = array();
         }
         if ($sAttCode != 'id') {
             // id is not a real attribute code and, moreover, is always loaded
             $aColumnsToLoad[$sAlias][] = $sAttCode;
         }
         $aAliasByField[$sExtendedAttCode] = array('alias' => $sAlias, 'attcode' => $sAttCode);
     }
     $iCount = 0;
     $sData = '';
     $oSet->OptimizeColumnLoad($aColumnsToLoad);
     $iPreviousTimeLimit = ini_get('max_execution_time');
     $iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
     while ($aRow = $oSet->FetchAssoc()) {
         set_time_limit($iLoopTimeLimit);
         $sFirstAlias = reset($aAliases);
         $sHilightClass = $aRow[$sFirstAlias]->GetHilightClass();
         if ($sHilightClass != '') {
             $sData .= "<tr class=\"{$sHilightClass}\">";
         } else {
             $sData .= "<tr>";
         }
         foreach ($aAliasByField as $aAttCode) {
             $sField = '';
             switch ($aAttCode['attcode']) {
                 case 'id':
                     $sField = $aRow[$aAttCode['alias']]->GetHyperlink();
                     break;
                 default:
                     $sField = $aRow[$aAttCode['alias']]->GetAsHtml($aAttCode['attcode']);
             }
             $sValue = $sField === '' ? '&nbsp;' : $sField;
             $sData .= "<td>{$sValue}</td>";
         }
         $sData .= "</tr>";
         $iCount++;
     }
     set_time_limit($iPreviousTimeLimit);
     $this->aStatusInfo['position'] += $this->iChunkSize;
     if ($this->aStatusInfo['total'] == 0) {
         $iPercentage = 100;
     } else {
         $iPercentage = floor(min(100.0, 100.0 * $this->aStatusInfo['position'] / $this->aStatusInfo['total']));
     }
     if ($iCount < $this->iChunkSize) {
         $sRetCode = 'done';
     }
     $aStatus = array('code' => $sRetCode, 'message' => Dict::S('Core:BulkExport:RetrievingData'), 'percentage' => $iPercentage);
     return $sData;
 }
开发者ID:henryavila,项目名称:itop,代码行数:73,代码来源:htmlbulkexport.class.inc.php

示例4: GetInteractiveFieldsWidget

    protected function GetInteractiveFieldsWidget(WebPage $oP, $sWidgetId)
    {
        $oSet = new DBObjectSet($this->oSearch);
        $aSelectedClasses = $this->oSearch->GetSelectedClasses();
        $aAuthorizedClasses = array();
        foreach ($aSelectedClasses as $sAlias => $sClassName) {
            if (UserRights::IsActionAllowed($sClassName, UR_ACTION_BULK_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) {
                $aAuthorizedClasses[$sAlias] = $sClassName;
            }
        }
        $aAllFieldsByAlias = array();
        foreach ($aAuthorizedClasses as $sAlias => $sClass) {
            $aAllFields = array();
            if (count($aAuthorizedClasses) > 1) {
                $sShortAlias = $sAlias . '.';
            } else {
                $sShortAlias = '';
            }
            if ($this->IsValidField($sClass, 'id')) {
                $aAllFields[] = array('code' => $sShortAlias . 'id', 'unique_label' => $sShortAlias . Dict::S('Core:BulkExport:Identifier'), 'label' => $sShortAlias . 'id', 'subattr' => array(array('code' => $sShortAlias . 'id', 'unique_label' => $sShortAlias . Dict::S('Core:BulkExport:Identifier'), 'label' => $sShortAlias . 'id'), array('code' => $sShortAlias . 'friendlyname', 'unique_label' => $sShortAlias . Dict::S('Core:BulkExport:Friendlyname'), 'label' => $sShortAlias . Dict::S('Core:BulkExport:Friendlyname'))));
            }
            foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
                if ($this->IsSubAttribute($sClass, $sAttCode, $oAttDef)) {
                    continue;
                }
                if ($this->IsValidField($sClass, $sAttCode, $oAttDef)) {
                    $sShortLabel = $oAttDef->GetLabel();
                    $sLabel = $sShortAlias . $oAttDef->GetLabel();
                    $aSubAttr = $this->GetSubAttributes($sClass, $sAttCode, $oAttDef);
                    $aValidSubAttr = array();
                    foreach ($aSubAttr as $aSubAttDef) {
                        if ($this->IsValidField($sClass, $aSubAttDef['code'], $aSubAttDef['attdef'])) {
                            $aValidSubAttr[] = array('code' => $sShortAlias . $aSubAttDef['code'], 'label' => $aSubAttDef['label'], 'unique_label' => $aSubAttDef['unique_label']);
                        }
                    }
                    $aAllFields[] = array('code' => $sShortAlias . $sAttCode, 'label' => $sShortLabel, 'unique_label' => $sLabel, 'subattr' => $aValidSubAttr);
                }
            }
            usort($aAllFields, array(get_class($this), 'SortOnLabel'));
            if (count($aAuthorizedClasses) > 1) {
                $sKey = MetaModel::GetName($sClass) . ' (' . $sAlias . ')';
            } else {
                $sKey = MetaModel::GetName($sClass);
            }
            $aAllFieldsByAlias[$sKey] = $aAllFields;
        }
        $oP->add('<div id="' . $sWidgetId . '"></div>');
        $JSAllFields = json_encode($aAllFieldsByAlias);
        $oSet = new DBObjectSet($this->oSearch);
        $iCount = $oSet->Count();
        $iPreviewLimit = 3;
        $oSet->SetLimit($iPreviewLimit);
        $aSampleData = array();
        while ($aRow = $oSet->FetchAssoc()) {
            $aSampleRow = array();
            foreach ($aAuthorizedClasses as $sAlias => $sClass) {
                if (count($aAuthorizedClasses) > 1) {
                    $sShortAlias = $sAlias . '.';
                } else {
                    $sShortAlias = '';
                }
                if ($this->IsValidField($sClass, 'id')) {
                    $aSampleRow[$sShortAlias . 'id'] = $this->GetSampleKey($aRow[$sAlias]);
                }
                foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
                    if ($this->IsValidField($sClass, $sAttCode, $oAttDef)) {
                        $aSampleRow[$sShortAlias . $sAttCode] = $this->GetSampleData($aRow[$sAlias], $sAttCode);
                    }
                }
            }
            $aSampleData[] = $aSampleRow;
        }
        $sJSSampleData = json_encode($aSampleData);
        $aLabels = array('preview_header' => Dict::S('Core:BulkExport:DragAndDropHelp'), 'empty_preview' => Dict::S('Core:BulkExport:EmptyPreview'), 'columns_order' => Dict::S('Core:BulkExport:ColumnsOrder'), 'columns_selection' => Dict::S('Core:BulkExport:AvailableColumnsFrom_Class'), 'check_all' => Dict::S('Core:BulkExport:CheckAll'), 'uncheck_all' => Dict::S('Core:BulkExport:UncheckAll'), 'no_field_selected' => Dict::S('Core:BulkExport:NoFieldSelected'));
        $sJSLabels = json_encode($aLabels);
        $oP->add_ready_script(<<<EOF
\$('#{$sWidgetId}').tabularfieldsselector({fields: {$JSAllFields}, value_holder: '#tabular_fields', advanced_holder: '#tabular_advanced', sample_data: {$sJSSampleData}, total_count: {$iCount}, preview_limit: {$iPreviewLimit}, labels: {$sJSLabels} });
EOF
);
    }
开发者ID:henryavila,项目名称:itop,代码行数:80,代码来源:tabularbulkexport.class.inc.php

示例5: GetInteractiveFieldsWidget

    protected function GetInteractiveFieldsWidget(WebPage $oP, $sWidgetId)
    {
        $oSet = new DBObjectSet($this->oSearch);
        $aSelectedClasses = $this->oSearch->GetSelectedClasses();
        $aAuthorizedClasses = array();
        foreach ($aSelectedClasses as $sAlias => $sClassName) {
            if (UserRights::IsActionAllowed($sClassName, UR_ACTION_BULK_READ, $oSet) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) {
                $aAuthorizedClasses[$sAlias] = $sClassName;
            }
        }
        $aAllFieldsByAlias = array();
        $aAllAttCodes = array();
        foreach ($aAuthorizedClasses as $sAlias => $sClass) {
            $aAllFields = array();
            if (count($aAuthorizedClasses) > 1) {
                $sShortAlias = $sAlias . '.';
            } else {
                $sShortAlias = '';
            }
            if ($this->IsExportableField($sClass, 'id')) {
                $sFriendlyNameAttCode = MetaModel::GetFriendlyNameAttributeCode($sClass);
                if (is_null($sFriendlyNameAttCode)) {
                    // The friendly name is made of several attribute
                    $aSubAttr = array(array('attcodeex' => 'id', 'code' => $sShortAlias . 'id', 'unique_label' => $sShortAlias . Dict::S('UI:CSVImport:idField'), 'label' => $sShortAlias . 'id'), array('attcodeex' => 'friendlyname', 'code' => $sShortAlias . 'friendlyname', 'unique_label' => $sShortAlias . Dict::S('Core:FriendlyName-Label'), 'label' => $sShortAlias . Dict::S('Core:FriendlyName-Label')));
                } else {
                    // The friendly name has no added value
                    $aSubAttr = array();
                }
                $aAllFields[] = array('attcodeex' => 'id', 'code' => $sShortAlias . 'id', 'unique_label' => $sShortAlias . Dict::S('UI:CSVImport:idField'), 'label' => Dict::S('UI:CSVImport:idField'), 'subattr' => $aSubAttr);
            }
            foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
                if ($this->IsSubAttribute($sClass, $sAttCode, $oAttDef)) {
                    continue;
                }
                if ($this->IsExportableField($sClass, $sAttCode, $oAttDef)) {
                    $sShortLabel = $oAttDef->GetLabel();
                    $sLabel = $sShortAlias . $oAttDef->GetLabel();
                    $aSubAttr = $this->GetSubAttributes($sClass, $sAttCode, $oAttDef);
                    $aValidSubAttr = array();
                    foreach ($aSubAttr as $aSubAttDef) {
                        $aValidSubAttr[] = array('attcodeex' => $aSubAttDef['code'], 'code' => $sShortAlias . $aSubAttDef['code'], 'label' => $aSubAttDef['label'], 'unique_label' => $sShortAlias . $aSubAttDef['unique_label']);
                    }
                    $aAllFields[] = array('attcodeex' => $sAttCode, 'code' => $sShortAlias . $sAttCode, 'label' => $sShortLabel, 'unique_label' => $sLabel, 'subattr' => $aValidSubAttr);
                }
            }
            usort($aAllFields, array(get_class($this), 'SortOnLabel'));
            if (count($aAuthorizedClasses) > 1) {
                $sKey = MetaModel::GetName($sClass) . ' (' . $sAlias . ')';
            } else {
                $sKey = MetaModel::GetName($sClass);
            }
            $aAllFieldsByAlias[$sKey] = $aAllFields;
            foreach ($aAllFields as $aFieldSpec) {
                $sAttCode = $aFieldSpec['attcodeex'];
                if (count($aFieldSpec['subattr']) > 0) {
                    foreach ($aFieldSpec['subattr'] as $aSubFieldSpec) {
                        $aAllAttCodes[$sAlias][] = $aSubFieldSpec['attcodeex'];
                    }
                } else {
                    $aAllAttCodes[$sAlias][] = $sAttCode;
                }
            }
        }
        $oP->add('<div id="' . $sWidgetId . '"></div>');
        $JSAllFields = json_encode($aAllFieldsByAlias);
        // First, fetch only the ids - the rest will be fetched by an object reload
        $oSet = new DBObjectSet($this->oSearch);
        $iCount = $oSet->Count();
        foreach ($this->oSearch->GetSelectedClasses() as $sAlias => $sClass) {
            $aColumns[$sAlias] = array();
        }
        $oSet->OptimizeColumnLoad($aColumns);
        $iPreviewLimit = 3;
        $oSet->SetLimit($iPreviewLimit);
        $aSampleData = array();
        while ($aRow = $oSet->FetchAssoc()) {
            $aSampleRow = array();
            foreach ($aAuthorizedClasses as $sAlias => $sClass) {
                if (count($aAuthorizedClasses) > 1) {
                    $sShortAlias = $sAlias . '.';
                } else {
                    $sShortAlias = '';
                }
                foreach ($aAllAttCodes[$sAlias] as $sAttCodeEx) {
                    $oObj = $aRow[$sAlias];
                    $aSampleRow[$sShortAlias . $sAttCodeEx] = $oObj ? $this->GetSampleData($oObj, $sAttCodeEx) : '';
                }
            }
            $aSampleData[] = $aSampleRow;
        }
        $sJSSampleData = json_encode($aSampleData);
        $aLabels = array('preview_header' => Dict::S('Core:BulkExport:DragAndDropHelp'), 'empty_preview' => Dict::S('Core:BulkExport:EmptyPreview'), 'columns_order' => Dict::S('Core:BulkExport:ColumnsOrder'), 'columns_selection' => Dict::S('Core:BulkExport:AvailableColumnsFrom_Class'), 'check_all' => Dict::S('Core:BulkExport:CheckAll'), 'uncheck_all' => Dict::S('Core:BulkExport:UncheckAll'), 'no_field_selected' => Dict::S('Core:BulkExport:NoFieldSelected'));
        $sJSLabels = json_encode($aLabels);
        $oP->add_ready_script(<<<EOF
\$('#{$sWidgetId}').tabularfieldsselector({fields: {$JSAllFields}, value_holder: '#tabular_fields', advanced_holder: '#tabular_advanced', sample_data: {$sJSSampleData}, total_count: {$iCount}, preview_limit: {$iPreviewLimit}, labels: {$sJSLabels} });
EOF
);
    }
开发者ID:leandroborgeseng,项目名称:bhtm,代码行数:98,代码来源:tabularbulkexport.class.inc.php

示例6: GetNextChunk

 public function GetNextChunk(&$aStatus)
 {
     $sRetCode = 'run';
     $iPercentage = 0;
     $oSet = new DBObjectSet($this->oSearch);
     $aSelectedClasses = $this->oSearch->GetSelectedClasses();
     $oSet->SetLimit($this->iChunkSize, $this->aStatusInfo['position']);
     $aAliasByField = array();
     $aColumnsToLoad = array();
     // Prepare the list of aliases / columns to load
     foreach ($this->aStatusInfo['fields'] as $sExtendedAttCode) {
         if (preg_match('/^([^\\.]+)\\.(.+)$/', $sExtendedAttCode, $aMatches)) {
             $sAlias = $aMatches[1];
             $sAttCode = $aMatches[2];
         } else {
             $sAlias = reset($aSelectedClasses);
             $sAttCode = $sExtendedAttCode;
         }
         if (!array_key_exists($sAlias, $aSelectedClasses)) {
             throw new Exception("Invalid alias '{$sAlias}' for the column '{$sExtendedAttCode}'. Availables aliases: '" . implode("', '", array_keys($aSelectedClasses)) . "'");
         }
         if (!array_key_exists($sAlias, $aColumnsToLoad)) {
             $aColumnsToLoad[$sAlias] = array();
         }
         if ($sAttCode != 'id') {
             // id is not a real attribute code and, moreover, is always loaded
             $aColumnsToLoad[$sAlias][] = $sAttCode;
         }
         $aAliasByField[$sExtendedAttCode] = array('alias' => $sAlias, 'attcode' => $sAttCode);
     }
     $iCount = 0;
     $sData = '';
     $oSet->OptimizeColumnLoad($aColumnsToLoad);
     $iPreviousTimeLimit = ini_get('max_execution_time');
     $iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
     while ($aRow = $oSet->FetchAssoc()) {
         set_time_limit($iLoopTimeLimit);
         $sData .= "<tr>";
         foreach ($aAliasByField as $aAttCode) {
             $sField = '';
             $oObj = $aRow[$aAttCode['alias']];
             if ($oObj == null) {
                 $sData .= "<td x:str>{$sField}</td>";
                 continue;
             }
             switch ($aAttCode['attcode']) {
                 case 'id':
                     $sField = $oObj->GetName();
                     $sData .= "<td>{$sField}</td>";
                     break;
                 default:
                     $oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $aAttCode['attcode']);
                     $oFinalAttDef = $oAttDef->GetFinalAttDef();
                     if (get_class($oFinalAttDef) == 'AttributeDateTime') {
                         $iDate = AttributeDateTime::GetAsUnixSeconds($oObj->Get($aAttCode['attcode']));
                         $sData .= '<td>' . date('Y-m-d', $iDate) . '</td>';
                         // Add the first column directly
                         $sField = date('H:i:s', $iDate);
                         // Will add the second column below
                         $sData .= "<td>{$sField}</td>";
                     } else {
                         if ($oAttDef instanceof AttributeCaseLog) {
                             $rawValue = $oObj->Get($aAttCode['attcode']);
                             $sField = str_replace("\n", "<br/>", htmlentities($rawValue->__toString(), ENT_QUOTES, 'UTF-8'));
                             // Trick for Excel: treat the content as text even if it begins with an equal sign
                             $sData .= "<td x:str>{$sField}</td>";
                         } else {
                             $rawValue = $oObj->Get($aAttCode['attcode']);
                             // Due to custom formatting rules, empty friendlynames may be rendered as non-empty strings
                             // let's fix this and make sure we render an empty string if the key == 0
                             if ($oAttDef instanceof AttributeFriendlyName) {
                                 $sKeyAttCode = $oAttDef->GetKeyAttCode();
                                 if ($sKeyAttCode != 'id') {
                                     if ($oObj->Get($sKeyAttCode) == 0) {
                                         $sValue = '';
                                     }
                                 }
                             }
                             if ($this->aStatusInfo['localize']) {
                                 $sField = htmlentities($oFinalAttDef->GetEditValue($rawValue), ENT_QUOTES, 'UTF-8');
                             } else {
                                 $sField = htmlentities($rawValue, ENT_QUOTES, 'UTF-8');
                             }
                             $sData .= "<td>{$sField}</td>";
                         }
                     }
             }
         }
         $sData .= "</tr>";
         $iCount++;
     }
     set_time_limit($iPreviousTimeLimit);
     $this->aStatusInfo['position'] += $this->iChunkSize;
     if ($this->aStatusInfo['total'] == 0) {
         $iPercentage = 100;
     } else {
         $iPercentage = floor(min(100.0, 100.0 * $this->aStatusInfo['position'] / $this->aStatusInfo['total']));
     }
     if ($iCount < $this->iChunkSize) {
         $sRetCode = 'done';
//.........这里部分代码省略.........
开发者ID:henryavila,项目名称:itop,代码行数:101,代码来源:spreadsheetbulkexport.class.inc.php

示例7: GetSynchroData

 /**
  * Get all the synchro data related to this object
  * @param none
  * @return array of data_source_id => array
  * 	'source' => $oSource,
  * 	'attributes' => array of $oSynchroAttribute
  * 	'replica' => array of $oReplica (though only one should exist, misuse of the data sync can have this consequence)
  */
 public function GetSynchroData()
 {
     if (is_null($this->m_aSynchroData)) {
         $sOQL = "SELECT replica,datasource FROM SynchroReplica AS replica JOIN SynchroDataSource AS datasource ON replica.sync_source_id=datasource.id WHERE replica.dest_class = :dest_class AND replica.dest_id = :dest_id";
         $oReplicaSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array('dest_class' => get_class($this), 'dest_id' => $this->GetKey()));
         $this->m_aSynchroData = array();
         while ($aData = $oReplicaSet->FetchAssoc()) {
             $iSourceId = $aData['datasource']->GetKey();
             if (!array_key_exists($iSourceId, $this->m_aSynchroData)) {
                 $aAttributes = array();
                 $oAttrSet = $aData['datasource']->Get('attribute_list');
                 while ($oSyncAttr = $oAttrSet->Fetch()) {
                     $aAttributes[$oSyncAttr->Get('attcode')] = $oSyncAttr;
                 }
                 $this->m_aSynchroData[$iSourceId] = array('source' => $aData['datasource'], 'attributes' => $aAttributes, 'replica' => array());
             }
             // Assumption: $aData['datasource'] will not be null because the data source id is always set...
             $this->m_aSynchroData[$iSourceId]['replica'][] = $aData['replica'];
         }
     }
     return $this->m_aSynchroData;
 }
开发者ID:leandroborgeseng,项目名称:bhtm,代码行数:30,代码来源:dbobject.class.php

示例8: GetNextChunk

 public function GetNextChunk(&$aStatus)
 {
     $sRetCode = 'run';
     $iPercentage = 0;
     $hFile = fopen($this->aStatusInfo['tmp_file'], 'ab');
     $oSet = new DBObjectSet($this->oSearch);
     $aSelectedClasses = $this->oSearch->GetSelectedClasses();
     $aAliases = array_keys($aSelectedClasses);
     $oSet->SetLimit($this->iChunkSize, $this->aStatusInfo['position']);
     $aAliasByField = array();
     $aColumnsToLoad = array();
     // Prepare the list of aliases / columns to load
     foreach ($this->aStatusInfo['fields'] as $sExtendedAttCode) {
         if (preg_match('/^([^\\.]+)\\.(.+)$/', $sExtendedAttCode, $aMatches)) {
             $sAlias = $aMatches[1];
             $sAttCode = $aMatches[2];
         } else {
             $sAlias = reset($aAliases);
             $sAttCode = $sExtendedAttCode;
         }
         if (!in_array($sAlias, $aAliases)) {
             throw new Exception("Invalid alias '{$sAlias}' for the column '{$sExtendedAttCode}'. Availables aliases: '" . implode("', '", $aAliases) . "'");
         }
         if (!array_key_exists($sAlias, $aColumnsToLoad)) {
             $aColumnsToLoad[$sAlias] = array();
         }
         if ($sAttCode != 'id') {
             // id is not a real attribute code and, moreover, is always loaded
             $aColumnsToLoad[$sAlias][] = $sAttCode;
         }
         $aAliasByField[$sExtendedAttCode] = array('alias' => $sAlias, 'attcode' => $sAttCode);
     }
     $iCount = 0;
     $oSet->OptimizeColumnLoad($aColumnsToLoad);
     $iPreviousTimeLimit = ini_get('max_execution_time');
     $iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
     while ($aRow = $oSet->FetchAssoc()) {
         set_time_limit($iLoopTimeLimit);
         $aData = array();
         foreach ($aAliasByField as $aAttCode) {
             $sField = '';
             switch ($aAttCode['attcode']) {
                 case 'id':
                     $sField = $aRow[$aAttCode['alias']]->GetKey();
                     break;
                 default:
                     $value = $aRow[$aAttCode['alias']]->Get($aAttCode['attcode']);
                     if ($value instanceof ormCaseLog) {
                         // Extract the case log as text and remove the "===" which make Excel think that the cell contains a formula the next time you edit it!
                         $sField = trim(preg_replace('/========== ([^=]+) ============/', '********** $1 ************', $value->GetText()));
                     } else {
                         if ($value instanceof DBObjectSet) {
                             $oAttDef = MetaModel::GetAttributeDef(get_class($aRow[$aAttCode['alias']]), $aAttCode['attcode']);
                             $sField = $oAttDef->GetAsCSV($value, '', '', $aRow[$aAttCode['alias']]);
                         } else {
                             $oAttDef = MetaModel::GetAttributeDef(get_class($aRow[$aAttCode['alias']]), $aAttCode['attcode']);
                             $sField = $oAttDef->GetEditValue($value, $aRow[$aAttCode['alias']]);
                         }
                     }
             }
             $aData[] = $sField;
         }
         fwrite($hFile, json_encode($aData) . "\n");
         $iCount++;
     }
     set_time_limit($iPreviousTimeLimit);
     $this->aStatusInfo['position'] += $this->iChunkSize;
     if ($this->aStatusInfo['total'] == 0) {
         $iPercentage = 100;
         $sRetCode = 'done';
         // Next phase (GetFooter) will be to build the xlsx file
     } else {
         $iPercentage = floor(min(100.0, 100.0 * $this->aStatusInfo['position'] / $this->aStatusInfo['total']));
     }
     if ($iCount < $this->iChunkSize) {
         $sRetCode = 'done';
     }
     $aStatus = array('code' => $sRetCode, 'message' => Dict::S('Core:BulkExport:RetrievingData'), 'percentage' => $iPercentage);
     return '';
     // The actual XLSX file is built in GetFooter();
 }
开发者ID:henryavila,项目名称:itop,代码行数:81,代码来源:excelbulkexport.class.inc.php


注:本文中的DBObjectSet::FetchAssoc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。