/** * Pre-process content into a uniform format for output * * @param Array $content By reference */ protected function processContent(&$content) { foreach ($content as &$item) { $contentType = val('RecordType', $item); $userID = val('InsertUserID', $item); $itemProperties = array(); $itemFields = array('DiscussionID', 'DateInserted', 'DateUpdated', 'Body', 'Format', 'RecordType', 'Url', 'CategoryID', 'CategoryName', 'CategoryUrl'); switch (strtolower($contentType)) { case 'comment': $itemFields = array_merge($itemFields, array('CommentID')); // Comment specific $itemProperties['Name'] = sprintf(t('Re: %s'), valr('Discussion.Name', $item, val('Name', $item))); $url = CommentUrl($item); break; case 'discussion': $itemFields = array_merge($itemFields, array('Name', 'Type')); $url = DiscussionUrl($item); break; } $item['Url'] = $url; if ($categoryId = val('CategoryID', $item)) { $category = CategoryModel::categories($categoryId); $item['CategoryName'] = val('Name', $category); $item['CategoryUrl'] = CategoryUrl($category); } $itemFields = array_fill_keys($itemFields, true); $filteredItem = array_intersect_key($item, $itemFields); $itemProperties = array_merge($itemProperties, $filteredItem); $item = $itemProperties; // Attach User $userFields = array('UserID', 'Name', 'Title', 'Location', 'PhotoUrl', 'RankName', 'Url', 'Roles', 'RoleNames'); $user = Gdn::userModel()->getID($userID); $roleModel = new RoleModel(); $roles = $roleModel->GetByUserID($userID)->resultArray(); $roleNames = ''; foreach ($roles as $role) { $roleNames[] = val('Name', $role); } // check $rankName = null; if (class_exists('RankModel')) { $rankName = val('Name', RankModel::Ranks(val('RankID', $user)), null); } $userProperties = array('Url' => url(userUrl($user), true), 'PhotoUrl' => UserPhotoUrl($user), 'RankName' => $rankName, 'RoleNames' => $roleNames, 'CssClass' => val('_CssClass', $user)); $user = (array) $user; $userFields = array_fill_keys($userFields, true); $filteredUser = array_intersect_key($user, $userFields); $userProperties = array_merge($filteredUser, $userProperties); $item['Author'] = $userProperties; } }