1<?php 2/** 3 * DokuWiki Plugin struct (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12use plugin\struct\meta\SchemaData; 13 14class action_plugin_struct_entry extends DokuWiki_Action_Plugin { 15 16 17 /** @var helper_plugin_sqlite */ 18 protected $sqlite; 19 20 /** 21 * Registers a callback function for a given event 22 * 23 * @param Doku_Event_Handler $controller DokuWiki's event controller object 24 * @return void 25 */ 26 public function register(Doku_Event_Handler $controller) { 27 28 $controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handle_editform'); 29 30 } 31 32 /** 33 * [Custom event handler which performs action] 34 * 35 * @param Doku_Event $event event object by reference 36 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 37 * handler was registered] 38 * @return bool 39 */ 40 public function handle_editform(Doku_Event $event, $param) { 41 42 /** @var \helper_plugin_struct_db $helper */ 43 $helper = plugin_load('helper', 'struct_db'); 44 $this->sqlite = $helper->getDB(); 45 46 global $ID; 47 48 $res = $this->sqlite->query("SELECT tbl FROM schema_assignments WHERE assign = ?",array($ID,)); 49 if (!$this->sqlite->res2count($res)) return false; 50 51 $tables = array_map(function ($value){return $value['tbl'];},$this->sqlite->res2arr($res)); 52 53 54 foreach ($tables as $table) { 55 $this->createForm($table, $event->data); 56 } 57 58 return true; 59 } 60 61 /** 62 * @param string $tablename 63 * @param Doku_Form $data 64 */ 65 private function createForm($tablename, $data) { 66 global $ID; 67 $schema = new SchemaData($tablename, $ID, 0); 68 $schemadata = $schema->getData(); 69 70 $data->insertElement(4, "<h3>$tablename</h3>"); 71 72 $cols = $schema->getColumns(false); 73 foreach ($cols as $index => $col) { 74 $type = $col->getType(); 75 $label = $type->getLabel(); 76 $name = "Schema[$tablename][$label]"; 77 $input = $type->valueEditor($name, $schemadata[$label]); 78 $element = "<label>$label $input</label><br />"; 79 $data->insertElement(5 + $index, $element); 80 } 81 } 82 83} 84 85// vim:ts=4:sw=4:et: 86