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

source: OpenPNE3/trunk/lib/action/sfOpenPNEFriendAction.class.php @ 11691

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

removed the code depend on Propel

File size: 4.9 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 * sfOpenPNEFriendAction
13 *
14 * @package    OpenPNE
15 * @subpackage action
16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
17 * @author     Shogo Kawahara <kawahara@tejimaya.net>
18 */
19abstract class sfOpenPNEFriendAction extends sfActions
20{
21  public function preExecute()
22  {
23    $this->id = $this->getRequestParameter('id', $this->getUser()->getMemberId());
24
25    $this->relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($this->getUser()->getMemberId(), $this->id);
26    if (!$this->relation) {
27      $this->relation = new MemberRelationship();
28      $this->relation->setMemberIdFrom($this->getUser()->getMemberId());
29      $this->relation->setMemberIdTo($this->id);
30    }
31  }
32
33 /**
34  * Executes list action
35  *
36  * @param sfRequest $request A request object
37  */
38  public function executeList($request)
39  {
40    $this->redirectIf($this->relation->isAccessBlocked(), '@error');
41
42    if (!$this->size)
43    {
44      $this->size = 20;
45    }
46    $this->pager = Doctrine::getTable('MemberRelationship')->getFriendListPager($this->id, $request->getParameter('page', 1), $this->size);
47
48    if (!$this->pager->getNbResults())
49    {
50      return sfView::ERROR;
51    }
52
53    return sfView::SUCCESS;
54  }
55
56 /**
57  * Executes link action
58  *
59  * @param sfRequest $request A request object
60  */
61  public function executeLink($request)
62  {
63    $this->redirectIf($this->relation->isAccessBlocked(), '@error');
64
65    if ($this->relation->isFriend())
66    {
67      $this->getUser()->setFlash('error', 'This member already belongs to my friends.');
68      $this->redirect('member/profile?id='.$this->id);
69    }
70    if ($this->relation->isFriendPreFrom())
71    {
72      $this->getUser()->setFlash('error', 'My friends request is already sent.');
73      $this->redirect('member/profile?id='.$this->id);
74    }
75
76    $this->form = new FriendLinkForm();
77
78    if ($request->isMethod(sfWebRequest::POST))
79    {
80      $this->form->bind($request->getParameter('friend_link'));
81      if ($this->form->isValid())
82      {
83        $this->getUser()->setFlash('notice', 'You have requested friend link.');
84        $this->redirectToHomeIfIdIsNotValid();
85        $this->relation->setFriendPre();
86        $this->dispatcher->notify(new sfEvent($this, 'op_action.post_execute_'.$this->moduleName.'_'.$this->actionName, array(
87          'moduleName' => $this->moduleName,
88          'actionName' => $this->actionName,
89          'actionInstance' => $this,
90          'result'     => sfView::SUCCESS,
91        )));
92        $this->redirect('member/profile?id='.$this->id);
93      }
94    }
95
96    $this->member = Doctrine::getTable('Member')->find($this->id);
97
98    return sfView::INPUT;
99  }
100
101 /**
102  * Executes linkAccept action
103  *
104  * @param sfRequest $request A request object
105  */
106  public function executeLinkAccept($request)
107  {
108    if (!$this->relation->isFriendPreTo())
109    {
110      return sfView::ERROR;
111    }
112
113    $this->redirectToHomeIfIdIsNotValid();
114
115    $this->relation->setFriend();
116
117    $this->redirect('member/profile?id='.$this->id);
118  }
119
120 /**
121  * Executes linkReject action
122  *
123  * @param sfRequest $request A request object
124  */
125  public function executeLinkReject($request)
126  {
127    if (!$this->relation->isFriendPreTo())
128    {
129      return sfView::ERROR;
130    }
131
132    $this->redirectToHomeIfIdIsNotValid();
133
134    $this->relation->removeFriendPre();
135
136    $this->redirect('@homepage');
137  }
138
139 /**
140  * Executes unlink action
141  *
142  * @param sfRequest $request A request object
143  */
144  public function executeUnlink($request)
145  {
146    if (!$this->relation->isFriend())
147    {
148      $this->getUser()->setFlash('error', 'This member is not your friend.');
149      $this->redirect('friend/manage');
150    }
151    $this->redirectToHomeIfIdIsNotValid();
152    $this->relation->removeFriend();
153    $this->redirect('friend/manage');
154  }
155
156 /**
157  * Redirects to your home if ID is yours or it is empty.
158  */
159  protected function redirectToHomeIfIdIsNotValid()
160  {
161    $this->redirectUnless($this->id, 'member/home');
162    $this->redirectIf(($this->id == $this->getUser()->getMemberId()), 'member/home');
163  }
164
165 /**
166  * Executes manage action
167  */
168  public function executeManage($request)
169  {
170    $this->pager = Doctrine::getTable('MemberRelationship')->getFriendListPager($this->getUser()->getMemberId(), $request->getParameter('page', 1));
171
172    if (!$this->pager->getNbResults()) {
173      return sfView::ERROR;
174    }
175
176    return sfView::SUCCESS;
177  }
178
179  /**
180   * Executes show member iamges action
181   *
182   * @param sfRequest $request A request object
183   */
184  public function executeShowImage($request)
185  {
186    $this->forward404Unless($this->id);
187
188    $this->member = Doctrine::getTable('Member')->find($this->id);
189    $this->forward404Unless($this->member, 'Undefined member.');
190
191    return sfView::SUCCESS;
192  }
193
194}
Note: See TracBrowser for help on using the repository browser.