ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 7861


Ignore:
Timestamp:
Jul 29, 2008, 4:46:35 PM (12 years ago)
Author:
ebihara
Message:

#2862:コミュニティの参加・退会ができるようにし、管理者にはコミュニティ編集権限を与えた

Location:
OpenPNE3/trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/apps/pc_frontend/modules/community/actions/actions.class.php

    r7860 r7861  
    1111class communityActions extends sfActions
    1212{
     13  public $id = 0;
     14
     15  public function preExecute()
     16  {
     17    $this->getUser()->removeCredential('communityAdmin');
     18    $this->getUser()->removeCredential('editCommunity');
     19    $this->getUser()->removeCredential('communityMember');
     20    $this->getUser()->removeCredential('non-communityMember');
     21
     22    $this->id = $this->getRequestParameter('id');
     23
     24    if (CommunityMemberPeer::isMember($this->getUser()->getMemberId(), $this->id)) {
     25      $this->getUser()->addCredential('communityMember');
     26    } else {
     27      $this->getUser()->addCredential('non-communityMember');
     28    }
     29
     30    if (CommunityMemberPeer::isAdmin($this->getUser()->getMemberId(), $this->id)) {
     31      $this->getUser()->addCredential('communityAdmin', 'editCommunity');
     32    }
     33  }
     34
    1335 /**
    1436  * Executes index action
     
    2850  public function executeEdit($request)
    2951  {
    30     $this->community = CommunityPeer::retrieveByPk($request->getParameter('id'));
     52    if ($this->id && !$this->getUser()->hasCredential('editCommunity')) {
     53      $this->forward('default', 'secure');
     54    }
     55
     56    $this->community = CommunityPeer::retrieveByPk($this->id);
    3157    $this->form = new CommunityForm($this->community);
    3258
     
    3561      if ($this->form->isValid()) {
    3662        $community = $this->form->save();
     63
    3764        $this->redirect('community/home?id=' . $community->getId());
    3865      }
     
    4774  public function executeHome($request)
    4875  {
    49     $this->community = CommunityPeer::retrieveByPk($request->getParameter('id'));
     76    $this->community = CommunityPeer::retrieveByPk($this->id);
    5077  }
    5178
     
    6390    return sfView::SUCCESS;
    6491  }
     92
     93 /**
     94  * Executes join action
     95  *
     96  * @param sfRequest $request A request object
     97  */
     98  public function executeJoin($request)
     99  {
     100    CommunityMemberPeer::join($this->getUser()->getMemberId(), $this->id);
     101    $this->redirect('community/home?id=' . $this->id);
     102  }
     103
     104 /**
     105  * Executes quit action
     106  *
     107  * @param sfRequest $request A request object
     108  */
     109  public function executeQuit($request)
     110  {
     111    CommunityMemberPeer::quit($this->getUser()->getMemberId(), $this->id);
     112    $this->redirect('community/home?id=' . $this->id);
     113  }
    65114}
  • OpenPNE3/trunk/apps/pc_frontend/modules/community/templates/homeSuccess.php

    r7860 r7861  
    22
    33<ul>
     4<?php if ($sf_user->hasCredential('editCommunity')) : ?>
    45<li><?php echo link_to('このコミュニティを編集する', 'community/edit?id=' . $community->getId()) ?></li>
     6<?php endif; ?>
     7
     8<?php if (!$sf_user->hasCredential('communityAdmin')) : ?>
     9<?php if ($sf_user->hasCredential('communityMember')) : ?>
     10<li><?php echo link_to('このコミュニティを退会する', 'community/quit?id=' . $community->getId()) ?></li>
     11<?php else : ?>
     12<li><?php echo link_to('このコミュニティに参加する', 'community/join?id=' . $community->getId()) ?></li>
     13<?php endif; ?>
     14<?php endif; ?>
    515</ul>
  • OpenPNE3/trunk/lib/form/CommunityForm.class.php

    r7858 r7861  
    1313  {
    1414  }
     15
     16  public function save($con = null)
     17  {
     18    $community = parent::save($con);
     19
     20    if ($this->isNew()) {
     21      $communityMember = new CommunityMember();
     22      $communityMember->setPosition('admin');
     23      $communityMember->setMemberId(sfContext::getInstance()->getUser()->getMemberId());
     24      $communityMember->setCommunityId($community->getId());
     25      $communityMember->save();
     26    }
     27
     28    return $community;
     29  }
    1530}
  • OpenPNE3/trunk/lib/model/CommunityMemberPeer.php

    r7857 r7861  
    1010class CommunityMemberPeer extends BaseCommunityMemberPeer
    1111{
     12  public static function retrieveByMemberIdAndCommunityId($memberId, $communityId)
     13  {
     14    $c = new Criteria();
     15    $c->add(self::MEMBER_ID, $memberId);
     16    $c->add(self::COMMUNITY_ID, $communityId);
     17    return self::doSelectOne($c);
     18  }
     19
     20  public static function isMember($memberId, $communityId)
     21  {
     22    return (bool)self::retrieveByMemberIdAndCommunityId($memberId, $communityId);
     23  }
     24
     25  public static function isAdmin($memberId, $communityId)
     26  {
     27    $communityMember = self::retrieveByMemberIdAndCommunityId($memberId, $communityId);
     28    if (!$communityMember) {
     29      return false;
     30    }
     31
     32    if ($communityMember->getPosition() != 'admin') {
     33      return false;
     34    }
     35
     36    return true;
     37  }
     38
     39  public static function join($memberId, $communityId)
     40  {
     41    $communityMember = new CommunityMember();
     42    $communityMember->setMemberId($memberId);
     43    $communityMember->setCommunityId($communityId);
     44    $communityMember->save();
     45  }
     46
     47  public static function quit($memberId, $communityId)
     48  {
     49    $communityMember = self::retrieveByMemberIdAndCommunityId($memberId, $communityId);
     50    $communityMember->delete();
     51  }
    1252}
Note: See TracChangeset for help on using the changeset viewer.