/**
  * Render the module.
  *
  * @return string
  */
 public function ToString()
 {
     // Set CategoryID if we have one.
     if ($this->CategoryID === NULL) {
         $this->CategoryID = Gdn::Controller()->Data('Category.CategoryID', FALSE);
     }
     // Allow plugins and themes to modify parameters.
     Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this;
     Gdn::Controller()->FireEvent('BeforeNewDiscussionButton');
     // Make sure the user has the most basic of permissions first.
     $PermissionCategory = CategoryModel::PermissionCategory($this->CategoryID);
     if ($this->CategoryID) {
         $Category = CategoryModel::Categories($this->CategoryID);
         $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', GetValue('CategoryID', $PermissionCategory));
     } else {
         $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
     }
     // Determine if this is a guest & we're using "New Discussion" button as call to action.
     $PrivilegedGuest = $this->ShowGuests && !Gdn::Session()->IsValid();
     // No module for you!
     if (!$HasPermission && !$PrivilegedGuest) {
         return '';
     }
     // Grab the allowed discussion types.
     $DiscussionTypes = CategoryModel::AllowedDiscussionTypes($PermissionCategory);
     foreach ($DiscussionTypes as $Key => $Type) {
         if (isset($Type['AddPermission']) && !Gdn::Session()->CheckPermission($Type['AddPermission'])) {
             unset($DiscussionTypes[$Key]);
             continue;
         }
         // If user !$HasPermission, they are $PrivilegedGuest so redirect to $GuestUrl.
         $Url = $HasPermission ? GetValue('AddUrl', $Type) : $this->GuestUrl;
         if (!$Url) {
             continue;
         }
         if (isset($Category) && $HasPermission) {
             $Url .= '/' . rawurlencode(GetValue('UrlCode', $Category));
         }
         $this->AddButton(T(GetValue('AddText', $Type)), $Url);
     }
     // Add QueryString to URL if one is defined.
     if ($this->QueryString && $HasPermission) {
         foreach ($this->Buttons as &$Row) {
             $Row['Url'] .= (strpos($Row['Url'], '?') !== FALSE ? '&' : '?') . $this->QueryString;
         }
     }
     return parent::ToString();
 }
 public function ToString()
 {
     if ($this->CategoryID === NULL) {
         $this->CategoryID = Gdn::Controller()->Data('Category.CategoryID', FALSE);
     }
     Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this;
     Gdn::Controller()->FireEvent('BeforeNewDiscussionButton');
     // Make sure the user has the most basic of permissions first.
     $PermissionCategory = CategoryModel::PermissionCategory($this->CategoryID);
     if ($this->CategoryID) {
         $Category = CategoryModel::Categories($this->CategoryID);
         $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', GetValue('CategoryID', $PermissionCategory));
     } else {
         $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
     }
     if (!$HasPermission) {
         return '';
     }
     // Grab the allowed discussion types.
     $DiscussionTypes = CategoryModel::AllowedDiscussionTypes($PermissionCategory);
     foreach ($DiscussionTypes as $Key => $Type) {
         if (isset($Type['AddPermission']) && !Gdn::Session()->CheckPermission($Type['AddPermission'])) {
             unset($DiscussionTypes[$Key]);
             continue;
         }
         $Url = GetValue('AddUrl', $Type);
         if (!$Url) {
             continue;
         }
         if (isset($Category)) {
             $Url .= '/' . rawurlencode(GetValue('UrlCode', $Category));
         }
         $this->AddButton(T(GetValue('AddText', $Type)), $Url);
     }
     if ($this->QueryString) {
         foreach ($this->Buttons as &$Row) {
             $Row['Url'] .= (strpos($Row['Url'], '?') !== FALSE ? '&' : '?') . $this->QueryString;
         }
     }
     return parent::ToString();
 }