FriendshipHandler::deleteAll()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 4
nop 3
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Suico;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * @category        Module
17
 * @copyright       {@link https://xoops.org/ XOOPS Project}
18
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author          Bruno Barthez, Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
20
 */
21
22
use Criteria;
23
use CriteriaCompo;
24
use CriteriaElement;
25
use XoopsDatabase;
26
use XoopsFormButton;
27
use XoopsFormHidden;
28
use XoopsFormLabel;
29
use XoopsFormRadio;
30
use XoopsFormRadioYN;
31
use XoopsObject;
32
use XoopsPersistableObjectHandler;
33
use XoopsThemeForm;
34
35
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
36
/**
37
 * Includes of form objects and uploader
38
 */
39
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
40
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
41
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
42
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
43
44
/**
45
 * suico_friendshiphandler class.
46
 * This class provides simple mechanism for Friendship object
47
 */
48
class FriendshipHandler extends XoopsPersistableObjectHandler
49
{
50
    public Helper $helper;
51
    public        $isAdmin;
52
53
    /**
54
     * Constructor
55
     * @param \XoopsDatabase|null             $xoopsDatabase
56
     * @param \XoopsModules\Suico\Helper|null $helper
57
     */
58
    public function __construct(
59
        ?XoopsDatabase $xoopsDatabase = null,
60
        $helper = null
61
    ) {
62
        /** @var \XoopsModules\Suico\Helper $this- >helper */
63
        if (null === $helper) {
64
            $this->helper = Helper::getInstance();
65
        } else {
66
            $this->helper = $helper;
67
        }
68
        $this->isAdmin = $this->helper->isUserAdmin();
69
        parent::__construct($xoopsDatabase, 'suico_friendships', Friendship::class, 'friendship_id', 'friendship_id');
70
    }
71
72
    /**
73
     * create a new Groups
74
     *
75
     * @param bool $isNew flag the new objects as "new"?
76
     * @return \XoopsObject Groups
77
     */
78
    public function create(
79
        $isNew = true
80
    ) {
81
        $obj = parent::create($isNew);
82
        if ($isNew) {
83
            $obj->setNew();
84
        } else {
85
            $obj->unsetNew();
86
        }
87
        $obj->helper = $this->helper;
88
89
        return $obj;
90
    }
91
92
    /**
93
     * retrieve a Friendship
94
     *
95
     * @param int|null $id of the Friendship
96
     * @param null     $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
97
     * @return false|\XoopsModules\Suico\Friendship reference to the {@link Friendship} object, FALSE if failed
98
     */
99
    public function get2(
100
        $id = null,
101
        $fields = null
0 ignored issues
show
Unused Code introduced by
The parameter $fields is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

101
        /** @scrutinizer ignore-unused */ $fields = null

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
102
    ) {
103
        $sql = 'SELECT * FROM ' . $this->db->prefix('suico_friendships') . ' WHERE friendship_id=' . $id;
104
        if (!$result = $this->db->query($sql)) {
105
            return false;
106
        }
107
        $numrows = $this->db->getRowsNum($result);
108
        if (1 === $numrows) {
109
            $suico_friendship = new Friendship();
110
            $suico_friendship->assignVars($this->db->fetchArray($result));
111
112
            return $suico_friendship;
113
        }
114
115
        return false;
116
    }
117
118
    /**
119
     * insert a new Friendship in the database
120
     *
121
     * @param \XoopsObject $object       reference to the {@link Friendship}
122
     *                                        object
123
     * @param bool         $force
124
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
125
     */
126
    public function insert2(
127
        XoopsObject $object,
128
        $force = false
129
    ) {
130
        global $xoopsConfig;
131
        if (!$object instanceof Friendship) {
132
            return false;
133
        }
134
        if (!$object->isDirty()) {
135
            return true;
136
        }
137
        if (!$object->cleanVars()) {
138
            return false;
139
        }
140
        $fan           = '';
141
        $cool          = '';
142
        $trust         = '';
143
        $hot           = '';
144
        $level         = '';
145
        $friend2_uid   = '';
146
        $friend1_uid   = '';
147
        $friendship_id = '';
148
        foreach ($object->cleanVars as $k => $v) {
149
            ${$k} = $v;
150
        }
151
        //        $now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)';
152
        if ($object->isNew()) {
153
            // ajout/modification d'un Friendship
154
            $object = new Friendship();
155
            $format      = 'INSERT INTO %s (friendship_id, friend1_uid, friend2_uid, LEVEL, hot, trust, cool, fan)';
156
            $format      .= 'VALUES (%u, %u, %u, %u, %u, %u, %u, %u)';
157
            $sql         = \sprintf(
158
                $format,
159
                $this->db->prefix('suico_friendships'),
160
                $friendship_id,
161
                $friend1_uid,
162
                $friend2_uid,
163
                $level,
164
                $hot,
165
                $trust,
166
                $cool,
167
                $fan
168
            );
169
            $force       = true;
170
        } else {
171
            $format = 'UPDATE %s SET ';
172
            $format .= 'friendship_id=%u, friend1_uid=%u, friend2_uid=%u, level=%u, hot=%u, trust=%u, cool=%u, fan=%u';
173
            $format .= ' WHERE friendship_id = %u';
174
            $sql    = \sprintf(
175
                $format,
176
                $this->db->prefix('suico_friendships'),
177
                $friendship_id,
178
                $friend1_uid,
179
                $friend2_uid,
180
                $level,
181
                $hot,
182
                $trust,
183
                $cool,
184
                $fan,
185
                $friendship_id
186
            );
187
        }
188
        if ($force) {
189
            $result = $this->db->queryF($sql);
190
        } else {
191
            $result = $this->db->query($sql);
192
        }
193
        if (!$result) {
194
            return false;
195
        }
196
        if (empty($friendship_id)) {
0 ignored issues
show
introduced by
The condition empty($friendship_id) is always true.
Loading history...
197
            $friendship_id = $this->db->getInsertId();
198
        }
199
        $object->assignVar('friendship_id', $friendship_id);
200
201
        return true;
202
    }
203
204
    /**
205
     * delete a Friendship from the database
206
     *
207
     * @param \XoopsObject $object reference to the Friendship to delete
208
     * @param bool         $force
209
     * @return bool FALSE if failed.
210
     */
211
    public function delete(
212
        XoopsObject $object,
213
        $force = false
214
    ) {
215
        if (!$object instanceof Friendship) {
216
            return false;
217
        }
218
        $sql = \sprintf(
219
            'DELETE FROM %s WHERE friendship_id = %u',
220
            $this->db->prefix('suico_friendships'),
221
            (int)$object->getVar('friendship_id')
222
        );
223
        if ($force) {
224
            $result = $this->db->queryF($sql);
225
        } else {
226
            $result = $this->db->query($sql);
227
        }
228
        if (!$result) {
229
            return false;
230
        }
231
232
        return true;
233
    }
234
235
    /**
236
     * retrieve suico_friendships from the database
237
     *
238
     * @param \CriteriaElement|\CriteriaCompo|null $criteria {@link \CriteriaElement} conditions to be met
239
     * @param bool                                 $id_as_key       use the UID as key for the array?
240
     * @param bool                                 $as_object
241
     * @return array array of {@link Friendship} objects
242
     */
243
    public function &getObjects(
244
        ?CriteriaElement $criteria = null,
245
        $id_as_key = false,
246
        $as_object = true
247
    ) {
248
        $ret   = [];
249
        $start = 0;
250
        $limit = 0;
251
        $sql   = 'SELECT * FROM ' . $this->db->prefix('suico_friendships');
252
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
253
            $sql .= ' ' . $criteria->renderWhere();
0 ignored issues
show
Bug introduced by
The method renderWhere() does not exist on CriteriaElement. Did you maybe mean render()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

253
            $sql .= ' ' . $criteria->/** @scrutinizer ignore-call */ renderWhere();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
254
            if ('' !== $criteria->getSort()) {
255
                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
256
            }
257
            $limit = $criteria->getLimit();
258
            $start = $criteria->getStart();
259
        }
260
        $result = $this->db->query($sql, $limit, $start);
261
        if (!$result) {
262
            return $ret;
263
        }
264
        while (false !== ($myrow = $this->db->fetchArray($result))) {
265
            $suico_friendship = new Friendship();
266
            $suico_friendship->assignVars($myrow);
267
            if ($id_as_key) {
268
                $ret[$myrow['friendship_id']] = &$suico_friendship;
269
            } else {
270
                $ret[] = &$suico_friendship;
271
            }
272
            unset($suico_friendship);
273
        }
274
275
        return $ret;
276
    }
277
278
    /**
279
     * count suico_friendships matching a condition
280
     *
281
     * @param \CriteriaElement|\CriteriaCompo|null $criteria {@link \CriteriaElement} to match
282
     * @return int count of suico_friendships
283
     */
284
    public function getCount(
285
        ?CriteriaElement $criteria = null
286
    ) {
287
        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('suico_friendships');
288
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
289
            $sql .= ' ' . $criteria->renderWhere();
290
        }
291
        $result = $this->db->query($sql);
292
        if (!$result) {
293
            return 0;
294
        }
295
        [$count] = $this->db->fetchRow($result);
296
297
        return (int)$count;
298
    }
