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

source: OpenPNE3/branches/goto_doctrine/lib/action/sfOpenPNEFriendAction.class.php @ 11219

Last change on this file since 11219 was 11219, checked in by ebihara, 12 years ago

#3765:imported new models for Doctrine from some old models for Propel to enable to login

File size: 4.2 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      return sfView::ERROR;
50    }
51
52    return sfView::SUCCESS;
53  }
54
55 /**
56  * Executes link action
57  *
58  * @param sfRequest $request A request object
59  */
60  public function executeLink($request)
61  {
62    $this->redirectIf($this->relation->isAccessBlocked(), '@error');
63
64    if ($this->relation->isFriend())
65    {
66      $this->getUser()->setFlash('error', 'This member already belongs to my friends.');
67      $this->redirect('member/profile?id='.$this->id);
68    }
69    if ($this->relation->isFriendPreFrom())
70    {
71      $this->getUser()->setFlash('error', 'My friends request is already sent.');
72      $this->redirect('member/profile?id='.$this->id);
73    }
74
75    $this->redirectToHomeIfIdIsNotValid();
76
77    $this->relation->setFriendPre();
78
79    $this->redirect('member/profile?id='.$this->id);
80  }
81
82 /**
83  * Executes linkAccept action
84  *
85  * @param sfRequest $request A request object
86  */
87  public function executeLinkAccept($request)
88  {
89    if (!$this->relation->isFriendPreTo())
90    {
91      return sfView::ERROR;
92    }
93
94    $this->redirectToHomeIfIdIsNotValid();
95
96    $this->relation->setFriend();
97
98    $this->redirect('member/profile?id='.$this->id);
99  }
100
101 /**
102  * Executes linkReject action
103  *
104  * @param sfRequest $request A request object
105  */
106  public function executeLinkReject($request)
107  {
108    if (!$this->relation->isFriendPreTo())
109    {
110      return sfView::ERROR;
111    }
112
113    $this->redirectToHomeIfIdIsNotValid();
114
115    $this->relation->removeFriendPre();
116
117    $this->redirect('@homepage');
118  }
119
120 /**
121  * Executes unlink action
122  *
123  * @param sfRequest $request A request object
124  */
125  public function executeUnlink($request)
126  {
127    if (!$this->relation->isFriend())
128    {
129      $this->getUser()->setFlash('error', 'This member is not your friend.');
130      $this->redirect('friend/manage');
131    }
132    $this->redirectToHomeIfIdIsNotValid();
133    $this->relation->removeFriend();
134    $this->redirect('friend/manage');
135  }
136
137 /**
138  * Redirects to your home if ID is yours or it is empty.
139  */
140  protected function redirectToHomeIfIdIsNotValid()
141  {
142    $this->redirectUnless($this->id, 'member/home');
143    $this->redirectIf(($this->id == $this->getUser()->getMemberId()), 'member/home');
144  }
145
146 /**
147  * Executes manage action
148  */
149  public function executeManage($request)
150  {
151    $this->pager = Doctrine::getTable('MemberRelationship')->getFriendListPager($this->getUser()->getMemberId(), $request->getParameter('page', 1));
152
153    if (!$this->pager->getNbResults()) {
154      return sfView::ERROR;
155    }
156
157    return sfView::SUCCESS;
158  }
159
160  /**
161   * Executes show member iamges action
162   *
163   * @param sfRequest $request A request object
164   */
165  public function executeShowImage($request)
166  {
167    $this->forward404Unless($this->id);
168
169    $this->member = Doctrine::getTable('Member')->find($this->id);
170    $this->forward404Unless($this->member, 'Undefined member.');
171
172    return sfView::SUCCESS;
173  }
174
175}
Note: See TracBrowser for help on using the repository browser.