diff --git a/application/controllers/crm/Statusgrund.php b/application/controllers/crm/Statusgrund.php index 3c7e43736..690e830c1 100644 --- a/application/controllers/crm/Statusgrund.php +++ b/application/controllers/crm/Statusgrund.php @@ -23,6 +23,7 @@ class Statusgrund extends Auth_Controller $this->load->model('crm/Status_model', 'StatusModel'); $this->load->model('crm/Statusgrund_model', 'StatusgrundModel'); $this->load->model('system/Sprache_model', 'SpracheModel'); + $this->load->model('crm/Statusgrundstatus_model', 'StatusgrundstatusModel'); } public function index() @@ -47,7 +48,8 @@ class Statusgrund extends Auth_Controller public function listGrund($status_kurzbz) { - $statusGrund = $this->StatusgrundModel->loadWhere(array("status_kurzbz" => $status_kurzbz)); + $this->StatusgrundModel->addJoin('public.tbl_status_grund_status', 'statusgrund_id'); + $statusGrund = $this->StatusgrundModel->loadWhere(array("tbl_status_grund_status.status_kurzbz" => $status_kurzbz)); if ($statusGrund->error) { show_error(getError($statusGrund)); @@ -245,7 +247,6 @@ class Statusgrund extends Auth_Controller } $data = array( - "status_kurzbz" => $status_kurzbz, "aktiv" => $aktiv, "bezeichnung_mehrsprachig" => $bezeichnung_mehrsprachig, "beschreibung" => $beschreibung, @@ -258,6 +259,19 @@ class Statusgrund extends Auth_Controller { show_error(getError($statusgrund)); } + else + { + $statusData = array( + "status_kurzbz" => $status_kurzbz, + "statusgrund_id" => $statusgrund->retval + ); + $statusgrundstatus = $this->StatusgrundstatusModel->insert($statusData); + + if ($statusgrundstatus->error) + { + show_error(getError($statusgrundstatus)); + } + } redirect("/crm/Statusgrund/editGrund/" . $statusgrund->retval . "/" . true); } diff --git a/application/models/crm/Status_model.php b/application/models/crm/Status_model.php index 1ee2a5199..82f58274c 100644 --- a/application/models/crm/Status_model.php +++ b/application/models/crm/Status_model.php @@ -16,16 +16,17 @@ class Status_model extends DB_Model { $lang = '[(SELECT index FROM public.tbl_sprache WHERE sprache=' . $this->escape(getUserLanguage()) . ' LIMIT 1)]'; - $this->addSelect('sg.status_kurzbz'); + $this->addSelect('sgs.status_kurzbz'); - $this->addSelect('statusgrund_id'); + $this->addSelect('sg.statusgrund_id'); $this->addSelect('sg.bezeichnung_mehrsprachig' . $lang . ' AS bezeichnung'); $this->addSelect('sg.beschreibung' . $lang . ' AS beschreibung'); - $this->addJoin('public.tbl_status_grund sg', 'ON (sg.status_kurzbz = public.tbl_status.status_kurzbz)', 'LEFT'); + $this->addJoin('public.tbl_status_grund_status sgs', 'ON (sgs.status_kurzbz = public.tbl_status.status_kurzbz)', 'LEFT'); + $this->addJoin('public.tbl_status_grund sg', 'ON (sgs.statusgrund_id = sg.statusgrund_id)', 'LEFT'); return $this->loadWhere([ - 'aktiv'=> true, + 'sg.aktiv'=> true, ]); } } diff --git a/application/models/crm/Statusgrund_model.php b/application/models/crm/Statusgrund_model.php index 8fc2a3a62..01a42cba2 100644 --- a/application/models/crm/Statusgrund_model.php +++ b/application/models/crm/Statusgrund_model.php @@ -16,8 +16,12 @@ class Statusgrund_model extends DB_Model { $this->addOrder('bezeichnung_mehrsprachig'); $where = array(); + if (!is_null($status_kurzbz)) - $where['status_kurzbz'] = $status_kurzbz; + { + $this->addJoin('public.tbl_status_grund_status', 'statusgrund_id'); + $where['tbl_status_grund_status.status_kurzbz'] = $status_kurzbz; + } if (!is_null($aktiv)) $where['aktiv'] = $aktiv; if (!is_null($statusgrund_kurzbz)) @@ -32,9 +36,11 @@ class Statusgrund_model extends DB_Model { $lang = '[(SELECT index FROM public.tbl_sprache WHERE sprache=' . $this->escape(getUserLanguage()) . ' LIMIT 1)]'; - $this->addSelect('tbl_status_grund.*'); + $this->addSelect('tbl_status_grund.*, tbl_status_grund_status.status_kurzbz'); + $this->addSelect('bezeichnung_mehrsprachig' . $lang . ' AS bezeichnung'); $this->addSelect('beschreibung' . $lang . ' AS beschreibung'); + $this->addJoin('public.tbl_status_grund_status', 'statusgrund_id'); $this->addOrder('bezeichnung_mehrsprachig' . $lang); diff --git a/application/models/crm/Statusgrundstatus_model.php b/application/models/crm/Statusgrundstatus_model.php new file mode 100644 index 000000000..1f441c464 --- /dev/null +++ b/application/models/crm/Statusgrundstatus_model.php @@ -0,0 +1,16 @@ +dbTable = "public.tbl_status_grund_status"; + $this->pk = array('status_kurzbz', 'statusgrund_id'); + + } + +} diff --git a/application/widgets/Statusgrund_widget.php b/application/widgets/Statusgrund_widget.php index d0f9d2f58..b9249e067 100644 --- a/application/widgets/Statusgrund_widget.php +++ b/application/widgets/Statusgrund_widget.php @@ -8,7 +8,7 @@ class Statusgrund_widget extends DropdownWidget $this->load->model('crm/statusgrund_model', 'StatusgrundModel'); $this->StatusgrundModel->addOrder('statusgrund_id'); - $this->addSelectToModel($this->StatusgrundModel, 'statusgrund_id', 'bezeichnung_mehrsprachig[1]'); + $this->addSelectToModel($this->StatusgrundModel, 'statusgrund_id', '(bezeichnung_mehrsprachig[1])'); $this->setElementsArray( $this->StatusgrundModel->load(), diff --git a/include/statusgrund.class.php b/include/statusgrund.class.php index 6b2c12e03..1ffe8cac9 100644 --- a/include/statusgrund.class.php +++ b/include/statusgrund.class.php @@ -58,11 +58,12 @@ class statusgrund extends basis_db $beschreibung = $sprache->getSprachQuery('beschreibung'); $qry = " SELECT - *,".$bezeichnung_mehrsprachig.",".$beschreibung." + statusgrund.*, statusgrund.".$bezeichnung_mehrsprachig.",".$beschreibung.", statusgrundstatus.status_kurzbz FROM - public.tbl_status_grund + public.tbl_status_grund statusgrund + JOIN public.tbl_status_grund_status statusgrundstatus ON statusgrund.statusgrund_id = statusgrundstatus.statusgrund_id WHERE - statusgrund_id=".$this->db_add_param($statusgrund_id, FHC_INTEGER); + statusgrund.statusgrund_id=".$this->db_add_param($statusgrund_id, FHC_INTEGER); if($this->db_query($qry)) { @@ -103,14 +104,16 @@ class statusgrund extends basis_db $beschreibung = $sprache->getSprachQuery('beschreibung'); $qry = " SELECT - *,".$bezeichnung_mehrsprachig.",".$beschreibung." + statusgrund.*, + statusgrund.".$bezeichnung_mehrsprachig.",".$beschreibung." FROM - public.tbl_status_grund + public.tbl_status_grund statusgrund + JOIN public.tbl_status_grund_status statusgrundstatus ON statusgrund.statusgrund_id = statusgrundstatus.statusgrund_id WHERE - status_kurzbz=".$this->db_add_param($status_kurzbz); + statusgrundstatus.status_kurzbz=".$this->db_add_param($status_kurzbz); if(!is_null($aktiv)) - $qry.=" AND aktiv=".($aktiv?'true':'false'); - $qry.=" ORDER BY bezeichnung_mehrsprachig[0]"; + $qry.=" AND statusgrund.aktiv=".($aktiv?'true':'false'); + $qry.=" ORDER BY statusgrund.bezeichnung_mehrsprachig[0]"; if($this->db_query($qry)) { @@ -150,14 +153,16 @@ class statusgrund extends basis_db $beschreibung = $sprache->getSprachQuery('beschreibung'); $qry = " SELECT - *,".$bezeichnung_mehrsprachig.",".$beschreibung." + statusgrund.*,statusgrund.".$bezeichnung_mehrsprachig.",".$beschreibung.", statusgrundstatus.status_kurzbz FROM - public.tbl_status_grund + public.tbl_status_grund statusgrund + JOIN public.tbl_status_grund_status statusgrundstatus ON statusgrund.statusgrund_id = statusgrundstatus.statusgrund_id + "; if(!is_null($aktiv)) - $qry.="WHERE aktiv=".($aktiv?'true':'false'); - $qry.=" ORDER BY status_kurzbz, bezeichnung_mehrsprachig[0]"; + $qry.="WHERE statusgrund.aktiv=".($aktiv?'true':'false'); + $qry.=" ORDER BY statusgrundstatus.status_kurzbz, statusgrund.bezeichnung_mehrsprachig[0]"; if($this->db_query($qry)) { diff --git a/system/dbupdate_3.4.php b/system/dbupdate_3.4.php index c6e64edb3..5df6684e6 100644 --- a/system/dbupdate_3.4.php +++ b/system/dbupdate_3.4.php @@ -69,6 +69,7 @@ require_once('dbupdate_3.4/40717_lv_faktor.php'); require_once('dbupdate_3.4/48526_pep_tagging.php'); require_once('dbupdate_3.4/41950_perm_gehaelter.php'); require_once('dbupdate_3.4/53903_valorisierung.php'); +require_once('dbupdate_3.4/40431_statusgrund_tabelle_zuordnung_zu_status.php'); // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen echo '

Pruefe Tabellen und Attribute!

'; diff --git a/system/dbupdate_3.4/40431_statusgrund_tabelle_zuordnung_zu_status.php b/system/dbupdate_3.4/40431_statusgrund_tabelle_zuordnung_zu_status.php new file mode 100644 index 000000000..04ecde908 --- /dev/null +++ b/system/dbupdate_3.4/40431_statusgrund_tabelle_zuordnung_zu_status.php @@ -0,0 +1,32 @@ +db_query('SELECT 1 FROM public.tbl_status_grund_status LIMIT 1')) +{ + $qry = 'CREATE TABLE public.tbl_status_grund_status + ( + status_kurzbz varchar(20) NOT NULL, + statusgrund_id int NOT NULL, + + CONSTRAINT pk_status_grund_status PRIMARY KEY (status_kurzbz, statusgrund_id), + CONSTRAINT fk_status_grund_status_kurzbz FOREIGN KEY (status_kurzbz) + REFERENCES public.tbl_status (status_kurzbz) ON DELETE RESTRICT, + + CONSTRAINT fk_status_grund_status_statusgrund_id FOREIGN KEY (statusgrund_id) + REFERENCES public.tbl_status_grund (statusgrund_id) ON DELETE RESTRICT + ); + + GRANT SELECT ON public.tbl_status_grund_status TO web; + GRANT SELECT, UPDATE, INSERT, DELETE ON public.tbl_status_grund_status TO vilesci; + + INSERT INTO public.tbl_status_grund_status (status_kurzbz, statusgrund_id) + SELECT status_kurzbz, statusgrund_id FROM public.tbl_status_grund; + + /*ALTER TABLE public.tbl_status_grund DROP COLUMN status_kurzbz;*/ + '; + + if(!$db->db_query($qry)) + echo 'public.tbl_status_grund_status: '.$db->db_last_error().'
'; + else + echo 'public.tbl_status_grund_status: Tabelle hinzugefuegt
'; +} \ No newline at end of file