PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / import / classes / coupons.php
vikappointments / site / helpers / libraries / import / classes Last commit date
cities.php 3 days ago coupons.php 3 days ago customers.php 3 days ago empgroups.php 3 days ago employees.php 3 days ago groups.php 3 days ago index.html 3 days ago locations.php 3 days ago optiongroups.php 3 days ago options.php 3 days ago reviews.php 3 days ago services.php 3 days ago states.php 3 days ago
coupons.php
129 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 VAPLoader::import('libraries.import.object');
15
16 /**
17 * Class used to handle an import event for the COUPONS.
18 *
19 * @see ImportObject
20 * @since 1.6
21 */
22 class ImportObjectCoupons extends ImportObject
23 {
24 /**
25 * Overloaded bind function.
26 *
27 * @param object &$data The object of the record to import.
28 * @param array $args Associative list of additional parameters.
29 *
30 * @return boolean True if the record should be imported, otherwise false.
31 */
32 protected function bind(&$data, array $args = array())
33 {
34 // check whether the start date uses the military format as described in the sample file
35 if (preg_match("/^[0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2}$/", $data->dstart, $match))
36 {
37 // yes, convert it in timestamp
38 $data->dstart = strtotime($data->dstart);
39 }
40
41 // check whether the end date uses the military format as described in the sample file
42 if (preg_match("/^[0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2}$/", $data->dend, $match))
43 {
44 // yes, convert it in timestamp
45 $data->dend = strtotime($data->dend);
46 }
47
48 // call parent method to check the data integrity
49 return parent::bind($data);
50 }
51
52 /**
53 * Builds the base query to export all the records.
54 * @since 1.7 $app and $dbo are now included within the $options argument.
55 *
56 * @param JObject $options A registry of export options.
57 * @param string $alias The table alias.
58 *
59 * @return mixed The query builder object.
60 *
61 * @uses getColumns()
62 * @uses getTable()
63 * @uses getPrimaryKey()
64 */
65 protected function buildExportQuery($options, $alias = 'c')
66 {
67 $app = $options->get('app');
68 $dbo = $options->get('dbo');
69
70 $filters = array();
71 $filters['keys'] = $app->getUserStateFromRequest('vapcoupons.keys', 'keys', '', 'string');
72 $filters['type'] = $app->getUserStateFromRequest('vapcoupons.type', 'type', 0, 'uint');
73 $filters['value'] = $app->getUserStateFromRequest('vapcoupons.value', 'value', 0, 'uint');
74 $filters['status'] = $app->getUserStateFromRequest('vapcoupons.status', 'status', 0, 'uint');
75 $filters['id_group'] = $app->getUserStateFromRequest('vapcoupons.group', 'id_group', -1, 'int');
76
77 $q = parent::buildExportQuery($options, $alias);
78
79 // search filter
80 if (strlen($filters['keys']))
81 {
82 $q->where($dbo->qn('c.code') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"));
83 }
84
85 // type filter (GIFT or PERMANENT)
86 if ($filters['type'])
87 {
88 $q->where($dbo->qn('c.type') . ' = ' . $filters['type']);
89 }
90
91 // value filter (PERCENT or TOTAL)
92 if ($filters['value'])
93 {
94 $q->where($dbo->qn('c.percentot') . ' = ' . $filters['value']);
95 }
96
97 // status filter (ACTIVE, NOT ACTIVE or EXPIRED)
98 if ($filters['status'] == 1)
99 {
100 $q->where(array(
101 $dbo->qn('c.dend') . ' > 0',
102 $dbo->qn('c.dend') . ' < ' . time(),
103 ));
104 }
105 else if ($filters['status'] == 2)
106 {
107 $q->andWhere(array(
108 $dbo->qn('c.dend') . ' <= 0',
109 time() . ' BETWEEN ' . $dbo->qn('c.dstart') . ' AND ' . $dbo->qn('c.dend'),
110 ), 'OR');
111 }
112 else if ($filters['status'] == 3)
113 {
114 $q->where(array(
115 $dbo->qn('c.dstart') . ' > 0',
116 $dbo->qn('c.dstart') . ' > ' . time(),
117 ));
118 }
119
120 // group filter
121 if ($filters['id_group'] != -1)
122 {
123 $q->where($dbo->qn('c.id_group') . ' = ' . $filters['id_group']);
124 }
125
126 return $q;
127 }
128 }
129