|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ffcms\Core\Helper; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Ffcms\Core\App; |
|
7
|
|
|
use Ffcms\Core\Helper\Type\Obj; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Simplify. Simplification of ofter used logic and methods. |
|
11
|
|
|
* @package Ffcms\Core\Helper |
|
12
|
|
|
*/ |
|
13
|
|
|
class Simplify |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Get user nickname by user id with predefined value on empty or not exist profile |
|
17
|
|
|
* @param $userId |
|
18
|
|
|
* @param string $onEmpty |
|
19
|
|
|
* @return string |
|
20
|
|
|
*/ |
|
21
|
|
|
public static function parseUserNick($userId = null, $onEmpty = 'guest') |
|
22
|
|
|
{ |
|
23
|
|
|
// try to get user id as integer |
|
24
|
|
|
if (Obj::isLikeInt($userId)) { |
|
25
|
|
|
$userId = (int)$userId; |
|
26
|
|
|
} else { // user id is empty, lets return default value |
|
27
|
|
|
return \App::$Security->strip_tags($onEmpty); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// try to find user active record as object |
|
31
|
|
|
$identity = App::$User->identity($userId); |
|
32
|
|
|
if ($identity === null || $identity === false) { |
|
33
|
|
|
return \App::$Security->strip_tags($onEmpty); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
// return user nickname from profile |
|
37
|
|
|
return $identity->getProfile()->getNickname(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Prepare HTML DOM link (a href) to user with him name or guest name without link |
|
42
|
|
|
* @param int $userId |
|
43
|
|
|
* @param string $onEmpty |
|
44
|
|
|
* @param string $controllerAction |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function parseUserLink($userId = null, $onEmpty = 'guest', $controllerAction = 'profile/show') |
|
48
|
|
|
{ |
|
49
|
|
|
$nick = self::parseUserNick($userId, $onEmpty); |
|
50
|
|
|
// new name is not found, lets return default |
|
51
|
|
|
if ($nick === $onEmpty || (int)$userId < 1) { |
|
52
|
|
|
return $nick; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return Url::link([$controllerAction, (int)$userId], $nick); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |