XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
favoritesAction.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
18{
19 private $mService;
20 private $favorites;
21
22 public function __construct()
23 {
24 parent::__construct();
25 $this->mService = $this->root->mServiceManager->getService('UserSearch');
26 $this->setUrl('index.php?action=favorites');
27 }
28
29 private function addFavorites()
30 {
31 $ret = [];
32 $adduid = $this->root->mContext->mRequest->getRequest('adduid');
33 if (!is_array($adduid) || 0 == count($adduid)) {
34 $this->setErr(_MD_MESSAGE_FAVORITES0);
35 return true;
36 }
37 $mid = $this->root->mContext->mXoopsModule->get('mid');
38 $client = $this->root->mServiceManager->createClient($this->mService);
39 foreach ($adduid as $fuid) {
40 $ret[] = $client->call('addFavorites', ['mid' => $mid, 'fuid' => $fuid, 'weight' => 0]);
41 }
42 if (in_array(false, $ret, true)) {
43 $this->setErr(_MD_MESSAGE_FAVORITES1);
44 } else {
45 $this->setErr(_MD_MESSAGE_FAVORITES2);
46 }
47 }
48
49 private function edtFavorites()
50 {
51 $weight = $this->root->mContext->mRequest->getRequest('weight');
52 if (!is_array($weight) || 0 == count($weight)) {
53 return true;
54 }
55 $client = $this->root->mServiceManager->createClient($this->mService);
56 foreach ($weight as $id => $w) {
57 $ret[] = $client->call('edtFavorites', ['id' => $id, 'weight' => $w]);
58 }
59 if (in_array(false, $ret, true)) {
60 $this->setErr(_MD_MESSAGE_FAVORITES3);
61 return false;
62 }
63
64 $this->setErr(_MD_MESSAGE_FAVORITES4);
65 return true;
66 }
67
68 private function delFavorites()
69 {
70 $delid = $this->root->mContext->mRequest->getRequest('delid');
71 if (!is_array($delid) || 0 == count($delid)) {
72 return;
73 }
74 $client = $this->root->mServiceManager->createClient($this->mService);
75 foreach ($delid as $id) {
76 $ret[] = $client->call('delFavorites', ['id' => $id]);
77 }
78 if (in_array(false, $ret, true)) {
79 $this->setErr(_MD_MESSAGE_FAVORITES3);
80 } else {
81 $this->setErr(_MD_MESSAGE_FAVORITES5);
82 }
83 }
84
85 private function getFavorites()
86 {
87 $mid = $this->root->mContext->mXoopsModule->get('mid');
88 $client = $this->root->mServiceManager->createClient($this->mService);
89 $this->favorites = $client->call('getFavoritesUsers', ['mid' => $mid]);
90 }
91
92 public function execute()
93 {
94 if (!$this->chk_use()) {
95 $this->setUrl('index.php?action=settings');
96 $this->setErr(_MD_MESSAGE_SETTINGS_MSG5);
97 } else {
98 if (null == $this->mService) {
99 $this->setErr('Service Not loaded.');
100 return;
101 }
102
103 $this->root->mLanguageManager->loadModuleMessageCatalog('usersearch');
104 $cmd = $this->root->mContext->mRequest->getRequest('cmd');
105 if ('' == $cmd) {
106 $this->getFavorites();
107 } else {
108 switch ($cmd) {
109 case 'add':
110 $this->addFavorites();
111 break;
112 case 'edt':
113 if ($this->edtFavorites()) {
114 $this->delFavorites();
115 }
116 break;
117 }
118 }
119 }
120 }
121
122 public function executeView(&$render)
123 {
124 $render->setTemplateName('message_favorites.html');
125 $render->setAttribute('fuser', $this->favorites);
126 }
127}