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

source: OpenPNE3/trunk/lib/action/sfOpenPNECommunityAction.class.php @ 10467

Last change on this file since 10467 was 10467, checked in by ogawa, 14 years ago

#3469:fixed community editting unique check for the name

File size: 4.7 KB
Line 
1<?php
2
3/**
4 * This file is part of the OpenPNE package.
5 * (c) OpenPNE Project (http://www.openpne.jp/)
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file and the NOTICE file that were distributed with this source code.
9 */
10
11/**
12 * sfOpenPNECommunityAction
13 *
14 * @package    OpenPNE
15 * @subpackage action
16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
17 */
18abstract class sfOpenPNECommunityAction extends sfActions
19{
20  public function preExecute()
21  {
22    $this->id = $this->getRequestParameter('id');
23
24    $this->isCommunityMember = CommunityMemberPeer::isMember($this->getUser()->getMemberId(), $this->id);
25    $this->isAdmin = CommunityMemberPeer::isAdmin($this->getUser()->getMemberId(), $this->id);
26    $this->isEditCommunity = $this->isAdmin;
27  }
28
29 /**
30  * Executes home action
31  *
32  * @param sfRequest $request A request object
33  */
34  public function executeHome($request)
35  {
36    $this->community = CommunityPeer::retrieveByPk($this->id);
37    $this->forward404Unless($this->community, 'Undefined community.');
38    $this->community_admin = CommunityMemberPeer::getCommunityAdmin($this->id);
39    $this->community_admin = MemberPeer::retrieveByPk($this->community_admin->getMemberId());
40  }
41
42 /**
43  * Executes edit action
44  *
45  * @param sfRequest $request A request object
46  */
47  public function executeEdit($request)
48  {
49    if ($this->id && !$this->isEditCommunity)
50    {
51      $this->forward('default', 'secure');
52    }
53
54    $this->community = CommunityPeer::retrieveByPk($this->id);
55    $this->form = new CommunityForm($this->community);
56
57    if ($request->isMethod('post'))
58    {
59      $params = $request->getParameter('community');
60      $params['id'] = $this->id;
61      $this->form->bind($params, $request->getFiles('community'));
62      if ($this->form->isValid())
63      {
64        $community = $this->form->save();
65
66        $this->redirect('community/home?id='.$community->getId());
67      }
68    }
69  }
70
71 /**
72  * Executes joinlist action
73  *
74  * @param sfRequest $request A request object
75  */
76  public function executeJoinlist($request)
77  {
78    $memberId = $request->getParameter('member_id', $this->getUser()->getMemberId());
79
80    $this->member = MemberPeer::retrieveByPK($memberId);
81    $this->forward404Unless($this->member);
82
83    $this->pager = CommunityPeer::getJoinCommunityListPager($memberId, $request->getParameter('page', 1));
84
85    if (!$this->pager->getNbResults())
86    {
87      return sfView::ERROR;
88    }
89
90    return sfView::SUCCESS;
91  }
92
93 /**
94  * Executes memberList action
95  *
96  * @param sfRequest $request A request object
97  */
98  public function executeMemberList($request)
99  {
100    $this->community = CommunityPeer::retrieveByPk($this->id);
101    $this->pager = CommunityPeer::getCommunityMemberListPager($this->id, $request->getParameter('page', 1));
102
103    if (!$this->pager->getNbResults()) {
104      return sfView::ERROR;
105    }
106
107    return sfView::SUCCESS;
108  }
109
110 /**
111  * Executes join action
112  *
113  * @param sfRequest $request A request object
114  */
115  public function executeJoin($request)
116  {
117    if ($this->isCommunityMember) {
118      return sfView::ERROR;
119    }
120
121    CommunityMemberPeer::join($this->getUser()->getMemberId(), $this->id);
122    $this->redirect('community/home?id=' . $this->id);
123  }
124
125 /**
126  * Executes quit action
127  *
128  * @param sfRequest $request A request object
129  */
130  public function executeQuit($request)
131  {
132    if (!$this->isCommunityMember || $this->isAdmin)
133    {
134      return sfView::ERROR;
135    }
136
137    CommunityMemberPeer::quit($this->getUser()->getMemberId(), $this->id);
138    $this->redirect('community/home?id=' . $this->id);
139  }
140
141 /**
142  * Executes memberManage action
143  *
144  * @param sfRequest $request A request object
145  */
146  public function executeMemberManage($request)
147  {
148    $this->redirectUnless($this->isAdmin, '@error');
149
150    $this->community = CommunityPeer::retrieveByPk($this->id);
151    $this->pager = CommunityPeer::getCommunityMemberListPager($this->id, $request->getParameter('page', 1));
152
153    if (!$this->pager->getNbResults())
154    {
155      return sfView::ERROR;
156    }
157
158    return sfView::SUCCESS;
159  }
160
161 /**
162  * Executes dropMember action
163  *
164  * @param sfRequest $request A request object
165  */
166  public function executeDropMember($request)
167  {
168    $this->redirectUnless($this->isAdmin, '@error');
169    $member = MemberPeer::retrieveByPk($request->getParameter('member_id'));
170    $this->forward404Unless($member);
171
172    $isCommunityMember = CommunityMemberPeer::isMember($member->getId(), $this->id);
173    $this->redirectUnless($this->isAdmin, '@error');
174    $isAdmin = CommunityMemberPeer::isAdmin($member->getId(), $this->id);
175    $this->redirectIf($isAdmin, '@error');
176
177    CommunityMemberPeer::quit($member->getId(), $this->id);
178    $this->redirect('community/memberManage?id='.$this->id);
179  }
180
181}
Note: See TracBrowser for help on using the repository browser.