299
300
    /**
301
     * delete suico_friendships matching a set of conditions
302
     *
303
     * @param \CriteriaElement|\CriteriaCompo|null $criteria {@link \CriteriaElement}
304
     * @param bool                                 $force
305
     * @param bool                                 $asObject
306
     * @return bool FALSE if deletion failed
307
     */
308
    public function deleteAll(
309
        ?CriteriaElement $criteria = null,
310
        $force = true,
311
        $asObject = false
312
    ) {
313
        $sql = 'DELETE FROM ' . $this->db->prefix('suico_friendships');
314
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
315
            $sql .= ' ' . $criteria->renderWhere();
316
        }
317
        if (!$result = $this->db->query($sql)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
318
            return false;
319
        }
320
321
        return true;
322
    }
323
324
    /**
325
     * @param int  $countFriends
326
     * @param null $criteria
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $criteria is correct as it would always require null to be passed?
Loading history...
327
     * @param int  $shuffle
328
     * @return array
329
     */
330
    public function getFriends(
331
        $countFriends,
332
        $criteria = null,
333
        $shuffle = 1
334
    ) {
335
        $ret   = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
336
        $start = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $start is dead and can be removed.
Loading history...
337
        $limit = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $limit is dead and can be removed.
Loading history...
338
        $sql   = 'SELECT uname, user_avatar, friend2_uid FROM ' . $this->db->prefix(
339
                'suico_friendships'
340
            ) . ', ' . $this->db->prefix(
341
                'users'
342
            );
343
        if (($criteria instanceof \CriteriaCompo) || ($criteria instanceof \Criteria)) {
344
            $sql .= ' ' . $criteria->renderWhere();
345
            //attention here this is kind of a hack
346
            $sql .= ' AND uid = friend2_uid ';
347
            if ('' !== $criteria->getSort()) {
348
                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
349
            }
350
            $limit  = $criteria->getLimit();
351
            $start  = $criteria->getStart();
352
            $result = $this->db->query($sql, $limit, $start);
353
            $vetor  = [];
354
            $i      = 0;
355
            while (false !== ($myrow = $this->db->fetchArray($result))) {
356
                $vetor[$i]['uid']         = $myrow['friend2_uid'];
357
                $vetor[$i]['uname']       = $myrow['uname'];
358
                $vetor[$i]['user_avatar'] = $myrow['user_avatar'];
359
                $i++;
360
            }
361
            if (1 === $shuffle) {
362
                \shuffle($vetor);
363
                $vetor = \array_slice($vetor, 0, (int)$countFriends);
364
            }
365
366
            return $vetor;
367
        }
368
    }
