Completed
Branch master (fe7a1b)
by Pierre-Henry
32:46
created

UserCoreModel::getUserWithAvatarOnlySql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * @title          User Core Model Class
4
 *
5
 * @author         Pierre-Henry Soria <[email protected]>
6
 * @copyright      (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved.
7
 * @license        GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
8
 * @package        PH7 / App / System / Core / Model
9
 */
10
11
namespace PH7;
12
13
use PH7\Framework\Mvc\Model\Engine\Model;
14
use PH7\Framework\Mvc\Model\Engine\Db;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, PH7\Db.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use PH7\Framework\Mvc\Model\DbConfig;
16
use PH7\Framework\Mvc\Model\Engine\Util\Various;
17
use PH7\Framework\Str\Str;
18
use PH7\Framework\Date\CDateTime;
19
use PH7\Framework\Session\Session;
20
use PH7\Framework\Security\Security;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, PH7\Security.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
21
use PH7\Framework\CArray\ObjArr;
22
use PH7\Framework\Ip\Ip;
23
use stdClass;
24
25
// Abstract Class
26
class UserCoreModel extends Model
27
{
28
    const CACHE_GROUP = 'db/sys/mod/user', CACHE_TIME = 604800;
29
30
    /** @var string */
31
    protected $sCurrentDate;
32
33
    /** @var string */
34
    protected $iProfileId;
35
36
    public function __construct()
37
    {
38
        parent::__construct();
39
40
        $this->sCurrentDate = (new CDateTime)->get()->dateTime('Y-m-d H:i:s');
41
        $this->iProfileId = (new Session)->get('member_id');
42
    }
43
44
    public static function checkGroup()
45
    {
46
        $oSession = new Session;
47
48
        if (!$oSession->exists('member_group_id')) {
49
            $oSession->regenerateId();
50
            $oSession->set('member_group_id', PermissionCore::VISITOR_GROUP_ID);
51
        }
52
53
        $rStmt = Db::getInstance()->prepare('SELECT permissions FROM' . Db::prefix('Memberships') . 'WHERE groupId = :groupId LIMIT 1');
54
        $rStmt->bindValue(':groupId', $oSession->get('member_group_id'), \PDO::PARAM_INT);
55
        $rStmt->execute();
56
        $oFetch = $rStmt->fetch(\PDO::FETCH_OBJ);
57
        Db::free($rStmt);
58
        unset($oSession);
59
60
        return ObjArr::toObject(unserialize($oFetch->permissions));
61
    }
62
63
    /**
64
     * Login method for Members and Affiliate, but not for Admins since it has another method PH7\AdminModel::adminLogin() even more secure.
65
     *
66
     * @param string $sEmail Not case sensitive since on lot of mobile devices (such as iPhone), the first letter is uppercase.
67
     * @param string $sPassword
68
     * @param string $sTable Default 'Members'
69
     *
70
     * @return mixed (boolean "true" or string "message")
71
     */
72
    public function login($sEmail, $sPassword, $sTable = 'Members')
73
    {
74
        Various::checkModelTable($sTable);
75
76
        $rStmt = Db::getInstance()->prepare('SELECT email, password FROM' . Db::prefix($sTable) . 'WHERE email = :email LIMIT 1');
77
        $rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR);
78
        $rStmt->execute();
79
        $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
80
        Db::free($rStmt);
81
82
        $sDbEmail = (!empty($oRow->email)) ? $oRow->email : '';
83
        $sDbPassword = (!empty($oRow->password)) ? $oRow->password : '';
84
85
        if (strtolower($sEmail) !== strtolower($sDbEmail)) {
86
            return 'email_does_not_exist';
87
        }
88
        if (!Security::checkPwd($sPassword, $sDbPassword)) {
89
            return 'password_does_not_exist';
90
        }
91
92
        return true;
93
    }
94
95
    /**
96
     * Set Log Session.
97
     *
98
     * @param string $sEmail
99
     * @param string $sUsername
100
     * @param string $sFirstName
101
     * @param string $sTable
102
     * @param string $sTable Default 'Members'
103
     *
104
     * @return void
105
     */
106
    public function sessionLog($sEmail, $sUsername, $sFirstName, $sTable = 'Members')
107
    {
108
        Various::checkModelTable($sTable);
109
110
        $rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix($sTable.'LogSess') . '(email, username, firstName, ip)
111
        VALUES (:email, :username, :firstName, :ip)');
112
        $rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR);
113
        $rStmt->bindValue(':username', $sUsername, \PDO::PARAM_STR);
114
        $rStmt->bindValue(':firstName', $sFirstName, \PDO::PARAM_STR);
115
        $rStmt->bindValue(':ip', Ip::get(), \PDO::PARAM_STR);
116
        $rStmt->execute();
117
        Db::free($rStmt);
118
    }
119
120
    /**
121
     * Read Profile Data.
122
     *
123
     * @param integer $iProfileId The user ID
124
     * @param string $sTable Default 'Members'
125
     *
126
     * @return stdClass The data of a member
127
     */
128
    public function readProfile($iProfileId, $sTable = 'Members')
129
    {
130
        $this->cache->start(self::CACHE_GROUP, 'readProfile' . $iProfileId . $sTable, static::CACHE_TIME);
131
132
        if (!$oData = $this->cache->get()) {
133
            Various::checkModelTable($sTable);
134
135
            $rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1');
136
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
137
            $rStmt->execute();
138
            $oData = $rStmt->fetch(\PDO::FETCH_OBJ);
139
            Db::free($rStmt);
140
            $this->cache->put($oData);
141
        }
142
143
        return $oData;
144
    }
145
146
    /**
147
     * Get the total number of members.
148
     *
149
     * @param string $sTable Default 'Members'
150
     * @param integer $iDay Default '0'
151
     * @param string $sGenger Values ​​available 'all', 'male', 'female'. 'couple' is only available to Members. Default 'all'
152
     *
153
     * @return integer Total Users
154
     */
155
    public function total($sTable = 'Members', $iDay = 0, $sGenger = 'all')
156
    {
157
        Various::checkModelTable($sTable);
158
        $iDay = (int) $iDay;
159
160
        $bIsDay = ($iDay > 0);
161
        $bIsGenger = ($sTable === 'Members' ? ($sGenger === 'male' || $sGenger === 'female' || $sGenger === 'couple') : ($sGenger === 'male' || $sGenger === 'female'));
162
163
        $sSqlDay = $bIsDay ? ' AND (joinDate + INTERVAL :day DAY) > NOW()' : '';
164
        $sSqlGender = $bIsGenger ? ' AND sex = :gender' : '';
165
166
        $rStmt = Db::getInstance()->prepare('SELECT COUNT(profileId) AS totalUsers FROM' . Db::prefix($sTable) . 'WHERE username <> \'' . PH7_GHOST_USERNAME . '\'' . $sSqlDay . $sSqlGender);
167
        if ($bIsDay) $rStmt->bindValue(':day', $iDay, \PDO::PARAM_INT);
168
        if ($bIsGenger) $rStmt->bindValue(':gender', $sGenger, \PDO::PARAM_STR);
169
        $rStmt->execute();
170
        $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
171
        Db::free($rStmt);
172
        return (int) $oRow->totalUsers;
173
    }
174
175
    /**
176
     * Update profile data.
177
     *
178
     * @param string $sSection
179
     * @param string $sValue
180
     * @param integer $iProfileId Profile ID
181
     * @param string $sTable Default 'Members'
182
     *
183
     * @return void
184
     */
185
    public function updateProfile($sSection, $sValue, $iProfileId, $sTable ='Members')
186
    {
187
        Various::checkModelTable($sTable);
188
189
        $this->orm->update($sTable, $sSection, $sValue, 'profileId', $iProfileId);
190
    }
191
192
    /**
193
     * Update Privacy setting data.
194
     *
195
     * @param string $sSection
196
     * @param string $sValue
197
     * @param integer $iProfileId Profile ID
198
     *
199
     * @return void
200
     */
201
    public function updatePrivacySetting($sSection, $sValue, $iProfileId)
202
    {
203
        $this->orm->update('MembersPrivacy', $sSection, $sValue, 'profileId', $iProfileId);
204
    }
205
206
    /**
207
     * Change password of a member.
208
     *
209
     * @param string $sEmail
210
     * @param string $sNewPassword
211
     * @param string $sTable
212
     *
213
     * @return boolean
214
     */
215
    public function changePassword($sEmail, $sNewPassword, $sTable)
