|
2 | 2 | /** Community Controller*/
|
3 | 3 | class CommunityController extends AppController
|
4 | 4 | {
|
5 |
| - public $_models = array('Community', 'Folder', 'Group', 'Folderpolicygroup', 'Group', 'User', 'Feed', "Feedpolicygroup", "Feedpolicyuser", 'Item'); |
| 5 | + public $_models = array('Community', 'Folder', 'Group', 'Folderpolicygroup', 'Group', 'User', 'Feed', "Feedpolicygroup", "Feedpolicyuser", 'Item', 'CommunityInvitation'); |
6 | 6 | public $_daos = array('Community', 'Folder', 'Group', 'Folderpolicygroup', 'Group', 'User');
|
7 | 7 | public $_components = array('Sortdao', 'Date');
|
8 | 8 | public $_forms = array('Community');
|
@@ -243,12 +243,26 @@ function viewAction()
|
243 | 243 | throw new Zend_Exception("This community doesn't exist or you don't have the permissions.");
|
244 | 244 | }
|
245 | 245 | $joinCommunity = $this->_getParam('joinCommunity');
|
| 246 | + $leaveCommunity = $this->_getParam('leaveCommunity'); |
246 | 247 | $canJoin = $communityDao->getCanJoin() == MIDAS_COMMUNITY_CAN_JOIN;
|
| 248 | + |
| 249 | + $this->view->isInvited = $this->CommunityInvitation->isInvited($communityDao, $this->userSession->Dao); |
247 | 250 | $this->view->canJoin = $canJoin;
|
248 |
| - if($canJoin && $this->userSession->Dao != null && isset($joinCommunity) && $communityDao->getPrivacy() == MIDAS_COMMUNITY_PUBLIC) |
| 251 | + if($this->userSession->Dao != null && isset($joinCommunity) && ($canJoin || $this->view->isInvited)) |
249 | 252 | {
|
250 | 253 | $member_group = $communityDao->getMemberGroup();
|
251 | 254 | $this->Group->addUser($member_group, $this->userSession->Dao);
|
| 255 | + if($this->view->isInvited) |
| 256 | + { |
| 257 | + $this->CommunityInvitation->removeInvitation($communityDao, $this->userSession->Dao); |
| 258 | + } |
| 259 | + } |
| 260 | + |
| 261 | + if($this->userSession->Dao != null && isset($leaveCommunity)) |
| 262 | + { |
| 263 | + $member_group = $communityDao->getMemberGroup(); |
| 264 | + $this->Group->removeUser($member_group, $this->userSession->Dao); |
| 265 | + $this->_redirect('/'); |
252 | 266 | }
|
253 | 267 |
|
254 | 268 | $this->Community->incrementViewCount($communityDao);
|
@@ -278,6 +292,7 @@ function viewAction()
|
278 | 292 | $this->view->isModerator = $this->Community->policyCheck($communityDao, $this->userSession->Dao, MIDAS_POLICY_WRITE);
|
279 | 293 | $this->view->isAdmin = $this->Community->policyCheck($communityDao, $this->userSession->Dao, MIDAS_POLICY_ADMIN);
|
280 | 294 | $this->view->json['community'] = $communityDao->toArray();
|
| 295 | + $this->view->json['community']['sendInvitation'] = $this->t('Send invitation'); |
281 | 296 |
|
282 | 297 | if($this->view->isMember)
|
283 | 298 | {
|
@@ -310,6 +325,47 @@ function deleteAction()
|
310 | 325 | $this->_redirect('/');
|
311 | 326 | }//end delete
|
312 | 327 |
|
| 328 | + /** Invit user to a community*/ |
| 329 | + function invitationAction() |
| 330 | + { |
| 331 | + $this->_helper->layout->disableLayout(); |
| 332 | + |
| 333 | + $communityId = $this->_getParam("communityId"); |
| 334 | + if(!isset($communityId) || (!is_numeric($communityId) && strlen($communityId) != 32)) // This is tricky! and for Cassandra for now |
| 335 | + { |
| 336 | + throw new Zend_Exception("Community ID should be a number"); |
| 337 | + } |
| 338 | + $communityDao = $this->Community->load($communityId); |
| 339 | + if($communityDao === false || !$this->Community->policyCheck($communityDao, $this->userSession->Dao, MIDAS_POLICY_WRITE)) |
| 340 | + { |
| 341 | + throw new Zend_Exception("This community doesn't exist or you don't have the permissions."); |
| 342 | + } |
| 343 | + |
| 344 | + if($this->_request->isPost()) |
| 345 | + { |
| 346 | + $this->_helper->viewRenderer->setNoRender(); |
| 347 | + $sendInvitation = $this->_getParam('sendInvitation'); |
| 348 | + if(isset($sendInvitation)) |
| 349 | + { |
| 350 | + $userId = $this->_getParam('userId'); |
| 351 | + $userDao = $this->User->load($userId); |
| 352 | + if($userDao == false) |
| 353 | + { |
| 354 | + throw new Zend_Exception("Unable to find user."); |
| 355 | + } |
| 356 | + $invitation = $this->CommunityInvitation->createInvitation($communityDao, $this->userSession->Dao, $userDao); |
| 357 | + if($invitation == false) |
| 358 | + { |
| 359 | + echo JsonComponent::encode(array(false, $this->t('Error'))); |
| 360 | + } |
| 361 | + else |
| 362 | + { |
| 363 | + echo JsonComponent::encode(array(true, $userDao->getFullName().' '.$this->t('has been invited'))); |
| 364 | + } |
| 365 | + } |
| 366 | + } |
| 367 | + }//end delete |
| 368 | + |
313 | 369 | /** create a community (ajax)*/
|
314 | 370 | function createAction()
|
315 | 371 | {
|
|
0 commit comments