noalyss Version-10
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_var_name ()
 
 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_var_name ($var_name)
 
 set_widget_code (string $widget_code)
 
 title ( $title)
 display the title and the icon for zooming + refresh if possible
 

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_refresh_js ($widget_code, $widget_id, $var_name)
 build refresh javascript
 
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
 

Protected Attributes

 $var_name
 < $var_name string name of the variable in javascript
 

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 38 of file widget.php.

39 {
40 if ($db == null) {
41 $this->db=\Dossier::connect();
42 }
43 $this->var_name='';
44 }
$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 199 of file widget.php.

199 {
200 $box= sprintf( '%s_%s',$widget->get_widget_code(),$widget->get_user_widget_id());
201 $widget->open_div();
202 echo h2(_("Un instant, on charge :-)"),' class="title" ');
203
204
205 print '<div style="display:flex;justify-content: center">';
206 print '<div style="margin-top: 50px;margin-left: 20px;">';
207 print '<div class="loading_msg"></div>';
208 print '<div class="loading_msg"></div>';
209 print '<div class="loading_msg"></div>';
210 print '<div class="loading_msg"></div>';
211 print '<div class="loading_msg"></div>';
212 print '</div>';
213 print '</div>';
214
215 $widget->close_div();
216
217 $dossier_id=\Dossier::id();
218 $widgetjs=uniqid('widget');
219 echo <<<EOF
220<script>
221var {$widgetjs}= new Widget('{$dossier_id}')
222{$widgetjs}.display('{$box}',{$widget->get_user_widget_id()},'{$widget->get_widget_code()}','{$widgetjs}')
223</script>
224
225
226EOF;
227
228
229
230 }
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_refresh_js()

static Noalyss\Widget\Widget::build_refresh_js ( $widget_code,
$widget_id,
$var_name )
static

build refresh javascript

Parameters
$widget_idint id from DB
$widget_codestring code of the widget
$var_namestring name of the js variable

Definition at line 410 of file widget.php.

411 {
412 // var $box string DOM ID of the DIV containing the widget
413 $box= sprintf( '%s_%s',$widget_code,$widget_id);
414 $refresh=sprintf("%s.display('%s','%s','%s','%s')",
415 $var_name,
416 $box,
417 $widget_id,
418 $widget_code,
419 $var_name
420 );
421 return $refresh;
422 }

References $refresh, and $var_name.

Referenced by Noalyss\Widget\Agenda\display(), Noalyss\Widget\Last_Operation\display(), and title().

◆ 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 159 of file widget.php.

159 :?Widget
160 {
161 // load the class if file (code/code.php) exists.
162 if (file_exists(NOALYSS_INCLUDE."/widget/$widget_code/$widget_code.php")) {
163 require_once NOALYSS_INCLUDE."/widget/$widget_code/$widget_code.php";
164 $class=sprintf("\\Noalyss\\Widget\\%s",$widget_code);
165 $obj= new $class;
166 $obj->set_widget_code($widget_code);
167 $obj->set_user_widget_id($user_widget_id);
168 return $obj;
169 }
170
171 // return the object
172 return null;
173 }
catch(Exception $e) $obj
$class
Display the Plugin and for each profile were it is installed or not.

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 379 of file widget.php.

379 {
380 $bt = \Icon_Action::zoom(uniqid(), sprintf("widget.toggle_full_size('%s')",$this->get_div_domid()));
381 return $bt;
382 }

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 236 of file widget.php.

237 {
238
239 $aWidget=Widget::get_enabled_widget();
240 echo '<ul class="list-unstyled" id="contain_widget">';
241 foreach ($aWidget as $item) {
242 $widget=Widget::build_user_widget($item['uw_id'],$item['wd_code']);
243 $widget->input();
244 }
245 echo '</ul>';
246 echo \HtmlInput::hidden("order_widget_hidden", "");
247 create_script("widget.create_sortable()");
248 }
$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 333 of file widget.php.