216
    {
217
        Various::checkModelTable($sTable);
218
219
        $rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix($sTable) . 'SET password = :newPassword WHERE email = :email LIMIT 1');
220
        $rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR);
221
        $rStmt->bindValue(':newPassword', Security::hashPwd($sNewPassword), \PDO::PARAM_STR);
222
223
        return $rStmt->execute();
224
    }
225
226
    /**
227
     * Set a new hash validation.
228
     *
229
     * @param integer $iProfileId
230
     * @param string $sHash
231
     * @param string $sTable
232
     *
233
     * @return boolean
234
     */
235
    public function setNewHashValidation($iProfileId, $sHash, $sTable)
236
    {
237
        Various::checkModelTable($sTable);
238
239
        $rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix($sTable) . 'SET hashValidation = :hash WHERE profileId = :profileId LIMIT 1');
240
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
241
        $rStmt->bindParam(':hash', $sHash, \PDO::PARAM_STR, 40);
242
243
        return $rStmt->execute();
244
    }
245
246
    /**
247
     * Check the hash validation.
248
     *
249
     * @param string $sEmail
250
     * @param string $sHash
251
     * @param string $sTable
252
     *
253
     * @return boolean
254
     */
255
    public function checkHashValidation($sEmail, $sHash, $sTable)
256
    {
257
        Various::checkModelTable($sTable);
258
259
        $rStmt = Db::getInstance()->prepare('SELECT COUNT(profileId) FROM' . Db::prefix($sTable) . 'WHERE email = :email AND hashValidation = :hash LIMIT 1');
260
        $rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR);
261
        $rStmt->bindParam(':hash', $sHash, \PDO::PARAM_STR, 40);
262
        $rStmt->execute();
263
264
        return $rStmt->fetchColumn() == 1;
265
    }
266
267
    /**
268
     * Search users.
269
     *
270
     * @param array $aParams
271
     * @param boolean $bCount
272
     * @param integer $iOffset
273
     * @param integer $iLimit
274
     *
275
     * @return stdClass|integer Object for the users list returned or Integer for the total number users returned.
276
     */
277
    public function search(array $aParams, $bCount, $iOffset, $iLimit)
278
    {
279
        $bCount = (bool) $bCount;
280
        $iOffset = (int) $iOffset;
281
        $iLimit = (int) $iLimit;
282
283
        $bIsFirstName = !empty($aParams[SearchQueryCore::FIRST_NAME]) && Str::noSpaces($aParams[SearchQueryCore::FIRST_NAME]);
284
        $bIsMiddleName = !empty($aParams[SearchQueryCore::MIDDLE_NAME]) && Str::noSpaces($aParams[SearchQueryCore::MIDDLE_NAME]);
285
        $bIsLastName = !empty($aParams[SearchQueryCore::LAST_NAME]) && Str::noSpaces($aParams[SearchQueryCore::LAST_NAME]);
286
        $bIsSingleAge = !empty($aParams[SearchQueryCore::AGE]);
287
        $bIsAge = empty($aParams[SearchQueryCore::AGE]) && !empty($aParams[SearchQueryCore::MIN_AGE]) && !empty($aParams[SearchQueryCore::MAX_AGE]);
288
        $bIsHeight = !empty($aParams[SearchQueryCore::HEIGHT]);
289
        $bIsWeight = !empty($aParams[SearchQueryCore::WEIGHT]);
290
        $bIsCountry = !empty($aParams[SearchQueryCore::COUNTRY]) && Str::noSpaces($aParams[SearchQueryCore::COUNTRY]);
291
        $bIsCity = !empty($aParams[SearchQueryCore::CITY]) && Str::noSpaces($aParams[SearchQueryCore::CITY]);
292
        $bIsState = !empty($aParams[SearchQueryCore::STATE]) && Str::noSpaces($aParams[SearchQueryCore::STATE]);
293
        $bIsZipCode = !empty($aParams[SearchQueryCore::ZIP_CODE]) && Str::noSpaces($aParams[SearchQueryCore::ZIP_CODE]);
294
        $bIsMail = !empty($aParams[SearchQueryCore::EMAIL]) && Str::noSpaces($aParams[SearchQueryCore::EMAIL]);
295
        $bIsSex = !empty($aParams[SearchQueryCore::SEX]);
296
        $bHideUserLogged = !empty($this->iProfileId);
297
        $bIsMatchSex = !empty($aParams[SearchQueryCore::MATCH_SEX]);
298
299
        $sSqlLimit = !$bCount ? 'LIMIT :offset, :limit' : '';
300
        $sSqlSelect = !$bCount ? '*' : 'COUNT(m.profileId) AS totalUsers';
301
        $sSqlFirstName = $bIsFirstName ? ' AND firstName = :firstName' : '';
302
        $sSqlMiddleName = $bIsMiddleName ? ' AND middleName = :middleName' : '';
303
        $sSqlLastName = $bIsLastName ? ' AND lastName = :lastName' : '';
304
        $sSqlSingleAge = $bIsSingleAge ? ' AND birthDate LIKE :birthDate ' : '';
305
        $sSqlAge = $bIsAge ? ' AND birthDate BETWEEN DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL :age2 YEAR) AND DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL :age1 YEAR) ' : '';
306
        $sSqlHeight = $bIsHeight ? ' AND height = :height ' : '';
307
        $sSqlWeight = $bIsWeight ? ' AND weight = :weight ' : '';
308
        $sSqlCountry = $bIsCountry ? ' AND country = :country ' : '';
309
        $sSqlCity = $bIsCity ? ' AND city LIKE :city ' : '';
310
        $sSqlState = $bIsState ? ' AND state LIKE :state ' : '';
311
        $sSqlZipCode = $bIsZipCode ? ' AND zipCode LIKE :zipCode ' : '';
312
        $sSqlEmail = $bIsMail ? ' AND email LIKE :email ' : '';
313
        $sSqlOnline = !empty($aParams[SearchQueryCore::ONLINE]) ? ' AND userStatus = 1 AND lastActivity > DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL ' . DbConfig::getSetting('userTimeout') . ' MINUTE) ' : '';
314
        $sSqlAvatar = !empty($aParams[SearchQueryCore::AVATAR]) ? $this->getUserWithAvatarOnlySql() : '';
315
        $sSqlHideLoggedProfile = $bHideUserLogged ? ' AND (m.profileId <> :profileId)' : '';
316
317
        if (empty($aParams[SearchQueryCore::ORDER])) {
318
            $aParams[SearchQueryCore::ORDER] = SearchCoreModel::LATEST; // Default is "ORDER BY joinDate"
319
        }
320
321
        if (empty($aParams[SearchQueryCore::SORT])) {
322
            $aParams[SearchQueryCore::SORT] = SearchCoreModel::ASC; // Default is "ascending"
323
        }
324
325
        $sSqlOrder = SearchCoreModel::order($aParams[SearchQueryCore::ORDER], $aParams[SearchQueryCore::SORT]);
326
327
        $sSqlMatchSex = $bIsMatchSex ? ' AND matchSex LIKE :matchSex ' : '';
328
329
        if ($bIsSex) {
330
            $sGender = '';
331
            $aSex = $aParams[SearchQueryCore::SEX];
332
            foreach ($aSex as $sSex) {
333
                if ($sSex === 'male') {
334
                    $sGender .= '\'male\',';
335
                }
336
337
                if ($sSex === 'female') {
338
                    $sGender .= '\'female\',';
339
                }
340
341
                if ($sSex === 'couple') {
342
                    $sGender .= '\'couple\',';
343
                }
344
            }
345
346
            $sSqlSex = ' AND sex IN (' . rtrim($sGender, ',') . ') ';
347
        } else {
348
            $sSqlSex = '';
349
        }
350
351
        $rStmt = Db::getInstance()->prepare(
352
            'SELECT ' . $sSqlSelect . ' FROM' . Db::prefix('Members') . 'AS m LEFT JOIN' . Db::prefix('MembersPrivacy') . 'AS p USING(profileId)
353
            LEFT JOIN' . Db::prefix('MembersInfo') . 'AS i USING(profileId) WHERE username <> \'' . PH7_GHOST_USERNAME . '\' AND searchProfile = \'yes\'
354
            AND (groupId <> 1) AND (groupId <> 9) AND (ban = 0)' . $sSqlHideLoggedProfile . $sSqlFirstName . $sSqlMiddleName . $sSqlLastName . $sSqlMatchSex . $sSqlSex . $sSqlSingleAge . $sSqlAge . $sSqlCountry . $sSqlCity . $sSqlState .
355
            $sSqlZipCode . $sSqlHeight . $sSqlWeight . $sSqlEmail . $sSqlOnline . $sSqlAvatar . $sSqlOrder . $sSqlLimit
356
        );
357
358
        if ($bIsMatchSex) $rStmt->bindValue(':matchSex', '%' . $aParams[SearchQueryCore::MATCH_SEX] . '%', \PDO::PARAM_STR);
359
        if ($bIsFirstName) $rStmt->bindValue(':firstName', $aParams[SearchQueryCore::FIRST_NAME], \PDO::PARAM_STR);
360
        if ($bIsMiddleName) $rStmt->bindValue(':middleName', $aParams[SearchQueryCore::MIDDLE_NAME], \PDO::PARAM_STR);
361
        if ($bIsLastName) $rStmt->bindValue(':lastName', $aParams[SearchQueryCore::LAST_NAME], \PDO::PARAM_STR);
362
        if ($bIsSingleAge) $rStmt->bindValue(':birthDate', '%' . $aParams[SearchQueryCore::AGE] . '%', \PDO::PARAM_STR);
363
        if ($bIsAge) $rStmt->bindValue(':age1', $aParams[SearchQueryCore::MIN_AGE], \PDO::PARAM_INT);
364
        if ($bIsAge) $rStmt->bindValue(':age2', $aParams[SearchQueryCore::MAX_AGE], \PDO::PARAM_INT);
365
        if ($bIsHeight) $rStmt->bindValue(':height', $aParams[SearchQueryCore::HEIGHT], \PDO::PARAM_INT);
366
        if ($bIsWeight) $rStmt->bindValue(':weight', $aParams[SearchQueryCore::WEIGHT], \PDO::PARAM_INT);
367
        if ($bIsCountry) $rStmt->bindParam(':country', $aParams[SearchQueryCore::COUNTRY], \PDO::PARAM_STR, 2);
368
        if ($bIsCity) $rStmt->bindValue(':city', '%' . str_replace('-', ' ', $aParams[SearchQueryCore::CITY]) . '%', \PDO::PARAM_STR);
369
        if ($bIsState) $rStmt->bindValue(':state', '%' . str_replace('-', ' ', $aParams[SearchQueryCore::STATE]) . '%', \PDO::PARAM_STR);
370
        if ($bIsZipCode) $rStmt->bindValue(':zipCode', '%' . $aParams[SearchQueryCore::ZIP_CODE] . '%', \PDO::PARAM_STR);
371
        if ($bIsMail) $rStmt->bindValue(':email', '%' . $aParams[SearchQueryCore::EMAIL] . '%', \PDO::PARAM_STR);
372
        if ($bHideUserLogged) $rStmt->bindValue(':profileId', $this->iProfileId, \PDO::PARAM_INT);
373
374
        if (!$bCount) {
375
            $rStmt->bindParam(':offset', $iOffset, \PDO::PARAM_INT);
376
            $rStmt->bindParam(':limit', $iLimit, \PDO::PARAM_INT);
377
        }
378
379
        $rStmt->execute();
380
381
        if (!$bCount) {
382
            $oRow = $rStmt->fetchAll(\PDO::FETCH_OBJ);
383
            Db::free($rStmt);
384
            return $oRow;
385
        } else {
386
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
387
            Db::free($rStmt);
388
            return (int) $oRow->totalUsers;
389
        }
390
    }
