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

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

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

merged changes from the goto_doctrine branch. trunk is now Doctrinize

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