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

source: OpenPNE3/trunk/lib/model/doctrine/Member.class.php @ 12110

Last change on this file since 12110 was 12110, checked in by ogawa, 11 years ago

#4062:replaced leftJoin() with subquery to avoid Doctrine_Record value being changed by Doctrine_Hydrator_Graph::hydrateResultSet()

File size: 6.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
11class Member extends BaseMember
12{
13  public function getProfiles($viewableCheck = false, $myMemberId = null)
14  {
15    if ($viewableCheck)
16    {
17      return Doctrine::getTable('MemberProfile')->getViewableProfileListByMemberId($this->getId(), $myMemberId);
18    }
19
20    return Doctrine::getTable('MemberProfile')->getProfileListByMemberId($this->getId());
21  }
22
23  public function getProfile($profileName)
24  {
25    $profile = Doctrine::getTable('MemberProfile')->retrieveByMemberIdAndProfileName($this->getId(), $profileName);
26
27    return $profile;
28  }
29
30  public function getConfig($configName)
31  {
32    $config = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($configName, $this->getId());
33
34    if (!$config)
35    {
36      return null;
37    }
38
39    return $config->getValue();
40  }
41
42  public function setConfig($configName, $value)
43  {
44    $config = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($configName, $this->getId());
45    if (!$config)
46    {
47      $config = new MemberConfig();
48      $config->setMember($this);
49      $config->setName($configName);
50    }
51    $config->setValue($value);
52    $config->save();
53  }
54
55  public function getFriends($limit = null, $isRandom = false)
56  {
57    $subQuery = Doctrine::getTable('MemberRelationship')->createQuery()
58        ->select('mr.member_id_to')
59        ->from('MemberRelationship mr')
60        ->where('member_id_from = ?')
61        ->andWhere('is_friend = ?');
62
63    $q = Doctrine::getTable('Member')->createQuery()
64        ->where('id IN ('.$subQuery->getDql().')', array($this->getId(), true));
65
66    if (!is_null($limit))
67    {
68      $q->limit($limit);
69    }
70
71    if ($isRandom)
72    {
73      $expr = new Doctrine_Expression('RANDOM()');
74      $q->orderBy($expr);
75    }
76
77    return $q->execute();
78  }
79
80  public function countFriends()
81  {
82    return $this->getFriends()->count();
83  }
84
85  public function getNameAndCount($format = '%s (%d)')
86  {
87    return sprintf($format, $this->getName(), $this->countFriends());
88  }
89 
90  public function getJoinCommunities($limit = null, $isRandom = false)
91  {
92    return Doctrine::getTable('Community')->retrievesByMemberId($this->getId(), $limit, $isRandom);
93  }
94
95  public function getFriendPreTo(Doctrine_Query $q = null)
96  {
97    if (!$q)
98    {
99      $q = Doctrine::getTable('MemberRelationship')->createQuery();
100    }
101    $q->where('member_id_to = ?', $this->getId());
102    $q->addWhere('is_friend_pre = ?', true);
103
104    return $q->execute();
105  }
106
107  public function countFriendPreTo(Doctrine_Query $q = null)
108  {
109    if (!$q)
110    {
111      $q = Doctrine::getTable('MemberRelationship')->createQuery();
112    }
113    $q->where('member_id_to = ?', $this->getId());
114    $q->addWhere('is_friend_pre = ?', true);
115
116    return $q->count();
117  }
118
119  public function getFriendPreFrom(Doctrine_Query $q = null)
120  {
121    if (!$q)
122    {
123      $q = Doctrine::getTable('MemberRelationship')->createQuery();
124    }
125    $q->where('member_id_from = ?', $this->getId());
126    $q->addWhere('is_friend_pre = ?', true);
127
128    return $q->execute();
129  }
130
131  public function countFriendPreFrom(Doctrine_Query $q = null)
132  {
133    if (!$q)
134    {
135      $q = Doctrine::getTable('MemberRelationship')->createQuery();
136    }
137    $q->where('member_id_from = ?', $this->getId());
138    $q->addWhere('is_friend_pre = ?', true);
139
140    return $q->count();
141  }
142
143  public function getImage()
144  {
145    return Doctrine::getTable('MemberImage')->createQuery()
146      ->where('member_id = ?', $this->getId())
147      ->orderBy('is_primary DESC')
148      ->fetchOne();
149  }
150
151  public function getImageFileName()
152  {
153    if ($this->getImage())
154    {
155      return $this->getImage()->getFile();
156    }
157
158    return false;
159  }
160
161  public function updateLastLoginTime()
162  {
163    $this->setConfig('lastLogin', time());
164  }
165
166  public function getLastLoginTime()
167  {
168    return $this->getConfig('lastLogin');
169  }
170
171  public function isOnBlackList()
172  {
173    $uid = $this->getConfig('mobile_uid');
174    if ($uid)
175    {
176      return (bool)Doctrine::getTable('Blacklist')->retrieveByUid($uid);
177    }
178
179    return false;
180  }
181
182  public function getInvitingMembers()
183  {
184    return Doctrine::getTable('Member')->retrivesByInviteMemberId($this->getId());
185  }
186
187  public function getInviteMember()
188  {
189    return Doctrine::getTable('Member')->find($this->getInviteMemberId());
190  }
191
192  public function getEmailAddress($isPriorityMobile = null)
193  {
194    if (is_null($isPriorityMobile))
195    {
196      $isPriorityMobile = false;
197      if (sfConfig::get('sf_app') == 'mobile_frontend')
198      {
199        $isPriorityMobile = true;
200      }
201    }
202
203    $memberPcAddress     = $this->getConfig('pc_address');
204    $memberMobileAddress = $this->getConfig('mobile_address');
205
206    if ($memberMobileAddress && ($isPriorityMobile || !$memberPcAddress))
207    {
208      return $memberMobileAddress;
209    }
210
211    if ($memberPcAddress)
212    {
213      return $memberPcAddress;
214    }
215
216    return null;
217  }
218
219  public function getEmailAddresses()
220  {
221    $result = array();
222
223    $memberPcAddress     = $this->getConfig('pc_address');
224    $memberMobileAddress = $this->getConfig('mobile_address');
225
226    if ($memberPcAddress)
227    {
228      $result[] = $memberPcAddress;
229    }
230
231    if ($memberMobileAddress)
232    {
233      $result[] = $memberMobileAddress;
234    }
235
236    return $result;
237  }
238
239  public function delete(Doctrine_Connection $conn = null)
240  {
241    $memberId = $this->getId();
242    $communityMemberTable = Doctrine::getTable('CommunityMember');
243    $adminCommunity = $communityMemberTable->getCommunityIdsOfAdminByMemberId($this->getId());
244    foreach ($adminCommunity as $community)
245    {
246      $communityId = $community['community_id'];
247      $memberCount = $communityMemberTable->getCommunityMemberCount($communityId);
248      if (!$memberCount)
249      {
250          $community = Doctrine::getTable('Community')->find($communityId);
251          $community->delete();
252          continue;
253      }
254      $communityMember = $communityMemberTable->createQuery()
255        ->where('community_id = ?', $communityId)
256        ->addWhere('position = ?', '')
257        ->orderBy('random()')
258        ->limit(1)
259        ->fetchOne();
260      $communityMember->setPosition('admin');
261      $communityMember->save();
262      $communityMember = $communityMemberTable->retrieveByMemberIdAndCommunityId($memberId, $communityId);
263      $communityMember->delete();
264    }
265    return parent::delete($conn);
266  }
267}
Note: See TracBrowser for help on using the repository browser.