391
392
    /**
393
     * Check online status.
394
     *
395
     * @param integer $iProfileId
396
     * @param integer $iTime Number of minutes that a member becomes inactive (offline). Default 1 minute
397
     *
398
     * @return boolean
399
     */
400
    public function isOnline($iProfileId, $iTime = 1)
401
    {
402
        $iProfileId = (int) $iProfileId;
403
        $iTime = (int) $iTime;
404
405
        $rStmt = Db::getInstance()->prepare('SELECT profileId FROM' . Db::prefix('Members') . 'WHERE profileId = :profileId
406
            AND userStatus = 1 AND lastActivity >= DATE_SUB(:currentTime, INTERVAL :time MINUTE) LIMIT 1');
407
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
408
        $rStmt->bindValue(':time', $iTime, \PDO::PARAM_INT);
409
        $rStmt->bindValue(':currentTime', $this->sCurrentDate, \PDO::PARAM_STR);
410
        $rStmt->execute();
411
        return $rStmt->rowCount() === 1;
412
    }
413
414
    /**
415
     * Set the user status.
416
     *
417
     * @param integer iProfileId
418
     * @param integer $iStatus Values: 0 = Offline, 1 = Online, 2 = Busy, 3 = Away
419
     *
420
     * @return void
421
     */
422
    public function setUserStatus($iProfileId, $iStatus)
423
    {
424
        $this->orm->update('Members', 'userStatus', $iStatus, 'profileId', $iProfileId);
425
    }
426
427
    /**
428
     * Get the user status.
429
     *
430
     * @param integer $iProfileId
431
     *
432
     * @return integer The user status. 0 = Offline, 1 = Online, 2 = Busy, 3 = Away
433
     */
434
    public function getUserStatus($iProfileId)
435
    {
436
        $this->cache->start(self::CACHE_GROUP, 'userStatus' . $iProfileId, static::CACHE_TIME);
437
438
        if (!$iData = $this->cache->get())
439
        {
440
            $rStmt = Db::getInstance()->prepare('SELECT userStatus FROM' . Db::prefix('Members') . 'WHERE profileId = :profileId LIMIT 1');
441
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
442
            $rStmt->execute();
443
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
444
            Db::free($rStmt);
445
            $iData = (int) $oRow->userStatus;
446
            unset($oRow);
447
            $this->cache->put($iData);
448
        }
449
450
        return $iData;
451
    }
452
453
    /**
454
     * Update the notifications.
455
     *
456
     * @param string $sSection
457
     * @param string $sValue
458
     * @param integer $iProfileId Profile ID
459
     *
460
     * @return void
461
     */
462
    public function setNotification($sSection, $sValue, $iProfileId)
463
    {
464
        $this->orm->update('MembersNotifications', $sSection, $sValue, 'profileId', $iProfileId);
465
    }
466
467
    /**
468
     * Get the user notifications.
469
     *
470
     * @param integer $iProfileId
471
     *
472
     * @return stdClass
473
     */
474
    public function getNotification($iProfileId)
475
    {
476
        $this->cache->start(self::CACHE_GROUP, 'notification' . $iProfileId, static::CACHE_TIME);
477
478
        if (!$oData = $this->cache->get())
479
        {
480
            $rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix('MembersNotifications') . 'WHERE profileId = :profileId LIMIT 1');
481
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
482
            $rStmt->execute();
483
            $oData = $rStmt->fetch(\PDO::FETCH_OBJ);
484
            Db::free($rStmt);
485
            $this->cache->put($oData);
486
        }
487
488
        return $oData;
489
    }
490
491
    /**
492
     * Check notifications.
493
     *
494
     * @param integer $iProfileId
495
     * @param string $sNotiName Notification name.
496
     *
497
     * @return boolean
498
     */
499
    public function isNotification($iProfileId, $sNotiName)
500
    {
501
        $this->cache->start(self::CACHE_GROUP, 'isNotification' . $iProfileId, static::CACHE_TIME);
502
503
        if (!$bData = $this->cache->get()) {
504
            $rStmt = Db::getInstance()->prepare('SELECT ' . $sNotiName . ' FROM' . Db::prefix('MembersNotifications') . 'WHERE profileId = :profileId AND ' . $sNotiName . ' = 1 LIMIT 1');
505
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
506
            $rStmt->execute();
507
            $bData = ($rStmt->rowCount() === 1);
508
            Db::free($rStmt);
509
            $this->cache->put($bData);
0 ignored issues
show
Documentation introduced by
$bData is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
510
        }
511
512
        return $bData;
513
    }
514
515
    /**
516
     * Set the last activity of a user.
517
     *
518
     * @param integer $iProfileId
519
     * @param string $sTable Default 'Members'
520
     *
521
     * @return void
522
     */
523
    public function setLastActivity($iProfileId, $sTable = 'Members')
524
    {
525
        Various::checkModelTable($sTable);
526
527
        $this->orm->update($sTable, 'lastActivity', $this->sCurrentDate, 'profileId', $iProfileId);
528
    }
529
530
    /**
531
     * Set the last edit account of a user.
532
     *
533
     * @param integer $iProfileId
534
     * @param string $sTable Default 'Members'
535
     *
536
     * @return void
537
     */
