/**
  * Internally called method to assist with early binding of objects
  * on load methods.  Can only early-bind references that this class owns in the database.
  * @param string $strParentAlias the alias of the parent (if any)
  * @param string $strAlias the alias of this object
  * @param array $objExpansionMap map of referenced columns to be immediately expanded via early-binding
  * @param QueryExpansion an already instantiated QueryExpansion object (used as a utility object to assist with object expansion)
  */
 public static function ExpandQuery($strParentAlias, $strAlias, $objExpansionMap, QQueryExpansion $objQueryExpansion)
 {
     if ($strAlias) {
         $objQueryExpansion->AddFromItem(sprintf('LEFT JOIN `category_custom_field_helper` AS `%s__%s` ON `%s`.`%s` = `%s__%s`.`category_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`category_id` AS `%s__%s__category_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $strParentAlias = $strParentAlias . '__' . $strAlias;
     }
     if (is_array($objExpansionMap)) {
         foreach ($objExpansionMap as $strKey => $objValue) {
             switch ($strKey) {
                 case 'category_id':
                     try {
                         Category::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 default:
                     throw new QCallerException(sprintf('Unknown Object to Expand in %s: %s', $strParentAlias, $strKey));
             }
         }
     }
 }
 /**
  * Internally called method to assist with early binding of objects
  * on load methods.  Can only early-bind references that this class owns in the database.
  * @param string $strParentAlias the alias of the parent (if any)
  * @param string $strAlias the alias of this object
  * @param array $objExpansionMap map of referenced columns to be immediately expanded via early-binding
  * @param QueryExpansion an already instantiated QueryExpansion object (used as a utility object to assist with object expansion)
  */
 public static function ExpandQuery($strParentAlias, $strAlias, $objExpansionMap, QQueryExpansion $objQueryExpansion)
 {
     if ($strAlias) {
         $objQueryExpansion->AddFromItem(sprintf('LEFT JOIN `inventory_model` AS `%s__%s` ON `%s`.`%s` = `%s__%s`.`inventory_model_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`inventory_model_id` AS `%s__%s__inventory_model_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`category_id` AS `%s__%s__category_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`manufacturer_id` AS `%s__%s__manufacturer_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`inventory_model_code` AS `%s__%s__inventory_model_code`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`short_description` AS `%s__%s__short_description`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`long_description` AS `%s__%s__long_description`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`image_path` AS `%s__%s__image_path`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`price` AS `%s__%s__price`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`created_by` AS `%s__%s__created_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`creation_date` AS `%s__%s__creation_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_by` AS `%s__%s__modified_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_date` AS `%s__%s__modified_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $strParentAlias = $strParentAlias . '__' . $strAlias;
     }
     if (is_array($objExpansionMap)) {
         foreach ($objExpansionMap as $strKey => $objValue) {
             switch ($strKey) {
                 case 'category_id':
                     try {
                         Category::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'manufacturer_id':
                     try {
                         Manufacturer::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'created_by':
                     try {
                         UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'modified_by':
                     try {
                         UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 default:
                     throw new QCallerException(sprintf('Unknown Object to Expand in %s: %s', $strParentAlias, $strKey));
             }
         }
     }
 }
Example #3
0
    public static function LoadAllWithCustomFields($strOrderBy = null, $strLimit = null, $objExpansionMap = null)
    {
        Category::ArrayQueryHelper($strOrderBy, $strLimit, $strLimitPrefix, $strLimitSuffix, $strExpandSelect, $strExpandFrom, $objExpansionMap, $objDatabase);
        // Setup QueryExpansion
        $objQueryExpansion = new QQueryExpansion();
        if ($objExpansionMap) {
            try {
                Category::ExpandQuery('category', null, $objExpansionMap, $objQueryExpansion);
            } catch (QCallerException $objExc) {
                $objExc->IncrementOffset();
                throw $objExc;
            }
        }
        $arrCustomFieldSql = CustomField::GenerateSql(6);
        $strQuery = sprintf('
				SELECT
					%s
					`category`.`category_id` AS `category_id`,
					`category`.`short_description` AS `short_description`,
					`category`.`long_description` AS `long_description`,
					`category`.`image_path` AS `image_path`,
					`category`.`asset_flag` AS `asset_flag`,
					`category`.`inventory_flag` AS `inventory_flag`,
					`category`.`created_by` AS `created_by`,
					`category`.`creation_date` AS `creation_date`,
					`category`.`modified_by` AS `modified_by`,
					`category`.`modified_date` AS `modified_date`
					%s
					%s
				FROM
					`category` AS `category`
					%s
					%s
				WHERE
				1=1
				%s
				%s
			', $strLimitPrefix, $objQueryExpansion->GetSelectSql(",\n\t\t\t\t\t", ",\n\t\t\t\t\t"), $arrCustomFieldSql['strSelect'], $objQueryExpansion->GetFromSql("", "\n\t\t\t\t\t"), $arrCustomFieldSql['strFrom'], $strOrderBy, $strLimitSuffix);
        //echo($strQuery); exit;
        $objDbResult = $objDatabase->Query($strQuery);
        return Category::InstantiateDbResult($objDbResult);
    }