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 * Manage the Friends module
30 * @see /library/Pivip/Module/Abstract.php
32 class Friends_Module
extends Pivip_Module_Abstract
35 * Checks whether the Friends module is installed
37 * The Friends module is installed if the database tables have been created.
39 * @return boolean Whether Friends is already installed.
41 public static function isInstalled()
43 if(!file_exists(CODE_PATH
44 . 'application/models/generated/BaseFriend.php'))
50 $friendsTable = Doctrine
::getTable('Friend');
51 } catch(Exception
$e) {
58 * @return boolean False
60 public static function needsConfiguring()
66 * Creates the table in the database and perform the first authentication
68 * @throws Pivip_Install_Exception
69 * @return boolean Whether the installation succeeded
71 public function install()
73 if($this->isInstalled())
77 $nextRequest = new Zend_Controller_Request_Simple('index',
80 $this->_pushStack($nextRequest);
84 * Remove the table from the database
86 * @throws Pivip_Install_Exception
87 * @return boolean Whether uninstallation succeeded
89 public function uninstall()
94 * @return array A list of the blocks this module provides for normal pages,
96 * array('section' => array('Link to add this block'
99 public static function getPageBlocks($location)
101 if(!self
::isInstalled())
105 $translate = Zend_Registry
::get('Zend_Translate');
106 $route = Zend_Controller_Front
::getInstance()->getRouter()
107 ->getRoute('Friends_AddList');
109 $sections = array('sitecontext');
110 foreach($sections as $section)
112 $blocks[$section] = array($route->assemble(array('section' => $section,
115 => $translate->_('Contact list'));
121 * Load the generic cache for use by this module
125 public static function loadCache()
127 $frontendOptions = array('automatic_serialization' => true);
128 $cacheConfig = Zend_Registry
::get('cacheConfig');
129 $cache = Zend_Cache
::factory('Core',
130 $cacheConfig->cache
->backend
,
132 $cacheConfig->backendOptions
->toArray());
139 * @todo Allow the admins to edit the ACL.
141 public function bootstrap()
143 // Only load if installed
144 if(!$this->isInstalled())
148 // Define the Access Control List
149 $acl = Zend_Registry
::get('acl');
150 $acl->add(new Zend_Acl_Resource('friendlist'))
151 ->allow('guest', 'friendlist', 'apply');
152 Zend_Registry
::set('acl', $acl);
154 $router = Zend_Controller_Front
::getInstance()->getRouter();
155 $options = array('module' => 'friends', 'controller' => 'list',
156 'action' => 'add', 'location' => '');
157 $route = new Zend_Controller_Router_Route(
158 'contactlist/add/:section/:location', $options);
159 $router->addRoute('Friends_AddList', $route);
160 $options = array('module' => 'friends', 'controller' => 'list',
162 $route = new Zend_Controller_Router_Route_Static(
163 'contactlist/edit', $options);
164 $router->addRoute('Friends_EditList', $route);
165 $options = array('module' => 'friends', 'controller' => 'friend',
167 $route = new Zend_Controller_Router_Route('contacts/apply',
169 $router->addRoute('Friends_ApplyAsFriend', $route);
170 $options = array('module' => 'friends', 'controller' => 'friend',
171 'action' => 'add', 'friend' => '');
172 $route = new Zend_Controller_Router_Route('contacts/add/:friend',
174 $router->addRoute('Friends_AddFriend', $route);
175 $options = array('module' => 'friends', 'controller' => 'friend',
177 $route = new Zend_Controller_Router_Route('contacts/edit/:friend',
179 $router->addRoute('Friends_EditFriend', $route);
180 $options = array('module' => 'friends', 'controller' => 'friend',
181 'action' => 'delete');
182 $route = new Zend_Controller_Router_Route('contacts/delete/:friend',
184 $router->addRoute('Friends_DeleteFriend', $route);
185 $options = array('module' => 'friends', 'controller' => 'friend',
187 $route = new Zend_Controller_Router_Route('contacts/rest/*', $options);
188 $router->addRoute('Friends_Rest', $route);