XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
CommentDeleteAction.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_MODULE_PATH . '/legacy/class/AbstractDeleteAction.class.php';
17require_once XOOPS_MODULE_PATH . '/legacy/admin/forms/CommentAdminDeleteForm.class.php';
18require_once XOOPS_MODULE_PATH . '/legacy/admin/actions/CommentEditAction.class.php';
19
21{
22 public function _getId()
23 {
24 return isset($_REQUEST['com_id']) ? xoops_getrequest('com_id') : 0;
25 }
26
27 public function &_getHandler()
28 {
29 $handler =& xoops_getmodulehandler('comment');
30 $handler->mDeleteSuccess->add([&$this, 'doDelete']);
31 return $handler;
32 }
33
34 public function _setupActionForm()
35 {
36 $this->mActionForm =new Legacy_CommentAdminDeleteForm();
37 $this->mActionForm->prepare();
38 }
39
40 public function executeViewInput(&$controller, &$xoopsUser, &$render)
41 {
42 //
43 // Lazy load
44 //
45 $this->mObject->loadUser();
46 $this->mObject->loadModule();
47 $this->mObject->loadStatus();
48
49 //
50 // Load children and load their module and commentater.
51 //
52 $handler =& xoops_getmodulehandler('comment');
53 $criteria =new Criteria('com_pid', $this->mObject->get('com_id'));
54 $children =& $handler->getObjects($criteria);
55
56 if ((is_countable($children) ? count($children) : 0) > 0) {
57 foreach (array_keys($children) as $key) {
58 $children[$key]->loadModule();
59 $children[$key]->loadUser();
60 }
61 }
62
63 $render->setTemplateName('comment_delete.html');
64 $render->setAttribute('actionForm', $this->mActionForm);
65 $render->setAttribute('object', $this->mObject);
66 $render->setAttribute('children', $children);
67 }
68
69 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
70 {
71 $controller->executeForward('./index.php?action=CommentList');
72 }
73
74 public function executeViewError(&$controller, &$xoopsUser, &$render)
75 {
76 $controller->executeRedirect('./index.php?action=CommentList', 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
77 }
78
79 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
80 {
81 $controller->executeForward('./index.php?action=CommentList');
82 }
83
84 public function doDelete($comment)
85 {
86 //
87 // Adjust user's post count.
88 //
89 if (1 != $comment->get('com_status') && $comment->get('com_uid') > 0) {
90 $handler =& xoops_gethandler('member');
91
92 //
93 // TODO We should adjust the following lines and handler's design.
94 // We think we should not use getUser() and updateUserByField in XCube 2.1.
95 //
96 $user =& $handler->getUser($comment->get('com_uid'));
97 if (is_object($user)) {
98 $count = $user->get('posts');
99
100 if ($count > 0) {
101 $handler->updateUserByField($user, 'posts', $count - 1);
102 }
103 }
104 }
105
106 //
107 // callback
108 //
109 $comment_config = (new Legacy_CommentEditAction())->loadCallbackFile($comment);
110
111 if (false == $comment_config) {
112 return;
113 }
114
115 $function = $comment_config['callback']['update'];
116
117 if (function_exists($function)) {
118 $criteria = new CriteriaCompo(new Criteria('com_modid', $comment->get('com_modid')));
119 $criteria->add(new Criteria('com_itemid', $comment->get('com_itemid')));
120 $criteria->add(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
121
122 $handler =& xoops_gethandler('comment');
123 $commentCount = $handler->getCount($criteria);
124
125 call_user_func($function, $comment->get('com_id'), $commentCount);
126 }
127 }
128}