From 76d8c8f91bf6cf1589a6fc32941f38fdd81363dd Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 8 Apr 2016 18:06:50 +0200 Subject: [PATCH] - [x] Graphique de type #FIELD - [x] Definition des donnees - [x] Definition graphique + implementation --- config/modules.json | 7 + manager/module/charts.php | 161 ++++++++++++++ manager/module/machineDefault.php | 345 ------------------------------ view/charts.php | 48 ++++- view/dashboard.php | 2 +- 5 files changed, 207 insertions(+), 356 deletions(-) create mode 100644 manager/module/charts.php delete mode 100755 manager/module/machineDefault.php diff --git a/config/modules.json b/config/modules.json index e087254..01a4320 100755 --- a/config/modules.json +++ b/config/modules.json @@ -6,6 +6,13 @@ ], + "charts": [ + + "field_data", + "field_render" + + ], + "userDefault" :[ "create", diff --git a/manager/module/charts.php b/manager/module/charts.php new file mode 100644 index 0000000..fca1d81 --- /dev/null +++ b/manager/module/charts.php @@ -0,0 +1,161 @@ + 17, + + /* (2) Liste des alters */ + 'alter' => array( + // Pour chaque alter, on a ID_ALTER, NOM_ALTER, AFFINITE_ALTER + array(15, 'Jean', 90), // 90% proche + array(3, 'George', 20), + array(18, 'Jacques', 30), + array(11, 'Jacquie', 40), + array(1, 'Martin', 50), + array(12, 'Martine', 60) + ), + + /* (1) Liste des relations */ + 'inter' => array( + array(15, 3), // Jean connait George + array(15, 1), // Jean connait Martin + array(12, 18), // Martine connait Jacques + ) + + ); + + + /* [5] Gestion du retour + =========================================================*/ + return array( + 'ModuleError' => ManagerError::Success, + 'data' => $data + ); + } + + + + + + + + + + + + /* RETOURNE UN SVG CORRESPONDANT AU GRAPHIQUE #FIELD + * + * @data Jeu de donnees + * + * @return render Contenu du svg representation graphique des donnees + * + */ + public static function field_render($data){ + + + + + debug(); + + + + + + $render = ""; + /* [1] On genere le debut du svg + =========================================================*/ + $render .= ''; + $render .= ''; + + /* [2] On cree le contexte (cercles dont ego) + =========================================================*/ + $ego = ""; + $close = ""; + $veryclose = ""; + + + /* [3] On cree les elements dynamiques + =========================================================*/ + /* (1) On calcule l'angle de diff entre chaque ALTER */ + $ang = 2*pi() / count($data['alter']); + + /* (2) On ajoute tous les alters */ + $alters = array(); + $origins = array(); + foreach($data['alter'] as $i=>$alter){ + // On calcule l'origine (centre du cercle) + $origins[$alter[0]] = array( + 'x' => 500 + (100-$alter[2])*(400/100) * cos($ang*$i), + 'y' => 500 + (100-$alter[2])*(400/100) * sin($ang*$i) + ); + + // On ajoute le cercle associe a l'alter courant + $alters[$i] = ""; + + } + + + /* [4] On relie toutes les relations + =========================================================*/ + $inter = array(); + foreach($data['inter'] as $rel){ + $lefthand = isset($origins[$rel[0]]) && is_array($origins[$rel[0]]); + $righthand = isset($origins[$rel[1]]) && is_array($origins[$rel[1]]); + + // Si les deux existent, on les relie + if( $lefthand && $righthand ) + array_push($inter, + "" + ); + } + + + + /* [5] On ajoute les elements et on ferme le svg + =========================================================*/ + $render .= $close; + $render .= $veryclose; + foreach($inter as $rel) $render .= $rel; // les relations + foreach($alters as $alter) $render .= $alter; // les alters + $render .= $ego; + + $render .= ""; + + + /* [6] Gestion du retour + =========================================================*/ + return array( + 'ModuleError' => ManagerError::Success, + 'render' => $render + ); + } + + + + + + + + + + + + } + + +?> \ No newline at end of file diff --git a/manager/module/machineDefault.php b/manager/module/machineDefault.php deleted file mode 100755 index 2aa4c61..0000000 --- a/manager/module/machineDefault.php +++ /dev/null @@ -1,345 +0,0 @@ - Code RFID de la machine - * @name Identifiant de la machine - * - * @return status Retourne si oui ou non, tout s'est bien passe - * - */ - public static function create($code=null, $name=null){ - /* [1] Normalisation + verification des donnees - =========================================================*/ - $correct_param = Database::check('machine.code', $code); - $correct_param = $correct_param && Database::check('machine.name', $name); - - // Si les parametres ne sont pas corrects, on retourne une erreur - if( !$correct_param ) - return array('ModuleError' => ManagerError::ParamError); - - - - - /* [2] Creation de la machine - =========================================================*/ - $create_machine = new Repo('machine/create', array($code, $name) ); - $id_machine = $create_machine->answer(); - - // Si une erreur est retournee, on retourne une erreur - if( $id_machine === false ) - return array('ModuleError' => ManagerError::ModuleError); - - - - - /* [3] Creation du groupe de meme nom que la machine - =========================================================*/ - $create_group = new Repo('cluster/create', array($name) ); - $id_group = $create_group->answer(); - - // Si une erreur est retournee, on retourne une erreur - if( $id_group === false ) - return array('ModuleError' => ManagerError::ModuleError); - - - - - /* [4] Association au groupe - =========================================================*/ - $assoc_goup = new Repo('cluster/link', array($id_group, $id_machine, clusterRepo::MACHINE_CLASS)); - $id_assoc = $assoc_goup->answer(); - - // Si une erreur est retournee, on retourne une erreur - if( $id_assoc === false ) - return array('ModuleError' => ManagerError::ModuleError); - - - - /* [5] Gestion du retour - =========================================================*/ - return array( - 'ModuleError' => ManagerError::Success, - 'id_machine' => $id_machine, - 'id_cluster' => $id_group - ); - } - - - - - - /* AJOUTE UNE MACHINE DONNEE A UN GROUPE DONNE - * - * @id_cluster UID du groupe - * @id_machine UID de la machine - * - * @return association Renvoie l'UID de l'association cree - * Renvoie FALSE si une erreur occure - * - */ - public static function link($id_cluster, $id_machine){ - /* [1] Normalisation + verification des donnees - =========================================================*/ - $correct_param = Database::check('auto_increment_id', $id_cluster); - $correct_param = $correct_param && Database::check('auto_increment_id', $id_machine); - - // Si les parametres ne sont pas corrects, on retourne une erreur - if( !$correct_param ) - return array('ModuleError' => ManagerError::ParamError); - - /* [2] Creation de l'association - =========================================================*/ - $link_machine = new Repo('cluster/link', array($id_cluster, $id_machine, clusterRepo::MACHINE_CLASS)); - - return $link_machine; - - } - - - - - - /* RETIRE UNE MACHINE DONNEE A UN GROUPE DONNE - * - * @id_cluster UID du groupe - * @id_machine UID de la machine - * - * @return association Renvoie l'UID de l'association cree - * Renvoie FALSE si une erreur occure - * - */ - public static function unlink($id_cluster, $id_machine){ - /* [1] Normalisation + verification des donnees - =========================================================*/ - $correct_param = Database::check('auto_increment_id', $id_cluster); - $correct_param = $correct_param && Database::check('auto_increment_id', $id_machine); - - // Si les parametres ne sont pas corrects, on retourne une erreur - if( !$correct_param ) - return array('ModuleError' => ManagerError::ParamError); - - /* [2] Suppression de l'association - =========================================================*/ - $link_machine = new Repo('cluster/unlink', array($id_cluster, $id_machine, clusterRepo::MACHINE_CLASS)); - - return $link_machine; - - } - - - - - - /* RENVOIE UNE MACHINE EN FONCTION D'UN MOT CLE - * - * @keyword Element de recherche - * - * @return machines Retourne la liste des machines trouvees - * - */ - public static function search($keyword){ - // On recupere les donnees - $machine = new Repo('machine/search', array($keyword)); - - return array( - 'machines' => $machine->answer() - ); - } - - - - - - /* RENVOIE LA LISTE EXHAUSTIVE DES MACHINES - * - * @return machines Liste des machines - * - */ - public static function getAll(){ - // On recupere les donnees - $machines = new Repo('machine/getAll'); - - return array( - 'machines' => $machines->answer() - ); - } - - - - - - /* RENVOIE LA MACHINE D'UID DONNE - * - * @id_machine UID de la machine en question - * - * @return machine Machine d'UID donne - * - */ - public static function getById($id_machine){ - // On recupere les donnees - $request = new Repo('machine/getById', array($id_machine)); - $answer = $request->answer(); - - // Si aucun resultat, on retourne une erreur - if( $answer === false ) - return array( 'ModuleError' => ManagerError::ModuleError ); - - - return array( - 'machine' => $answer - ); - } - - - - - - /* RENVOIE LA MACHINE DE CODE DONNE - * - * @code Code de la machine en question - * - * @return machine Machine de code donne - * - */ - public static function getByCode($code){ - // On recupere les donnees - $request = new Repo('machine/getByCode', array($code)); - $answer = $request->answer(); - - // Si aucun resultat, on retourne une erreur - if( $answer === false ) - return array( 'ModuleError' => ManagerError::ModuleError ); - - - return array( - 'machine' => $answer - ); - } - - - - - - /* RENVOIE LES GROUPES D'UNE MACHINE DONNEE - * - * @id_machine UID de la machine en question - * - * @return clusters Groupes de la machine donne - * - */ - public static function getClusters($id_machine){ - // On recupere les donnees - $request = new Repo('machine/getClusters', array($id_machine)); - $answer = $request->answer(); - - // Si aucun resultat, on retourne une erreur - if( $answer === false ) - return array( 'ModuleError' => ManagerError::ModuleError ); - - - return array( - 'clusters' => $answer - ); - } - - - - - - /* MODIFIE UNE MACHINE DONNEE - * - * @id_machine UID de la machine - * @code Code RFID de la machine - * @name Identifiant l'utilisateur - * - * @return status Retourne si oui ou non tout s'est bien deroule - * - */ - public static function edit($id_machine=null, $code=null, $name=null){ - // Si @id_machine n'est pas au bon format, on retourne une erreur - if( !Database::check('auto_increment_id', $id_machine) ) - return array('ModuleError' => ManagerError::ModuleError); - - - /* [1] On verifie l'existence de la machine - =========================================================*/ - $machine_exists = new Repo('machine/getById', array($id_machine)); - $machine_data = $machine_exists->answer(); - - // Si on a recupere aucune machine, on retourne une erreur - if( !is_array($machine_data) ) - return array('ModuleError' => ManagerError::ModuleError); - - - - - /* [2] Normalisation + verification des donnees - =========================================================*/ - - /* (1) Verification des parametres (si correct et different)*/ - $correct_param = array( - 'code' => Database::check('machine.code', $code ) && $machine_data['code'] != $code, - 'name' => Database::check('machine.name', $name ) && $machine_data['name'] != $name - ); - - /* (2) Gestion des parametres optionnels */ - $opt_data = array( - 'code' => ($correct_param['code']) ? $code : $machine_data['code'], - 'name' => ($correct_param['name']) ? $name : $machine_data['name'] - ); - - - /* [3] Modification de la machine - =========================================================*/ - $request = new Repo('machine/edit', array( - $id_machine, - $opt_data['code'], - $opt_data['name'] - )); - - - return array( - 'status' => $request->answer() - ); - } - - - - - - /* SUPPRIME UNE MACHINE DONNEE - * - * @id_machine UID de la machine en question - * - * @return status Retourne si oui ou non tout s'est bien deroule - * - */ - public static function delete($id_machine){ - // On recupere les donnees - $request = new Repo('machine/delete', array($id_machine)); - $answer = $request->answer(); - - return array( - 'status' => $answer - ); - } - - - - - - } - - -?> \ No newline at end of file diff --git a/view/charts.php b/view/charts.php index 39f90cd..a9bc5ed 100755 --- a/view/charts.php +++ b/view/charts.php @@ -3,16 +3,44 @@ use \manager\ModuleRequest; use \manager\ManagerError; use \manager\ResourceDispatcher; + + + + + + + +/* [1] Gestion du cercle des relations +=======================================*/ +/* (1) On recupere les donnees */ +$getData = new ModuleRequest('charts/field_data'); +$answer = $getData->dispatch(); + +// Si pas d'erreur +if( $answer->error != ManagerError::Success ) + var_dump( ManagerError::explicit($answer->error) ); + +// On enregistre les donnees +$data = $answer->get('data'); + + +/* (2) On recupere le rendu */ +$getRender = new ModuleRequest('charts/field_render', array($data)); +$answer = $getRender->dispatch(); + +// Si pas d'erreur +if( $answer->error != ManagerError::Success ) + var_dump( ManagerError::explicit($answer->error) ); + +// On enregistre les donnees +$render = $answer->get('render'); + + + ?> - - - \ No newline at end of file +
+
CERCLE DES RELATIONS
+ +
\ No newline at end of file diff --git a/view/dashboard.php b/view/dashboard.php index 13e039a..85b3edd 100755 --- a/view/dashboard.php +++ b/view/dashboard.php @@ -19,7 +19,7 @@ -
+
sexe