538
    public function setLastEdit($iProfileId, $sTable = 'Members')
539
    {
540
        Various::checkModelTable($sTable);
541
542
        $this->orm->update($sTable, 'lastEdit', $this->sCurrentDate, 'profileId', $iProfileId);
543
    }
544
545
    /**
546
     * Approve a profile.
547
     *
548
     * @param integer $iProfileId
549
     * @param integer $iStatus 1 = apprved | 0 = not approved
550
     * @param string $sTable Default 'Members'
551
     *
552
     * @return void
553
     */
554
    public function approve($iProfileId, $iStatus, $sTable = 'Members')
555
    {
556
        Various::checkModelTable($sTable);
557
558
        $this->orm->update($sTable, 'active', $iStatus, 'profileId', $iProfileId);
559
    }
560
561
    /**
562
     * Get member data. The hash of course but also some useful data for sending the activation email. (hash, email, username, firstName).
563
     *
564
     * @param string $sEmail User's email address.
565
     * @param string $sTable Default 'Members'
566
     *
567
     * @return stdClass|boolean Returns the data member (email, username, firstName, hashValidation) on success, otherwise returns false if there is an error.
568
     */
569
    public function getHashValidation($sEmail, $sTable = 'Members')
570
    {
571
        Various::checkModelTable($sTable);
572
573
        $rStmt = Db::getInstance()->prepare('SELECT email, username, firstName, hashValidation FROM' . Db::prefix($sTable) . 'WHERE email = :email AND active = 2');
574
        $rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR);
575
        $rStmt->execute();
576
        $oRow =  $rStmt->fetch(\PDO::FETCH_OBJ);
577
        Db::free($rStmt);
578
579
        return $oRow;
580
    }
581
582
    /**
583
     * Valid on behalf of a user with the hash.
584
     *
585
     * @param string $sEmail
586
     * @param string $sHash
587
     * @param string $sTable Default 'Members'
588
     *
589
     * @return boolean
590
     */
591
    public function validateAccount($sEmail, $sHash, $sTable = 'Members')
592
    {
593
        Various::checkModelTable($sTable);
594
595
        $rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix($sTable) . 'SET active = 1 WHERE email = :email AND hashValidation = :hash AND active = 2');
596
        $rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR);
597
        $rStmt->bindParam(':hash', $sHash, \PDO::PARAM_STR, 40);
598
        return $rStmt->execute();
599
    }
600
601
    /**
602
     * Adding a User.
603
     *
604
     * @param array $aData
605
     *
606
     * @return integer The ID of the User.
607
     */
608
    public function add(array $aData)
609
    {
610
        $sHashValidation = (!empty($aData['hash_validation']) ? $aData['hash_validation'] : null);
611
612
        $rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('Members') . '(email, username, password, firstName, lastName, sex, matchSex, birthDate, active, ip, hashValidation, joinDate, lastActivity)
613
            VALUES (:email, :username, :password, :firstName, :lastName, :sex, :matchSex, :birthDate, :active, :ip, :hashValidation, :joinDate, :lastActivity)');
614
        $rStmt->bindValue(':email',   trim($aData['email']), \PDO::PARAM_STR);
615
        $rStmt->bindValue(':username', trim($aData['username']), \PDO::PARAM_STR);
616
        $rStmt->bindValue(':password', Security::hashPwd($aData['password']), \PDO::PARAM_STR);
617
        $rStmt->bindValue(':firstName', $aData['first_name'], \PDO::PARAM_STR);
618
        $rStmt->bindValue(':lastName', $aData['last_name'], \PDO::PARAM_STR);
619
        $rStmt->bindValue(':sex', $aData['sex'], \PDO::PARAM_STR);
620
        $rStmt->bindValue(':matchSex', Form::setVal($aData['match_sex']), \PDO::PARAM_STR);
621
        $rStmt->bindValue(':birthDate', $aData['birth_date'], \PDO::PARAM_STR);
622
        $rStmt->bindValue(':active', (!empty($aData['is_active']) ? $aData['is_active'] : 1), \PDO::PARAM_INT);
623
        $rStmt->bindValue(':ip', $aData['ip'], \PDO::PARAM_STR);
624
        $rStmt->bindParam(':hashValidation', $sHashValidation, \PDO::PARAM_STR, 40);
625
        $rStmt->bindValue(':joinDate', $this->sCurrentDate, \PDO::PARAM_STR);
626
        $rStmt->bindValue(':lastActivity', $this->sCurrentDate, \PDO::PARAM_STR);
627
        $rStmt->execute();
628
        $this->setKeyId( Db::getInstance()->lastInsertId() ); // Set the user's ID
629
        Db::free($rStmt);
630
        $this->setInfoFields($aData);
631
        $this->setDefaultPrivacySetting();
632
        $this->setDefaultNotification();
633
634
        // Last one, update the membership with the correct details
635
        $this->updateMembership(
636
            (int)DbConfig::getSetting('defaultMembershipGroupId'),
637
            $this->getKeyId(),
638
            $this->sCurrentDate
639
        );
640
641
        return $this->getKeyId();
642
    }
643
644
    /**
645
     * @param array $aData
646
     *
647
     * @return boolean
648
     */
649
    public function setInfoFields(array $aData)
650
    {
651
        $rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersInfo') . '(profileId, middleName, country, city, state, zipCode, description, website, socialNetworkSite)
652
            VALUES (:profileId, :middleName, :country, :city, :state, :zipCode, :description, :website, :socialNetworkSite)');
653
        $rStmt->bindValue(':profileId', $this->getKeyId(), \PDO::PARAM_INT);
654
        $rStmt->bindValue(':middleName', (!empty($aData['middle_name']) ? $aData['middle_name'] : ''), \PDO::PARAM_STR);
655
        $rStmt->bindValue(':country', (!empty($aData['country']) ? $aData['country'] : ''), \PDO::PARAM_STR);
656
        $rStmt->bindValue(':city', (!empty($aData['city']) ? $aData['city'] : ''), \PDO::PARAM_STR);
657
        $rStmt->bindValue(':state', (!empty($aData['state']) ? $aData['state'] : ''), \PDO::PARAM_STR);
658
        $rStmt->bindValue(':zipCode', (!empty($aData['zip_code']) ? $aData['zip_code'] : ''), \PDO::PARAM_STR);
659
        $rStmt->bindValue(':description', (!empty($aData['description']) ? $aData['description'] : ''), \PDO::PARAM_STR);
660
        $rStmt->bindValue(':website', (!empty($aData['website']) ? trim($aData['website']) : ''), \PDO::PARAM_STR);
661
        $rStmt->bindValue(':socialNetworkSite', (!empty($aData['social_network_site']) ? trim($aData['social_network_site']) : ''), \PDO::PARAM_STR);
662
663
        return $rStmt->execute();
664
    }
665
666
    /**
667
     * Set the default privacy settings.
668
     *
669
     * @return boolean Returns TRUE on success or FALSE on failure.
670
     */
671
    public function setDefaultPrivacySetting()
672
    {
673
        $rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersPrivacy') .
674
            '(profileId, privacyProfile, searchProfile, userSaveViews)
675
            VALUES (:profileId, \'all\', \'yes\', \'yes\')');
676
        $rStmt->bindValue(':profileId', $this->getKeyId(), \PDO::PARAM_INT);
677
        return $rStmt->execute();
678
    }
679
680
    /**
681
     * Set the default notifications.
682
     *
683
     * @return boolean Returns TRUE on success or FALSE on failure.
684
     */
685
    public function setDefaultNotification()
686
    {
687
        $rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersNotifications') .
688
            '(profileId, enableNewsletters, newMsg, friendRequest)
689
            VALUES (:profileId, 0, 1, 1)');
690
        $rStmt->bindValue(':profileId', $this->getKeyId(), \PDO::PARAM_INT);
691
        return $rStmt->execute();
692
    }
693
694
    /**
695
     * To avoid flooding!
696
     * Waiting time before a new registration with the same IP address.
697
     *
698
     * @param string $sIp
699
     * @param integer $iWaitTime In minutes!
700
     * @param string $sCurrentTime In date format: 0000-00-00 00:00:00
701
     * @param string $sTable Default 'Members'
702
     *
703
     * @return boolean Return TRUE if the weather was fine, FALSE otherwise.
704
     */
705
    public function checkWaitJoin($sIp, $iWaitTime, $sCurrentTime, $sTable = 'Members')