369
370
    /**
371
     * @param      $countFriends
372
     * @param null $criteria
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $criteria is correct as it would always require null to be passed?
Loading history...
373
     * @param int  $shuffle
374
     * @return array
375
     */
376
    public function getFans(
377
        $countFriends,
378
        $criteria = null,
379
        $shuffle = 1
380
    ) {
381
        $ret   = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
382
        $start = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $start is dead and can be removed.
Loading history...
383
        $limit = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $limit is dead and can be removed.
Loading history...
384
        $sql   = 'SELECT uname, user_avatar, friend1_uid FROM ' . $this->db->prefix(
385
                'suico_friendships'
386
            ) . ', ' . $this->db->prefix(
387
                'users'
388
            );
389
        if (($criteria instanceof \CriteriaCompo) || ($criteria instanceof \Criteria)) {
390
            $sql .= ' ' . $criteria->renderWhere();
391
            //attention here this is kind of a hack
392
            $sql .= ' AND uid = friend1_uid ';
393
            if ('' !== $criteria->getSort()) {
394
                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
395
            }
396
            $limit  = $criteria->getLimit();
397
            $start  = $criteria->getStart();
398
            $result = $this->db->query($sql, $limit, $start);
399
            $vetor  = [];
400
            $i      = 0;
401
            while (false !== ($myrow = $this->db->fetchArray($result))) {
402
                $vetor[$i]['uid']         = $myrow['friend1_uid'];
403
                $vetor[$i]['uname']       = $myrow['uname'];
404
                $vetor[$i]['user_avatar'] = $myrow['user_avatar'];
405
                $i++;
406
            }
407
            if (1 === $shuffle) {
408
                \shuffle($vetor);
409
                $vetor = \array_slice($vetor, 0, $countFriends);
410
            }
411
412
            return $vetor;
413
        }
414
    }
