1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/sources/system/controllers/AjaxController.php
2016-03-15 16:28:38 +01:00

75 lines
1.7 KiB
PHP

<?php
/**
* @file AjaxController.php
* This file is part of Movim.
*
* @brief Description
*
* @author Timothée jaussoin
*
* @date 14 November 2013
*/
class AjaxController extends BaseController
{
protected $funclist = array();
protected static $instance;
protected $widgetlist = array();
public function __construct()
{
parent::__construct();
}
public static function getInstance()
{
if(!is_object(self::$instance)) {
self::$instance = new AjaxController();
}
return self::$instance;
}
/**
* Generates the javascript part of the ajax.
*/
public function genJs()
{
if(empty($this->funclist)) {
return '';
}
$buffer = '<script type="text/javascript">';
foreach($this->funclist as $key => $funcdef) {
$parlist = implode(', ', $funcdef['params']);
$buffer .= "function " . $funcdef['object'] . '_'
. $funcdef['funcname'] . "(${parlist}) {";
$buffer .= "MovimWebsocket.send('".$funcdef['object']."', '".$funcdef['funcname']."', [${parlist}]);}\n";
}
return $buffer . "</script>\n";
}
/**
* Check if the widget is registered
*/
public function isRegistered($widget)
{
return array_key_exists($widget, $this->widgetlist);
}
/**
* Defines a new function.
*/
public function defun($widget, $funcname, array $params)
{
array_push($this->widgetlist, $widget);
$this->funclist[$widget.$funcname] = array(
'object' => $widget,
'funcname' => $funcname,
'params' => $params,
);
}
}
?>