noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Noalyss\Widget\Widget Class Reference

Main class for widget. More...

+ Inheritance diagram for Noalyss\Widget\Widget:
+ Collaboration diagram for Noalyss\Widget\Widget:

Public Member Functions

 __construct (protected int $user_widget_id=0, protected string $widget_code="", protected $db=null)
 
 button_zoom ()
 compute the button ZOOM to put in the title
 
 close_div ()
 
 display ()
 display the content for the current connected user of the widget with the parameter
 
 display_parameter ()
 MUST BE overrided if the widget needs extra parameters, display the content of extra-parameter.
 
 get_div_domid ()
 compute the DIV ID
 
 get_parameter ()
 get the parameter of the widget and returns an array
 
 get_user_widget_id ()
 
 get_widget_code ()
 
 input ($flnumber=true)
 display a description of the widget and allow to save it for the current user, call input_param function of the widget if it exists
 
 input_parameter ()
 MUST BE overrided if the widget needs extra parameters, create a FORM to add extra-parameter.
 
 make_form ($html_input)
 open a form with the DOMID "widget_code"_param, it appears once only for each widget in the dialog box for adding widget to the dashboard
 
 open_div ()
 output the DIV HTML with class and id for the widget
 
 set_user_widget_id (int $user_widget_id)
 
 set_widget_code (string $widget_code)
 
 title ( $title)
 display the title and the icon for zooming
 

Static Public Member Functions

static ajax_display (Widget $widget)
 display a box and fills it with the content of an ajax calls , the ajax calls Widget::display
 
static build_user_widget ($user_widget_id, $widget_code)
 Build a widget thank the user_widget_id (SQL :PK : USER_WIDGET.UW_ID) and $widget_code.
 
static display_available ()
 @brier display activated widgets
 
static get_enabled_widget ()
 returns an array of widget for the connected user, ordered
 
static save ($array)
 save widget order from an array
 
static scanfolder ()
 scan folder to find install.php file , include them if the code is not in DB
 
static select_available ()
 show all the widget that can be added
 

Detailed Description

Main class for widget.

Definition at line 31 of file widget.php.

Constructor & Destructor Documentation

◆ __construct()

Noalyss\Widget\Widget::__construct ( protected int $user_widget_id = 0,
protected string $widget_code = "",
protected $db = null )

Definition at line 34 of file widget.php.

35 {
36 if ($db == null) {
37 $this->db=\Dossier::connect();
38 }
39 }
$SecUser db

References db.

Member Function Documentation

◆ ajax_display()

static Noalyss\Widget\Widget::ajax_display ( Widget $widget)
static

display a box and fills it with the content of an ajax calls , the ajax calls Widget::display

Parameters
Widget$widget
Returns
void

Definition at line 177 of file widget.php.

177 {
178 $box= sprintf( '%s_%s',$widget->get_widget_code(),$widget->get_user_widget_id());
179 $widget->open_div();
180 echo h2(_("Un instant, on charge :-)"),' class="title" ');
181
182
183 print '<div style="display:flex;justify-content: center">';
184 print '<div style="margin-top: 50px;margin-left: 20px;">';
185 print '<div class="loading_msg"></div>';
186 print '<div class="loading_msg"></div>';
187 print '<div class="loading_msg"></div>';
188 print '<div class="loading_msg"></div>';
189 print '<div class="loading_msg"></div>';
190 print '</div>';
191 print '</div>';
192
193 $widget->close_div();
194
195 $dossier_id=\Dossier::id();
196 $widgetjs=uniqid('widget');
197 echo <<<EOF
198<script>
199var {$widgetjs}= new Widget('{$dossier_id}')
200{$widgetjs}.display('{$box}',{$widget->get_user_widget_id()},'{$widget->get_widget_code()}')
201</script>
202
203
204EOF;
205
206
207
208 }
h2($p_string, $p_class="", $raw="")
Definition ac_common.php:68
$dossier_id
_("actif, passif,charge,...")
print
Type of printing.

References $dossier_id, _, close_div(), display(), get_user_widget_id(), get_widget_code(), h2(), open_div(), and print.

+ Here is the call graph for this function:

◆ build_user_widget()

static Noalyss\Widget\Widget::build_user_widget ( $user_widget_id,
$widget_code )
static

