Пример #1
0
    /**
     * Count the total inventories by the search parameters using the inventory_model_custom_field_helper table
     *
     * @param string $strInventoryModelCode
     * @param int $intLocationId
     * @param int $intInventoryModelId
     * @param int $intCategoryId
     * @param int $intManufacturerId
     * @param string $strShortDescription
     * @param array $arrCustomFields
     * @param string $strDateModified
     * @param string $strDateModifiedFirst
     * @param string $strDateModifiedLast
     * @param bool $blnAttachment
     * @param array $objExpansionMap
     * @return integer Count
     */
    public static function CountBySearchHelper($strInventoryModelCode = null, $intLocationId = null, $intInventoryModelId = null, $intCategoryId = null, $intManufacturerId = null, $strShortDescription = null, $arrCustomFields = null, $strDateModified = null, $strDateModifiedFirst = null, $strDateModifiedLast = null, $blnAttachment = null, $objExpansionMap = null)
    {
        // Call to QueryHelper to Get the Database Object
        InventoryModel::QueryHelper($objDatabase);
        // Setup QueryExpansion
        $objQueryExpansion = new QQueryExpansion();
        if ($objExpansionMap) {
            try {
                InventoryModel::ExpandQuery('inventory_model', null, $objExpansionMap, $objQueryExpansion);
            } catch (QCallerException $objExc) {
                $objExc->IncrementOffset();
                throw $objExc;
            }
        }
        $arrSearchSql = InventoryModel::GenerateSearchSql($strInventoryModelCode, $intLocationId, $intInventoryModelId, $intCategoryId, $intManufacturerId, $strShortDescription, $arrCustomFields, $strDateModified, $strDateModifiedFirst, $strDateModifiedLast, $blnAttachment);
        $arrCustomFieldSql = CustomField::GenerateHelperSql(EntityQtype::Inventory);
        $arrAttachmentSql = Attachment::GenerateSql(EntityQtype::Inventory);
        $strQuery = sprintf('
				SELECT
					COUNT(DISTINCT inventory_model.inventory_model_id) AS row_count
				FROM
					`inventory_model` AS `inventory_model`
					LEFT JOIN `inventory_location` AS `inventory_location` ON `inventory_model` . `inventory_model_id` = `inventory_location` . `inventory_model_id`
					%s
					%s
					%s
				WHERE
				  1=1
				  %s
				  %s
				  %s
				  %s
				  %s
				  %s
				  %s
				  %s
				  %s
				  %s
			', $objQueryExpansion->GetFromSql("", "\n\t\t\t\t\t"), $arrAttachmentSql['strFrom'], $arrCustomFieldSql['strFrom'], $arrSearchSql['strInventoryModelCodeSql'], $arrSearchSql['strLocationSql'], $arrSearchSql['strInventoryModelSql'], $arrSearchSql['strCategorySql'], $arrSearchSql['strManufacturerSql'], $arrSearchSql['strShortDescriptionSql'], $arrSearchSql['strCustomFieldsSql'], $arrSearchSql['strDateModifiedSql'], $arrSearchSql['strAttachmentSql'], $arrSearchSql['strAuthorizationSql']);
        $objDbResult = $objDatabase->Query($strQuery);
        $strDbRow = $objDbResult->FetchRow();
        return QType::Cast($strDbRow[0], QType::Integer);
    }