706
    {
707
        Various::checkModelTable($sTable);
708
709
        $rStmt = Db::getInstance()->prepare('SELECT profileId FROM' . Db::prefix($sTable) .
710
            'WHERE ip = :ip AND DATE_ADD(joinDate, INTERVAL :waitTime MINUTE) > :currentTime LIMIT 1');
711
        $rStmt->bindValue(':ip', $sIp, \PDO::PARAM_STR);
712
        $rStmt->bindValue(':waitTime', $iWaitTime, \PDO::PARAM_INT);
713
        $rStmt->bindValue(':currentTime', $sCurrentTime, \PDO::PARAM_STR);
714
        $rStmt->execute();
715
716
        return $rStmt->rowCount() === 0;
717
    }
718
719
720
    /********** AVATAR **********/
721
722
    /**
723
     * Update or add a new avatar.
724
     *
725
     * @param integer $iProfileId
726
     * @param string $sAvatar
727
     * @param integer $iApproved
728
     *
729
     * @return boolean
730
     */
731
    public function setAvatar($iProfileId, $sAvatar, $iApproved)
732
    {
733
        $rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix('Members') . 'SET avatar = :avatar, approvedAvatar = :approved WHERE profileId = :profileId');
734
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
735
        $rStmt->bindValue(':avatar', $sAvatar, \PDO::PARAM_STR);
736
        $rStmt->bindValue(':approved', $iApproved, \PDO::PARAM_INT);
737
738
        return $rStmt->execute();
739
    }
740
741
    /**
742
     * Get avatar.
743
     *
744
     * @param integer $iProfileId
745
     * @param integer $iApproved (1 = approved | 0 = pending | NULL = approved and pending)
746
     *
747
     * @return stdClass The Avatar (SQL alias is pic), profileId and approvedAvatar
748
     */
749
    public function getAvatar($iProfileId, $iApproved = null)
750
    {
751
        $this->cache->start(self::CACHE_GROUP, 'avatar' . $iProfileId, static::CACHE_TIME);
752
753
        if (!$oData = $this->cache->get()) {
754
            $sSqlApproved = (isset($iApproved)) ? ' AND approvedAvatar = :approved ' : ' ';
755
            $rStmt = Db::getInstance()->prepare('SELECT profileId, avatar AS pic, approvedAvatar FROM' . Db::prefix('Members') . 'WHERE profileId = :profileId' . $sSqlApproved . 'LIMIT 1');
756
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
757
            if (isset($iApproved)) $rStmt->bindValue(':approved', $iApproved, \PDO::PARAM_INT);
758
            $rStmt->execute();
759
            $oData = $rStmt->fetch(\PDO::FETCH_OBJ);
760
            Db::free($rStmt);
761
            $this->cache->put($oData);
762
        }
763
764
        return $oData;
765
    }
766
767
    /**
768
     * Delete an avatar in the database.
769
     *
770
     * @param integer $iProfileId
771
     *
772
     * @return boolean
773
     */
774
    public function deleteAvatar($iProfileId)
775
    {
776
        return $this->setAvatar($iProfileId, null, 1);
777
    }
778
779
780
    /********** BACKGROUND **********/
781
782
    /**
783
     * Get file of a user background.
784
     *
785
     * @param integer $iProfileId
786
     * @param integer $iApproved (1 = approved | 0 = pending | NULL = approved and pending) Default NULL
787
     *
788
     * @return string
789
     */
790
    public function getBackground($iProfileId, $iApproved = null)
791
    {
792
        $this->cache->start(self::CACHE_GROUP, 'background' . $iProfileId, static::CACHE_TIME);
793
794
        if (!$sData = $this->cache->get()) {
795
            $sSqlApproved = (isset($iApproved)) ? ' AND approved = :approved ' : ' ';
796
            $rStmt = Db::getInstance()->prepare('SELECT file FROM' . Db::prefix('MembersBackground') . 'WHERE profileId = :profileId' . $sSqlApproved . 'LIMIT 1');
797
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
798
            if (isset($iApproved)) $rStmt->bindValue(':approved', $iApproved, \PDO::PARAM_INT);
799
            $rStmt->execute();
800
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
801
            Db::free($rStmt);
802
            $sData = @$oRow->file;
803
            unset($oRow);
804
            $this->cache->put($sData);
805
        }
806
807
        return $sData;
808
    }
809
810
    /**
811
     * Add profile background.
812
     *
813
     * @param integer $iProfileId
814
     * @param string $sFile
815
     * @param integer $iApproved
816
     *
817
     * @return boolean
818
     */
819
    public function addBackground($iProfileId, $sFile, $iApproved = 1)
820
    {
821
        $rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersBackground') . '(profileId, file, approved) VALUES (:profileId, :file, :approved)');
822
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
823
        $rStmt->bindValue(':file', $sFile, \PDO::PARAM_STR);
824
        $rStmt->bindValue(':approved', $iApproved, \PDO::PARAM_INT);
825
826
        return $rStmt->execute();
827
    }
828
829
    /**
830
     * Delete profile background.
831
     *
832
     * @param integer $iProfileId
833
     *
834
     * @return boolean
835
     */
836
    public function deleteBackground($iProfileId)
837
    {
838
        $rStmt = Db::getInstance()->prepare('DELETE FROM' . Db::prefix('MembersBackground') . 'WHERE profileId = :profileId');
839
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
840
        return $rStmt->execute();
841
    }
842
843
    /**
844
     * Delete User.
845
     *
846
     * @param integer $iProfileId
847
     * @param string $sUsername
848
     *
849
     * @return void
850
     */
851
    public function delete($iProfileId, $sUsername)
