/[openfoncier]/trunk/obj/task.class.php
ViewVC logotype

Contents of /trunk/obj/task.class.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9304 - (show annotations)
Fri Apr 17 16:42:49 2020 UTC (4 years, 9 months ago) by softime
Original Path: branches/4.14.0-develop_demat/obj/task.class.php
File size: 5485 byte(s)
* WIP - Ajout filtre "state" view json tab task
* WIP - Modification table document_numerise_type
* WIP - Ajout nomenclature dans init_data

1 <?php
2 //$Id$
3 //gen openMairie le 14/04/2020 14:11
4
5 require_once "../gen/obj/task.class.php";
6
7 class task extends task_gen {
8
9 /**
10 * Définition des actions disponibles sur la classe.
11 *
12 * @return void
13 */
14 public function init_class_actions() {
15 parent::init_class_actions();
16 //
17 $this->class_actions[998] = array(
18 "identifier" => "view_json",
19 "view" => "view_json",
20 "permission_suffix" => "consulter",
21 );
22 }
23
24 /**
25 * TREATMENT - add_task
26 * Ajoute un enregistrement.
27 *
28 * @param array $params Tableau des paramètres
29 * @return boolean
30 */
31 public function add_task($params = array()) {
32 $this->begin_treatment(__METHOD__);
33 $timestamp_log = json_encode(array(
34 'creation_date' => date('Y-m-d H:i:s'),
35 ));
36 // Mise à jour du DI
37 $valF = array(
38 'task' => '',
39 'type' => $params['val']['type'],
40 'timestamp_log' => $timestamp_log,
41 'state' => 'draft',
42 'id' => $params['val']['id'],
43 );
44 $add = $this->ajouter($valF);
45 if ($add === false) {
46 $this->addToLog($this->msg, DEBUG_MODE);
47 return $this->end_treatment(__METHOD__, false);
48 }
49 return $this->end_treatment(__METHOD__, true);
50 }
51
52 /**
53 * TREATMENT - update_task
54 * Met à jour l'enregistrement instancié.
55 *
56 * @param array $params Tableau des paramètres
57 * @return boolean
58 */
59 public function update_task($params = array()) {
60 $this->begin_treatment(__METHOD__);
61 $timestamp_log = $this->get_timestamp_log();
62 if ($timestamp_log === false) {
63 $this->addToLog(__('XXX'), DEBUG_MODE);
64 return $this->end_treatment(__METHOD__, false);
65 }
66 array_push($timestamp_log, array(
67 'modification_date' => date('Y-m-d H:i:s'),
68 'state' => $params['val']['state'],
69 'prev_state' => $this->getVal('state'),
70 ));
71 $timestamp_log = json_encode($timestamp_log);
72 $valF = array(
73 'task' => $this->getVal($this->clePrimaire),
74 'type' => $this->getVal('type'),
75 'timestamp_log' => $timestamp_log,
76 'state' => $params['val']['state'],
77 'id' => $this->getVal('id'),
78 );
79 $update = $this->modifier($valF);
80 if ($update === false) {
81 $this->addToLog($this->msg, DEBUG_MODE);
82 return $this->end_treatment(__METHOD__, false);
83 }
84 return $this->end_treatment(__METHOD__, true);
85 }
86
87 /**
88 * Récupère le journal d'horodatage dans le champ timestamp_log de
89 * l'enregistrement instancié.
90 *
91 * @param array $params Tableau des paramètres
92 * @return array sinon false en cas d'erreur
93 */
94 protected function get_timestamp_log($params = array()) {
95 $val = $this->getVal('timestamp_log');
96 if ($val === '') {
97 $val = json_encode(array());
98 }
99 if($this->isJson($val) === false) {
100 return false;
101 }
102 return json_decode($val, true);
103 }
104
105 /**
106 * VIEW - view_json
107 * Affiche l'enregistrement dans le format JSON.
108 *
109 * @return void
110 */
111 public function view_json() {
112 $this->checkAccessibility();
113 if ($this->getParameter('idx') !== ']'
114 && $this->getParameter('idx') !== '0') {
115 //
116 $this->view_form_json();
117 }
118 else {
119 $this->view_tab_json();
120 }
121 }
122
123 protected function view_tab_json() {
124 $where = '';
125 if ($this->f->get_submitted_get_value('state') !== null
126 && $this->f->get_submitted_get_value('state') !== '') {
127 //
128 $where = sprintf(' WHERE state = \'%s\' ', $this->f->get_submitted_get_value('state'));
129 }
130 $query = sprintf('
131 SELECT
132 *
133 FROM %1$stask
134 %2$s
135 ',
136 DB_PREFIXE,
137 $where
138 );
139 $res = $this->f->get_all_results_from_db_query($query, true);
140 if ($res['code'] === 'KO') {
141 return false;
142 }
143 $list_tasks = array();
144 foreach ($res['result'] as $task) {
145 $list_tasks[$task['task']] = $task;
146 }
147 printf(json_encode($list_tasks));
148 }
149
150 protected function view_form_json() {
151 $val = array_combine($this->champs, $this->val);
152 printf(json_encode($val));
153 if ($this->f->get_submitted_post_value('valid') === 'true'
154 && $this->f->get_submitted_post_value('state') !== null) {
155 //
156 $params = array(
157 'val' => array(
158 'state' => $this->f->get_submitted_post_value('state')
159 ),
160 );
161 $update = $this->update_task($params);
162 $message_class = "valid";
163 $message = $this->msg;
164 if ($update === false) {
165 $this->addToLog($this->msg, DEBUG_MODE);
166 $message_class = "error";
167 $message = sprintf(
168 '%s %s',
169 __('Impossible de mettre à jour la tâche.'),
170 __('Veuillez contacter votre administrateur.')
171 );
172 }
173 $this->f->displayMessage($message_class, $message);
174 }
175 }
176 }

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26