XoopsModules25x /
suico
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace XoopsModules\Yogurt; |
||
| 6 | |||
| 7 | /* |
||
| 8 | You may not change or alter any portion of this comment or credits |
||
| 9 | of supporting developers from this source code or any supporting source code |
||
| 10 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 11 | |||
| 12 | This program is distributed in the hope that it will be useful, |
||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 15 | */ |
||
| 16 | /** |
||
| 17 | * Module: Yogurt |
||
| 18 | * |
||
| 19 | * @category Module |
||
| 20 | * @package yogurt |
||
| 21 | * @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
||
| 22 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 23 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 24 | */ |
||
| 25 | |||
| 26 | // Friendship.php,v 1 |
||
| 27 | // ---------------------------------------------------------------- // |
||
| 28 | // Author: Bruno Barthez // |
||
| 29 | // ----------------------------------------------------------------- // |
||
| 30 | |||
| 31 | use Criteria; |
||
| 32 | use CriteriaCompo; |
||
| 33 | use CriteriaElement; |
||
| 34 | use XoopsDatabase; |
||
| 35 | use XoopsFormButton; |
||
| 36 | use XoopsFormHidden; |
||
| 37 | use XoopsFormLabel; |
||
| 38 | use XoopsFormRadio; |
||
| 39 | use XoopsFormRadioYN; |
||
| 40 | use XoopsObject; |
||
| 41 | use XoopsPersistableObjectHandler; |
||
| 42 | use XoopsThemeForm; |
||
| 43 | |||
| 44 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
||
| 45 | /** |
||
| 46 | * Includes of form objects and uploader |
||
| 47 | */ |
||
| 48 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
| 49 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
||
| 50 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 51 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
||
| 52 | |||
| 53 | // ------------------------------------------------------------------------- |
||
| 54 | // ------------------Friendship user handler class ------------------- |
||
| 55 | // ------------------------------------------------------------------------- |
||
| 56 | |||
| 57 | /** |
||
| 58 | * yogurt_friendshiphandler class. |
||
| 59 | * This class provides simple mecanisme for Friendship object |
||
| 60 | */ |
||
| 61 | class FriendshipHandler extends XoopsPersistableObjectHandler |
||
| 62 | { |
||
| 63 | public $helper; |
||
| 64 | |||
| 65 | public $isAdmin; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Constructor |
||
| 69 | * @param \XoopsDatabase|null $xoopsDatabase |
||
| 70 | * @param \XoopsModules\Yogurt\Helper|null $helper |
||
| 71 | */ |
||
| 72 | public function __construct( |
||
| 73 | ?XoopsDatabase $xoopsDatabase = null, |
||
| 74 | $helper = null |
||
| 75 | ) { |
||
| 76 | /** @var \XoopsModules\Yogurt\Helper $this ->helper */ |
||
| 77 | if (null === $helper) { |
||
| 78 | $this->helper = Helper::getInstance(); |
||
| 79 | } else { |
||
| 80 | $this->helper = $helper; |
||
| 81 | } |
||
| 82 | $isAdmin = $this->helper->isUserAdmin(); |
||
| 83 | parent::__construct($xoopsDatabase, 'yogurt_friendships', Friendship::class, 'friendship_id', 'friendship_id'); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * create a new Groups |
||
| 88 | * |
||
| 89 | * @param bool $isNew flag the new objects as "new"? |
||
| 90 | * @return \XoopsObject Groups |
||
| 91 | */ |
||
| 92 | public function create( |
||
| 93 | $isNew = true |
||
| 94 | ) { |
||
| 95 | $obj = parent::create($isNew); |
||
| 96 | if ($isNew) { |
||
| 97 | $obj->setNew(); |
||
| 98 | } else { |
||
| 99 | $obj->unsetNew(); |
||
| 100 | } |
||
| 101 | $obj->helper = $this->helper; |
||
| 102 | |||
| 103 | return $obj; |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * retrieve a Friendship |
||
| 108 | * |
||
| 109 | * @param int $id of the Friendship |
||
| 110 | * @param null $fields |
||
| 111 | * @return mixed reference to the {@link Friendship} object, FALSE if failed |
||
| 112 | */ |
||
| 113 | public function get2( |
||
| 114 | $id = null, |
||
| 115 | $fields = null |
||
| 116 | ) { |
||
| 117 | $sql = 'SELECT * FROM ' . $this->db->prefix('yogurt_friendships') . ' WHERE friendship_id=' . $id; |
||
| 118 | if (!$result = $this->db->query($sql)) { |
||
| 119 | return false; |
||
| 120 | } |
||
| 121 | $numrows = $this->db->getRowsNum($result); |
||
| 122 | if (1 === $numrows) { |
||
| 123 | $yogurt_friendship = new Friendship(); |
||
| 124 | $yogurt_friendship->assignVars($this->db->fetchArray($result)); |
||
| 125 | |||
| 126 | return $yogurt_friendship; |
||
| 127 | } |
||
| 128 | |||
| 129 | return false; |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * insert a new Friendship in the database |
||
| 134 | * |
||
| 135 | * @param \XoopsObject $xoopsObject reference to the {@link Friendship} |
||
| 136 | * object |
||
| 137 | * @param bool $force |
||
| 138 | * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
||
| 139 | */ |
||
| 140 | public function insert2( |
||
| 141 | XoopsObject $xoopsObject, |
||
| 142 | $force = false |
||
| 143 | ) { |
||
| 144 | global $xoopsConfig; |
||
| 145 | if (!$xoopsObject instanceof Friendship) { |
||
| 146 | return false; |
||
| 147 | } |
||
| 148 | if (!$xoopsObject->isDirty()) { |
||
| 149 | return true; |
||
| 150 | } |
||
| 151 | if (!$xoopsObject->cleanVars()) { |
||
| 152 | return false; |
||
| 153 | } |
||
| 154 | |||
| 155 | $friendship_id = $friend1_uid = $friend2_uid = $level = $hot = $trust = $cool = $fan = ''; |
||
| 156 | |||
| 157 | foreach ($xoopsObject->cleanVars as $k => $v) { |
||
| 158 | ${$k} = $v; |
||
| 159 | } |
||
| 160 | // $now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)'; |
||
| 161 | |||
| 162 | if ($xoopsObject->isNew()) { |
||
| 163 | // ajout/modification d'un Friendship |
||
| 164 | $xoopsObject = new Friendship(); |
||
| 165 | $format = 'INSERT INTO %s (friendship_id, friend1_uid, friend2_uid, LEVEL, hot, trust, cool, fan)'; |
||
| 166 | $format .= 'VALUES (%u, %u, %u, %u, %u, %u, %u, %u)'; |
||
| 167 | $sql = \sprintf( |
||
| 168 | $format, |
||
| 169 | $this->db->prefix('yogurt_friendships'), |
||
| 170 | $friendship_id, |
||
| 171 | $friend1_uid, |
||
| 172 | $friend2_uid, |
||
| 173 | $level, |
||
| 174 | $hot, |
||
| 175 | $trust, |
||
| 176 | $cool, |
||
| 177 | $fan |
||
| 178 | ); |
||
| 179 | $force = true; |
||
| 180 | } else { |
||
| 181 | $format = 'UPDATE %s SET '; |
||
| 182 | $format .= 'friendship_id=%u, friend1_uid=%u, friend2_uid=%u, level=%u, hot=%u, trust=%u, cool=%u, fan=%u'; |
||
| 183 | $format .= ' WHERE friendship_id = %u'; |
||
| 184 | $sql = \sprintf( |
||
| 185 | $format, |
||
| 186 | $this->db->prefix('yogurt_friendships'), |
||
| 187 | $friendship_id, |
||
| 188 | $friend1_uid, |
||
| 189 | $friend2_uid, |
||
| 190 | $level, |
||
| 191 | $hot, |
||
| 192 | $trust, |
||
| 193 | $cool, |
||
| 194 | $fan, |
||
| 195 | $friendship_id |
||
| 196 | ); |
||
| 197 | } |
||
| 198 | if ($force) { |
||
| 199 | $result = $this->db->queryF($sql); |
||
| 200 | } else { |
||
| 201 | $result = $this->db->query($sql); |
||
| 202 | } |
||
| 203 | if (!$result) { |
||
| 204 | return false; |
||
| 205 | } |
||
| 206 | if (empty($friendship_id)) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 207 | $friendship_id = $this->db->getInsertId(); |
||
| 208 | } |
||
| 209 | $xoopsObject->assignVar('friendship_id', $friendship_id); |
||
| 210 | |||
| 211 | return true; |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * delete a Friendship from the database |
||
| 216 | * |
||
| 217 | * @param \XoopsObject $xoopsObject reference to the Friendship to delete |
||
| 218 | * @param bool $force |
||
| 219 | * @return bool FALSE if failed. |
||
| 220 | */ |
||
| 221 | public function delete( |
||
| 222 | XoopsObject $xoopsObject, |
||
| 223 | $force = false |
||
| 224 | ) { |
||
| 225 | if (!$xoopsObject instanceof Friendship) { |
||
| 226 | return false; |
||
| 227 | } |
||
| 228 | $sql = \sprintf( |
||
| 229 | 'DELETE FROM %s WHERE friendship_id = %u', |
||
| 230 | $this->db->prefix('yogurt_friendships'), |
||
| 231 | $xoopsObject->getVar('friendship_id') |
||
| 232 | ); |
||
| 233 | if ($force) { |
||
| 234 | $result = $this->db->queryF($sql); |
||
| 235 | } else { |
||
| 236 | $result = $this->db->query($sql); |
||
| 237 | } |
||
| 238 | if (!$result) { |
||
| 239 | return false; |
||
| 240 | } |
||
| 241 | |||
| 242 | return true; |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * retrieve yogurt_friendships from the database |
||
| 247 | * |
||
| 248 | * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement} conditions to be met |
||
| 249 | * @param bool $id_as_key use the UID as key for the array? |
||
| 250 | * @param bool $as_object |
||
| 251 | * @return array array of {@link Friendship} objects |
||
| 252 | */ |
||
| 253 | public function &getObjects( |
||
| 254 | ?CriteriaElement $criteriaElement = null, |
||
| 255 | $id_as_key = false, |
||
| 256 | $as_object = true |
||
| 257 | ) { |
||
| 258 | $ret = []; |
||
| 259 | $limit = $start = 0; |
||
| 260 | $sql = 'SELECT * FROM ' . $this->db->prefix('yogurt_friendships'); |
||
| 261 | if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) { |
||
| 262 | $sql .= ' ' . $criteriaElement->renderWhere(); |
||
| 263 | if ('' !== $criteriaElement->getSort()) { |
||
| 264 | $sql .= ' ORDER BY ' . $criteriaElement->getSort() . ' ' . $criteriaElement->getOrder(); |
||
| 265 | } |
||
| 266 | $limit = $criteriaElement->getLimit(); |
||
| 267 | $start = $criteriaElement->getStart(); |
||
| 268 | } |
||
| 269 | $result = $this->db->query($sql, $limit, $start); |
||
| 270 | if (!$result) { |
||
| 271 | return $ret; |
||
| 272 | } |
||
| 273 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 274 | $yogurt_friendship = new Friendship(); |
||
| 275 | $yogurt_friendship->assignVars($myrow); |
||
| 276 | if (!$id_as_key) { |
||
| 277 | $ret[] = &$yogurt_friendship; |
||
| 278 | } else { |
||
| 279 | $ret[$myrow['friendship_id']] = &$yogurt_friendship; |
||
| 280 | } |
||
| 281 | unset($yogurt_friendship); |
||
| 282 | } |
||
| 283 | |||
| 284 | return $ret; |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * count yogurt_friendships matching a condition |
||
| 289 | * |
||
| 290 | * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement} to match |
||
| 291 | * @return int count of yogurt_friendships |
||
| 292 | */ |
||
| 293 | public function getCount( |
||
| 294 | ?CriteriaElement $criteriaElement = null |
||
| 295 | ) { |
||
| 296 | $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('yogurt_friendships'); |
||
| 297 | if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) { |
||
| 298 | $sql .= ' ' . $criteriaElement->renderWhere(); |
||
| 299 | } |
||
| 300 | $result = $this->db->query($sql); |
||
| 301 | if (!$result) { |
||
| 302 | return 0; |
||
| 303 | } |
||
| 304 | [$count] = $this->db->fetchRow($result); |
||
| 305 | |||
| 306 | return (int)$count; |
||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * delete yogurt_friendships matching a set of conditions |
||
| 311 | * |
||
| 312 | * @param \CriteriaElement|\CriteriaCompo|null $criteriaElement {@link \CriteriaElement} |
||
| 313 | * @param bool $force |
||
| 314 | * @param bool $asObject |
||
| 315 | * @return bool FALSE if deletion failed |
||
| 316 | */ |
||
| 317 | public function deleteAll( |
||
| 318 | ?CriteriaElement $criteriaElement = null, |
||
| 319 | $force = true, |
||
| 320 | $asObject = false |
||
| 321 | ) { |
||
| 322 | $sql = 'DELETE FROM ' . $this->db->prefix('yogurt_friendships'); |
||
| 323 | if (isset($criteriaElement) && $criteriaElement instanceof CriteriaElement) { |
||
| 324 | $sql .= ' ' . $criteriaElement->renderWhere(); |
||
| 325 | } |
||
| 326 | if (!$result = $this->db->query($sql)) { |
||
| 327 | return false; |
||
| 328 | } |
||
| 329 | |||
| 330 | return true; |
||
| 331 | } |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param $nbfriends |
||
| 335 | * @param null $criteria |
||
| 336 | * @param int $shuffle |
||
| 337 | * @return array |
||
| 338 | */ |
||
| 339 | public function getFriends( |
||
| 340 | $nbfriends, |
||
| 341 | $criteria = null, |
||
| 342 | $shuffle = 1 |
||
| 343 | ) { |
||
| 344 | $ret = []; |
||
| 345 | $limit = $start = 0; |
||
| 346 | $sql = 'SELECT uname, user_avatar, friend2_uid FROM ' . $this->db->prefix( |
||
| 347 | 'yogurt_friendships' |
||
| 348 | ) . ', ' . $this->db->prefix( |
||
| 349 | 'users' |
||
| 350 | ); |
||
| 351 | if (isset($criteria) && $criteria instanceof CriteriaElement) { |
||
| 352 | $sql .= ' ' . $criteria->renderWhere(); |
||
| 353 | //attention here this is kind of a hack |
||
| 354 | $sql .= ' AND uid = friend2_uid '; |
||
| 355 | if ('' !== $criteria->getSort()) { |
||
| 356 | $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
||
| 357 | } |
||
| 358 | |||
| 359 | $limit = $criteria->getLimit(); |
||
| 360 | $start = $criteria->getStart(); |
||
| 361 | |||
| 362 | $result = $this->db->query($sql, $limit, $start); |
||
| 363 | $vetor = []; |
||
| 364 | $i = 0; |
||
| 365 | |||
| 366 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 367 | $vetor[$i]['uid'] = $myrow['friend2_uid']; |
||
| 368 | $vetor[$i]['uname'] = $myrow['uname']; |
||
| 369 | $vetor[$i]['user_avatar'] = $myrow['user_avatar']; |
||
| 370 | $i++; |
||
| 371 | } |
||
| 372 | if (1 === $shuffle) { |
||
| 373 | \shuffle($vetor); |
||
| 374 | $vetor = \array_slice($vetor, 0, $nbfriends); |
||
| 375 | } |
||
| 376 | |||
| 377 | return $vetor; |
||
| 378 | } |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @param $nbfriends |
||
| 383 | * @param null $criteria |
||
| 384 | * @param int $shuffle |
||
| 385 | * @return array |
||
| 386 | */ |
||
| 387 | public function getFans( |
||
| 388 | $nbfriends, |
||
| 389 | $criteria = null, |
||
| 390 | $shuffle = 1 |
||
| 391 | ) { |
||
| 392 | $ret = []; |
||
| 393 | $limit = $start = 0; |
||
| 394 | $sql = 'SELECT uname, user_avatar, friend1_uid FROM ' . $this->db->prefix( |
||
| 395 | 'yogurt_friendships' |
||
| 396 | ) . ', ' . $this->db->prefix( |
||
| 397 | 'users' |
||
| 398 | ); |
||
| 399 | if (isset($criteria) && $criteria instanceof CriteriaElement) { |
||
| 400 | $sql .= ' ' . $criteria->renderWhere(); |
||
| 401 | //attention here this is kind of a hack |
||
| 402 | $sql .= ' AND uid = friend1_uid '; |
||
| 403 | if ('' !== $criteria->getSort()) { |
||
| 404 | $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
||
| 405 | } |
||
| 406 | |||
| 407 | $limit = $criteria->getLimit(); |
||
| 408 | $start = $criteria->getStart(); |
||
| 409 | |||
| 410 | $result = $this->db->query($sql, $limit, $start); |
||
| 411 | $vetor = []; |
||
| 412 | $i = 0; |
||
| 413 | |||
| 414 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 415 | $vetor[$i]['uid'] = $myrow['friend1_uid']; |
||
| 416 | $vetor[$i]['uname'] = $myrow['uname']; |
||
| 417 | $vetor[$i]['user_avatar'] = $myrow['user_avatar']; |
||
| 418 | $i++; |
||
| 419 | } |
||
| 420 | if (1 === $shuffle) { |
||
| 421 | \shuffle($vetor); |
||
| 422 | $vetor = \array_slice($vetor, 0, $nbfriends); |
||
| 423 | } |
||
| 424 | |||
| 425 | return $vetor; |
||
| 426 | } |
||
| 427 | } |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @param $friend |
||
| 431 | */ |
||
| 432 | public function renderFormSubmit($friend) |
||
| 433 | { |
||
| 434 | global $xoopsUser; |
||
| 435 | /** |
||
| 436 | * criteria fetch friendship to be edited |
||
| 437 | */ |
||
| 438 | $criteria_friend1 = new Criteria( |
||
| 439 | 'friend1_uid', $xoopsUser->getVar( |
||
| 440 | 'uid' |
||
| 441 | ) |
||
| 442 | ); |
||
| 443 | |||
| 444 | $field_friend_fan = $field_friend_friendly = $field_friend_funny = $field_friend_cool = ''; |
||
| 445 | |||
| 446 | $criteria_friend2 = new Criteria('friend2_uid', $friend->getVar('uid')); |
||
| 447 | $criteria_friendship = new CriteriaCompo($criteria_friend1); |
||
| 448 | $criteria_friendship->add($criteria_friend2); |
||
| 449 | $friendships = $this->getObjects($criteria_friendship); |
||
| 450 | $friendship = $friendships[0]; |
||
| 451 | |||
| 452 | $form = new XoopsThemeForm( |
||
| 453 | \_MD_YOGURT_EDIT_FRIENDSHIP, 'form_editfriendship', 'editfriendship.php', 'post', true |
||
| 454 | ); |
||
| 455 | //$field_friend_avatar = new XoopsFormLabel(_MD_YOGURT_PHOTO, "<img src=../../uploads/".$friend->getVar('user_avatar').">"); |
||
| 456 | if ('avatars/blank.gif' === $friend->getVar( |
||
| 457 | 'user_avatar' |
||
| 458 | )) { |
||
| 459 | $field_friend_avatar = new XoopsFormLabel(\_MD_YOGURT_PHOTO, '<img src=assets/images/noavatar.gif>'); |
||
| 460 | } else { |
||
| 461 | $field_friend_avatar = new XoopsFormLabel( |
||
| 462 | \_MD_YOGURT_PHOTO, '<img src=../../uploads/' . $friend->getVar( |
||
| 463 | 'user_avatar' |
||
| 464 | ) . '>' |
||
| 465 | ); |
||
| 466 | } |
||
| 467 | $field_friend_name = new XoopsFormLabel(\_MD_YOGURT_FRIENDNAME, $friend->getVar('uname')); |
||
| 468 | |||
| 469 | if (1 === $this->helper->getConfig('allow_friendshiplevel')) { |
||
| 470 | $field_friend_level = new XoopsFormRadio(\_MD_YOGURT_LEVEL, 'level', $friendship->getVar('level'), '<br>'); |
||
| 471 | |||
| 472 | $field_friend_level->addOption('1', \_MD_YOGURT_UNKNOWN_ACCEPTED); |
||
| 473 | $field_friend_level->addOption('3', \_MD_YOGURT_AQUAITANCE); |
||
| 474 | $field_friend_level->addOption('5', \_MD_YOGURT_FRIEND); |
||
| 475 | $field_friend_level->addOption('7', \_MD_YOGURT_BESTFRIEND); |
||
| 476 | } |
||
| 477 | |||
| 478 | if (1 === $this->helper->getConfig('allow_fanssevaluation')) { |
||
| 479 | $field_friend_fan = new XoopsFormRadioYN( |
||
| 480 | \_MD_YOGURT_FAN, 'fan', $friendship->getVar( |
||
| 481 | 'fan' |
||
| 482 | ), '<img src="assets/images/fans.gif" alt="' . \_YES . '" title="' . \_YES . '">', '<img src="assets/images/fansbw.gif" alt="' . \_NO . '" title="' . \_NO . '">' |
||
| 483 | ); |
||
| 484 | |||
| 485 | $field_friend_friendly = new XoopsFormRadio(\_MD_YOGURT_FRIENDLY, 'hot', $friendship->getVar('hot')); |
||
| 486 | $field_friend_friendly->addOption( |
||
| 487 | '1', |
||
| 488 | '<img src="assets/images/friendlya.gif" alt="' . \_MD_YOGURT_FRIENDLYNO . '" title="' . \_MD_YOGURT_FRIENDLYNO . '">' |
||
| 489 | ); |
||
| 490 | $field_friend_friendly->addOption( |
||
| 491 | '2', |
||
| 492 | '<img src="assets/images/friendlyb.gif" alt="' . \_MD_YOGURT_FRIENDLYYES . '" title="' . \_MD_YOGURT_FRIENDLYYES . '">' |
||
| 493 | ); |
||
| 494 | $field_friend_friendly->addOption( |
||
| 495 | '3', |
||
| 496 | '<img src="assets/images/friendlyc.gif" alt="' . \_MD_YOGURT_FRIENDLYALOT . '" title="' . \_MD_YOGURT_FRIENDLYALOT . '">' |
||
| 497 | ); |
||
| 498 | |||
| 499 | $field_friend_funny = new XoopsFormRadio(\_MD_YOGURT_FUNNY, 'trust', $friendship->getVar('trust')); |
||
| 500 | $field_friend_funny->addOption( |
||
| 501 | '1', |
||
| 502 | '<img src="assets/images/funnya.gif" alt="' . \_MD_YOGURT_FUNNYNO . '" title="' . \_MD_YOGURT_FUNNYNO . '">' |
||
| 503 | ); |
||
| 504 | $field_friend_funny->addOption( |
||
| 505 | '2', |
||
| 506 | '<img src="assets/images/funnyb.gif" alt="' . \_MD_YOGURT_FUNNYYES . '" title="' . \_MD_YOGURT_FUNNYYES . '">' |
||
| 507 | ); |
||
| 508 | $field_friend_funny->addOption( |
||
| 509 | '3', |
||
| 510 | '<img src="assets/images/funnyc.gif" alt="' . \_MD_YOGURT_FUNNYALOT . '" title="' . \_MD_YOGURT_FUNNYALOT . '">' |
||
| 511 | ); |
||
| 512 | |||
| 513 | $field_friend_cool = new XoopsFormRadio(\_MD_YOGURT_COOL, 'cool', $friendship->getVar('cool')); |
||
| 514 | $field_friend_cool->addOption( |
||
| 515 | '1', |
||
| 516 | '<img src="assets/images/coola.gif" alt="' . \_MD_YOGURT_COOLNO . '" title="' . \_MD_YOGURT_COOLNO . '">' |
||
| 517 | ); |
||
| 518 | $field_friend_cool->addOption( |
||
| 519 | '2', |
||
| 520 | '<img src="assets/images/coolb.gif" alt="' . \_MD_YOGURT_COOLYES . '" title="' . \_MD_YOGURT_COOLYES . '">' |
||
| 521 | ); |
||
| 522 | $field_friend_cool->addOption( |
||
| 523 | '3', |
||
| 524 | '<img src="assets/images/coolc.gif" alt="' . \_MD_YOGURT_COOLALOT . '" title="' . \_MD_YOGURT_COOLALOT . '">' |
||
| 525 | ); |
||
| 526 | } |
||
| 527 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 528 | $buttonSend = new XoopsFormButton('', 'submit_button', \_MD_YOGURT_UPDATEFRIEND, 'submit'); |
||
| 529 | $field_friend_friendid = new XoopsFormHidden('friend_uid', $friend->getVar('uid')); |
||
| 530 | $field_friend_marker = new XoopsFormHidden('marker', '1'); |
||
| 531 | $field_friend_friendshio_id = new XoopsFormHidden('friendship_id', $friendship->getVar('friendship_id')); |
||
| 532 | $form->addElement($field_friend_friendid); |
||
| 533 | $form->addElement($field_friend_friendshio_id); |
||
| 534 | $form->addElement($field_friend_marker); |
||
| 535 | $form->addElement($field_friend_avatar); |
||
| 536 | $form->addElement($field_friend_name); |
||
| 537 | $form->addElement($field_friend_level); |
||
| 538 | $form->addElement($field_friend_fan); |
||
| 539 | $form->addElement($field_friend_friendly); |
||
| 540 | $form->addElement($field_friend_funny); |
||
| 541 | $form->addElement($field_friend_cool); |
||
| 542 | |||
| 543 | $form->addElement($buttonSend); |
||
| 544 | |||
| 545 | $form->display(); |
||
| 546 | } |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Get the averages of each evaluation hot funny etc... |
||
| 550 | * |
||
| 551 | * @param int $user_uid |
||
| 552 | * @return array with averages |
||
| 553 | */ |
||
| 554 | public function getMoyennes( |
||
| 555 | $user_uid |
||
| 556 | ) { |
||
| 557 | global $xoopsUser; |
||
| 558 | |||
| 559 | $vetor = []; |
||
| 560 | $vetor['mediahot'] = 0; |
||
| 561 | $vetor['mediatrust'] = 0; |
||
| 562 | $vetor['mediacool'] = 0; |
||
| 563 | $vetor['sumfan'] = 0; |
||
| 564 | |||
| 565 | //Calculating avg(hot) |
||
| 566 | $sql = 'SELECT friend2_uid, Avg(hot) AS mediahot FROM ' . $this->db->prefix( |
||
| 567 | 'yogurt_friendships' |
||
| 568 | ); |
||
| 569 | $sql .= ' WHERE (hot>0) GROUP BY friend2_uid HAVING (friend2_uid=' . $user_uid . ') '; |
||
| 570 | $result = $this->db->query($sql); |
||
| 571 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 572 | $vetor['mediahot'] = $myrow['mediahot'] * 16; |
||
| 573 | } |
||
| 574 | |||
| 575 | //Calculating avg(trust) |
||
| 576 | $sql = 'SELECT friend2_uid, Avg(trust) AS mediatrust FROM ' . $this->db->prefix( |
||
| 577 | 'yogurt_friendships' |
||
| 578 | ); |
||
| 579 | $sql .= ' WHERE (trust>0) GROUP BY friend2_uid HAVING (friend2_uid=' . $user_uid . ') '; |
||
| 580 | $result = $this->db->query($sql); |
||
| 581 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 582 | $vetor['mediatrust'] = $myrow['mediatrust'] * 16; |
||
| 583 | } |
||
| 584 | //Calculating avg(cool) |
||
| 585 | $sql = 'SELECT friend2_uid, Avg(cool) AS mediacool FROM ' . $this->db->prefix( |
||
| 586 | 'yogurt_friendships' |
||
| 587 | ); |
||
| 588 | $sql .= ' WHERE (cool>0) GROUP BY friend2_uid HAVING (friend2_uid=' . $user_uid . ') '; |
||
| 589 | $result = $this->db->query($sql); |
||
| 590 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 591 | $vetor['mediacool'] = $myrow['mediacool'] * 16; |
||
| 592 | } |
||
| 593 | |||
| 594 | //Calculating sum(fans) |
||
| 595 | $sql = 'SELECT friend2_uid, Sum(fan) AS sumfan FROM ' . $this->db->prefix( |
||
| 596 | 'yogurt_friendships' |
||
| 597 | ); |
||
| 598 | $sql .= ' GROUP BY friend2_uid HAVING (friend2_uid=' . $user_uid . ') '; |
||
| 599 | $result = $this->db->query($sql); |
||
| 600 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 601 | $vetor['sumfan'] = $myrow['sumfan']; |
||
| 602 | } |
||
| 603 | |||
| 604 | return $vetor; |
||
| 605 | } |
||
| 606 | } |
||
| 607 |