333 {
334 throw new \Exception(__FUNCTION__." not implemented");
335 }

Referenced by input().

◆ get_div_domid()

Noalyss\Widget\Widget::get_div_domid ( )

compute the DIV ID

Returns
string

Definition at line 187 of file widget.php.

187 :string {
188 return sprintf( "%s_%s",$this->widget_code,$this->user_widget_id);
189 }

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 137 of file widget.php.

137 :array
138 {
139 global $g_user,$cn;
140 return $cn->get_array("
141 select
142 uw.uw_id,
143 uw.dashboard_widget_id ,
144 wd.wd_code,
145 wd.wd_description
146 from user_widget uw
147join widget_dashboard wd on (uw.dashboard_widget_id=wd.wd_id)
148where use_login=$1 order by uw.uw_order
149",[$g_user->login]);
150
151 }
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 367 of file widget.php.

368 {
369 $param = $this->db->get_value("select uw_parameter from user_widget where uw_id=$1",[$this->user_widget_id]);
370 if (empty ($param)) return [];
371 parse_str($param,$aParam);
372 return $aParam;
373 }

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 63 of file widget.php.

63 : int
64 {
65 return $this->user_widget_id;
66 }

Referenced by ajax_display(), Noalyss\Widget\Agenda\display(), and title().

◆ get_var_name()

Noalyss\Widget\Widget::get_var_name ( )
Returns
mixed

Definition at line 49 of file widget.php.

50 {
51 return $this->var_name;
52 }

References $var_name.

Referenced by Noalyss\Widget\Agenda\display(), Noalyss\Widget\Last_Operation\display(), and title().

◆ get_widget_code()

Noalyss\Widget\Widget::get_widget_code ( )

Definition at line 74 of file widget.php.

74 : string
75 {
76 return $this->widget_code;
77 }

Referenced by ajax_display(), Noalyss\Widget\Agenda\display(), and title().

◆ 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 96 of file widget.php.

97 {
98 static $nb=0;
99 $nb++;
100 //read description from database
101 $row=$this->db->get_row("
102 select
103 wd_code
104 ,wd_name
105 ,wd_parameter,
106 wd_description
107 from
108 widget_dashboard
109 where
110 wd_code=$1",
111 [$this->widget_code]);
112 $strNumber="";
113 if ( $flnumber) $strNumber="[ $nb ]";
114 echo "<li id=\"elt_{$this->user_widget_id}\"> $strNumber <span class='widget-name'>{$row['wd_name']}</span>{$row['wd_description']}";
115
116 if ( $this->user_widget_id > 0) {
117 if ( $row['wd_parameter'] == 1) {
118 $this->display_parameter();
119 }
120 echo '<span style="float:right;color:red">'.\Icon_Action::trash(uniqid(),sprintf("widget.delete('%s')",$this->user_widget_id));
121 }
122 else {
123 if ( $row['wd_parameter'] == 1) {
124 $this->input_parameter();
125 }
126 echo '<span style="float:right;">'.\Icon_Action::icon_add(uniqid(),sprintf("widget.add('%s')",$this->widget_code));
127 }
128
129 echo '</span>';
130 echo '</li>';
131 }

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 321 of file widget.php.

322 {
323 throw new \Exception(__FUNCTION__." not implemented");
324 }

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 309 of file widget.php.

310 {
311 printf ('<form id="%s_param" style="display:inline">',$this->widget_code);
312 echo $html_input;
313 printf ('</form>');
314 }

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 179 of file widget.php.

179 {
180 printf( '<div id="%s" class="box widget-box">',$this->get_div_domid());
181 }

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 256 of file widget.php.

256 {
257 global $cn,$g_user;
258 if (empty($array)) {
259 $cn->exec_sql("delete from user_widget where use_login = $1",[$g_user->getLogin()]);
260 return;
261 }
262 try {
263 $cn->start();
264 $order=10;
265 $cn->exec_sql("create temporary table tmp_widget(user_widget_id integer,tw_order integer )");
266 foreach ($array as $item) {
267 $cn->exec_sql('insert into tmp_widget(user_widget_id,tw_order ) values ($1,$2)',
268 [$item,$order]);
269 $order+=20;
270 }
271 $cn->exec_sql("delete from user_widget where use_login = $1 and uw_id not in (select user_widget_id from tmp_widget)",
272 array($g_user->getLogin()));
273
274 $cn->exec_sql("update user_widget set uw_order =tw_order from tmp_widget where user_widget_id=uw_id");
275
276 $cn->commit();
277
278 } catch (\Exception $e) {
279 throw ($e);
280 }
281
282
283 }

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 341 of file widget.php.

342 {
343 global $cn;
344 $handle=opendir(NOALYSS_INCLUDE."/widget");
345 while (($dir = readdir($handle)) != false ) {
346 $directory=NOALYSS_INCLUDE."/widget".DIRECTORY_SEPARATOR.$dir;
347 if (is_dir($directory) && $dir != "." && $dir != "..") {
348 // code exists in DB ?
349 $cnt=$cn->get_value("select count(*) from widget_dashboard where wd_code = $1",[$dir]);
350 if ( $cnt > 0) {
351 continue;
352 } else {
353 // include the install.php file if any and install the widget
354 if (file_exists($directory . DIRECTORY_SEPARATOR . "install.php")){
355 include $directory . DIRECTORY_SEPARATOR . "install.php";
356 }
357 }
358 }
359 }
360
361 }
for($i=0; $i< $nb_vatex_code; $i++)($i % 2==0) ? " odd " $cnt
$directory
Definition test.php:75

References $cn, $cnt, and $directory.

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 289 of file widget.php.

290 {
291 global $cn;
292 Widget::scanfolder();
293 $aWidget=$cn->get_array("select wd_code,wd_name, wd_description,wd_parameter from widget_dashboard order by wd_name");
294 echo '<ul id="widget_add" class="list-unstyled">';
295 foreach ($aWidget as $item) {
296 $widget=Widget::build_user_widget(-1,$item['wd_code']);
297 $widget?->input(false);
298
299 }
300 echo '</ul>';
301 }

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 68 of file widget.php.

68 : Widget
69 {
70 $this->user_widget_id = $user_widget_id;
71 return $this;
72 }

◆ set_var_name()

Noalyss\Widget\Widget::set_var_name ( $var_name)
Parameters
mixed$var_name

Definition at line 57 of file widget.php.

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

References $var_name.

◆ set_widget_code()

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

Definition at line 79 of file widget.php.

79 : Widget
80 {
81 $this->widget_code = $widget_code;
82 return $this;
83 }

◆ title()

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

display the title and the icon for zooming + refresh if possible

Parameters
$titlestring title of the widget

Definition at line 387 of file widget.php.

387 {
388 // var $refresh string javascript to refresh the widget
389 $refresh='';
390 if ( $this->get_var_name() !="") {
391 $refresh=Widget::build_refresh_js( $this->get_widget_code(),
392 $this->get_user_widget_id(),
393 $this->get_var_name());
394
395 }
396
397 $r='<div class="bxbutton">';
398 $r.=\Icon_Action::refresh(uniqid(), $refresh);
399 $r.='<span id="span_'.uniqid().'" style="float:right;margin-right:5px">'.$this->button_zoom()."</span>";
400 $r.='</div>';
401 $r.=sprintf('<h2 class="title">%s</h2>',$title);
402 echo $r;
403 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r

References $r, $refresh, $title, build_refresh_js(), button_zoom(), get_user_widget_id(), get_var_name(), get_widget_code(), and Icon_Action\refresh().

+ Here is the call graph for this function:

Field Documentation

◆ $var_name

Noalyss\Widget\Widget::$var_name
protected

< $var_name string name of the variable in javascript

Definition at line 34 of file widget.php.

Referenced by build_refresh_js(), get_var_name(), and set_var_name().


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