180 lines
10 KiB
PHP
180 lines
10 KiB
PHP
<% /*
|
|
$Revision$
|
|
$Id$
|
|
|
|
File: model_issues.inc
|
|
|
|
Description: Melding model. Dit bestand heeft niets met interfacing te maken
|
|
maar werkt uitsluitend op JSON-data
|
|
Parameters:
|
|
Context:
|
|
|
|
Notes: TODO on demand: PUT/POST/DELETE
|
|
TODO test autorisatie-toepassing (MGE?)
|
|
*/
|
|
|
|
%>
|
|
<!-- #include file="../Shared/discx3d.inc" -->
|
|
<!-- #include file="../mld/mld.inc" -->
|
|
<!-- #include file="model_objects.inc"-->
|
|
<%
|
|
|
|
model_issues =
|
|
{
|
|
module: "MLD",
|
|
table: "mld_melding",
|
|
primary: "mld_melding_key",
|
|
records_name: "issues",
|
|
record_name: "issue",
|
|
fields: [{ name: "id", dbs: "mld_melding_key", typ: "key", filter: "exact" },
|
|
{ name: "name", dbs: "mld_melding_id", typ: "varchar", sql: "ins_srtdiscipline.ins_srtdiscipline_prefix||mld_melding_key", filter: "exact" },
|
|
{ name: "contact", dbs: "prs_perslid_key", typ: "key", foreign: "prs_perslid", track: L("lcl_mld_name"), filter: "exact" },
|
|
{ name: "requestor", dbs: "prs_perslid_key_voor", typ: "key", foreign: "prs_perslid", track: L("lcl_mld_call_for"), filter: "exact" },
|
|
{ name: "issuedate", dbs: "mld_melding_datum", typ: "datetime", track: L("lcl_mld_date_time")},
|
|
{ name: "enddate", dbs: "mld_melding_einddatum", typ: "datetime", track: L("lcl_mld_enddate")},
|
|
{ name: "issuetype", dbs: "mld_stdmelding_key", typ: "varchar", foreign: "mld_stdmelding", track: L("lcl_complain"), filter: "exact" },
|
|
{ name: "description", dbs: "mld_melding_omschrijving", typ: "varchar", track: L("lcl_descr"), filter: "like" },
|
|
{ name: "remark", dbs: "mld_melding_opmerking", typ: "varchar", track: L("lcl_remark")},
|
|
{ name: "status", dbs: "mld_melding_status", typ: "key", foreign: mld.getmldstatustext, track: L("lcl_status"), filter: "exact" },
|
|
{ name: "account", dbs: "prs_kostenplaats_key", typ: "key", foreign: "prs_kostenplaats", track: L("lcl_account"), filter: "exact" },
|
|
{ name: "handler", dbs: "mld_melding_behandelaar_key", typ: "key", foreign: "prs_perslid", track: L("lcl_mld_behandelaar"), filter: "exact" },
|
|
{ name: "location", dbs: "mld_alg_locatie_key", typ: "key", foreign: "alg_locatie", track: L("lcl_location"), filter: "exact" },
|
|
{ name: "building", dbs: "alg_v_allonroerendgoed.alg_gebouw_key", typ: "key", foreign: "alg_gebouw", track: L("lcl_building"), filter: "exact" },
|
|
{ name: "floor", dbs: "alg_v_allonroerendgoed.alg_verdieping_key", typ: "key", foreign: "alg_verdieping", track: L("lcl_floor"), filter: "exact" },
|
|
{ name: "room", dbs: "alg_v_allonroerendgoed.alg_ruimte_key", typ: "key", foreign: "alg_ruimte", track: L("lcl_room"), filter: "exact" },
|
|
{ name: "terrain", dbs: "alg_v_allonroerendgoed.alg_terreinsector_key", typ: "key", foreign: "alg_terreinsector", track: L("lcl_room"), filter: "exact" }
|
|
],
|
|
includes: {
|
|
"objects": {
|
|
model: model_objects,
|
|
joinfield: "ins_deel_key",
|
|
single_only: false,
|
|
joinfunction: function (params)
|
|
{
|
|
return "ins_deel_key IN (SELECT ins_deel_key FROM mld_melding_object WHERE mld_melding_object.mld_melding_key = mld_melding.mld_melding_key AND mld_melding_object_verwijder IS NULL)";
|
|
}
|
|
},
|
|
"notes": { // TODO later
|
|
//model: model_notes,
|
|
joinfield: "ins_deel_key",
|
|
single_only: false,
|
|
joinfunction: function (params)
|
|
{
|
|
/* gaat uit dat die wordt geimplementeerd met een view fac_v_notes (module, key, columns....) */
|
|
return "module='MLD' AND fac_v_notes.key = mld_melding.mld_melding_key";
|
|
}
|
|
}
|
|
},
|
|
|
|
REST_GET: function _GET(params)
|
|
{
|
|
var scope = getQParamSafe("scope", "fe");
|
|
var autfunction = { fe : "WEB_MLDUSE", fo : "WEB_MLDFOF", bo : "WEB_MLDBOF", mi : "WEB_MLDBAC" } [scope];
|
|
params.authparams = user.checkAutorisation(autfunction, null, null, true); /* pessimistic */
|
|
|
|
// Hier kom je niet meer terecht als bovenstaande autorisatiecheck niet tot succes leidt.
|
|
|
|
var alg3d = false;
|
|
var prs3d = false;
|
|
|
|
var query = api2.sqlfields(params, model_issues );
|
|
|
|
if (scope == "fe")
|
|
{
|
|
query.wheres.push("prs_perslid_key=" + user_key);
|
|
}
|
|
|
|
if (!params.filter.id)
|
|
{
|
|
/* You can't go any further back in time than the GUI could (ongeveer)*/
|
|
if (S("mld_max_history") > 0)
|
|
{
|
|
query.wheres.push("mld_melding_datum > SYSDATE - "+ S("mld_max_history"));
|
|
}
|
|
if (!params.filter.status)
|
|
{
|
|
/* Limitation: if no status filter, then default to the active statusses (all except 1,6,5) */
|
|
// Zou zo kunnen, params.filter.status = [0,2,3,4,7];, maar eigenlijk is dit logischer
|
|
query.wheres.push("mld_melding_status IN (0,2,3,4,7)");
|
|
|
|
}
|
|
}
|
|
|
|
/* we need the prefix for the name */
|
|
query.tables.push("mld_stdmelding");
|
|
query.wheres.push("mld_melding.mld_stdmelding_key = mld_stdmelding.mld_stdmelding_key");
|
|
query.tables.push("ins_tab_discipline");
|
|
query.wheres.push("mld_stdmelding.mld_ins_discipline_key = ins_tab_discipline.ins_discipline_key");
|
|
query.tables.push("ins_srtdiscipline");
|
|
query.wheres.push("ins_tab_discipline.ins_srtdiscipline_key = ins_srtdiscipline.ins_srtdiscipline_key");
|
|
|
|
query.tables.push("alg_v_allonroerendgoed");
|
|
query.wheres.push("mld_alg_onroerendgoed_keys = alg_v_allonroerendgoed.alg_onroerendgoed_keys(+)");
|
|
|
|
if (params.authparams.ALGreadlevel > -1)
|
|
{
|
|
/* required for 3D ALG scopeing */
|
|
alg3d = true;
|
|
__Log("ALGreadlevel="+params.authparams.ALGreadlevel);
|
|
query.tables.push("alg_locatie"); /* opletten: outerjoin denk ik? */
|
|
query.wheres.push("mld_alg_onroerendgoed_keys = alg_locatie.alg_locatie_key(+)");
|
|
query.tables.push("alg_district");
|
|
query.wheres.push("alg_locatie.alg_district_key = alg_district.alg_district_key(+)");
|
|
}
|
|
if (params.authparams.PRSreadlevel > -1)
|
|
{
|
|
/* required for 3D PRS scopeing */
|
|
prs3d = true;
|
|
__Log("PRSreadlevel="+params.authparams.PRSreadlevel);
|
|
query.tables.push("prs_v_afdeling");
|
|
query.wheres.push("mld_melding.prs_perslid_key = prs_v_afdeling.prs_afdeling_key");
|
|
}
|
|
|
|
var wheres = api2.sqlfilter(params, model_issues);
|
|
query.wheres = query.wheres.concat(wheres);
|
|
|
|
var sql = "SELECT " + query.selects.join(", ")
|
|
+ " FROM " + query.tables.join(", ")
|
|
+ " WHERE " + query.wheres.join(" AND " );
|
|
|
|
// Over het resultaat moet nog de 3D rasp, altijd
|
|
sql = discx3d (sql,
|
|
"ins_tab_discipline.ins_discipline_key",
|
|
(alg3d ? "alg_regio_key" : null),
|
|
(alg3d ? "alg_district_key" : null),
|
|
(alg3d ? "mld_melding.alg_locatie_key" : null),
|
|
(alg3d ? "alg_v_allonroerendgoed.alg_gebouw_key" : null),
|
|
(alg3d ? "alg_v_allonroerendgoed.alg_verdieping_key" : null),
|
|
(alg3d ? "alg_v_allonroerendgoed.alg_ruimte_key" : null),
|
|
(prs3d ? "prs_bedrijf_key" : null),
|
|
(prs3d ? "prs_afdeling_key" : null),
|
|
autfunction,
|
|
"", /* no additional discipline restrictions */
|
|
(alg3d && prs3d ? 2 : prs3d ? 1 : 0)
|
|
);
|
|
|
|
sql += " ORDER BY mld_melding_key";
|
|
|
|
var json = api2.sql2json (params, sql, model_issues );
|
|
|
|
return json;
|
|
},
|
|
_analyze_fields: function (fields, params, jsondata) /* analyseer inkomende data, common voor PUT en POST */
|
|
{
|
|
},
|
|
_validate_fields: function (fields, params, jsondata) /* valideer fields, alle constraints die niet door de database worden afgevangen */
|
|
{
|
|
},
|
|
|
|
REST_PUT: function (params, jsondata, the_key) /* update call */
|
|
{
|
|
},
|
|
REST_POST: function (params, jsondata) /* new call */
|
|
{
|
|
},
|
|
|
|
REST_DELETE: function (params, jsondata, the_key) /* delete call */
|
|
{
|
|
}
|
|
}
|
|
%> |