/** * This loads an expanded array of CustomFieldSelections and their associated values * The values for each selection can be accessed by looping through: $CustomFieldSelections[$i]->CustomFieldValue->ShortDescription * * @param integer $intAssetId * @param integer $intCustomAssetFieldId * @param string $strOrderBy * @param string $strLimit * @param ExpansionMap Object $objExpansionMap * @return CustomAssetFieldSelection */ public static function LoadExpandedArray($intEntityId, $intEntityQtypeId, $intCustomFieldId, $strOrderBy = null, $strLimit = null, $objExpansionMap = null) { switch ($intEntityQtypeId) { case 1: $strPrimaryKey = 'asset_id'; $strId = 'asset`.`asset_id'; $strHelperTable = '`asset_custom_field_helper`'; break; case 2: $strPrimaryKey = 'inventory_model_id'; $strId = 'inventory_model`.`inventory_model_id'; $strHelperTable = '`inventory_model_custom_field_helper`'; break; case 4: $strPrimaryKey = 'asset_model_id'; $strId = 'asset_model`.`asset_model_id'; $strHelperTable = '`asset_model_custom_field_helper`'; break; case 5: $strPrimaryKey = 'manufacturer_id'; $strId = 'manufacturer`.`manufacturer_id'; $strHelperTable = '`manufacturer_custom_field_helper`'; break; case 6: $strPrimaryKey = 'category_id'; $strId = 'category`.`category_id'; $strHelperTable = '`category_custom_field_helper`'; break; case 7: $strPrimaryKey = 'company_id'; $strId = 'company`.`company_id'; $strHelperTable = '`company_custom_field_helper`'; break; case 8: $strPrimaryKey = 'contact_id'; $strId = 'contact`.`contact_id'; $strHelperTable = '`contact_custom_field_helper`'; break; case 9: $strPrimaryKey = 'address_id'; $strId = 'address`.`address_id'; $strHelperTable = '`address_custom_field_helper`'; break; case 10: $strPrimaryKey = 'shipment_id'; $strId = 'shipment`.`shipment_id'; $strHelperTable = '`shipment_custom_field_helper`'; break; case 11: $strPrimaryKey = 'receipt_id'; $strId = 'receipt`.`receipt_id'; $strHelperTable = '`receipt_custom_field_helper`'; break; } $objDatabase = CustomField::GetDatabase(); $strQuery = sprintf("SELECT * FROM %s WHERE %s = %s", $strHelperTable, $strPrimaryKey, $intEntityId); $objDbResult = $objDatabase->Query($strQuery); $objToReturn = array(); $objDbRow = $objDbResult->GetNextRow(); $strShortDescription = $objDbRow->GetColumn('cfv_' . $intCustomFieldId, 'String'); $objCustomFieldSelection = new CustomFieldSelection(); $objCustomFieldSelection->intEntityQtypeId = $intEntityQtypeId; $objCustomFieldSelection->intEntityId = $intEntityId; $objCustomFieldSelection->CustomFieldSelectionId = 0; $objCustomField = CustomField::Load($intCustomFieldId); // If it is a select custom field if ($objCustomField->CustomFieldQtypeId == 2 && !empty($strShortDescription)) { @($objCustomFieldValue = CustomFieldValue::LoadByCustomFieldShortDescription($intCustomFieldId, $strShortDescription)); if ($objCustomFieldValue) { $objCustomFieldSelection->CustomFieldValueId = $objCustomFieldValue->CustomFieldValueId; } } else { $objCustomFieldSelection->CustomFieldValueId = 0; $objCustomFieldValue = new CustomFieldValue(); $objCustomFieldValue->CustomFieldValueId = 0; $objCustomFieldValue->CustomFieldId = $intCustomFieldId; //$objCustomFieldValue->ShortDescription = $objDbRow->GetColumn('cfv_' . $intCustomFieldId, 'String'); $objCustomFieldValue->ShortDescription = $strShortDescription; } $objCustomFieldSelection->CustomFieldValue = $objCustomFieldValue; $objToReturn = $objCustomFieldSelection; return $objToReturn; /* // Expand to include Values $objExpansionMap[CustomFieldSelection::ExpandCustomFieldValue] = true; // Call to ArrayQueryHelper to Get Database Object and Get SQL Clauses CustomFieldSelection::ArrayQueryHelper($strOrderBy, $strLimit, $strLimitPrefix, $strLimitSuffix, $strExpandSelect, $strExpandFrom, $objExpansionMap, $objDatabase); // Properly Escape All Input Parameters using Database->SqlVariable() $intEntityId = $objDatabase->SqlVariable($intEntityId); $intEntityQtypeId = $objDatabase->SqlVariable($intEntityQtypeId); $intCustomFieldId = $objDatabase->SqlVariable($intCustomFieldId); $strQuery = sprintf(' SELECT %s `custom_field_selection`.* %s FROM `custom_field_selection` %s WHERE `custom_field_selection` . `entity_id` = %s AND `custom_field_selection` . `entity_qtype_id` = %s AND `custom_field_selection__custom_field_value_id` . `custom_field_id` = %s %s %s', $strLimitPrefix, $strExpandSelect, $strExpandFrom, $intEntityId, $intEntityQtypeId, $intCustomFieldId, $strOrderBy, $strLimitSuffix); // Perform the Query and Instantiate the Result $objDbResult = $objDatabase->Query($strQuery); return CustomFieldSelection::InstantiateDbRow($objDbResult->GetNextRow());*/ }