|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Wgevents; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
You may not change or alter any portion of this comment or credits |
|
7
|
|
|
of supporting developers from this source code or any supporting source code |
|
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* wgEvents module for xoops |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright 2021 XOOPS Project (https://xoops.org) |
|
19
|
|
|
* @license GPL 2.0 or later |
|
20
|
|
|
* @package wgevents |
|
21
|
|
|
* @since 1.0.0 |
|
22
|
|
|
* @min_xoops 2.5.11 Beta1 |
|
23
|
|
|
* @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
use XoopsModules\Wgevents; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class Object Handler Account |
|
31
|
|
|
*/ |
|
32
|
|
|
class AccountHandler extends \XoopsPersistableObjectHandler |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* Constructor |
|
36
|
|
|
* |
|
37
|
|
|
* @param \XoopsDatabase $db |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(\XoopsDatabase $db) |
|
40
|
|
|
{ |
|
41
|
|
|
parent::__construct($db, 'wgevents_account', Account::class, 'id', 'type'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param bool $isNew |
|
46
|
|
|
* |
|
47
|
|
|
* @return object |
|
48
|
|
|
*/ |
|
49
|
|
|
public function create($isNew = true) |
|
50
|
|
|
{ |
|
51
|
|
|
return parent::create($isNew); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* retrieve a field |
|
56
|
|
|
* |
|
57
|
|
|
* @param int $id field id |
|
58
|
|
|
* @param $fields |
|
59
|
|
|
* @return \XoopsObject|null reference to the {@link Get} object |
|
60
|
|
|
*/ |
|
61
|
|
|
public function get($id = null, $fields = null) |
|
62
|
|
|
{ |
|
63
|
|
|
return parent::get($id, $fields); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* get inserted id |
|
68
|
|
|
* |
|
69
|
|
|
* @return int reference to the {@link Get} object |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getInsertId() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->db->getInsertId(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get Count Account in the database |
|
78
|
|
|
* @param int $start |
|
79
|
|
|
* @param int $limit |
|
80
|
|
|
* @param string $sort |
|
81
|
|
|
* @param string $order |
|
82
|
|
|
* @return int |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getCountAccounts($start = 0, $limit = 0, $sort = 'id ASC, type', $order = 'ASC') |
|
85
|
|
|
{ |
|
86
|
|
|
$crCountAccounts = new \CriteriaCompo(); |
|
87
|
|
|
$crCountAccounts = $this->getAccountsCriteria($crCountAccounts, $start, $limit, $sort, $order); |
|
88
|
|
|
return $this->getCount($crCountAccounts); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get All Account in the database |
|
93
|
|
|
* @param int $start |
|
94
|
|
|
* @param int $limit |
|
95
|
|
|
* @param string $sort |
|
96
|
|
|
* @param string $order |
|
97
|
|
|
* @return array |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getAllAccounts($start = 0, $limit = 0, $sort = 'id ASC, type', $order = 'ASC') |
|
100
|
|
|
{ |
|
101
|
|
|
$crAllAccounts = new \CriteriaCompo(); |
|
102
|
|
|
$crAllAccounts = $this->getAccountsCriteria($crAllAccounts, $start, $limit, $sort, $order); |
|
103
|
|
|
return $this->getAll($crAllAccounts); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get Criteria Account |
|
108
|
|
|
* @param $crAccount |
|
109
|
|
|
* @param int $start |
|
110
|
|
|
* @param int $limit |
|
111
|
|
|
* @param string $sort |
|
112
|
|
|
* @param string $order |
|
113
|
|
|
* @return int |
|
114
|
|
|
*/ |
|
115
|
|
|
private function getAccountsCriteria($crAccount, int $start, int $limit, string $sort, string $order) |
|
116
|
|
|
{ |
|
117
|
|
|
$crAccount->setStart($start); |
|
118
|
|
|
$crAccount->setLimit($limit); |
|
119
|
|
|
$crAccount->setSort($sort); |
|
120
|
|
|
$crAccount->setOrder($order); |
|
121
|
|
|
return $crAccount; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Get primary Account |
|
126
|
|
|
* returns |
|
127
|
|
|
* - array with defaults if no primary account found (website email settings will be used) |
|
128
|
|
|
* - an array with settings of the primary account |
|
129
|
|
|
* |
|
130
|
|
|
* @return array |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getPrimary() { |
|
133
|
|
|
|
|
134
|
|
|
$crAccount = new \CriteriaCompo(); |
|
135
|
|
|
$crAccount->add(new \Criteria('primary', 1)); |
|
136
|
|
|
$primaryCount = $this->getCount($crAccount); |
|
137
|
|
|
$accountConfig = []; |
|
138
|
|
|
// default settings |
|
139
|
|
|
$accountConfig['type'] = 0; |
|
140
|
|
|
$accountConfig['yourname'] = ''; |
|
141
|
|
|
$accountConfig['yourmail'] = ''; |
|
142
|
|
|
$accountConfig['password'] = ''; |
|
143
|
|
|
$accountConfig['server_out'] = ''; |
|
144
|
|
|
$accountConfig['port_out'] = ''; |
|
145
|
|
|
$accountConfig['securetype_out'] = ''; |
|
146
|
|
|
if ($primaryCount > 0) { |
|
147
|
|
|
$accountAll = $this->getAll($crAccount); |
|
148
|
|
|
foreach (\array_keys($accountAll) as $i) { |
|
149
|
|
|
$accountConfig['type'] = $accountAll[$i]->getVar('type'); |
|
150
|
|
|
$accountConfig['yourname'] = $accountAll[$i]->getVar('yourname'); |
|
151
|
|
|
$accountConfig['yourmail'] = $accountAll[$i]->getVar('yourmail'); |
|
152
|
|
|
$accountConfig['password'] = $accountAll[$i]->getVar('password'); |
|
153
|
|
|
$accountConfig['server_out'] = $accountAll[$i]->getVar('server_out'); |
|
154
|
|
|
$accountConfig['port_out'] = $accountAll[$i]->getVar('port_out'); |
|
155
|
|
|
$accountConfig['securetype_out'] = $accountAll[$i]->getVar('securetype_out'); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
return $accountConfig; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Get the value of limit_hour of primary account |
|
163
|
|
|
* @return int |
|
164
|
|
|
*/ |
|
165
|
|
|
public function getLimitHour() { |
|
166
|
|
|
|
|
167
|
|
|
$limitHour = 0; |
|
168
|
|
|
$crAccount = new \CriteriaCompo(); |
|
169
|
|
|
$crAccount->add(new \Criteria('primary', 1)); |
|
170
|
|
|
$primaryCount = $this->getCount($crAccount); |
|
171
|
|
|
if ($primaryCount > 0) { |
|
172
|
|
|
$accountAll = $this->getAll($crAccount); |
|
173
|
|
|
foreach (\array_keys($accountAll) as $i) { |
|
174
|
|
|
$limitHour = $accountAll[$i]->getVar('limit_hour'); |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
return (int)$limitHour; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|