mirror of
https://github.com/cosmocode/dokuwiki-plugin-struct.git
synced 2025-08-03 15:59:53 +00:00
moved more assignment related stuff to the Assignment class
This commit is contained in:
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
// must be run within Dokuwiki
|
// must be run within Dokuwiki
|
||||||
use dokuwiki\Form\Form;
|
use dokuwiki\Form\Form;
|
||||||
|
use plugin\struct\meta\Assignments;
|
||||||
use plugin\struct\meta\Schema;
|
use plugin\struct\meta\Schema;
|
||||||
use plugin\struct\meta\SchemaEditor;
|
use plugin\struct\meta\SchemaEditor;
|
||||||
|
|
||||||
@ -48,24 +49,19 @@ class admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin {
|
|||||||
public function handle() {
|
public function handle() {
|
||||||
global $INPUT;
|
global $INPUT;
|
||||||
|
|
||||||
/** @var \helper_plugin_struct_db $helper */
|
$assignments = new Assignments();
|
||||||
$helper = plugin_load('helper', 'struct_db');
|
|
||||||
$this->sqlite = $helper->getDB();
|
|
||||||
|
|
||||||
if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) {
|
if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) {
|
||||||
$assignment = $INPUT->arr('assignment');
|
$assignment = $INPUT->arr('assignment');
|
||||||
|
$ok = false;
|
||||||
if ($INPUT->str('action') === 'delete') {
|
if ($INPUT->str('action') === 'delete') {
|
||||||
$sql = 'DELETE FROM schema_assignments WHERE assign = ? AND tbl = ?';
|
$ok = $assignments->remove($assignment['assign'], $assignment['tbl']);
|
||||||
|
} else if($INPUT->str('action') === 'add') {
|
||||||
|
$ok = $assignments->add($assignment['assign'], $assignment['tbl']);
|
||||||
}
|
}
|
||||||
if ($INPUT->str('action') === 'add') {
|
if(empty($sql) || empty($assignment['assign']) || empty($assignment['tbl']) || !$ok) {
|
||||||
$sql = 'REPLACE INTO schema_assignments (assign, tbl) VALUES (?,?)';
|
|
||||||
}
|
|
||||||
$opts = array($assignment['assign'], $assignment['tbl']);
|
|
||||||
if(empty($sql) || empty($assignment['assign']) || empty($assignment['tbl']) || !$this->sqlite->query($sql, $opts)) {
|
|
||||||
msg('something went wrong while saving', -1);
|
msg('something went wrong while saving', -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,9 +76,8 @@ class admin_plugin_struct_assignments extends DokuWiki_Admin_Plugin {
|
|||||||
$schemas = $this->sqlite->res2arr($res);
|
$schemas = $this->sqlite->res2arr($res);
|
||||||
$this->sqlite->res_close($res);
|
$this->sqlite->res_close($res);
|
||||||
|
|
||||||
$res = $this->sqlite->query('SELECT * FROM schema_assignments ORDER BY assign');
|
$ass = new Assignments();
|
||||||
$assignments = $this->sqlite->res2arr($res);
|
$assignments = $ass->getAll();
|
||||||
$this->sqlite->res_close($res);
|
|
||||||
|
|
||||||
echo '<ul>';
|
echo '<ul>';
|
||||||
foreach ($assignments as $assignment) {
|
foreach ($assignments as $assignment) {
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
namespace plugin\struct\meta;
|
namespace plugin\struct\meta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Assignments
|
||||||
|
*
|
||||||
|
* Manages the assignment of schemas (table names) to pages and namespaces
|
||||||
|
*
|
||||||
|
* @package plugin\struct\meta
|
||||||
|
*/
|
||||||
class Assignments {
|
class Assignments {
|
||||||
|
|
||||||
/** @var \helper_plugin_sqlite|null */
|
/** @var \helper_plugin_sqlite|null */
|
||||||
@ -31,6 +38,39 @@ class Assignments {
|
|||||||
$this->sqlite->res_close($res);
|
$this->sqlite->res_close($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new assignment to the assignment table
|
||||||
|
*
|
||||||
|
* @param string $assign
|
||||||
|
* @param string $table
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function add($assign, $table) {
|
||||||
|
$sql = 'REPLACE INTO schema_assignments (assign, tbl) VALUES (?,?)';
|
||||||
|
return (bool) $this->sqlite->query($sql, array($assign, $table));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an existing assignment from the assignment table
|
||||||
|
*
|
||||||
|
* @param string $assign
|
||||||
|
* @param string $table
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function remove($assign, $table) {
|
||||||
|
$sql = 'DELETE FROM schema_assignments WHERE assign = ? AND tbl = ?';
|
||||||
|
return (bool) $this->sqlite->query($sql, array($assign, $table));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the whole assignments table
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAll() {
|
||||||
|
return $this->assignments;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of table names assigned to the given page
|
* Returns a list of table names assigned to the given page
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user