Build a widget thank the user_widget_id (SQL :PK : USER_WIDGET.UW_ID) and $widget_code.

Parameters
$user_widget_idinteger (SQL :PK : USER_WIDGET.UW_ID)
$widget_codestring (SQL WIDGET_DASHBOARD.WD_CODE)
Returns
Widget

Definition at line 137 of file widget.php.

137 :?Widget
138 {
139 // load the class if file (code/code.php) exists.
140 if (file_exists(NOALYSS_INCLUDE."/widget/$widget_code/$widget_code.php")) {
141 require_once NOALYSS_INCLUDE."/widget/$widget_code/$widget_code.php";
142 $class=sprintf("\\Noalyss\\Widget\\%s",$widget_code);
143 $obj= new $class;
144 $obj->set_widget_code($widget_code);
145 $obj->set_user_widget_id($user_widget_id);
146 return $obj;
147 }
148
149 // return the object
150 return null;
151 }

References $class, and $obj.

Referenced by display_available(), and select_available().

◆ button_zoom()

Noalyss\Widget\Widget::button_zoom ( )

compute the button ZOOM to put in the title

Returns
\html

Definition at line 357 of file widget.php.

357 {
358 $bt = \Icon_Action::zoom(uniqid(), sprintf("widget.toggle_full_size('%s')",$this->get_div_domid()));
359 return $bt;
360 }

References get_div_domid(), and Icon_Action\zoom().

Referenced by title().

+ Here is the call graph for this function:

◆ close_div()

◆ display()

Noalyss\Widget\Widget::display ( )
abstract

◆ display_available()

static Noalyss\Widget\Widget::display_available ( )
static

@brier display activated widgets

Returns
void

Definition at line 214 of file widget.php.

215 {
216
217 $aWidget=Widget::get_enabled_widget();
218 echo '<ul class="list-unstyled" id="contain_widget">';
219 foreach ($aWidget as $item) {
220 $widget=Widget::build_user_widget($item['uw_id'],$item['wd_code']);
221 $widget->input();
222 }
223 echo '</ul>';
224 echo \HtmlInput::hidden("order_widget_hidden", "");
225 create_script("widget.create_sortable()");
226 }
$aWidget
Definition dashboard.php:28
create_script($p_string)
create the HTML for adding the script tags around of the script

References $aWidget, build_user_widget(), create_script(), and get_enabled_widget().

+ Here is the call graph for this function:

◆ display_parameter()

Noalyss\Widget\Widget::display_parameter ( )

MUST BE overrided if the widget needs extra parameters, display the content of extra-parameter.

Parameters
$user_widget_id
Returns
void
Exceptions

Exception

Reimplemented in Noalyss\Widget\Invoice, and Noalyss\Widget\Mini_Report.

Definition at line 311 of file widget.php.

311 {
312 throw new \Exception(__FUNCTION__." not implemented");
313 }

Referenced by input().

◆ get_div_domid()

Noalyss\Widget\Widget::get_div_domid ( )

compute the DIV ID

Returns
string

Definition at line 165 of file widget.php.

165 :string {
166 return sprintf( "%s_%s",$this->widget_code,$this->user_widget_id);
167 }

References return.

Referenced by button_zoom(), Noalyss\Widget\Mini_Report\display(), and open_div().

◆ get_enabled_widget()

static Noalyss\Widget\Widget::get_enabled_widget ( )
static

returns an array of widget for the connected user, ordered

