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 }
Rsi\Fred\Hint\add
add($id, $selector, $from=0, $limit=null, $config=null)
Add a hint.
Definition: Hint.php:30
Rsi\Fred\Hint\$closeCaption
$closeCaption
Caption for the close button (will be translated).
Definition: Hint.php:8
Rsi\Fred\Hint\trans
trans($id, $count=null)
Translate a hint.
Definition: Hint.php:40
Rsi\Fred\Hint
Definition: Hint.php:5
Rsi\Fred\Hint\$ignore
$ignore
ID's of hints to ignore (do not show - anymore).
Definition: Hint.php:9
Rsi\Fred\Hint\$transId
$transId
An asterisk will be replaced with the widget ID or type.
Definition: Hint.php:7
Rsi\Fred\Component
Basic component class.
Definition: Component.php:8
Rsi\Fred\Hint\clientConfig
clientConfig()
Public configuration.
Definition: Hint.php:15
Rsi\Fred\Component\component
component($name)
Get a component (local or default).
Definition: Component.php:81
Rsi\Fred\Hint\$_hints
$_hints
Definition: Hint.php:13
Rsi\Fred\Hint\$counts
$counts
Definition: Hint.php:11
Rsi\Fred\Hint\$ignoreAll
$ignoreAll
Set to true to ignore all hints.
Definition: Hint.php:10
Rsi\Fred
Definition: Alive.php:3