415
416
    /**
417
     * @param $friend
418
     */
419
    public function renderFormSubmit($friend): void
420
    {
421
        global $xoopsUser;
422
        /**
423
         * criteria fetch friendship to be edited
424
         */
425
        $criteria_friend1      = new Criteria(
426
            'friend1_uid',
427
            $xoopsUser->getVar(
428
                'uid'
429
            )
430
        );
431
        $field_friend_cool     = '';
432
        $field_friend_funny    = '';
433
        $field_friend_friendly = '';
434
        $field_friend_fan      = '';
435
        $criteria_friend2      = new Criteria('friend2_uid', $friend->getVar('uid'));
436
        $criteria_friendship   = new CriteriaCompo($criteria_friend1);
437
        $criteria_friendship->add($criteria_friend2);
438
        $friendships = $this->getObjects($criteria_friendship);
439
        $friendship  = $friendships[0];
440
        $form        = new XoopsThemeForm(
441
            \_MD_SUICO_EDIT_FRIENDSHIP,
442
            'form_editfriendship',
443
            'editfriendship.php',
444
            'post',
445
            true
446
        );
447
        //$field_friend_avatar      = new XoopsFormLabel(_MD_SUICO_PHOTO, "<img src=../../uploads/".$friend->getVar('user_avatar').">");
448
        if ('avatars/blank.gif' === $friend->getVar(
449
                'user_avatar'
450
            )) {
451
            $field_friend_avatar = new XoopsFormLabel(\_MD_SUICO_PHOTO, '<img src=assets/images/noavatar.gif>');
452
        } else {
453
            $field_friend_avatar = new XoopsFormLabel(
454
                \_MD_SUICO_PHOTO,
455
                '<img src=../../uploads/' . $friend->getVar(
456
                    'user_avatar'
457
                ) . '>'
458
            );
459
        }
460
        $field_friend_name = new XoopsFormLabel(\_MD_SUICO_FRIENDNAME, $friend->getVar('uname'));
461
        if (1 === $this->helper->getConfig('allow_friendshiplevel')) {
462
            $field_friend_level = new XoopsFormRadio(\_MD_SUICO_LEVEL, 'level', $friendship->getVar('level'), '<br>');
463
            $field_friend_level->addOption('1', \_MD_SUICO_UNKNOWN_ACCEPTED);
464
            $field_friend_level->addOption('3', \_MD_SUICO_AQUAITANCE);
465
            $field_friend_level->addOption('5', \_MD_SUICO_FRIEND);
466
            $field_friend_level->addOption('7', \_MD_SUICO_BESTFRIEND);
467
        }
468
        if (1 === $this->helper->getConfig('allow_fanssevaluation')) {
469
            $field_friend_fan      = new XoopsFormRadioYN(
470
                \_MD_SUICO_FAN,
471
                'fan',
472
                $friendship->getVar(
473
                    'fan'
474
                ),
475
                '<img src="assets/images/fans.gif" alt="' . \_YES . '" title="' . \_YES . '">',
476
                '<img src="assets/images/fansbw.gif" alt="' . \_NO . '" title="' . \_NO . '">'
477
            );
478
            $field_friend_friendly = new XoopsFormRadio(\_MD_SUICO_FRIENDLY, 'hot', $friendship->getVar('hot'));
479
            $field_friend_friendly->addOption(
480
                '1',
481
                '<img src="assets/images/friendlya.gif" alt="' . \_MD_SUICO_FRIENDLYNO . '" title="' . \_MD_SUICO_FRIENDLYNO . '">'
482
            );
483
            $field_friend_friendly->addOption(
484
                '2',
485
                '<img src="assets/images/friendlyb.gif" alt="' . \_MD_SUICO_FRIENDLYYES . '" title="' . \_MD_SUICO_FRIENDLYYES . '">'
486
            );
487
            $field_friend_friendly->addOption(
488
                '3',
489
                '<img src="assets/images/friendlyc.gif" alt="' . \_MD_SUICO_FRIENDLYALOT . '" title="' . \_MD_SUICO_FRIENDLYALOT . '">'
490
            );
491
            $field_friend_funny = new XoopsFormRadio(\_MD_SUICO_FUNNY, 'trust', $friendship->getVar('trust'));
492
            $field_friend_funny->addOption(
493
                '1',
494
                '<img src="assets/images/funnya.gif" alt="' . \_MD_SUICO_FUNNYNO . '" title="' . \_MD_SUICO_FUNNYNO . '">'
495
            );
496
            $field_friend_funny->addOption(
497
                '2',
498
                '<img src="assets/images/funnyb.gif" alt="' . \_MD_SUICO_FUNNYYES . '" title="' . \_MD_SUICO_FUNNYYES . '">'
499
            );
500
            $field_friend_funny->addOption(
501
                '3',
502
                '<img src="assets/images/funnyc.gif" alt="' . \_MD_SUICO_FUNNYALOT . '" title="' . \_MD_SUICO_FUNNYALOT . '">'
503
            );
504
            $field_friend_cool = new XoopsFormRadio(\_MD_SUICO_COOL, 'cool', $friendship->getVar('cool'));
505
            $field_friend_cool->addOption(
506
                '1',
507
                '<img src="assets/images/coola.gif" alt="' . \_MD_SUICO_COOLNO . '" title="' . \_MD_SUICO_COOLNO . '">'
508
            );
509
            $field_friend_cool->addOption(
510
                '2',
511
                '<img src="assets/images/coolb.gif" alt="' . \_MD_SUICO_COOLYES . '" title="' . \_MD_SUICO_COOLYES . '">'
512
            );
513
            $field_friend_cool->addOption(
514
                '3',
515
                '<img src="assets/images/coolc.gif" alt="' . \_MD_SUICO_COOLALOT . '" title="' . \_MD_SUICO_COOLALOT . '">'
516
            );
517
        }
518
        $form->setExtra('enctype="multipart/form-data"');
519
        $buttonSend                 = new XoopsFormButton('', 'submit_button', \_MD_SUICO_UPDATEFRIEND, 'submit');
520
        $field_friend_friendid      = new XoopsFormHidden('friend_uid', $friend->getVar('uid'));
521
        $field_friend_marker        = new XoopsFormHidden('marker', '1');
522
        $field_friend_friendshio_id = new XoopsFormHidden('friendship_id', $friendship->getVar('friendship_id'));
523
        $form->addElement($field_friend_friendid);
524
        $form->addElement($field_friend_friendshio_id);
525
        $form->addElement($field_friend_marker);
526
        $form->addElement($field_friend_avatar);
527
        $form->addElement($field_friend_name);
528
        $form->addElement($field_friend_level);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $field_friend_level does not seem to be defined for all execution paths leading up to this point.
Loading history...
529
        $form->addElement($field_friend_fan);
530
        $form->addElement($field_friend_friendly);
531
        $form->addElement($field_friend_funny);
532
        $form->addElement($field_friend_cool);
533
        $form->addElement($buttonSend);
534
        $form->display();
535
    }
