Add explicit `return null;` statements
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / comment / response / StructuredCommentResponse.class.php
1 <?php
2
3 namespace wcf\data\comment\response;
4
5 use wcf\data\DatabaseObjectDecorator;
6 use wcf\data\user\UserProfile;
7 use wcf\system\cache\runtime\UserProfileRuntimeCache;
8
9 /**
10 * Provides methods to handle response data.
11 *
12 * @author Alexander Ebert
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\Data\Comment\Response
16 *
17 * @method CommentResponse getDecoratedObject()
18 * @mixin CommentResponse
19 */
20 class StructuredCommentResponse extends DatabaseObjectDecorator
21 {
22 /**
23 * @inheritDoc
24 */
25 public static $baseClass = CommentResponse::class;
26
27 /**
28 * deletable by current user
29 * @var bool
30 */
31 public $deletable = false;
32
33 /**
34 * editable for current user
35 * @var bool
36 */
37 public $editable = false;
38
39 /**
40 * user profile of the comment response author
41 * @var UserProfile
42 */
43 public $userProfile;
44
45 /**
46 * Sets the user's profile.
47 *
48 * @param UserProfile $userProfile
49 * @deprecated 3.0
50 */
51 public function setUserProfile(UserProfile $userProfile)
52 {
53 $this->userProfile = $userProfile;
54 }
55
56 /**
57 * Returns the user's profile.
58 *
59 * @return UserProfile
60 */
61 public function getUserProfile()
62 {
63 if ($this->userProfile === null) {
64 if ($this->userID) {
65 $this->userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
66 } else {
67 $this->userProfile = UserProfile::getGuestUserProfile($this->username);
68 }
69 }
70
71 return $this->userProfile;
72 }
73
74 /**
75 * Returns a structured response.
76 *
77 * @param int $responseID
78 * @return StructuredCommentResponse
79 */
80 public static function getResponse($responseID)
81 {
82 $response = new CommentResponse($responseID);
83 if (!$response->responseID) {
84 return null;
85 }
86
87 // prepare structured response
88 $response = new self($response);
89
90 // cache user profile
91 if ($response->userID) {
92 UserProfileRuntimeCache::getInstance()->cacheObjectID($response->userID);
93 }
94
95 return $response;
96 }
97
98 /**
99 * Sets deletable state.
100 *
101 * @param bool $deletable
102 */
103 public function setIsDeletable($deletable)
104 {
105 $this->deletable = $deletable;
106 }
107
108 /**
109 * Sets editable state.
110 *
111 * @param bool $editable
112 */
113 public function setIsEditable($editable)
114 {
115 $this->editable = $editable;
116 }
117
118 /**
119 * Returns true if the response is deletable by current user.
120 *
121 * @return bool
122 */
123 public function isDeletable()
124 {
125 return $this->deletable;
126 }
127
128 /**
129 * Returns true if the response is editable by current user.
130 *
131 * @return bool
132 */
133 public function isEditable()
134 {
135 return $this->editable;
136 }
137 }