/** * Get what messages are active for a template location. * * @param $Location * @param array $Exceptions * @param null $CategoryID * @return array|null */ public function getMessagesForLocation($Location, $Exceptions = array('[Base]'), $CategoryID = null) { $Session = Gdn::session(); $Prefs = $Session->getPreference('DismissedMessages', array()); if (count($Prefs) == 0) { $Prefs[] = 0; } $Exceptions = array_map('strtolower', $Exceptions); list($Application, $Controller, $Method) = explode('/', strtolower($Location)); if (Gdn::cache()->activeEnabled()) { // Get the messages from the cache. $Messages = self::messages(); $Result = array(); foreach ($Messages as $MessageID => $Message) { if (in_array($MessageID, $Prefs) || !$Message['Enabled']) { continue; } $MApplication = strtolower($Message['Application']); $MController = strtolower($Message['Controller']); $MMethod = strtolower($Message['Method']); $Visible = false; if (in_array($MController, $Exceptions)) { $Visible = true; } elseif ($MApplication == $Application && $MController == $Controller && $MMethod == $Method) { $Visible = true; } if ($Visible && !self::inCategory($CategoryID, val('CategoryID', $Message), val('IncludeSubcategories', $Message))) { $Visible = false; } if ($Visible) { $Result[] = $Message; } } return $Result; } $Result = $this->SQL->select()->from('Message')->where('Enabled', '1')->beginWhereGroup()->whereIn('Controller', $Exceptions)->orOp()->beginWhereGroup()->orWhere('Application', $Application)->where('Controller', $Controller)->where('Method', $Method)->endWhereGroup()->endWhereGroup()->whereNotIn('MessageID', $Prefs)->orderBy('Sort', 'asc')->get()->resultArray(); $Result = array_filter($Result, function ($Message) use($CategoryID) { return MessageModel::inCategory($CategoryID, val('CategoryID', $Message), val('IncludeSubcategories', $Message)); }); return $Result; }