Returns
array [ uw_id,dashboard_widget_id,wd_code,wd_description

Definition at line 115 of file widget.php.

115 :array
116 {
117 global $g_user,$cn;
118 return $cn->get_array("
119 select
120 uw.uw_id,
121 uw.dashboard_widget_id ,
122 wd.wd_code,
123 wd.wd_description
124 from user_widget uw
125join widget_dashboard wd on (uw.dashboard_widget_id=wd.wd_id)
126where use_login=$1 order by uw.uw_order
127",[$g_user->login]);
128
129 }
global $g_user
if no group available , then stop

References $cn, and $g_user.

Referenced by display_available().

◆ get_parameter()

Noalyss\Widget\Widget::get_parameter ( )

get the parameter of the widget and returns an array

Returns
array key=>value

Definition at line 345 of file widget.php.

346 {
347 $param = $this->db->get_value("select uw_parameter from user_widget where uw_id=$1",[$this->user_widget_id]);
348 if (empty ($param)) return [];
349 parse_str($param,$aParam);
350 return $aParam;
351 }

References db.

Referenced by Noalyss\Widget\Invoice\display(), Noalyss\Widget\Invoice\display_parameter(), and Noalyss\Widget\Mini_Report\display_parameter().

◆ get_user_widget_id()

Noalyss\Widget\Widget::get_user_widget_id ( )

Definition at line 41 of file widget.php.

41 : int
42 {
43 return $this->user_widget_id;
44 }

Referenced by ajax_display().

◆ get_widget_code()

Noalyss\Widget\Widget::get_widget_code ( )

Definition at line 52 of file widget.php.

52 : string
53 {
54 return $this->widget_code;
55 }

Referenced by ajax_display().

◆ input()

Noalyss\Widget\Widget::input ( $flnumber = true)

display a description of the widget and allow to save it for the current user, call input_param function of the widget if it exists

Returns
mixed

Definition at line 74 of file widget.php.

75 {
76 static $nb=0;
77 $nb++;
78 //read description from database
79 $row=$this->db->get_row("
80 select
81 wd_code
82 ,wd_name
83 ,wd_parameter,
84 wd_description
85 from
86 widget_dashboard
87 where
88 wd_code=$1",
89 [$this->widget_code]);
90 $strNumber="";
91 if ( $flnumber) $strNumber="[ $nb ]";
92 echo "<li id=\"elt_{$this->user_widget_id}\"> $strNumber <span class='widget-name'>{$row['wd_name']}</span>{$row['wd_description']}";
93
94 if ( $this->user_widget_id > 0) {
95 if ( $row['wd_parameter'] == 1) {
96 $this->display_parameter();
97 }
98 echo '<span style="float:right;color:red">'.\Icon_Action::trash(uniqid(),sprintf("widget.delete('%s')",$this->user_widget_id));
99 }
100 else {
101 if ( $row['wd_parameter'] == 1) {
102 $this->input_parameter();
103 }
104 echo '<span style="float:right;">'.\Icon_Action::icon_add(uniqid(),sprintf("widget.add('%s')",$this->widget_code));
105 }
106
107 echo '</span>';
108 echo '</li>';
109 }

References $nb, $row, db, display_parameter(), and input_parameter().

+ Here is the call graph for this function:

◆ input_parameter()

Noalyss\Widget\Widget::input_parameter ( )

MUST BE overrided if the widget needs extra parameters, create a FORM to add extra-parameter.

Returns
void
Exceptions

Exception

Reimplemented in Noalyss\Widget\Invoice, and Noalyss\Widget\Mini_Report.

Definition at line 299 of file widget.php.

300 {
301 throw new \Exception(__FUNCTION__." not implemented");
302 }

Referenced by input().

◆ make_form()

Noalyss\Widget\Widget::make_form ( $html_input)

open a form with the DOMID "widget_code"_param, it appears once only for each widget in the dialog box for adding widget to the dashboard

Parameters
$html_inputstring HTML string with all the HTML INPUT that will be enclosed by the FORM
Returns
void

Definition at line 287 of file widget.php.

288 {
289 printf ('<form id="%s_param" style="display:inline">',$this->widget_code);
290 echo $html_input;
291 printf ('</form>');
292 }

Referenced by Noalyss\Widget\Invoice\input_parameter(), and Noalyss\Widget\Mini_Report\input_parameter().

◆ open_div()

Noalyss\Widget\Widget::open_div ( )

output the DIV HTML with class and id for the widget

Returns
void

Definition at line 157 of file widget.php.

157 {
158 printf( '<div id="%s" class="box widget-box">',$this->get_div_domid());
159 }

References get_div_domid().

Referenced by ajax_display(), Noalyss\Widget\Agenda\display(), Noalyss\Widget\Bookmark\display(), Noalyss\Widget\Coming_Event\display(), Noalyss\Widget\Event\display(), Noalyss\Widget\Invoice\display(), Noalyss\Widget\Last_Event\display(), Noalyss\Widget\Last_Operation\display(), and Noalyss\Widget\Mini_Report\display().

+ Here is the call graph for this function:

◆ save()

static Noalyss\Widget\Widget::save ( $array)
static

save widget order from an array

Parameters
$arrayarray of USER_WIDGET.UW_ID
Returns
void
Exceptions
DatabaseCorefails , cannot update

Definition at line 234 of file widget.php.

234 {
235 global $cn,$g_user;
236 if (empty($array)) {
237 $cn->exec_sql("delete from user_widget where use_login = $1",[$g_user->getLogin()]);
238 return;
239 }
240 try {
241 $cn->start();
242 $order=10;
243 $cn->exec_sql("create temporary table tmp_widget(user_widget_id integer,tw_order integer )");
244 foreach ($array as $item) {
245 $cn->exec_sql('insert into tmp_widget(user_widget_id,tw_order ) values ($1,$2)',
246 [$item,$order]);
247 $order+=20;
248 }
249 $cn->exec_sql("delete from user_widget where use_login = $1 and uw_id not in (select user_widget_id from tmp_widget)",
250 array($g_user->getLogin()));
251
252 $cn->exec_sql("update user_widget set uw_order =tw_order from tmp_widget where user_widget_id=uw_id");
253
254 $cn->commit();
255
256 } catch (\Exception $e) {
257 throw ($e);
258 }
259
260
261 }

References $array, $cn, $e, $g_user, and $order.

◆ scanfolder()

static Noalyss\Widget\Widget::scanfolder ( )
static

scan folder to find install.php file , include them if the code is not in DB

Returns
void

Definition at line 319 of file widget.php.

320 {
321 global $cn;
322 $handle=opendir(NOALYSS_INCLUDE."/widget");
323 while (($dir = readdir($handle)) != false ) {
324 $directory=NOALYSS_INCLUDE."/widget".DIRECTORY_SEPARATOR.$dir;
325 if (is_dir($directory) && $dir != "." && $dir != "..") {
326 // code exists in DB ?
327 $cnt=$cn->get_value("select count(*) from widget_dashboard where wd_code = $1",[$dir]);
328 if ( $cnt > 0) {
329 continue;
330 } else {
331 // include the install.php file if any and install the widget
332 if (file_exists($directory . DIRECTORY_SEPARATOR . "install.php")){
333 include $directory . DIRECTORY_SEPARATOR . "install.php";
334 }
335 }
336 }
337 }
338
339 }

References $cn.

Referenced by select_available().

◆ select_available()

static Noalyss\Widget\Widget::select_available ( )
static

show all the widget that can be added

Returns
void

Definition at line 267 of file widget.php.

268 {
269 global $cn;
270 Widget::scanfolder();
271 $aWidget=$cn->get_array("select wd_code,wd_name, wd_description,wd_parameter from widget_dashboard order by wd_name");
272 echo '<ul id="widget_add" class="list-unstyled">';
273 foreach ($aWidget as $item) {
274 $widget=Widget::build_user_widget(-1,$item['wd_code']);
275 $widget?->input(false);
276
277 }
278 echo '</ul>';
279 }

References $aWidget, $cn, build_user_widget(), and scanfolder().

+ Here is the call graph for this function:

◆ set_user_widget_id()

Noalyss\Widget\Widget::set_user_widget_id ( int $user_widget_id)

Definition at line 46 of file widget.php.

46 : Widget
47 {
48 $this->user_widget_id = $user_widget_id;
49 return $this;
50 }

◆ set_widget_code()

Noalyss\Widget\Widget::set_widget_code ( string $widget_code)

Definition at line 57 of file widget.php.

57 : Widget
58 {
59 $this->widget_code = $widget_code;
60 return $this;
61 }

◆ title()

Noalyss\Widget\Widget::title ( $title)

display the title and the icon for zooming

Parameters
$titlestring title of the widget

Definition at line 365 of file widget.php.

365 {
366
367 $r='<div class="bxbutton">';
368 $r.='<span id="span_'.uniqid().'" style="float:right;margin-right:5px">'.$this->button_zoom()."</span>";
369 $r.='</div>';
370 $r.=sprintf('<h2 class="title">%s</h2>',$title);
371 echo $r;
372 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r

References $r, $title, and button_zoom().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: