/** * @param $Category */ private static function calculateUser(&$Category) { $Category['Url'] = url($Category['Url'], '//'); if ($Photo = val('Photo', $Category)) { $Category['PhotoUrl'] = Gdn_Upload::url($Photo); } if (!empty($Category['LastUrl'])) { $Category['LastUrl'] = url($Category['LastUrl'], '//'); } $Category['PermsDiscussionsView'] = Gdn::session()->checkPermission('Vanilla.Discussions.View', true, 'Category', $Category['PermissionCategoryID']); $Category['PermsDiscussionsAdd'] = Gdn::session()->checkPermission('Vanilla.Discussions.Add', true, 'Category', $Category['PermissionCategoryID']); $Category['PermsDiscussionsEdit'] = Gdn::session()->checkPermission('Vanilla.Discussions.Edit', true, 'Category', $Category['PermissionCategoryID']); $Category['PermsCommentsAdd'] = Gdn::session()->checkPermission('Vanilla.Comments.Add', true, 'Category', $Category['PermissionCategoryID']); $Code = $Category['UrlCode']; $Category['Name'] = TranslateContent("Categories." . $Code . ".Name", $Category['Name']); $Category['Description'] = TranslateContent("Categories." . $Code . ".Description", $Category['Description']); }
/** * Add UserCategory modifiers * * Update &$Categories in memory by applying modifiers from UserCategory for * the currently logged-in user. * * @since 2.0.18 * @access public * @param array &$Categories * @param bool $AddUserCategory */ public static function joinUserData(&$Categories, $AddUserCategory = true) { $IDs = array_keys($Categories); $DoHeadings = c('Vanilla.Categories.DoHeadings'); if ($AddUserCategory) { $SQL = clone Gdn::sql(); $SQL->reset(); if (Gdn::session()->UserID) { $Key = 'UserCategory_' . Gdn::session()->UserID; $UserData = Gdn::cache()->get($Key); if ($UserData === Gdn_Cache::CACHEOP_FAILURE) { $UserData = $SQL->getWhere('UserCategory', array('UserID' => Gdn::session()->UserID))->resultArray(); $UserData = Gdn_DataSet::Index($UserData, 'CategoryID'); Gdn::cache()->store($Key, $UserData); } } else { $UserData = array(); } // Gdn::controller()->setData('UserData', $UserData); foreach ($IDs as $ID) { $Category = $Categories[$ID]; $DateMarkedRead = val('DateMarkedRead', $Category); $Row = val($ID, $UserData); if ($Row) { $UserDateMarkedRead = $Row['DateMarkedRead']; if (!$DateMarkedRead || $UserDateMarkedRead && Gdn_Format::toTimestamp($UserDateMarkedRead) > Gdn_Format::toTimestamp($DateMarkedRead)) { $Categories[$ID]['DateMarkedRead'] = $UserDateMarkedRead; $DateMarkedRead = $UserDateMarkedRead; } $Categories[$ID]['Unfollow'] = $Row['Unfollow']; } else { $Categories[$ID]['Unfollow'] = false; } // Calculate the following field. $Following = !((bool) val('Archived', $Category) || (bool) val('Unfollow', $Row, false)); $Categories[$ID]['Following'] = $Following; // Calculate the read field. if ($DoHeadings && $Category['Depth'] <= 1) { $Categories[$ID]['Read'] = false; } elseif ($DateMarkedRead) { if (val('LastDateInserted', $Category)) { $Categories[$ID]['Read'] = Gdn_Format::toTimestamp($DateMarkedRead) >= Gdn_Format::toTimestamp($Category['LastDateInserted']); } else { $Categories[$ID]['Read'] = true; } } else { $Categories[$ID]['Read'] = false; } } } // Add permissions. $Session = Gdn::session(); foreach ($IDs as $CID) { $Category = $Categories[$CID]; $Categories[$CID]['Url'] = url($Category['Url'], '//'); if ($Photo = val('Photo', $Category)) { $Categories[$CID]['PhotoUrl'] = Gdn_Upload::url($Photo); } if (!empty($Category['LastUrl'])) { $Categories[$CID]['LastUrl'] = url($Category['LastUrl'], '//'); } $Categories[$CID]['PermsDiscussionsView'] = $Session->checkPermission('Vanilla.Discussions.View', true, 'Category', $Category['PermissionCategoryID']); $Categories[$CID]['PermsDiscussionsAdd'] = $Session->checkPermission('Vanilla.Discussions.Add', true, 'Category', $Category['PermissionCategoryID']); $Categories[$CID]['PermsDiscussionsEdit'] = $Session->checkPermission('Vanilla.Discussions.Edit', true, 'Category', $Category['PermissionCategoryID']); $Categories[$CID]['PermsCommentsAdd'] = $Session->checkPermission('Vanilla.Comments.Add', true, 'Category', $Category['PermissionCategoryID']); } // Translate name and description foreach ($IDs as $ID) { $Code = $Categories[$ID]['UrlCode']; $Categories[$ID]['Name'] = TranslateContent("Categories." . $Code . ".Name", $Categories[$ID]['Name']); $Categories[$ID]['Description'] = TranslateContent("Categories." . $Code . ".Description", $Categories[$ID]['Description']); } }