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

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

Last change on this file since 11045 was 11045, checked in by ebihara, 13 years ago

#3219:added limitation for creating community by the "is_allow_user_community" flag of community categories

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