536
537
    /**
538
     * Get the averages of each evaluation hot funny etc...
539
     *
540
     * @param int $user_uid
541
     * @return array with averages
542
     */
543
    public function getMoyennes(
544
        $user_uid
545
    ) {
546
        global $xoopsUser;
547
        $vetor               = [];
548
        $vetor['mediahot']   = 0;
549
        $vetor['mediatrust'] = 0;
550
        $vetor['mediacool']  = 0;
551
        $vetor['sumfan']     = 0;
552
        //Calculating avg(hot)
553
        $sql    = 'SELECT friend2_uid, Avg(hot) AS mediahot FROM ' . $this->db->prefix(
554
                'suico_friendships'
555
            );
556
        $sql    .= ' WHERE  (hot>0) GROUP BY friend2_uid HAVING (friend2_uid=' . $user_uid . ') ';
557
        $result = $this->db->query($sql);
558
        while (false !== ($myrow = $this->db->fetchArray($result))) {
559
            $vetor['mediahot'] = $myrow['mediahot'] * 16;
560
        }
561
        //Calculating avg(trust)
562
        $sql    = 'SELECT friend2_uid, Avg(trust) AS mediatrust FROM ' . $this->db->prefix(
563
                'suico_friendships'
564
            );
565
        $sql    .= ' WHERE  (trust>0) GROUP BY friend2_uid HAVING (friend2_uid=' . $user_uid . ') ';
566
        $result = $this->db->query($sql);
567
        while (false !== ($myrow = $this->db->fetchArray($result))) {
568
            $vetor['mediatrust'] = $myrow['mediatrust'] * 16;
569
        }
570
        //Calculating avg(cool)
571
        $sql    = 'SELECT friend2_uid, Avg(cool) AS mediacool FROM ' . $this->db->prefix(
572
                'suico_friendships'
573
            );
574
        $sql    .= ' WHERE  (cool>0) GROUP BY friend2_uid HAVING (friend2_uid=' . $user_uid . ') ';
575
        $result = $this->db->query($sql);
576
        while (false !== ($myrow = $this->db->fetchArray($result))) {
577
            $vetor['mediacool'] = $myrow['mediacool'] * 16;
578
        }
579
        //Calculating sum(fans)
580
        $sql    = 'SELECT friend2_uid, Sum(fan) AS sumfan FROM ' . $this->db->prefix(
581
                'suico_friendships'
582
            );
583
        $sql    .= ' GROUP BY friend2_uid HAVING (friend2_uid=' . $user_uid . ') ';
584
        $result = $this->db->query($sql);
585
        while (false !== ($myrow = $this->db->fetchArray($result))) {
586
            $vetor['sumfan'] = $myrow['sumfan'];
587
        }
588
589
        return $vetor;
590
    }
591
}
592