5 * Copyright (C) 2008 Vincent Tunru
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * @license http://www.fsf.org/licensing/licenses/info/GPLv2.html GPL v.2
21 * @category PivipModulesDefault
22 * @package Module_Friends
23 * @copyright (C) 2008 Vincent Tunru
24 * @author Vincent Tunru <email@vincentt.org>
28 * Display a list of contacts
30 class Friends_ListController
extends Page_Abstract
33 * Display the friend lists in the sitecontext section of the website
35 public function sitecontextAction()
37 require_once 'modules/friends/views/helpers/GetXfnLink.php';
38 $cache = Friends_Module
::loadCache();
39 if(!$rows = $cache->load('friendlist'))
41 $query = Doctrine_Query
::create();
44 ->where('approved=?', true);
45 $rows = $query->execute();
46 $cache->save($rows, 'friendlist',
47 array('friends', 'list', 'friendlist'));
49 $this->view
->contacts
= $rows;
50 $auth = Pivip_Auth
::getInstance();
51 $acl = Zend_Registry
::get('acl');
52 $identity = $auth->getIdentityProperties();
53 if($auth->hasIdentity() &&
54 $acl->isAllowed($identity->aclRole
, 'friendlist', 'apply'))
56 $this->view
->showOptions
= true;
57 $this->view
->allowApply
= true;
59 if($this->_isAllowed('edit'))
61 $this->view
->showOptions
= true;
62 $this->view
->allowEdit
= true;
69 public function addAction()
71 $this->_helper
->viewRenderer
->setNoRender();
72 $translate = Zend_Registry
::get('Zend_Translate');
73 $location = '/' . $this->_request
->getParam('location');
74 if(!$this->_isAllowed('add'))
76 $this->_flashMessenger
->addMessage($translate->_(
77 'You are not allowed to add a contact.'));
78 $this->_redirect($location);
80 $section = $this->_request
->getParam('section');
83 $this->_flashMessenger
->addMessage($translate->_(
84 'You need to specify a section to add the contact list to.'));
85 $this->_redirect($location);
90 $block->location
= $location;
91 $block->action
= $section;
92 $block->controller
= 'list';
93 $block->module
= 'friends';
95 $cacheId = Pivip_Utility_Cache
::toCacheId($location);
96 $cache = Page_Module
::loadCache();
97 $cache->remove($cacheId);
98 $this->_flashMessenger
99 ->addMessage($translate->_('Contact list added.'));
100 } catch(Exception
$e) {
101 $this->_flashMessenger
->setNamespace('error')
102 ->addMessage($translate->_('Failed to add the contact list.'));
104 $this->_redirect($location);
108 * Edit the friend list
110 public function editAction()
112 if(!$this->_isAllowed('edit'))
114 $translate = Zend_Registry
::get('Zend_Translate');
115 $this->_flashMessenger
->setNamespace('error')
116 ->addMessage($translate->_(
117 'You do not have enough rights to edit the contact list.'));
118 $this->_redirect('/');
120 $query = Doctrine_Query
::create();
123 ->where('approved=?', true);
124 $rows = $query->execute();
125 $this->view
->contacts
= $rows;
126 $query = Doctrine_Query
::create();
127 $query->select('name, website')
129 ->where('approved=?', false);
130 $rows = $query->execute();
131 $this->view
->toApprove
= $rows;
132 $defaultRequest = Zend_Registry
::get('defaultRequest');
133 $this->_helper
->actionStack($defaultRequest);
137 * Delete a friend list
139 * @todo Allow the user to undo this
141 public function deleteAction()
143 $listId = $this->_request
->getParam('list_id');
144 $translate = Zend_Registry
::get('Zend_Translate');
148 $this->_flashMessenger
->setNamespace('error')
149 ->addMessage($translate->_(
150 'No contact list specified.'));
154 $blockTable = Doctrine
::getTable('Block');
155 $block = $blockTable->find($listId);
157 if(!$this->_isAllowed('delete'))
159 $this->_flashMessenger
->setNamespace('error')
160 ->addMessage($translate->_(
161 'You are not allowed to delete the contact list.'));
162 $this->_redirect($block->location
);
168 $this->_flashMessenger
->addMessage($translate->_(
169 'Contact list deleted.'));
170 $cache = Page_Module
::loadCache();
171 $cache->remove(Pivip_Utility_Cache
::toCacheId($location));
172 } catch(Exception
$e) {
173 $this->_flashMessenger
->setNamespace('error')
174 ->addMessage($translate->_(
175 'An error occurred while deleting the contact list, ' .
176 'please try again.'));
178 $this->_redirect($location);
182 * @param $privileges What the user needs to be allowed to do to blocks
183 * @return bool Whether the user has sufficient rights
185 protected function _isAllowed($privileges = null)
187 $auth = Pivip_Auth
::getInstance();
188 $acl = Zend_Registry
::get('acl');
189 $identity = $auth->getIdentityProperties();
190 if(!$auth->hasIdentity())
192 return $acl->isAllowed('guest', 'block', $privileges);
194 return $acl->isAllowed($identity->aclRole
, 'block', $privileges);