852
    {
853
        $sUsername = (string) $sUsername;
854
        $iProfileId = (int) $iProfileId;
855
856
        if ($sUsername === PH7_GHOST_USERNAME) {
857
            exit('You cannot delete this profile!');
0 ignored issues
show
Coding Style Compatibility introduced by
The method delete() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
858
        }
859
860
        $oDb = Db::getInstance();
861
862
        // DELETE MESSAGES
863
        $oDb->exec('DELETE FROM' . Db::prefix('Messages') . 'WHERE sender = ' . $iProfileId);
864
        $oDb->exec('DELETE FROM' . Db::prefix('Messages') . 'WHERE recipient = ' . $iProfileId);
865
866
        // DELETE MESSAGES OF MESSENGER
867
        $oDb->exec('DELETE FROM' . Db::prefix('Messenger') . 'WHERE fromUser = ' . Db::getInstance()->quote($sUsername));
868
        $oDb->exec('DELETE FROM' . Db::prefix('Messenger') . 'WHERE toUser = ' . Db::getInstance()->quote($sUsername));
869
870
        // DELETE PROFILE COMMENTS
871
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsProfile') . 'WHERE sender = ' . $iProfileId);
872
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsProfile') . 'WHERE recipient = ' . $iProfileId);
873
874
        // DELETE PICTURE COMMENTS
875
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsPicture') . 'WHERE sender = ' . $iProfileId);
876
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsPicture') . 'WHERE recipient = ' . $iProfileId);
877
878
        // DELETE VIDEO COMMENTS
879
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsVideo') . 'WHERE sender = ' . $iProfileId);
880
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsVideo') . 'WHERE recipient = ' . $iProfileId);
881
882
        // DELETE NOTE COMMENTS
883
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsNote') . 'WHERE sender = ' . $iProfileId);
884
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsNote') . 'WHERE recipient = ' . $iProfileId);
885
886
        // DELETE BLOG COMMENTS
887
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsBlog') . 'WHERE sender = ' . $iProfileId);
888
889
        // DELETE GAME COMMENTS
890
        $oDb->exec('DELETE FROM' . Db::prefix('CommentsGame') . 'WHERE sender = ' . $iProfileId);
891
892
        // DELETE PICTURES ALBUMS AND PICTURES
893
        $oDb->exec('DELETE FROM' . Db::prefix('Pictures') . 'WHERE profileId = ' . $iProfileId);
894
        $oDb->exec('DELETE FROM' . Db::prefix('AlbumsPictures') . 'WHERE profileId = ' . $iProfileId);
895
896
        // DELETE VIDEOS ALBUMS AND VIDEOS
897
        $oDb->exec('DELETE FROM' . Db::prefix('Videos') . 'WHERE profileId = ' . $iProfileId);
898
        $oDb->exec('DELETE FROM' . Db::prefix('AlbumsVideos') . 'WHERE profileId = ' . $iProfileId);
899
900
        // DELETE FRIENDS
901
        $oDb->exec('DELETE FROM' . Db::prefix('MembersFriends') . 'WHERE profileId = ' . $iProfileId);
902
        $oDb->exec('DELETE FROM' . Db::prefix('MembersFriends') . 'WHERE friendId = ' . $iProfileId);
903
904
        // DELETE WALL
905
        $oDb->exec('DELETE FROM' . Db::prefix('MembersWall') . 'WHERE profileId = ' . $iProfileId);
906
907
        // DELETE BACKGROUND
908
        $oDb->exec('DELETE FROM' . Db::prefix('MembersBackground') . 'WHERE profileId = ' . $iProfileId);
909
910
        // DELETE NOTES
911
        $oDb->exec('DELETE FROM' . Db::prefix('NotesCategories') . 'WHERE profileId = ' . $iProfileId);
912
        $oDb->exec('DELETE FROM' . Db::prefix('Notes') . 'WHERE profileId = ' . $iProfileId);
913
914
        // DELETE LIKE
915
        $oDb->exec('DELETE FROM' . Db::prefix('Likes') . 'WHERE keyId LIKE ' . Db::getInstance()->quote('%' . $sUsername . '.html'));
916
917
        // DELETE PROFILE VISITS
918
        $oDb->exec('DELETE FROM' . Db::prefix('MembersWhoViews') . 'WHERE profileId = ' . $iProfileId);
919
        $oDb->exec('DELETE FROM' . Db::prefix('MembersWhoViews') . 'WHERE visitorId = ' . $iProfileId);
920
921
        // DELETE REPORT
922
        $oDb->exec('DELETE FROM' . Db::prefix('Report') . 'WHERE spammerId = ' . $iProfileId);
923
924
        // DELETE TOPICS of FORUMS
925
        /*
926
        No! Ghost Profile is ultimately the best solution!
927
        WARNING: Do not change this part of code without asking permission from Pierre-Henry Soria
928
        */
929
        //$oDb->exec('DELETE FROM' . Db::prefix('ForumsMessages') . 'WHERE profileId = ' . $iProfileId);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
930
        //$oDb->exec('DELETE FROM' . Db::prefix('ForumsTopics') . 'WHERE profileId = ' . $iProfileId);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
931
932
        // DELETE NOTIFICATIONS
933
        $oDb->exec('DELETE FROM' . Db::prefix('MembersNotifications') . 'WHERE profileId = ' . $iProfileId . ' LIMIT 1');
934
935
        // DELETE PRIVACY SETTINGS
936
        $oDb->exec('DELETE FROM' . Db::prefix('MembersPrivacy') . 'WHERE profileId = ' . $iProfileId . ' LIMIT 1');
937
938
        // DELETE INFO FIELDS
939
        $oDb->exec('DELETE FROM' . Db::prefix('MembersInfo') . 'WHERE profileId = ' . $iProfileId . ' LIMIT 1');
940
941
        // DELETE USER
942
        $oDb->exec('DELETE FROM' . Db::prefix('Members') . 'WHERE profileId = ' . $iProfileId . ' LIMIT 1');
943
944
        unset($oDb); // Destruction of the object
945
    }
946
947
    /**
948
     * @param string $sUsernameSearch
949
     * @param string $sTable Default 'Members'
950
     *
951
     * @return stdClass data of users (profileId, username, sex)
952
     */
953
    public function getUsernameList($sUsernameSearch, $sTable = 'Members')
954
    {
955
        Various::checkModelTable($sTable);
956
957
        $rStmt = Db::getInstance()->prepare('SELECT profileId, username, sex FROM' . Db::prefix($sTable) . 'WHERE username <> \'' . PH7_GHOST_USERNAME . '\' AND username LIKE :username');
958
        $rStmt->bindValue(':username', '%'.$sUsernameSearch.'%', \PDO::PARAM_STR);
959
        $rStmt->execute();
960
        $oRow = $rStmt->fetchAll(\PDO::FETCH_OBJ);
961
        Db::free($rStmt);
962
        return $oRow;
963
    }
964
965
    /**
966
     * Get profiles data.
967
     *
968
     * @param string $sOrder
969
     * @param integer $iOffset
970
     * @param integer $iLimit
971
     *
972
     * @return stdClass Data of users
973
     */
974
    public function getProfiles($sOrder = SearchCoreModel::LAST_ACTIVITY, $iOffset = null, $iLimit = null)
975
    {
976
        $bIsLimit = $iOffset !== null && $iLimit !== null;
977
        $bHideUserLogged = !empty($this->iProfileId);
978
        $bOnlyAvatarsSet = (bool) DbConfig::getSetting('profileWithAvatarSet');
979
980
        $iOffset = (int) $iOffset;
981
        $iLimit = (int) $iLimit;
982
983
        $sOrder = SearchCoreModel::order($sOrder, SearchCoreModel::DESC);
984
985
        $sSqlLimit = $bIsLimit ? 'LIMIT :offset, :limit' : '';
986
        $sSqlHideLoggedProfile = $bHideUserLogged ? ' AND (m.profileId <> :profileId)' : '';
987
        $sSqlShowOnlyWithAvatars = $bOnlyAvatarsSet ? $this->getUserWithAvatarOnlySql() : '';
988
989
        $rStmt = Db::getInstance()->prepare(
990
            'SELECT * FROM' . Db::prefix('Members') . 'AS m LEFT JOIN' . Db::prefix('MembersPrivacy') . 'AS p USING(profileId)
991
            LEFT JOIN' . Db::prefix('MembersInfo') . 'AS i USING(profileId) WHERE (username <> \'' . PH7_GHOST_USERNAME . '\') AND (searchProfile = \'yes\')
992
            AND (username IS NOT NULL) AND (firstName IS NOT NULL) AND (sex IS NOT NULL) AND (matchSex IS NOT NULL) AND (country IS NOT NULL)
993
            AND (city IS NOT NULL) AND (groupId <> 1) AND (groupId <> 9) AND (ban = 0)' .
994
            $sSqlHideLoggedProfile . $sSqlShowOnlyWithAvatars . $sOrder . $sSqlLimit
995
        );
996
997
        if ($bHideUserLogged) {
998
            $rStmt->bindValue(':profileId', $this->iProfileId, \PDO::PARAM_INT);
999
        }
1000
1001
        if ($bIsLimit) {
1002
            $rStmt->bindParam(':offset', $iOffset, \PDO::PARAM_INT);
1003
            $rStmt->bindParam(':limit', $iLimit, \PDO::PARAM_INT);
1004
        }
1005
1006
        $rStmt->execute();
1007
        $oRow = $rStmt->fetchAll(\PDO::FETCH_OBJ);
1008
        Db::free($rStmt);
1009
1010
        return $oRow;
1011
    }
1012
1013
    /**
1014
     * Get the users from the location data.
1015
     *
1016
     * @param string $sCountry
1017
     * @param string $sCity
1018
     * @param boolean $bCount
1019
     * @param string $sOrder
1020
     * @param integer $iOffset
1021
     * @param integer $iLimit
1022
     *
1023
     * @return stdClass|integer Object with the users list returned or integer for the total number users returned.
1024
     */
1025
    public function getGeoProfiles($sCountry, $sCity, $bCount, $sOrder, $iOffset, $iLimit)
1026
    {
1027
        $bCount = (bool) $bCount;
1028
        $iOffset = (int) $iOffset;
1029
        $iLimit = (int) $iLimit;
1030
1031
        $sOrder = !$bCount ? SearchCoreModel::order($sOrder, SearchCoreModel::DESC) : '';
1032
1033
        $sSqlLimit = !$bCount ? 'LIMIT :offset, :limit' : '';
1034
        $sSqlSelect = !$bCount ? '*' : 'COUNT(m.profileId) AS totalUsers';
1035
1036
        $sSqlCity = !empty($sCity) ?  'AND (city LIKE :city)' : '';
1037
1038
        $rStmt = Db::getInstance()->prepare(
1039
            'SELECT ' . $sSqlSelect . ' FROM' . Db::prefix('Members') . 'AS m LEFT JOIN' . Db::prefix('MembersInfo') . 'AS i USING(profileId)
1040
            WHERE (username <> \'' . PH7_GHOST_USERNAME . '\') AND (country = :country) ' . $sSqlCity . ' AND (username IS NOT NULL)
1041
            AND (firstName IS NOT NULL) AND (sex IS NOT NULL) AND (matchSex IS NOT NULL) AND (country IS NOT NULL)
1042
            AND (city IS NOT NULL) AND (groupId <> 1) AND (groupId <> 9) AND (ban = 0)' . $sOrder . $sSqlLimit
1043
        );
1044
        $rStmt->bindParam(':country', $sCountry, \PDO::PARAM_STR, 2);
1045
1046
        if (!empty($sCity)) {
1047
            $rStmt->bindValue(':city', '%' . $sCity . '%', \PDO::PARAM_STR);
1048
        }
1049
1050
        if (!$bCount) {
1051
            $rStmt->bindParam(':offset', $iOffset, \PDO::PARAM_INT);
1052
            $rStmt->bindParam(':limit', $iLimit, \PDO::PARAM_INT);
1053
        }
1054
1055
        $rStmt->execute();
1056
1057
        if (!$bCount) {
1058
            $oRow = $rStmt->fetchAll(\PDO::FETCH_OBJ);
1059
            Db::free($rStmt);
1060
            return $oRow;
1061
        } else {
1062
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1063
            Db::free($rStmt);
1064
            return (int) $oRow->totalUsers;
1065
        }
1066
1067
    }
1068
1069
    /**
1070
     * Updating the privacy settings.
1071
     *
1072
     * @param integer $iProfileId
1073
     *
1074
     * @return stdClass
1075
     */
1076
    public function getPrivacySetting($iProfileId)
1077
    {
1078
        $this->cache->start(self::CACHE_GROUP, 'privacySetting' . $iProfileId, static::CACHE_TIME);
1079
1080
        if (!$oData = $this->cache->get())
1081
        {
1082
            $iProfileId = (int) $iProfileId;
1083
1084
            $rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix('MembersPrivacy') . 'WHERE profileId = :profileId LIMIT 1');
1085
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1086
            $rStmt->execute();
1087
            $oData = $rStmt->fetch(\PDO::FETCH_OBJ);
1088
            Db::free($rStmt);
1089
            $this->cache->put($oData);
1090
        }
1091
1092
        return $oData;
1093
    }
1094
1095
    /**
1096
     * Get the Profile ID of a user.
1097
     *
1098
     * @param string $sEmail Default NULL
1099
     * @param string $sUsername Default NULL
1100
     * @param string $sTable Default 'Members'
1101
     *
1102
     * @return integer|boolean The Member ID if it is found or FALSE if not found.
1103
     */
1104
    public function getId($sEmail = null, $sUsername = null, $sTable = 'Members')
1105
    {
1106
        $this->cache->start(self::CACHE_GROUP, 'id' . $sEmail . $sUsername . $sTable, static::CACHE_TIME);
1107
1108
        if (!$iData = $this->cache->get()) {
1109
            Various::checkModelTable($sTable);
1110
1111
            if (!empty($sEmail)) {
1112
                $rStmt = Db::getInstance()->prepare('SELECT profileId FROM' . Db::prefix($sTable) . 'WHERE email = :email LIMIT 1');
1113
                $rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR);
1114
            } else {
1115
                $rStmt = Db::getInstance()->prepare('SELECT profileId FROM' . Db::prefix($sTable) . 'WHERE username = :username LIMIT 1');
1116
                $rStmt->bindValue(':username', $sUsername, \PDO::PARAM_STR);
1117
            }
1118
            $rStmt->execute();
1119
1120
            if ($rStmt->rowCount() === 0) {
1121
                return false;
1122
            } else {
1123
               $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1124
               Db::free($rStmt);
1125
               $iData = (int) $oRow->profileId;
1126
               unset($oRow);
1127
               $this->cache->put($iData);
1128
            }
1129
        }
1130
1131
        return $iData;
1132
    }
