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

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

Last change on this file since 11019 was 11019, checked in by ShogoKawahara, 13 years ago

#3248:added ability to set register policy of the community

File size: 7.3 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    $memberId = $this->getUser()->getMemberId();
25    $this->isCommunityMember = CommunityMemberPeer::isMember($memberId, $this->id);
26    $this->isCommunityPreMember = CommunityMemberPeer::isPreMember($memberId, $this->id);
27    $this->isAdmin = CommunityMemberPeer::isAdmin($memberId, $this->id);
28    $this->isEditCommunity = $this->isAdmin;
29  }
30
31 /**
32  * Executes home action
33  *
34  * @param sfRequest $request A request object
35  */
36  public function executeHome($request)
37  {
38    $this->community = CommunityPeer::retrieveByPk($this->id);
39    $this->forward404Unless($this->community, 'Undefined community.');
40    $this->community_admin = CommunityMemberPeer::getCommunityAdmin($this->id);
41    $this->community_admin = MemberPeer::retrieveByPk($this->community_admin->getMemberId());
42
43    if (!$this->membersSize)
44    {
45      $this->membersSize = 9;
46    }
47    $c = new Criteria();
48    $c->addAscendingOrderByColumn(Propel::getDB()->random(time()));
49    $this->members = $this->community->getMembers($this->membersSize, $c);
50  }
51
52 /**
53  * Executes edit action
54  *
55  * @param sfRequest $request A request object
56  */
57  public function executeEdit($request)
58  {
59    if ($this->id && !$this->isEditCommunity)
60    {
61      $this->forward('default', 'secure');
62    }
63
64    $this->community = CommunityPeer::retrieveByPk($this->id);
65    if (!$this->community)
66    {
67      $this->community = new Community();
68     
69    }
70
71    $this->communityForm       = new CommunityForm($this->community);
72    $this->communityConfigForm = new CommunityConfigForm(array(), array('community' => $this->community));
73    $this->communityFileForm   = new CommunityFileForm(array(), array('community' => $this->community));
74
75    if ($request->isMethod('post'))
76    {
77      $params = $request->getParameter('community');
78      $params['id'] = $this->id;
79      $this->communityForm->bind($params);
80      $this->communityConfigForm->bind($request->getParameter('community_config'));
81      $this->communityFileForm->bind($request->getParameter('community_file'), $request->getFiles('community_file'));
82      if ($this->communityForm->isValid() && $this->communityConfigForm->isValid() && $this->communityFileForm->isValid())
83      {
84        $this->communityForm->save();
85        $this->communityConfigForm->save();
86        $this->communityFileForm->save();
87
88        $this->redirect('community/home?id='.$this->community->getId());
89      }
90    }
91  }
92
93 /**
94  * Executes joinlist action
95  *
96  * @param sfRequest $request A request object
97  */
98  public function executeJoinlist($request)
99  {
100    $memberId = $request->getParameter('id', $this->getUser()->getMemberId());
101
102    $this->member = MemberPeer::retrieveByPK($memberId);
103    $this->forward404Unless($this->member);
104
105    if (!$this->size)
106    {
107      $this->size = 20;
108    }
109
110    $this->pager = CommunityPeer::getJoinCommunityListPager($memberId, $request->getParameter('page', 1), $this->size);
111
112    if (!$this->pager->getNbResults())
113    {
114      return sfView::ERROR;
115    }
116
117    $this->crownIds = CommunityMemberPeer::getCommunityIdsOfAdminByMemberId($memberId);
118
119    return sfView::SUCCESS;
120  }
121
122 /**
123  * Executes memberList action
124  *
125  * @param sfRequest $request A request object
126  */
127  public function executeMemberList($request)
128  {
129    $this->community = CommunityPeer::retrieveByPk($this->id);
130    $this->forward404Unless($this->community);
131
132    if (!$this->size)
133    {
134      $this->size = 20;
135    }
136    $this->pager = CommunityPeer::getCommunityMemberListPager($this->id, $request->getParameter('page', 1), $this->size);
137
138    if (!$this->pager->getNbResults()) {
139      return sfView::ERROR;
140    }
141   
142    $this->crownIds = array(CommunityMemberPeer::getCommunityAdmin($this->id)->getMemberId());
143   
144    return sfView::SUCCESS;
145  }
146
147 /**
148  * Executes join action
149  *
150  * @param sfRequest $request A request object
151  */
152  public function executeJoin($request)
153  {
154    if ($this->isCommunityMember || $this->isCommunityPreMember) {
155      return sfView::ERROR;
156    }
157
158    $community = CommunityPeer::retrieveByPk($this->id);
159    $this->forward404Unless($community);
160
161    CommunityMemberPeer::join($this->getUser()->getMemberId(), $this->id, $community->getConfig('register_poricy'));
162    $this->redirect('community/home?id=' . $this->id);
163  }
164
165  /**
166   * Executes joinAccept action
167   *
168   * @param sfRequest $request A request object
169   */
170  public function executeJoinAccept($request)
171  {
172    $this->forward404Unless($this->isAdmin);
173   
174    $communityMember = CommunityMemberPeer::retrieveByMemberIdAndCommunityId($request->getParameter('member_id'), $this->id);
175    $this->forward404Unless($communityMember);
176
177    if ($communityMember->getPosition() == 'pre')
178    {
179      $communityMember->setPosition('');
180      $communityMember->save();
181    }
182    $this->redirect('community/home?id='.$this->id);
183  }
184
185  /**
186   * Executes joinReject action
187   *
188   * @param sfRequest $request A request object
189   */
190  public function executeJoinReject($request)
191  {
192    $this->forward404Unless($this->isAdmin);
193   
194    $communityMember = CommunityMemberPeer::retrieveByMemberIdAndCommunityId($request->getParameter('member_id'), $this->id);
195    $this->forward404Unless($communityMember);
196
197    if ($communityMember->getPosition() == 'pre')
198    {
199      $communityMember->delete();
200    }
201    $this->redirect('community/home?id='.$this->id);   
202  }
203
204 /**
205  * Executes quit action
206  *
207  * @param sfRequest $request A request object
208  */
209  public function executeQuit($request)
210  {
211    if (!$this->isCommunityMember || $this->isAdmin)
212    {
213      return sfView::ERROR;
214    }
215
216    CommunityMemberPeer::quit($this->getUser()->getMemberId(), $this->id);
217    $this->redirect('community/home?id=' . $this->id);
218  }
219
220 /**
221  * Executes memberManage action
222  *
223  * @param sfRequest $request A request object
224  */
225  public function executeMemberManage($request)
226  {
227    $this->redirectUnless($this->isAdmin, '@error');
228
229    $this->community = CommunityPeer::retrieveByPk($this->id);
230    $this->pager = CommunityPeer::getCommunityMemberListPager($this->id, $request->getParameter('page', 1));
231
232    if (!$this->pager->getNbResults())
233    {
234      return sfView::ERROR;
235    }
236
237    return sfView::SUCCESS;
238  }
239
240 /**
241  * Executes dropMember action
242  *
243  * @param sfRequest $request A request object
244  */
245  public function executeDropMember($request)
246  {
247    $this->redirectUnless($this->isAdmin, '@error');
248    $member = MemberPeer::retrieveByPk($request->getParameter('member_id'));
249    $this->forward404Unless($member);
250
251    $isCommunityMember = CommunityMemberPeer::isMember($member->getId(), $this->id);
252    $this->redirectUnless($this->isAdmin, '@error');
253    $isAdmin = CommunityMemberPeer::isAdmin($member->getId(), $this->id);
254    $this->redirectIf($isAdmin, '@error');
255
256    CommunityMemberPeer::quit($member->getId(), $this->id);
257    $this->redirect('community/memberManage?id='.$this->id);
258  }
259
260}
Note: See TracBrowser for help on using the repository browser.