Files
MoniqueandClaude Opus 5.5 172fcf566c CodeIgniter 3.1.11 -> 3.4.5 (pocketarc fork) en PHP 8.3-fixes
- system/ vervangen door CodeIgniter 3.4.5 (pocketarc/codeigniter, PHP 8.2-8.5 compatibel)
- config.php, mimes.php, user_agents.php en error-views bijgewerkt naar 3.4.5
- composer.json: php-constraint "^7.4 || ^8.0" zodat composer install op 8.3 werkt
- PHP 8-fatals opgelost: count()/array-functies op FALSE/null, rekenen met lege
  strings, delen door nul, property zetten op FALSE, curly-brace string offsets,
  ongedefinieerde constanten, foute curl_setopt in Phantom_model::create_img
- dynamic properties gedeclareerd in libraries, optionele parameters voor verplichte opgelost
- vergelijkingen waar '' == 0 in PHP 8 anders uitvalt gecast naar (int)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 09:34:46 +02:00

258 lines
9.0 KiB
PHP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Description of Mutatieslog_model
*
* @author Theo Weijmer
* @date februari 4, 2013 11:57 AM
*
*
*
*/
class Mutatielog_model extends MY_Model{
protected $tablename = 'tb_mutatielog';
function __construct(){
parent::__construct();
$models = array('shared/Orgusers_model', 'shared/Users_model', 'shared/Organisaties_model');
$this->load->model($models);
}
function check_if_busy($type){
$this->db->where_in('mutatielog_result_'.$type, array(1,2));
$check = $this->Mutatielog_model->get_records_where();
return $check;
}
function get_mutaties($type, $limit){
$this->db->order_by('mutatielog_crud_'.$type.', id');
$this->db->limit($limit);
$data = array('mutatielog_result_'.$type=>1);
$where= array('mutatielog_result_'.$type=>0);
$this->Mutatielog_model->update_record_where($data, $where);
$mutaties = $this->Mutatielog_model->get_records_where(array('mutatielog_result_'.$type=>1));
return $mutaties;
}
function get_mutatie($mutatie){
$this->sql = "
SELECT *
FROM ".$mutatie->mutatielog_database.".".$mutatie->mutatielog_tablename."
WHERE ".$mutatie->mutatielog_tableid_name." = ".$mutatie->mutatielog_id;
return $this->get_query_row();
}
function mutatie_get(){
$this->load->model('Mutaties_model');
$counted = $this->Mutaties_model->get_instances();
$waiting = $this->Mutaties_model->get_waiting();
$faulted = $this->Mutaties_model->get_faulted();
$data = array('counted'=>$counted, 'waiting'=>$waiting, 'faulted'=>$faulted);
$this->response($data);
}
function faulted_get(){
$this->load->model('Mutaties_model');
$database = $this->get('db');
$tablename= $this->get('tb');
$instances = $this->Mutaties_model->get_faulted_instances($database, $tablename);
$this->response(array('instances'=>$instances));
}
function faulted_post(){
$this->load->model('Mutatielog_model');
$instanceid = $this->post('instanceid');
$this->Mutatielog_model->update_record(array('mutatielog_result'=>9), $instanceid);
}
function faulted_put(){
$this->load->model('Mutatielog_model');
$instanceid = $this->post('instanceid');
$this->Mutatielog_model->update_record(array('mutatielog_result'=>0, 'mutatielog_retry'=>0), $instanceid);
}
/**
* Insert een record
* checkt eerst of het record al bestaat (return excist)
*
* @param array $mutatie bevat alle data van de mutatie
* @return string resultaat van de insert
*/
function mutatie_insert($mutatie){
$record = $this->make_record($mutatie);
if($this->check_for_record($mutatie)){
$status = 'excist';
}else{
$this->db->set($record);
$this->db->insert($mutatie->mutatielog_tablename);
if($mutatie->mutatielog_tablename=='tb_orgusers'){
$newid = $this->db->insert_id();
$status = $this->set_orgusers($newid);
}elseif($mutatie->mutatielog_tablename=='tb_organisaties'){
$newid = $this->db->insert_id();
$status = $this->set_organisatie($newid);
}else{
$status = 'success';
}
}
return $status;
}
/**
* Functie update het user_id en organsiatie_id in de tabel orgusers
* het user_id en organsiatie_id zijn niet noodzakelijkerwijs identiek
* in source en target
*
* @param int $orguserid id van het record dat moet worden gewijzigd
* @return string resultaat van de update
*/
function set_orgusers($orguserid){
$result = 'orguser';
$orguser = $this->Orgusers_model->get_record_by_id($orguserid);
if($orguser){
$data = array('portal_id'=>$orguser->user_id);
$user = $this->Users_model->get_records_where($data, TRUE);
$data = array('portal_id'=>$orguser->organisatie_id);
$org = $this->Organisaties_model->get_records_where($data, TRUE);
// var_dump($user);
// var_dump($org);
if($user && $org){
$data = array( 'user_id' => $user->id ,
'organisatie_id'=> $org->id );
$this->Orgusers_model->update_record($data, $orguserid);
$result = 'success';
}
}
return $result;
}
function set_organisatie($orgid){
//haalt het zojuist geinserte record op
$org = $this->Organisaties_model->get_record_by_id($orgid);
if($org->id == $org->valtonder_id){
//als het een nieuw= bestuur is organisatieid gelijk aan het nieuw ingevoerde id
$bestuurid = $orgid;
}else{
//haalt het record op van het bestuur (organisatie_id staat nog op het portal id)
$bestuurid = $this->Organisaties_model->get_records_where(array('portal_id'=>$org->valtonder_id), TRUE)->id;
}
$this->Organisaties_model->update_record(array('valtonder_id'=>$bestuurid), $orgid);
return 'success';
}
function mutatie_update($mutatie){
$record = $this->make_record($mutatie);
if(!$this->check_for_record($mutatie)){
$status= 'no-record';
}else{
if($mutatie->mutatielog_tablename=='tb_orgusers'){
unset($record['user_id']);
unset($record['organisatie_id']);
}elseif($mutatie->mutatielog_tablename=='tb_organisaties'){
unset($record['valtonder_id']);
}
$this->db->where($mutatie->mutatielog_tableid_name, $mutatie->mutatielog_id);
$this->db->update($mutatie->mutatielog_tablename, $record);
$status = 'success';
}
return $status;
}
function mutatie_delete($mutatie){
$this->db->where($mutatie->mutatielog_tableid_name, $mutatie->mutatielog_id);
$this->db->delete($mutatie->mutatielog_tablename);
return 'success';
}
function store_mutatie($mutatie){
$sql = "
INSERT INTO replicatie.replicatielog (replicatie_data, creation_date, created_by, last_update_date, last_updated_by)
VALUES('".$this->db->escape_str(serialize($mutatie))."', NOW(), 'cron', NOW(), 'cron')";
$this->db->query($sql);
}
function check_for_record($mutatie){
$this->sql = "
SELECT *
FROM ".$mutatie->mutatielog_tablename."
WHERE ".$mutatie->mutatielog_tableid_name." = ".$mutatie->mutatielog_id;
return $this->get_query_result();
}
function make_record($mutatie){
if($mutatie->mutatielog_tablename=='tb_users') $mapping = $this->map_usertable();
if($mutatie->mutatielog_tablename=='tb_orgusers') $mapping = $this->map_orguserstable();
if($mutatie->mutatielog_tablename=='tb_organisaties') $mapping = $this->map_organisatietable();
foreach($mapping as $source => $target){
$record[$target] = $mutatie->record->$source;
}
return $record;
}
function map_usertable(){
$mapping = array(
'id' => 'portal_id' ,
'user_name' => 'gnaam' ,
'user_voornaam' => 'voornaam' ,
'user_tussenvoegsel'=> 'tussenvoegsel' ,
'user_achternaam' => 'achternaam' ,
'user_email' => 'email' ,
'user_password' => 'wachtwoord' ,
'user_salt' => 'zout' );
return $mapping;
}
function map_orguserstable(){
$mapping = array(
'id' => 'portal_id' ,
'organisatie_id'=> 'organisatie_id' ,
'user_id' => 'user_id'
// ,
// 'orguser_levelpartituur'=> 'orguser_level'
);
return $mapping;
}
function map_organisatietable(){
$mapping = array(
'id' => 'portal_id' ,
'organisatie_id' => 'valtonder_id' ,
'organisatie_naam' => 'naam' ,
'organisatie_naamkort' => 'onaamkort' ,
'organisatie_brin' => 'brin' ,
'organisatie_straat' => 'adres' ,
// 'organisatie_postcode' => 'organisatie_postcode' ,
'organisatie_plaats' => 'plaats' ,
// 'organisatie_mail' => 'organisatie_email' ,
// 'organisatie_telefoon' => 'organisatie_telefoon' ,
'organisatie_partituur' => 'partituur' ,
'organisatie_partituurdatum'=> 'partituurdatum' );
return $mapping;
}
}