noalyss Version-9
forecast_category_mtable.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22
23/**
24 * \file
25 * \brief display, add, delete and modify forecast category
26 *
27 */
28/**
29 * \class Forecast_Category_MTable
30 * \brief display, add, delete and modify forecast category
31 *
32 */
33require_once NOALYSS_INCLUDE."/database/forecast_category_sql.class.php";
34
36{
37 private $forecast_id;
38 public function __construct(Data_SQL $p_table)
39 {
40 parent::__construct($p_table);
41 $this->forecast_id=-1;
42 }
43 static function build($p_id=-1)
44 {
46 $forecast_category_sql=new Forecast_Category_SQL($cn,$p_id);
47 $forecast_category=new Forecast_Category_MTable($forecast_category_sql);
48 $forecast_category->add_json_param("ac",'FORECAST');
49 $forecast_category->add_json_param("op",'forecast_category');
50 $forecast_category->set_callback("ajax_misc.php");
51 $forecast_category->set_col_label("fc_desc", _("Nom"));
52 $forecast_category->set_col_label("fc_order", _("Ordre"));
53 $forecast_category->set_col_type("fc_order","numeric");
54 $forecast_category->set_sort_column("fc_order");
55 $forecast_category->set_col_type("fc_order","numeric");
56 $forecast_category->set_button_add_top(false);
57 $forecast_category->set_order(["fc_order","fc_desc"]);
58 if ( $p_id != -1 ) {
59 $forecast_id=$cn->get_value("select f_id
60 from
61 forecast_category fc
62 where
63 fc_id=$1",array($p_id));
64 $forecast_category->set_forecast_id($forecast_id);
65 }
66 return $forecast_category;
67 }
68 /**
69 * @return int
70 */
71 public function get_forecast_id(): int
72 {
73 return $this->forecast_id;
74 }
75
76 /**
77 * @param int $forecast_id
78 */
80 {
81 $this->forecast_id = $forecast_id;
82 $this->add_json_param("forecast_id", $forecast_id);
83 $this->get_table()->setp("f_id",$forecast_id);
84 }
85
86 function input()
87 {
88 parent::input();
89 $cn=$this->get_table()->cn;
90 $nb_element=$cn->get_value("select count(*) from forecast_item where fc_id=$1",
91 [$this->get_table()->getp("fc_id")]);
92 printf(_("Utilisation %s"),$nb_element);
93 echo '<p></p>';
94 }
95
96 function check()
97 {
98 $err=0;
99 $cn=$this->get_table()->cn;
100 $object=$this->get_table();
101 if (trim ($object->getp("fc_desc") ) == "" ) {
102 $this->set_error("fc_desc", _("Nom ne peut être vide"));
103 $err++;
104 }
105 $dupl=$cn->get_value("select count(*) from forecast_category
106 where
107 upper(replace (fc_desc,' ',''))= upper(replace ($2,' ',''))
108 and fc_id != $1 and f_id=$3",[$object->fc_id,$object->fc_desc,$this->forecast_id]);
109
110 if ( $dupl > 0) {
111 $this->set_error("fc_desc", _("Ce nom existe déjà"));
112 $err++;
113 }
114 if ( trim($object->fc_order) =='') {
115 $object->fc_order=$cn->get_value("select max(fc_order) from forecast_category where f_id=$1",
116 [$object->f_id])+10;
117 }
118 if ( $err > 0 ) { return false;}
119 return true;
120 }
121}
$err
catch(Exception $e) $forecast_category
catch(Exception $e) $object
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
static connect()
display, add, delete and modify forecast category
input()
display into a dialog box the datarow in order to be appended or modified.
ORM abstract of the table public.forecast_category.
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
add_json_param($p_attribute, $p_value)
Add json parameter to the current one.
set_error($p_col, $p_message)
set the error message for a wrong input