139 lines
4.5 KiB
PHP
139 lines
4.5 KiB
PHP
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Tabellen
|
|
{
|
|
private $hoofdstukkeuze;
|
|
private $orgversie;
|
|
private $versie;
|
|
private $content;
|
|
private $views;
|
|
private $view;
|
|
private $tab;
|
|
//ls okt 2020 private $imagecode;
|
|
private tabelid;
|
|
private $imagedata;
|
|
private $sopinhoud;
|
|
private $updateid;
|
|
|
|
private $CI;
|
|
|
|
public function getUpdateId(){
|
|
return $this->updateid;
|
|
}
|
|
|
|
public function __construct($sopinhoudid, $orgversie = false){
|
|
$this->CI =& get_instance();
|
|
$this->sopinhoudid = $sopinhoudid;
|
|
$this->orgversie = $orgversie;
|
|
$this->handle();
|
|
}
|
|
|
|
private function handle(){
|
|
|
|
$this->setSopinhoud();
|
|
|
|
$this->setInhoud();
|
|
|
|
$this->setHoofdstukKeuze();
|
|
$this->setSchool();
|
|
|
|
$this->setVersie();
|
|
|
|
$this->setViews();
|
|
|
|
$this->loopViews();
|
|
|
|
$this->updateContent();
|
|
}
|
|
|
|
private function setSopinhoud(){
|
|
$this->sopinhoud = $this->CI->Sopinhouden_model->get_record_by_id($this->sopinhoudid);
|
|
}
|
|
|
|
private function setInhoud(){
|
|
$this->content = $this->sopinhoud->content;
|
|
}
|
|
|
|
private function setHoofdstukKeuze(){
|
|
if( $this->orgversie == "false"){
|
|
$this->orgversie = $this->sopinhoud->orgversieid;};
|
|
$hoofdstukkeuze =
|
|
new Hoofdstukkeuze($this->sopinhoud->chapter_id, $this->orgversie);
|
|
$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;
|
|
$this->orgversie = $this->CI->Orgversies_model->get_record_by_id($this->sopinhoud->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 setViews(){
|
|
$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();
|
|
$this->maakAfbeelding();
|
|
$this->plaatsVerversteAfbeelding();
|
|
}
|
|
}
|
|
|
|
private function loadView(){
|
|
$pad = $this->view->pad;
|
|
$this->view->tab = $this->CI->load->view("monpas/sopkeuze/" . $pad, ['data' => $this->hoofdstukkeuze['data']], TRUE);
|
|
}
|
|
|
|
private function maakAfbeelding(){
|
|
if ($this->view->type != 'GRA') 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 plaatsVerversteAfbeelding(){
|
|
$afbeelding = '';
|
|
if($this->view->type === 'GRA'){
|
|
$afbeelding = $this->imagedata;
|
|
|
|
}
|
|
if($this->view->type === 'TAB'){
|
|
$afbeelding = $this->view->tab;
|
|
}
|
|
if($afbeelding == '') return;
|
|
|
|
$vervangstart = $this->view->css;
|
|
$vervangstartlengte = strlen($vervangstart)+2;
|
|
$vervangeind = $this->view->csseind;
|
|
$posstart = strpos($this->content,$vervangstart);
|
|
$posstart = $posstart + $vervangstartlengte;
|
|
$poseind = strpos($this->content, $vervangeind);
|
|
$lengte = $poseind - $posstart - 12; // de div, het woord class etc.
|
|
|
|
if (strpos($this->content, $vervangstart)) {
|
|
$this->content = substr_replace($this->content, $afbeelding, $posstart, $lengte);
|
|
}
|
|
}
|
|
|
|
private function updateContent(){
|
|
if( !($this->hoofdstukkeuze['data'])) return false;
|
|
$data = ['content' => $this->content];
|
|
|
|
$this->CI->Sopinhouden_model->update_record(
|
|
$data, $this->sopinhoudid);
|
|
}
|
|
|
|
} |