/** * Get coupon information from the database * * The array returned looks like * array( * 'code-payment_id' => array( * code => The Coupon code, * minimum_amount => The minimum amount for which the coupon is valid, * discount_rate => The discount rate, * discount_amount => The discount amount, * start_time => The validity period start time, * end_time => The validity period end time, * uses => The available number of uses, * global => Flag for globally available coupons, * customer_id => The Customer ID, * product_id => The Product ID, * payment_id => The Payment ID, * ), * ... more ... * ) * @param integer $offset The offset. Defaults to zero * @param integer $limit The limit. Defaults to 30. * @param integer $count By reference. Contains the actual * number of total records on * successful return * @param string $order The sorting order. Defaults to * '`end_time` DESC' * @return array The array of coupon data * @static */ static function getArray($offset = 0, $limit = 0, &$count = 0, $order = '') { global $objDatabase; $offset = max(0, intval($offset)); $limit = min(0, intval($limit)); if (empty($limit)) { $limit = 30; } // The count is zero if an error occurs. // Shuts up the code analyzer warning. $count -= $count; if (empty($order)) { $order = '`end_time` DESC'; } $query = "\n SELECT `code`, `payment_id`, `start_time`, `end_time`,\n `minimum_amount`, `discount_rate`, `discount_amount`,\n `uses`, `global`, `customer_id`, `product_id`\n FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_discount_coupon`\n ORDER BY {$order}"; $objResult = $objDatabase->SelectLimit($query, $limit, $offset); if (!$objResult) { return self::errorHandler(); } $arrCoupons = array(); while (!$objResult->EOF) { //echo("Fields: ".var_export($objResult->fields, true)); $objCoupon = new Coupon(); $code = $objResult->fields['code']; $payment_id = $objResult->fields['payment_id']; $objCoupon->code($code); $objCoupon->payment_id($payment_id); $objCoupon->start_time($objResult->fields['start_time']); $objCoupon->end_time($objResult->fields['end_time']); $objCoupon->minimum_amount($objResult->fields['minimum_amount']); $objCoupon->discount_rate($objResult->fields['discount_rate']); $objCoupon->discount_amount($objResult->fields['discount_amount']); $objCoupon->uses($objResult->fields['uses']); $objCoupon->is_global($objResult->fields['global']); $objCoupon->customer_id($objResult->fields['customer_id']); $objCoupon->product_id($objResult->fields['product_id']); $objCoupon->used = $objCoupon->getUsedCount(); $arrCoupons[$code . '-' . $objCoupon->customer_id] = $objCoupon; $objResult->MoveNext(); } $query = "\n SELECT COUNT(*) AS `numof_records`\n FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_discount_coupon`"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return false; } $count = $objResult->fields['numof_records']; return $arrCoupons; }