1133
1134
    /**
1135
     * @param integer $iProfileId
1136
     * @param string $sTable Default 'Members'
1137
     *
1138
     * @return string The email address of a member
1139
     */
1140
    public function getEmail($iProfileId, $sTable = 'Members')
1141
    {
1142
        $this->cache->start(self::CACHE_GROUP, 'email' . $iProfileId . $sTable, static::CACHE_TIME);
1143
1144
        if (!$sData = $this->cache->get()) {
1145
            Various::checkModelTable($sTable);
1146
1147
            $rStmt = Db::getInstance()->prepare('SELECT email FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1');
1148
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1149
            $rStmt->execute();
1150
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1151
            Db::free($rStmt);
1152
            $sData = @$oRow->email;
1153
            unset($oRow);
1154
            $this->cache->put($sData);
1155
        }
1156
1157
        return $sData;
1158
    }
1159
1160
    /**
1161
     * Retrieves the username from the user ID.
1162
     *
1163
     * @param integer $iProfileId
1164
     * @param string $sTable Default 'Members'
1165
     *
1166
     * @return string The Username of member
1167
     */
1168
    public function getUsername($iProfileId, $sTable = 'Members')
1169
    {
1170
        if ($iProfileId === PH7_ADMIN_ID) {
1171
            return t('Administration of %site_name%');
1172
        }
1173
1174
        $this->cache->start(self::CACHE_GROUP, 'username' . $iProfileId . $sTable, static::CACHE_TIME);
1175
1176
        if (!$sData = $this->cache->get()) {
1177
            Various::checkModelTable($sTable);
1178
1179
            $rStmt = Db::getInstance()->prepare('SELECT username FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1');
1180
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1181
            $rStmt->execute();
1182
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1183
            Db::free($rStmt);
1184
            $sData = @$oRow->username;
1185
            unset($oRow);
1186
            $this->cache->put($sData);
1187
        }
1188
1189
        return $sData;
1190
    }
1191
1192
    /**
1193
     * Retrieves the first name from the user ID.
1194
     *
1195
     * @param integer $iProfileId
1196
     * @param string $sTable Default 'Members'
1197
     *
1198
     * @return string The first name of member
1199
     */
1200
    public function getFirstName($iProfileId, $sTable = 'Members')
1201
    {
1202
        $this->cache->start(self::CACHE_GROUP, 'firstName' . $iProfileId . $sTable, static::CACHE_TIME);
1203
1204
        if (!$sData = $this->cache->get()) {
1205
            Various::checkModelTable($sTable);
1206
1207
            $rStmt = Db::getInstance()->prepare('SELECT firstName FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1');
1208
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1209
            $rStmt->execute();
1210
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1211
            Db::free($rStmt);
1212
            $sData = @$oRow->firstName;
1213
            unset($oRow);
1214
            $this->cache->put($sData);
1215
        }
1216
1217
        return $sData;
1218
   }
1219
1220
    /**
1221
     * Get Gender (sex) of a user.
1222
     *
1223
     * @param integer $iProfileId Default NULL
1224
     * @param string $sUsername Default NULL
1225
     * @param string $sTable Default 'Members'
1226
     *
1227
     * @return string The sex of a member
1228
     */
1229
    public function getSex($iProfileId = null, $sUsername = null, $sTable = 'Members')
1230
    {
1231
        $this->cache->start(self::CACHE_GROUP, 'sex' . $iProfileId . $sUsername . $sTable, static::CACHE_TIME);
1232
1233
        if (!$sData = $this->cache->get()) {
1234
            Various::checkModelTable($sTable);
1235
1236
            if (!empty($iProfileId)) {
1237
                $rStmt = Db::getInstance()->prepare('SELECT sex FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1');
1238
                $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1239
            } else {
1240
                $rStmt = Db::getInstance()->prepare('SELECT sex FROM' . Db::prefix($sTable) . 'WHERE username=:username LIMIT 1');
1241
                $rStmt->bindValue(':username', $sUsername, \PDO::PARAM_STR);
1242
            }
1243
1244
            $rStmt->execute();
1245
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1246
            Db::free($rStmt);
1247
            $sData = @$oRow->sex;
1248
            unset($oRow);
1249
            $this->cache->put($sData);
1250
        }
1251
1252
        return $sData;
1253
    }
1254
1255
    /**
1256
     * Get Match sex for a member (so only from the Members table, because Affiliates and Admins don't have match sex).
1257
     *
1258
     * @param integer $iProfileId
1259
     *
1260
     * @return string The User's birthdate.
1261
     */
1262
    public function getMatchSex($iProfileId)
1263
    {
1264
        $this->cache->start(self::CACHE_GROUP, 'matchsex' . $iProfileId, static::CACHE_TIME);
1265
1266
        if (!$sData = $this->cache->get())
1267
        {
1268
            $rStmt = Db::getInstance()->prepare('SELECT matchSex FROM' . Db::prefix('Members') . 'WHERE profileId = :profileId LIMIT 1');
1269
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1270
            $rStmt->execute();
1271
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1272
            Db::free($rStmt);
1273
            $sData = $oRow->matchSex;
1274
            unset($oRow);
1275
            $this->cache->put($sData);
1276
        }
1277
1278
        return $sData;
1279
    }
