FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Hint.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Rsi\Fred;
4 
5 class Hint extends Component{
6 
7  public $transId = 'hint-*'; //!< An asterisk will be replaced with the widget ID or type.
8  public $closeCaption = null; //!< Caption for the close button (will be translated).
9  public $ignore = []; //!< ID's of hints to ignore (do not show - anymore).
10  public $ignoreAll = false; //!< Set to true to ignore all hints.
11  public $counts = [];
12 
13  protected $_hints = [];
14 
15  public function clientConfig(){
16  return array_merge(parent::clientConfig(),[
17  'hints' => $this->_hints,
18  'counts' => $this->counts,
19  'closeCaption' => $this->component('trans')->str($this->closeCaption)
20  ]);
21  }
22  /**
23  * Add a hint.
24  * @param string $id Unique ID for the hint.
25  * @param string $selector Selector for the hint (e.g. CSS selector for HTML view).
26  * @param int $from Show this hint from this presentation onwards (1 = do not show hint first time).
27  * @param int $limit Show this hint only for this amount of times (empty = no limit).
28  * @param array $config Extra config for the hint.
29  */
30  public function add($id,$selector,$from = 0,$limit = null,$config = null){
31  if(!$this->ignoreAll && !in_array($id,$this->ignore))
32  $this->_hints[$id] = array_merge(array_filter(compact('selector','from','limit')),$config ?: []);
33  }
34  /**
35  * Translate a hint.
36  * @param string $id Hint ID.
37  * @param int $count Presentation counter (0 on first presentation).
38  * @return string Translated hint.
39  */
40  public function trans($id,$count = null){
41  return $this->component('trans')->id(str_replace('*',$id,$this->transId),($this->_hints[$id] ?? []) + ['count' => $count]);
42  }
43 
44 }
$closeCaption
Caption for the close button (will be translated).
Definition: Hint.php:8
clientConfig()
Definition: Hint.php:15
$ignore
ID&#39;s of hints to ignore (do not show - anymore).
Definition: Hint.php:9
add($id, $selector, $from=0, $limit=null, $config=null)
Add a hint.
Definition: Hint.php:30
$ignoreAll
Set to true to ignore all hints.
Definition: Hint.php:10
trans($id, $count=null)
Translate a hint.
Definition: Hint.php:40
Basic component class.
Definition: Component.php:8
$transId
An asterisk will be replaced with the widget ID or type.
Definition: Hint.php:7
component($name)
Get a component (local or default).
Definition: Component.php:80