src/ShopBundle/objects/db/TShopVoucherSeries.class.php
public function NumberOfTimesUsedByUser($iDataExtranetUserId = null, $aExcludeVouchers = array())
    {
        $iNumberOfVouchersUsed = 0;

        if (is_null($iDataExtranetUserId)) {
            $oUser = TdbDataExtranetUser::GetInstance();
            $iDataExtranetUserId = $oUser->id;
        }

        $sRestriction = '';
        if (count($aExcludeVouchers) > 0) {
            $aExcludeVouchers = TTools::MysqlRealEscapeArray($aExcludeVouchers);
            $sRestriction = "AND `shop_voucher`.`id` NOT IN ('".implode("','", $aExcludeVouchers)."')";
        }
        $query = "SELECT COUNT(DISTINCT `shop_voucher`.`id`) AS number_of_vouchers
                  FROM `shop_voucher_use`
            INNER JOIN `shop_voucher` ON `shop_voucher_use`.`shop_voucher_id` = `shop_voucher`.`id`
            INNER JOIN `shop_order` ON `shop_voucher_use`.`shop_order_id` = `shop_order`.`id`
                 WHERE `shop_order`.`data_extranet_user_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($iDataExtranetUserId)."'
                   AND `shop_voucher`.`shop_voucher_series_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                   {$sRestriction}
              GROUP BY `shop_voucher`.`shop_voucher_series_id`
               ";

        if ($aTmpRow = MySqlLegacySupport::getInstance()->fetch_assoc(MySqlLegacySupport::getInstance()->query($query))) {
            $iNumberOfVouchersUsed = $aTmpRow['number_of_vouchers'];
        }

        return $iNumberOfVouchersUsed;
    }
public function NumberOfTimesUsedByUser($iDataExtranetUserId = null, $aExcludeVouchers = array())
    {
        $iNumberOfVouchersUsed = 0;

        if (is_null($iDataExtranetUserId)) {
            $oUser = TdbDataExtranetUser::GetInstance();
            $iDataExtranetUserId = $oUser->id;
        }

        $sRestriction = '';
        if (count($aExcludeVouchers) > 0) {
            $aExcludeVouchers = TTools::MysqlRealEscapeArray($aExcludeVouchers);
            $sRestriction = "AND `shop_voucher`.`id` NOT IN ('".implode("','", $aExcludeVouchers)."')";
        }
        $query = "SELECT COUNT(DISTINCT `shop_voucher`.`id`) AS number_of_vouchers
                  FROM `shop_voucher_use`
            INNER JOIN `shop_voucher` ON `shop_voucher_use`.`shop_voucher_id` = `shop_voucher`.`id`
            INNER JOIN `shop_order` ON `shop_voucher_use`.`shop_order_id` = `shop_order`.`id`
                 WHERE `shop_order`.`data_extranet_user_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($iDataExtranetUserId)."'
                   AND `shop_voucher`.`shop_voucher_series_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                   {$sRestriction}
              GROUP BY `shop_voucher`.`shop_voucher_series_id`
               ";

        if ($aTmpRow = MySqlLegacySupport::getInstance()->fetch_assoc(MySqlLegacySupport::getInstance()->query($query))) {
            $iNumberOfVouchersUsed = $aTmpRow['number_of_vouchers'];
        }

        return $iNumberOfVouchersUsed;
    }
public function NumberOfTimesUsedByUser ( $ iDataExtranetUserId = null , $ aExcludeVouchers = array ( ) ) { $ iNumberOfVouchersUsed = 0 ; if ( is_null ( $ iDataExtranetUserId ) ) { $ oUser = TdbDataExtranetUser :: GetInstance ( ) ; $ iDataExtranetUserId = $ oUser -> id ; } $ sRestriction = '' ; if ( count ( $ aExcludeVouchers ) > 0 ) { $ aExcludeVouchers = TTools :: MysqlRealEscapeArray ( $ aExcludeVouchers ) ; $ sRestriction = "AND `shop_voucher`.`id` NOT IN ('" . implode ( "','" , $ aExcludeVouchers ) . "')" ; } $ query = "SELECT COUNT(DISTINCT `shop_voucher`.`id`) AS number_of_vouchers
                  FROM `shop_voucher_use`
            INNER JOIN `shop_voucher` ON `shop_voucher_use`.`shop_voucher_id` = `shop_voucher`.`id`
            INNER JOIN `shop_order` ON `shop_voucher_use`.`shop_order_id` = `shop_order`.`id`
                 WHERE `shop_order`.`data_extranet_user_id` = '" . MySqlLegacySupport :: getInstance ( ) -> real_escape_string ( $ iDataExtranetUserId ) . "'
                   AND `shop_voucher`.`shop_voucher_series_id` = '" . MySqlLegacySupport :: getInstance ( ) -> real_escape_string ( $ this -> id ) . "'
                   {$sRestriction}
              GROUP BY `shop_voucher`.`shop_voucher_series_id`
               " ; if ( $ aTmpRow = MySqlLegacySupport :: getInstance ( ) -> fetch_assoc ( MySqlLegacySupport :: getInstance ( ) -> query ( $ query ) ) ) { $ iNumberOfVouchersUsed = $ aTmpRow [ 'number_of_vouchers' ] ; } return $ iNumberOfVouchersUsed ; }
returns the number of vouchers from that series that have been used by the user (note, we count
also the vouchers that have been used in part only.

@param int   $iDataExtranetUserId (if null, use the current user)
@param array $aExcludeVouchers    - the voucher ids to exclude from the count

@return int
returns the number of vouchers from that series that have been used by the user ( note we count also the vouchers that have been used in part only .