|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Xnewsletter; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* **************************************************************************** |
|
7
|
|
|
* - A Project by Developers TEAM For Xoops - ( https://xoops.org ) |
|
8
|
|
|
* **************************************************************************** |
|
9
|
|
|
* XNEWSLETTER - MODULE FOR XOOPS |
|
10
|
|
|
* Copyright (c) 2007 - 2012 |
|
11
|
|
|
* Goffy ( wedega.com ) |
|
12
|
|
|
* |
|
13
|
|
|
* You may not change or alter any portion of this comment or credits |
|
14
|
|
|
* of supporting developers from this source code or any supporting |
|
15
|
|
|
* source code which is considered copyrighted (c) material of the |
|
16
|
|
|
* original comment or credit authors. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU General Public License for more details. |
|
22
|
|
|
* --------------------------------------------------------------------------- |
|
23
|
|
|
* @copyright Goffy ( wedega.com ) |
|
24
|
|
|
* @license GPL 2.0 |
|
25
|
|
|
* @package xnewsletter |
|
26
|
|
|
* @author Goffy ( [email protected] ) |
|
27
|
|
|
* |
|
28
|
|
|
* **************************************************************************** |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
//use XoopsModules\Xnewsletter; |
|
32
|
|
|
|
|
33
|
|
|
require_once dirname(__DIR__) . '/include/common.php'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class SubscrHandler |
|
37
|
|
|
*/ |
|
38
|
|
|
class SubscrHandler extends \XoopsPersistableObjectHandler |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @var Helper |
|
42
|
|
|
* @access public |
|
43
|
|
|
*/ |
|
44
|
|
|
public $helper = null; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param null|\XoopsDatabase $db |
|
48
|
|
|
* @param \XoopsModules\Xnewsletter\Helper|null $helper |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct(\XoopsDatabase $db = null, Helper $helper = null) |
|
51
|
|
|
{ |
|
52
|
|
|
parent::__construct($db, 'xnewsletter_subscr', Subscr::class, 'subscr_id', 'subscr_email'); |
|
53
|
|
|
/** @var Helper $this->helper */ |
|
54
|
|
|
if (null === $helper) { |
|
55
|
|
|
$this->helper = Helper::getInstance(); |
|
56
|
|
|
} else { |
|
57
|
|
|
$this->helper = $helper; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Delete subscriber ({@link subscr} object), subscriptions ({@link catsubscr} objects) and mailinglist (subscribingMLHandler function) |
|
63
|
|
|
* |
|
64
|
|
|
* @param \XoopsObject $subscrObj |
|
65
|
|
|
* @param bool $force |
|
66
|
|
|
* |
|
67
|
|
|
* @internal param object $object |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
|
|
public function delete(\XoopsObject$subscrObj, $force = false) |
|
71
|
|
|
{ |
|
72
|
|
|
$res = true; |
|
73
|
|
|
$subscr_id = (int)$subscrObj->getVar('subscr_id'); |
|
74
|
|
|
// delete subscriptions ({@link catsubscr} objects) |
|
75
|
|
|
if ($this->helper->getHandler('Catsubscr')->getCount(new \Criteria('catsubscr_subscrid', $subscr_id)) > 0) { |
|
76
|
|
|
$catsubscrObjs = $this->helper->getHandler('Catsubscr')->getAll(new \Criteria('catsubscr_subscrid', $subscr_id)); |
|
77
|
|
|
foreach ($catsubscrObjs as $catsubscr_id => $catsubscrObj) { |
|
78
|
|
|
$catObj = $this->helper->getHandler('Cat')->get($catsubscrObj->getVar('catsubscr_catid')); |
|
79
|
|
|
$cat_mailinglist = $catObj->getVar('cat_mailinglist'); |
|
80
|
|
|
if ($this->helper->getHandler('Catsubscr')->delete($catsubscrObj, $force)) { |
|
81
|
|
|
// handle mailinglists |
|
82
|
|
|
if (0 != $cat_mailinglist) { |
|
83
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/xnewsletter/include/mailinglist.php'; |
|
84
|
|
|
subscribingMLHandler(0, $subscr_id, $cat_mailinglist); |
|
85
|
|
|
} |
|
86
|
|
|
} else { |
|
87
|
|
|
$res = false; |
|
88
|
|
|
$subscrObj->setErrors($catsubscrObj->getErrors()); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
// delete subscriber ({@link subscr} object) |
|
93
|
|
|
if (true === $res) { |
|
94
|
|
|
$res = parent::delete($subscrObj, $force); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $res; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|