Exemplo n.º 1
0
 /**
  * Prepare output comment post information array
  * @return array|null
  */
 public function make()
 {
     if ($this->_record === null) {
         return null;
     }
     // build user data
     $userName = __('Unknown');
     $userAvatar = App::$Alias->scriptUrl . '/upload/user/avatar/small/default.jpg';
     $userObject = $this->_record->getUser();
     if ($userObject !== null) {
         $userName = $userObject->getProfile()->getNickname();
         $userAvatar = $userObject->getProfile()->getAvatarUrl('small');
     } else {
         if (!Str::likeEmpty($this->_record->guest_name)) {
             $userName = App::$Security->strip_tags($this->_record->guest_name);
         }
     }
     // return output json data
     $res = ['type' => $this->_type, 'id' => $this->_record->id, 'text' => $this->_record->message, 'date' => Date::convertToDatetime($this->_record->created_at, Date::FORMAT_TO_HOUR), 'pathway' => $this->_record->pathway, 'moderate' => (int) $this->_record->moderate, 'user' => ['id' => $this->_record->user_id, 'name' => $userName, 'avatar' => $userAvatar]];
     if ($this->_type === 'post' && method_exists($this->_record, 'getAnswerCount') && $this->_calcAnswers) {
         $res['answers'] = $this->_record->getAnswerCount();
     } elseif ($this->_type === 'answer') {
         $res['comment_id'] = $this->_record->comment_id;
     }
     return $res;
 }