1280
1281
    /**
1282
     * Get Birth Date of a user.
1283
     *
1284
     * @param integer $iProfileId
1285
     * @param string $sTable Default 'Members'
1286
     *
1287
     * @return string The User's birthdate.
1288
     */
1289
    public function getBirthDate($iProfileId, $sTable = 'Members')
1290
    {
1291
        $this->cache->start(self::CACHE_GROUP, 'birthdate' . $iProfileId . $sTable, static::CACHE_TIME);
1292
1293
        if (!$sData = $this->cache->get())
1294
        {
1295
            Various::checkModelTable($sTable);
1296
1297
            $rStmt = Db::getInstance()->prepare('SELECT birthDate FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1');
1298
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1299
            $rStmt->execute();
1300
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1301
            Db::free($rStmt);
1302
            $sData = $oRow->birthDate;
1303
            unset($oRow);
1304
            $this->cache->put($sData);
1305
        }
1306
1307
        return $sData;
1308
    }
1309
1310
    /**
1311
     * Get user's group.
1312
     *
1313
     * @param integer $iProfileId
1314
     * @param string sTable Default 'Members'
1315
     *
1316
     * @return integer The Group ID of a member
1317
     */
1318
    public function getGroupId($iProfileId, $sTable = 'Members')
1319
    {
1320
        $this->cache->start(self::CACHE_GROUP, 'groupId' . $iProfileId . $sTable, static::CACHE_TIME);
1321
1322
        if (!$sData = $this->cache->get())
1323
        {
1324
            Various::checkModelTable($sTable);
1325
1326
            $rStmt = Db::getInstance()->prepare('SELECT groupId FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1');
1327
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1328
            $rStmt->execute();
1329
            $oRow = $rStmt->fetch(\PDO::FETCH_OBJ);
1330
            Db::free($rStmt);
1331
            $sData = (int) $oRow->groupId;
1332
            unset($oRow);
1333
            $this->cache->put($sData);
1334
        }
1335
1336
        return $sData;
1337
    }
1338
1339
    /**
1340
     * Get the membership(s) data.
1341
     *
1342
     * @param integer $iGroupId Group ID. Select only the specific membership from a group ID.
1343
     *
1344
     * @return stdClass The membership(s) data.
1345
     */
1346
    public function getMemberships($iGroupId = null)
1347
    {
1348
        $this->cache->start(self::CACHE_GROUP, 'memberships' . $iGroupId, static::CACHE_TIME);
1349
1350
        if (!$mData = $this->cache->get())
1351
        {
1352
            $bIsGroupId = !empty($iGroupId);
1353
            $sSqlGroup = ($bIsGroupId) ? ' WHERE groupId = :groupId ' : ' ';
1354
1355
            $rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix('Memberships') . $sSqlGroup . 'ORDER BY enable DESC, name ASC');
1356
            if (!empty($iGroupId)) $rStmt->bindValue(':groupId', $iGroupId, \PDO::PARAM_INT);
1357
            $rStmt->execute();
1358
            $mData = ($bIsGroupId) ? $rStmt->fetch(\PDO::FETCH_OBJ) : $rStmt->fetchAll(\PDO::FETCH_OBJ);
1359
            Db::free($rStmt);
1360
            $this->cache->put($mData);
1361
        }
1362
1363
        return $mData;
1364
    }
1365
1366
    /**
1367
     * Get the membership details of a user.
1368
     *
1369
     * @param integer $iProfileId
1370
     *
1371
     * @return stdClass The membership detais.
1372
     */
1373
    public function getMembershipDetails($iProfileId)
1374
    {
1375
        $this->cache->start(self::CACHE_GROUP, 'membershipdetails' . $iProfileId, static::CACHE_TIME);
1376
1377
        if (!$oData = $this->cache->get()) {
1378
            $sSql = 'SELECT m.*, g.expirationDays, g.name AS membershipName FROM' . Db::prefix('Members'). 'AS m INNER JOIN ' . Db::prefix('Memberships') .
1379
            'AS g USING(groupId) WHERE profileId = :profileId LIMIT 1';
1380
1381
            $rStmt = Db::getInstance()->prepare($sSql);
1382
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1383
            $rStmt->execute();
1384
            $oData = $rStmt->fetch(\PDO::FETCH_OBJ);
1385
            Db::free($rStmt);
1386
            $this->cache->put($oData);
1387
        }
1388
1389
        return $oData;
1390
    }
1391
1392
    /**
1393
     * Check if membership is expired.
1394
     *
1395
     * @param integer $iProfileId
1396
     * @param string $sCurrentTime In date format: 0000-00-00 00:00:00
1397
     *
1398
     * @return boolean
1399
     */
1400
    public function checkMembershipExpiration($iProfileId, $sCurrentTime)
1401
    {
1402
        $rStmt = Db::getInstance()->prepare('SELECT m.profileId FROM' . Db::prefix('Members') . 'AS m INNER JOIN' . Db::prefix('Memberships') .
1403
            'AS pay USING(groupId) WHERE (pay.expirationDays = 0 OR DATE_ADD(m.membershipDate, INTERVAL pay.expirationDays DAY) >= :currentTime)
1404
             AND (m.profileId = :profileId) LIMIT 1');
1405
1406
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1407
        $rStmt->bindValue(':currentTime', $sCurrentTime, \PDO::PARAM_INT);
1408
        $rStmt->execute();
1409
        return ($rStmt->rowCount() === 1);
1410
    }
1411
1412
    /**
1413
     * Update the membership group of a user.
1414
     *
1415
     * @param integer $iNewGroupId The new ID of membership group.
1416
     * @param integer $iProfileId The user ID.
1417
     * @param string $sDateTime In date format: 0000-00-00 00:00:00
1418
     *
1419
     * @return boolean Returns TRUE on success or FALSE on failure.
1420
     */
1421
    public function updateMembership($iNewGroupId, $iProfileId, $sDateTime = null)
1422
    {
1423
        $bIsTime = !empty($sDateTime);
1424
1425
        $sSqlTime = ($bIsTime) ? ',membershipDate = :dateTime ' : ' ';
1426
        $sSqlQuery = 'UPDATE' . Db::prefix('Members') . 'SET groupId = :groupId' .
1427
            $sSqlTime . 'WHERE profileId = :profileId LIMIT 1';
1428
1429
        $rStmt = Db::getInstance()->prepare($sSqlQuery);
1430
        $rStmt->bindValue(':groupId', $iNewGroupId, \PDO::PARAM_INT);
1431
        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1432
        if ($bIsTime) $rStmt->bindValue(':dateTime', $sDateTime, \PDO::PARAM_STR);
1433
        return $rStmt->execute();
1434
    }
1435
1436
    /**
1437
     * Get Info Fields from profile ID.
1438
     *
1439
     * @param integer $iProfileId
1440
     * @param string $sTable Default 'MembersInfo'
1441
     *
1442
     * @return stdClass
1443
     */
1444
    public function getInfoFields($iProfileId, $sTable = 'MembersInfo')
1445
    {
1446
        $this->cache->start(self::CACHE_GROUP, 'infoFields' . $iProfileId . $sTable, static::CACHE_TIME);
1447
1448
        if (!$oData = $this->cache->get()) {
1449
            Various::checkModelTable($sTable);
1450
1451
            $rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1');
1452
            $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);
1453
            $rStmt->execute();
1454
            $oColumns = $rStmt->fetch(\PDO::FETCH_OBJ);
1455
            Db::free($rStmt);
1456
1457
            $oData = new stdClass;
1458
            foreach ($oColumns as $sColumn => $sValue)
1459
            {
1460
                if ($sColumn != 'profileId')
1461
                    $oData->$sColumn = $sValue;
1462
            }
1463
            $this->cache->put($oData);
0 ignored issues
show
Documentation introduced by
$oData is of type object<stdClass>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1464
        }
1465
1466
        return $oData;
1467
    }
1468
1469
    /**
1470
     * @return string
1471
     */
1472
    public function getUserWithAvatarOnlySql()
1473
    {
1474
        return ' AND avatar IS NOT NULL AND approvedAvatar = 1';
1475
    }
1476
1477
    /**
1478
     * Clone is set to private to stop cloning.
1479
     */
1480
    private function __clone() {}
1481
}
1482