1<?php 2 3//require_once DOKU_PLUGIN.'bez/exceptions.php'; 4 5//require_once 'acl.php'; 6//require_once 'validator.php'; 7 8//require_once 'users.php'; 9//require_once 'threads.php'; 10//require_once 'issuetypes.php'; 11//require_once 'tasks.php'; 12//require_once 'tasktypes.php'; 13//require_once 'commcauses.php'; 14//require_once 'timeline.php'; 15 16namespace dokuwiki\plugin\bez\mdl; 17 18 19class Model { 20 /** @var \helper_plugin_sqlite */ 21 protected $sqlite; 22 23 /** @var \SQLite3 */ 24 protected $db; 25 26 /** @var Acl */ 27 protected $acl; 28 29 //private $db; 30 31 //private $models = array('users', 'issues', 'tasks', 'tasktypes', 'commcauses', 'timeline'); 32 //private $users, $issues, $tasks, $tasktypes, $commcauses, $timeline; 33 34 protected $dw_auth, $user_nick, $action, $conf; 35 36 /** @var ThreadFactory */ 37 protected $threadFactory; 38 39 /** @var UserFactory */ 40 protected $userFactory; 41 42 /** @var LabelFactory */ 43 protected $labelFactory; 44 45 public function __get($property) { 46 $models = array('userFactory', 'threadFactory', 'labelFactory'); 47 if (in_array($property, $models) || 48 in_array($property, array('sqlite', 'db', 'acl', 'dw_auth', 'user_nick', 'action', 'conf'))) { 49 return $this->$property; 50 } 51 } 52 53 public function __construct($dw_auth, $user_nick, $action, $conf) { 54 $this->dw_auth = $dw_auth; 55 $this->user_nick = $user_nick; 56 $this->action = $action; 57 $this->conf = $conf; 58 59// $db_path = DOKU_INC . 'data/bez.sqlite'; 60// //if database not exists 61// if (!file_exists($db_path)) { 62// $this->db = new PDO('sqlite:/' . $db_path); 63// $schema = file_get_contents(DOKU_PLUGIN . 'bez/mdl/schema.sql'); 64// if ($schema === false) { 65// throw new Exception('cannot find schema file: '.$schema); 66// } 67// $this->db->exec($schema); 68// } else { 69// $this->db = new PDO('sqlite:/' . $db_path); 70// } 71// $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 72// 73// //convert NULLS to empty strings 74// $this->db->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_TO_STRING); 75 76 $this->sqlite = plugin_load('helper', 'sqlite'); 77 if(!$this->sqlite) { 78 throw new \Exception('Couldn\'t load sqlite.'); 79 } 80 81 if($this->sqlite->getAdapter()->getName() != DOKU_EXT_PDO) { 82 throw new \Exception('Couldn\'t load PDO sqlite.'); 83 } 84 $this->sqlite->getAdapter()->setUseNativeAlter(true); 85 86 // initialize the database connection 87 if(!$this->sqlite->init('b3p', DOKU_PLUGIN . 'bez/db/')) { 88 throw new \Exception('Couldn\'t init sqlite.'); 89 } 90 91 $this->db = $this->sqlite->getAdapter()->getDb(); 92 93 $this->acl = new Acl($this); 94 95 $this->userFactory = new UserFactory($this); 96 97 $this->threadFactory = new ThreadFactory($this); 98 99 $this->labelFactory = new LabelFactory($this); 100 101// $this->acl = new BEZ_mdl_Acl($this); 102// 103// $this->issues = new BEZ_mdl_Issues($this); 104// $this->tasks = new BEZ_mdl_Tasks($this); 105// 106// $this->users = new BEZ_mdl_Users($this); 107// 108// $this->issuetypes = new BEZ_mdl_Issuetypes($this); 109// 110// $this->tasktypes = new BEZ_mdl_Tasktypes($this); 111// 112// $this->commcauses = new BEZ_mdl_Commcauses($this); 113// $this->timeline = new BEZ_mdl_Timeline($this); 114 } 115 116// public function __destruct() { 117// //http://stackoverflow.com/questions/18277233/pdo-closing-connection 118// $this->db = NULL; 119// } 120} 121