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