1<?php 2// Copyright (C) 2010-2015 Combodo SARL 3// 4// This file is part of iTop. 5// 6// iTop is free software; you can redistribute it and/or modify 7// it under the terms of the GNU Affero General Public License as published by 8// the Free Software Foundation, either version 3 of the License, or 9// (at your option) any later version. 10// 11// iTop is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU Affero General Public License for more details. 15// 16// You should have received a copy of the GNU Affero General Public License 17// along with iTop. If not, see <http://www.gnu.org/licenses/> 18 19/** 20 * A provider for messages to be displayed in the iTop Newsroom 21 */ 22interface iNewsroomProvider 23{ 24 /** 25 * Inject the current configuration in the provider 26 * @param Config $oConfig 27 * @return void 28 */ 29 public function SetConfig(Config $oConfig); 30 31 /** 32 * Tells if this provider is enabled for the given user 33 * @param User $oUser The user for who to check if the provider is applicable. 34 * return bool 35 */ 36 public function IsApplicable(User $oUser = null); 37 38 /** 39 * The human readable (localized) label for this provider 40 * @return string 41 */ 42 public function GetLabel(); 43 44 /** 45 * The URL to query (from the browser, using jsonp) to fetch all unread messages 46 * @return string 47 */ 48 public function GetFetchURL(); 49 50 /** 51 * The URL to navigate to in order to display all messages 52 * @return string 53 */ 54 public function GetViewAllURL(); 55 56 /** 57 * The URL to query(from the browser, using jsonp) to mark all unread messages as read 58 * @return string 59 */ 60 public function GetMarkAllAsReadURL(); 61 62 /** 63 * Return the URL to configure the preferences for this provider or null is there is nothing to configure 64 * @return string|null 65 */ 66 public function GetPreferencesUrl(); 67 68 /** 69 * Return an array key => value to be replaced in URL of the messages 70 * Example: '%itop_root%' => utils::GetAbsoluteUrlAppRoot(); 71 * @return string[] 72 */ 73 public function GetPlaceholders(); 74 75 /** 76 * The duration between to refreshes of the cache (in seconds) 77 * @return int 78 */ 79 public function GetTTL(); 80} 81 82/** 83 * Basic implementation of a Newsroom provider, to be overloaded by your own provider implementation 84 * 85 */ 86abstract class NewsroomProviderBase implements iNewsroomProvider 87{ 88 /** 89 * The current configuration parameters 90 * @var Config 91 */ 92 protected $oConfig; 93 94 public function __construct() 95 { 96 $this->oConfig = null; 97 } 98 99 /** 100 * {@inheritDoc} 101 * @see iNewsroomProvider::SetConfig() 102 */ 103 public function SetConfig(Config $oConfig) 104 { 105 $this->oConfig = $oConfig; 106 } 107 108 /** 109 * {@inheritDoc} 110 * @see iNewsroomProvider::GetPreferencesUrl() 111 */ 112 public function GetPreferencesUrl() 113 { 114 return null; // No preferences 115 } 116 117 /** 118 * {@inheritDoc} 119 * @see iNewsroomProvider::GetLabel() 120 */ 121 public abstract function GetLabel(); 122 123 /** 124 * {@inheritDoc} 125 * @see iNewsroomProvider::GetFetchURL() 126 */ 127 public abstract function GetFetchURL(); 128 129 /** 130 * {@inheritDoc} 131 * @see iNewsroomProvider::GetMarkAllURL() 132 */ 133 public abstract function GetMarkAllAsReadURL(); 134 135 /** 136 * {@inheritDoc} 137 * @see iNewsroomProvider::GetViewAllURL() 138 */ 139 public abstract function GetViewAllURL(); 140 141 public function IsApplicable(User $oUser = null) 142 { 143 return false; 144 } 145 146 /** 147 * {@inheritDoc} 148 * @see iNewsroomProvider::GetPlaceholders() 149 */ 150 public function GetPlaceholders() 151 { 152 return array(); // By default, empty set of placeholders 153 } 154 155 public function GetTTL() 156 { 157 return 10*60; // Refresh every 10 minutes 158 } 159} 160