Files
monpas/application/libraries/monpas/Hoofdstuk.php
T
2022-11-17 11:34:44 +01:00

189 lines
6.0 KiB
PHP

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Hoofdstuk
{
private $content;
private $hoofdstukkeuze;
private $volgorde;
private $views;
private $orgversie;
private $versie;
private $labels;
private $label;
private $sopkeuze;
private $view;
private $tab;
private $tabelid;
private $imagedata;
private $vervangingscode;
private $contentid;
private $hoofdstuk;
private $CI;
public function __construct($chapterid, $profielid, $orgversieid = false)
{
$this->CI =& get_instance();
$this->chapterid = $chapterid;
$this->orgversieid = $orgversieid;
$this->profielid = $profielid;
$this->handle();
}
private function handle()
{
$this->setTekst();
$this->setHoofdstukKeuze();
$this->setSchool();
$this->setVersie();
$this->setSopKeuze();
$this->setLabels();
$this->setVolgordeInleiding();
$this->setVolgordeHoofdstukken();
$this->getViews();
$this->loopViews();
$this->saveContent();
}
private function setTekst(){
$this->content = $this->CI->Standaardteksten_model->get_fieldvalue(
["soort" => 1, "chapter_id" => $this->chapterid], 'content');
}
private function setHoofdstukKeuze(){
$hoofdstukkeuze =
new Hoofdstukkeuze($this->chapterid, $this->orgversieid);
$this->hoofdstukkeuze = $hoofdstukkeuze->getHoofdstukKeuze();
}
private function setSchool(){
if( !($this->hoofdstukkeuze['data']) ) return;
$this->hoofdstukkeuze['data']['school'] = $this->CI->Organisaties_model->get_record_by_id($this->CI->globorgid);
}
private function setVersie(){
if( !($this->hoofdstukkeuze['data'])) return;
if(! isset($this->orgversieid) || $this->orgversieid == "" || $this->orgversieid == null || $this->orgversieid ==0) return;
$this->orgversie = $this->CI->Orgversies_model->get_record_by_id($this->orgversieid);
$this->versie = $this->CI->Versies_model->get_record_by_id($this->orgversie->versie_id);
$this->versie->naam = $this->versie->naam . ', periode: ' . $this->orgversie->periodenummer . ':
' . $this->orgversie->geldigvanaf . ' - ' . $this->orgversie->geldigtm;
$this->hoofdstukkeuze['data']['versie'] = $this->versie;
}
private function setSopKeuze(){
$this->sopkeuze = new Sopkeuze($this->profielid);
}
private function setLabels(){
$this->labels = $this->sopkeuze->getHoofdstukLabels();
}
private function setVolgordeInleiding()
{
if ($this->hoofdstukkeuze['soort'] != 'INLEIDING') return;
$this->volgorde = 10;
}
private function setVolgordeHoofdstukken() {
if ($this->hoofdstukkeuze['soort'] === 'INLEIDING') return;
if(!$this->labels){
$this->volgorde = 20;}
if($this->labels){
$hoogste = 0;
foreach ($this->labels as $this->label) {
if($this->label->volgorde > $hoogste){
$hoogste = $this->label->volgorde;
}
}
$this->volgorde = $hoogste + 10;
}
}
private function getViews(){
$this->views = $this->CI->Sopviews_model->get_records_where(
['soort' =>$this->hoofdstukkeuze['soort']]);
}
private function loopViews(){
if(! $this->views) return;
if( !($this->hoofdstukkeuze['data']) ) return;
foreach ($this->views as $index => $this->view) {
$this->loadView($index);
$this->maakAfbeelding($index);
$this->plaatsAfbeelding();
}
}
private function loadView($index){
$pad = $this->view->pad;
$this->view->tab = $this->CI->load->view("monpas/sopkeuze/" . $pad, ['data' => $this->hoofdstukkeuze['data']], TRUE);
}
private function maakAfbeelding($index){
if ($this->view->type != 'GRA') return;
//ls okt 2020 if(!$this->view->imagecode) return;
if(!$this->view->tabelid) return;
$this->view->grafiek = $this->CI->Phantom_model->create_img($this->view->tab, 'test', FALSE, FALSE, array(650, 0));
//ls okt 2020 $this->imagedata = "<img src='data:image/png;base64," . $this->view->grafiek ."' id='" . $this->view->imagecode . "' />";
$this->imagedata = "<img src='data:image/png;base64," . $this->view->grafiek ."' id='" . $this->view->tabelid . "' />";
}
private function plaatsAfbeelding()
{
$afbeelding = "";
$vervang = $this->view->vervangingscode;
if (strpos($this->content, $vervang)) {
$lengte = strlen($vervang);
$pos = strpos($this->content, $vervang);
if($this->view->type === 'GRA'){
$afbeelding = $this->imagedata;
}
if($this->view->type === 'TAB'){
$afbeelding = $this->view->tab;
}
if ($afbeelding == "") return;
$this->content = substr_replace($this->content, $afbeelding, $pos, $lengte);
}
}
private function saveContent(){
if( !($this->hoofdstukkeuze['data'])) return false;
$this->hoofdstuk = array( 'profiel_id' => $this->profielid,
'chapter_id' => $this->chapterid,
'content' => $this->content,
'orgversieid' => $this->orgversieid,
'volgorde' => $this->volgorde);
$oldID = $this->CI->Sopinhouden_model->get(['profiel_id' => $this->profielid, 'chapter_id'=> $this->chapterid], 'id' , true) ;
if ($oldID){
$this->CI->Sopinhouden_model->update_record($this->hoofdstuk, $oldID);
} else {
$this->CI->Sopinhouden_model->insert_record($this->hoofdstuk);
}
}
}