From: <txm...@us...> - 2014-11-23 09:41:25
|
Revision: 12867 http://sourceforge.net/p/xoops/svn/12867 Author: txmodxoops Date: 2014-11-23 09:41:18 +0000 (Sun, 23 Nov 2014) Log Message: ----------- Added classes for autoLoader Fixed bugs Commented creation image file blank.gif in include/install.php for module repository Modified Paths: -------------- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/building.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/fields.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/user/objects.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/user/pages.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/include/common.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/include/install.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/templates/admin/tdmcreate_tables.tpl Added Paths: ----------- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/TDMCreateAutoload.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/cache/ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/cache/index.html XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateAbstract.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateArchitecture.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateFile.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateHtmlSmartyCodes.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateStructure.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateTableFields.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminAbout.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminFooter.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminHeader.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminIndex.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminMenu.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminObjects.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminPages.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminPermissions.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/blocks/BlocksFiles.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/classes/ClassFiles.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/classes/ClassFormElements.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/classes/ClassHelper.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/css/CssStyles.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/docs/DocsChangelog.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/docs/DocsFiles.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeCommentFunctions.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeComments.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeCommon.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeFunctions.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeInstall.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeJquery.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeNotifications.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeSearch.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/include/IncludeUpdate.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/language/LanguageAdmin.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/language/LanguageBlocks.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/language/LanguageDefines.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/language/LanguageHelp.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/language/LanguageMailTpl.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/language/LanguageMain.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/language/LanguageModinfo.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/sql/SqlFile.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminAbout.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminFooter.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminHeader.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminIndex.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminPages.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminPermissions.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/blocks/TemplatesBlocks.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/user/TemplatesUserFooter.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/user/TemplatesUserHeader.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/user/TemplatesUserIndex.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/user/TemplatesUserPages.php Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/building.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/building.php 2014-11-22 23:53:55 UTC (rev 12866) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/building.php 2014-11-23 09:41:18 UTC (rev 12867) @@ -43,7 +43,7 @@ } } // Structure - include_once TDMC_PATH . '/class/files/architecture.php'; + include_once TDMC_PATH . '/class/files/TDMCreateArchitecture.php'; $handler = TDMCreateArchitecture::getInstance(); $handler->getPath( TDMC_PATH ); $handler->getUploadPath( TDMC_UPLOAD_PATH ); Added: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/TDMCreateAutoload.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/TDMCreateAutoload.php (rev 0) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/TDMCreateAutoload.php 2014-11-23 09:41:18 UTC (rev 12867) @@ -0,0 +1,195 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +/** + * tdmcreate module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package tdmcreate + * @since 2.5.0 + * @author Txmod Xoops http://www.txmodxoops.org + * @version $Id: autoloader.php 12258 2014-01-02 09:33:29Z timgno $ + */ +defined('XOOPS_ROOT_PATH') or die('Restricted access'); +/** + * @since 1.91 + */ +class TDMCreateAutoload +{ + /** + * File where classes index is stored + */ + const INDEX_FILE = 'cache/class_index.php'; + + /** + * @var Autoload + */ + protected static $instance; + + /** + * @var string module directory + */ + protected $mod_dir; + + /** + * @var array array('classname' => 'path/to/filename') + */ + public $index = array(); + + protected static $class_aliases = array('Autoload' => 'TDMCreateAutoload'); + + protected function __construct() + { + $this->mod_dir = TDMC_PATH.'/'; + $file = TDMC_CLASSES_PATH.TDMCreateAutoload::INDEX_FILE; + if (@filemtime($file) && is_readable($file)) + $this->index = include($file); + else + $this->generateIndex(); + } + + /** + * Get instance of autoload + * + * @return TDMCreateAutoload + */ + public static function getInstance() + { + if (!TDMCreateAutoload::$instance) + TDMCreateAutoload::$instance = new TDMCreateAutoload(); + + return TDMCreateAutoload::$instance; + } + + /** + * Retrieve informations about a class in classes index and load it + * + * @param string $classname + */ + public function load($classname) + { + // Retrocompatibility + if (isset(TDMCreateAutoload::$class_aliases[$classname]) && !interface_exists($classname, false) && !class_exists($classname, false)) + return eval('class '.$classname.' extends '.TDMCreateAutoload::$class_aliases[$classname].' {}'); + // regenerate the class index if the requested file doesn't exists + if ((isset($this->index[$classname]) && $this->index[$classname]['path'] && !is_file($this->mod_dir.$this->index[$classname]['path']))) + $this->generateIndex(); + // Call directly class + if (isset($this->index[$classname]['path']) && $this->index[$classname]['path']) + require($this->mod_dir.$this->index[$classname]['path']); + } + + /** + * Generate classes index + */ + public function generateIndex() + { + $classes = array_merge( $this->getClassesFromDir('class/'), + $this->getClassesFromDir('class/files/'), + $this->getClassesFromDir('class/files/admin/'), + $this->getClassesFromDir('class/files/blocks/'), + $this->getClassesFromDir('class/files/classes/'), + $this->getClassesFromDir('class/files/css/'), + $this->getClassesFromDir('class/files/docs/'), + $this->getClassesFromDir('class/files/include/'), + $this->getClassesFromDir('class/files/language/'), + $this->getClassesFromDir('class/files/sql/'), + $this->getClassesFromDir('class/files/templates/'), + $this->getClassesFromDir('class/files/user/') ); + ksort($classes); + $content = '<?php return '.var_export($classes, true).'; ?>'; + + // Write classes index on disc to cache it + $filename = TDMC_CLASSES_PATH.TDMCreateAutoload::INDEX_FILE; + $filename_tmp = tempnam(dirname($filename), basename($filename.'.')); + if ($filename_tmp !== false && file_put_contents($filename_tmp, $content) !== false) + { + if (!@rename($filename_tmp, $filename)) + unlink($filename_tmp); + else + @chmod($filename, 0644); + } + // $filename_tmp couldn't be written . $filename should be there anyway (even if outdated), no need to die. + else + error_log('Cannot write temporary file '.$filename_tmp); + $this->index = $classes; + } + + /** + * Retrieve recursively all classes in a directory and its subdirectories + * + * @param string $path Relative path from root to the directory + * @return array + */ + protected function getClassesFromDir($path) + { + $classes = array(); + $mod_dir = $this->mod_dir; + + foreach (scandir($mod_dir.$path) as $file) + { + if ($file[0] != '.') + { + if (is_dir($mod_dir.$path.$file)) + $classes = array_merge($classes, $this->getClassesFromDir($path.$file.'/')); + else if (substr($file, -4) == '.php') + { + $content = file_get_contents($mod_dir.$path.$file); + $pattern = '#\W((abstract\s+)?class|interface)\s+(?P<classname>'.basename($file, '.php').'?)'.'(?:\s+extends\s+[a-z][a-z0-9_]*)?(?:\s+implements\s+[a-z][a-z0-9_]*(?:\s*,\s*[a-z][a-z0-9_]*)*)?\s*\{#i'; + if (preg_match($pattern, $content, $m)) { + $classes[$m['classname']] = array('path' => $path.$file); + } + } + } + } + + return $classes; + } + + public function getClassPath($classname) { + return (isset($this->index[$classname]) && isset($this->index[$classname]['path'])) ? $this->index[$classname]['path'] : null; + } +} +/* + function autoLoader($className) { + // Directories + $directories = array( + '', + 'files/', + 'files/admin/', + 'files/blocks/', + 'files/classes/', + 'files/css/', + 'files/docs/', + 'files/include/', + 'files/language/', + 'files/sql/', + 'files/templates/user/', + 'files/templates/admin/', + 'files/templates/blocks/', + 'files/user/' + ); + + // File naming format + $fileNameFormats = array( '%s.php' ); + + foreach($directories as $directory) { + foreach($fileNameFormats as $fileNameFormat) { + $path = $directory.sprintf($fileNameFormat, $className); + if(file_exists($path)) { + include_once $path; + return true; + } + } + } + return false; +}*/ +//spl_autoload_register('TDMCreateAutoload'); Added: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/cache/index.html =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/cache/index.html (rev 0) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/cache/index.html 2014-11-23 09:41:18 UTC (rev 12867) @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/fields.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/fields.php 2014-11-22 23:53:55 UTC (rev 12866) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/fields.php 2014-11-23 09:41:18 UTC (rev 12867) @@ -123,257 +123,297 @@ return $form; } - /* - * @public function getFormNew - * - * @param integer $field_mid - * @param integer $field_tid - * @param integer $field_numb - * @param string $f_name - * @param mixed $action - */ - public function getFormNew($field_mid = null, $field_tid = null, $field_numb = null, $f_name = null, $action = false) - { - // Header function class - $fields_form = TDMCreateFields::getInstance(); - $form = $fields_form->getHeaderForm($action); - // - $table_autoincrement = $this->tdmcreate->getHandler('tables')->get($field_tid); - // - $class = 'even'; - for($i = 1; $i <= $field_numb; $i++) { - $class = ($class == 'even') ? 'odd' : 'even'; - $form->addElement(new XoopsFormHidden('field_id['.$i.']', 'new')); - $form->addElement(new XoopsFormHidden('field_mid', $field_mid)); - $form->addElement(new XoopsFormHidden('field_tid', $field_tid)); - - $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">')); - // Index ID - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$i.'</td>')); - // Field Name - $this_field_name = (!empty($f_name) ? $f_name . '_' : ''); - $field_name = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$i.']', 15, 255, $this_field_name); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_name->render().'</td>')); - // Field Type - $fieldtype_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$i.']'); - $fieldtype_select->addOptionArray($this->tdmcreate->getHandler('fieldtype')->getList()); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldtype_select->render().'</td>')); - // Field Value - $value = ($i == 1) && ($table_autoincrement->getVar('table_autoincrement') == 1) ? '8' : ''; - $field_value = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$i.']', 5, 20, $value); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_value->render().'</td>')); - // Field Attributes - $field_attributes_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$i.']'); - $field_attributes_select->addOptionArray($this->tdmcreate->getHandler('fieldattributes')->getList()); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_attributes_select->render().'</td>')); - // Field Null - $field_null_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$i.']'); - $field_null_select->addOptionArray($this->tdmcreate->getHandler('fieldnull')->getList()); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_null_select->render().'</td>')); - // Field Default - $field_default = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$i.']', 15, 25); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_default->render().'</td>')); - // Field Key - $field_key_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$i.']'); - $field_key_select->addOptionArray($this->tdmcreate->getHandler('fieldkey')->getList()); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_key_select->render().'</td>')); - // Field Void - if( ($i == 1) && ($table_autoincrement->getVar('table_autoincrement') == 1)) { - $form->addElement(new TDMCreateFormLabel('<td> </td></tr>')); - } else { - // Box header row - $parameters_tray = new XoopsFormElementTray('', '<br />'); - // Field Elements - $criteria_element = new CriteriaCompo(); - $criteria_element->add(new Criteria('fieldelement_tid', 0)); - $criteria_table = new CriteriaCompo(); - $criteria_table->add(new Criteria('fieldelement_mid', $field_mid)); - $field_elements_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$i.']'); - $field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_element)); - $field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_table)); - unset($criteria_element); unset($criteria_table); - $parameters_tray->addElement($field_elements_select); - - $field_parent = 0; - $check_field_parent = new XoopsFormCheckBox(' ', 'field_parent['.$i.']'); - $check_field_parent->addOption($field_parent, _AM_TDMCREATE_FIELD_PARENT ); - $parameters_tray->addElement($check_field_parent); - - $field_inlist = 0; - $check_field_inlist = new XoopsFormCheckBox(' ', 'field_inlist['.$i.']', $field_inlist); - $check_field_inlist->addOption(1, _AM_TDMCREATE_FIELD_INLIST); - $parameters_tray->addElement($check_field_inlist); - - $field_inform = 0; - $check_field_inform = new XoopsFormCheckBox(' ', 'field_inform['.$i.']', $field_inform); - $check_field_inform->addOption(1, _AM_TDMCREATE_FIELD_INFORM); - $parameters_tray->addElement($check_field_inform); + /* + * @public function getFormNew + * + * @param integer $field_mid + * @param integer $field_tid + * @param integer $field_numb + * @param string $f_name + * @param mixed $action + */ + public function getFormNew($field_mid = null, $field_tid = null, $field_numb = null, $f_name = null, $action = false) + { + // Header function class + $fields_form = TDMCreateFields::getInstance(); + $form = $fields_form->getHeaderForm($action); + // Get handler tables + $table_obj = $this->tdmcreate->getHandler('tables')->get($field_tid); // Changed by goffy + $table_autoincrement = $table_obj->getVar('table_autoincrement'); // Added by goffy + // Loop for fields number + $class = 'even'; + for($i = 1; $i <= $field_numb; $i++) { + $class = ($class == 'even') ? 'odd' : 'even'; + // Replaced creation of new line by new function - goffy + $this->getFormNewLine($form, $class, $i, $field_mid, $field_tid, $f_name, $table_autoincrement); + } + // Footer form + return $fields_form->getFooterForm($form); + } + + /* + * @public function getFormNewLine + * + * @param mixed $form + * @param mixed $class + * @param integer $i + * @param integer $field_mid + * @param integer $field_tid + * @param mixed $f_name + * @param integer $table_autoincrement + * + * @author timgno - modified in getFormNewLine by goffy + */ + public function getFormNewLine($form, $class, $i, $field_mid, $field_tid, $f_name, $table_autoincrement) + { + $form->addElement(new XoopsFormHidden('field_id['.$i.']', 'new')); + $form->addElement(new XoopsFormHidden('field_mid', $field_mid)); + $form->addElement(new XoopsFormHidden('field_tid', $field_tid)); + + $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">')); + // Index ID + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$i.'</td>')); + // Field Name + $this_field_name = (!empty($f_name) ? $f_name . '_' : ''); + $field_name = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$i.']', 15, 255, $this_field_name); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_name->render().'</td>')); + // Field Type + $value = ($i == 1) && ($table_autoincrement == 1) ? '2' : ''; + $fieldtype_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$i.']', $value); + $fieldtype_select->addOptionArray($this->tdmcreate->getHandler('fieldtype')->getList()); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldtype_select->render().'</td>')); + // Field Value + $value = ($i == 1) && ($table_autoincrement == 1) ? '8' : ''; + $field_value = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$i.']', 5, 20, $value); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_value->render().'</td>')); + // Field Attributes + $field_attributes_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$i.']'); + $field_attributes_select->addOptionArray($this->tdmcreate->getHandler('fieldattributes')->getList()); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_attributes_select->render().'</td>')); + // Field Null + $field_null_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$i.']'); + $field_null_select->addOptionArray($this->tdmcreate->getHandler('fieldnull')->getList()); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_null_select->render().'</td>')); + // Field Default + $field_default = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$i.']', 15, 25); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_default->render().'</td>')); + // Field Key + $field_key_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$i.']'); + $field_key_select->addOptionArray($this->tdmcreate->getHandler('fieldkey')->getList()); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_key_select->render().'</td>')); + // Field Void + if( ($i == 1) && ($table_autoincrement == 1)) { + $form->addElement(new TDMCreateFormLabel('<td> </td></tr>')); + } else { + // Box header row + $parameters_tray = new XoopsFormElementTray('', '<br />'); + // Field Elements + $criteria_element = new CriteriaCompo(); + $criteria_element->add(new Criteria('fieldelement_tid', 0)); + $criteria_table = new CriteriaCompo(); + $criteria_table->add(new Criteria('fieldelement_mid', $field_mid)); + $field_elements_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$i.']'); + $field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_element)); + $field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_table)); + unset($criteria_element); unset($criteria_table); + $parameters_tray->addElement($field_elements_select); + + $field_parent = 0; + $check_field_parent = new XoopsFormCheckBox(' ', 'field_parent['.$i.']'); + $check_field_parent->addOption($field_parent, _AM_TDMCREATE_FIELD_PARENT ); + $parameters_tray->addElement($check_field_parent); + + $field_inlist = 0; + $check_field_inlist = new XoopsFormCheckBox(' ', 'field_inlist['.$i.']', $field_inlist); + $check_field_inlist->addOption(1, _AM_TDMCREATE_FIELD_INLIST); + $parameters_tray->addElement($check_field_inlist); + + $field_inform = 0; + $check_field_inform = new XoopsFormCheckBox(' ', 'field_inform['.$i.']', $field_inform); + $check_field_inform->addOption(1, _AM_TDMCREATE_FIELD_INFORM); + $parameters_tray->addElement($check_field_inform); - $field_admin = 0; - $check_field_admin = new XoopsFormCheckBox(' ', 'field_admin['.$i.']', $field_admin); - $check_field_admin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN); - $parameters_tray->addElement($check_field_admin); + $field_admin = 0; + $check_field_admin = new XoopsFormCheckBox(' ', 'field_admin['.$i.']', $field_admin); + $check_field_admin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN); + $parameters_tray->addElement($check_field_admin); - $field_user = 0; - $check_field_user = new XoopsFormCheckBox(' ', 'field_user['.$i.']', $field_user); - $check_field_user->addOption(1, _AM_TDMCREATE_FIELD_USER); - $parameters_tray->addElement($check_field_user); + $field_user = 0; + $check_field_user = new XoopsFormCheckBox(' ', 'field_user['.$i.']', $field_user); + $check_field_user->addOption(1, _AM_TDMCREATE_FIELD_USER); + $parameters_tray->addElement($check_field_user); - $field_block = 0; - $check_field_block = new XoopsFormCheckBox('', 'field_block['.$i.']', $field_block); - $check_field_block->addOption(1, _AM_TDMCREATE_FIELD_BLOCK); - $parameters_tray->addElement($check_field_block); - - if(($i == 1)) { - $field_main = 1; - $check_field_main = new XoopsFormRadio('', 'field_main['.$i.']', $field_main); - $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); - } else { - $field_main = 0; - $check_field_main = new XoopsFormRadio('', 'field_main['.$i.']'); - $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); - } - $parameters_tray->addElement($check_field_main); - - $field_search = 0; - $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$i.']', $field_search); - $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH); - $parameters_tray->addElement($check_field_search); + $field_block = 0; + $check_field_block = new XoopsFormCheckBox('', 'field_block['.$i.']', $field_block); + $check_field_block->addOption(1, _AM_TDMCREATE_FIELD_BLOCK); + $parameters_tray->addElement($check_field_block); + + if(($i == 1)) { + $field_main = 1; + $check_field_main = new XoopsFormRadio('', 'field_main['.$i.']', $field_main); + $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); + } else { + $field_main = 0; + $check_field_main = new XoopsFormRadio('', 'field_main['.$i.']'); + $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); + } + $parameters_tray->addElement($check_field_main); + + $field_search = 0; + $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$i.']', $field_search); + $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH); + $parameters_tray->addElement($check_field_search); - $field_required = 0; - $check_field_required = new XoopsFormCheckBox(' ', 'field_required['.$i.']', $field_required); - $check_field_required->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED); - $parameters_tray->addElement($check_field_required); - $form->addElement(new TDMCreateFormLabel('<td><div class="portlet"><div class="portlet-header">'._AM_TDMCREATE_FIELD_PARAMETERS_LIST.'</div><div class="portlet-content">'.$parameters_tray->render().'</div></div></td></tr>')); - } - } - // Footer form - return $fields_form->getFooterForm($form); - } - - /* - * @public function getFormEdit - * - * @param integer $field_mid - * @param integer $field_tid - * @param mixed $action - */ - public function getFormEdit($field_mid = null, $field_tid = null, $action = false) - { - // Header function class - $fields_form = TDMCreateFields::getInstance(); - $form = $fields_form->getHeaderForm($action); - // - $class = 'even'; - // Get the list of fields - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('field_mid', $field_mid)); - $criteria->add(new Criteria('field_tid', $field_tid)); - $fields = $this->tdmcreate->getHandler('fields')->getObjects($criteria); - unset($criteria); - $id = 1; - foreach($fields as $field) { - $class = ($class == 'even') ? 'odd' : 'even'; - $field_id = $field->getVar('field_id'); - // - $form->addElement(new XoopsFormHidden('field_id['.$field_id.']', $field_id)); - $form->addElement(new XoopsFormHidden('field_mid', $field_mid)); - $form->addElement(new XoopsFormHidden('field_tid', $field_tid)); - - $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">')); - // Index ID - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$id.'</td>')); - // Field Name - $field_name = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$field_id.']', 15, 255, $field->getVar('field_name')); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_name->render().'</td>')); - // Field Type - $fieldtype_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$field_id.']', $field->getVar('field_type')); - $fieldtype_select->addOptionArray($this->tdmcreate->getHandler('fieldtype')->getList()); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldtype_select->render().'</td>')); - // Field Value - $field_value = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$field_id.']', 5, 20, $field->getVar('field_value')); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_value->render().'</td>')); - // Field Attributes - $field_attributes_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$field_id.']', $field->getVar('field_attribute')); - $field_attributes_select->addOptionArray($this->tdmcreate->getHandler('fieldattributes')->getList()); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_attributes_select->render().'</td>')); - // Field Null - $field_null_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$field_id.']', $field->getVar('field_null')); - $field_null_select->addOptionArray($this->tdmcreate->getHandler('fieldnull')->getList()); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_null_select->render().'</td>')); - // Field Default - $field_default = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$field_id.']', 15, 25, $field->getVar('field_default')); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_default->render().'</td>')); - // Field Key - $field_key_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$field_id.']', $field->getVar('field_key')); - $field_key_select->addOptionArray($this->tdmcreate->getHandler('fieldkey')->getList()); - $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_key_select->render().'</td>')); - // Field Void - $table_autoincrement = $this->tdmcreate->getHandler('tables')->get($field_tid); - if( ($id == 1) && ($table_autoincrement->getVar('table_autoincrement') == 1)) { - $form->addElement(new TDMCreateFormLabel('<td> </td></tr>')); - } else { - // Box header row - $parameters_tray = new XoopsFormElementTray('', '<br />'); - // Field Elements - $criteria_element = new CriteriaCompo(); - $criteria_element->add(new Criteria('fieldelement_tid', 0)); - $criteria_table = new CriteriaCompo(); - $criteria_table->add(new Criteria('fieldelement_mid', $field_mid)); - $field_elements_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$field_id.']', $field->getVar('field_element')); - $field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_element)); - $field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_table)); - unset($criteria_element); unset($criteria_table); - $parameters_tray->addElement($field_elements_select); - - $check_field_parent = new XoopsFormCheckBox(' ', 'field_parent['.$field_id.']', $field->getVar('field_parent')); - $check_field_parent->addOption(1, _AM_TDMCREATE_FIELD_PARENT ); - $parameters_tray->addElement($check_field_parent); - - $check_field_inlist = new XoopsFormCheckBox(' ', 'field_inlist['.$field_id.']', $field->getVar('field_inlist')); - $check_field_inlist->addOption(1, _AM_TDMCREATE_FIELD_INLIST); - $parameters_tray->addElement($check_field_inlist); - - $check_field_inform = new XoopsFormCheckBox(' ', 'field_inform['.$field_id.']', $field->getVar('field_inform')); - $check_field_inform->addOption(1, _AM_TDMCREATE_FIELD_INFORM); - $parameters_tray->addElement($check_field_inform); + $field_required = 0; + $check_field_required = new XoopsFormCheckBox(' ', 'field_required['.$i.']', $field_required); + $check_field_required->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED); + $parameters_tray->addElement($check_field_required); + $form->addElement(new TDMCreateFormLabel('<td><div class="portlet"><div class="portlet-header">'._AM_TDMCREATE_FIELD_PARAMETERS_LIST.'</div><div class="portlet-content">'.$parameters_tray->render().'</div></div></td></tr>')); + } + } + + /* + * @public function getFormEdit + * + * @param integer $field_mid + * @param integer $field_tid + * @param mixed $action + */ + public function getFormEdit($field_mid = null, $field_tid = null, $action = false) + { + // Header function class + $fields_form = TDMCreateFields::getInstance(); + $form = $fields_form->getHeaderForm($action); + // + $class = 'even'; + // Get the number of fields - goffy + $tablesHandler =& $this->tdmcreate->getHandler('tables'); + $table_nbfields = $tablesHandler->get($field_tid)->getVar('table_nbfields'); + $f_name = $tablesHandler->get($field_tid)->getVar('table_fieldname'); - $check_field_admin = new XoopsFormCheckBox(' ', 'field_admin['.$field_id.']', $field->getVar('field_admin')); - $check_field_admin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN); - $parameters_tray->addElement($check_field_admin); + // Get the list of fields + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('field_mid', $field_mid)); + $criteria->add(new Criteria('field_tid', $field_tid)); + $criteria->setSort('field_id'); //added by goffy + $fields = $this->tdmcreate->getHandler('fields')->getObjects($criteria); + unset($criteria); + $id = 1; + foreach($fields as $field) { + $class = ($class == 'even') ? 'odd' : 'even'; + $field_id = $field->getVar('field_id'); + if ($id>$table_nbfields) { //delete additional fields, if number of fields is reduced - goffy + $fieldsObj =& $this->tdmcreate->getHandler('fields')->get( $field_id ); + $this->tdmcreate->getHandler('fields')->delete($fieldsObj, true); + } else { + // show field with settings + $form->addElement(new XoopsFormHidden('field_id['.$field_id.']', $field_id)); + $form->addElement(new XoopsFormHidden('field_mid', $field_mid)); + $form->addElement(new XoopsFormHidden('field_tid', $field_tid)); + + $form->addElement(new TDMCreateFormLabel('<tr class="'.$class.'">')); + // Index ID + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$id.'</td>')); + // Field Name + $field_name = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$field_id.']', 15, 255, $field->getVar('field_name')); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_name->render().'</td>')); + // Field Type + $fieldtype_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$field_id.']', $field->getVar('field_type')); + $fieldtype_select->addOptionArray($this->tdmcreate->getHandler('fieldtype')->getList()); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$fieldtype_select->render().'</td>')); + // Field Value + $field_value = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$field_id.']', 5, 20, $field->getVar('field_value')); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_value->render().'</td>')); + // Field Attributes + $field_attributes_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$field_id.']', $field->getVar('field_attribute')); + $field_attributes_select->addOptionArray($this->tdmcreate->getHandler('fieldattributes')->getList()); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_attributes_select->render().'</td>')); + // Field Null + $field_null_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$field_id.']', $field->getVar('field_null')); + $field_null_select->addOptionArray($this->tdmcreate->getHandler('fieldnull')->getList()); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_null_select->render().'</td>')); + // Field Default + $field_default = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$field_id.']', 15, 25, $field->getVar('field_default')); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_default->render().'</td>')); + // Field Key + $field_key_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$field_id.']', $field->getVar('field_key')); + $field_key_select->addOptionArray($this->tdmcreate->getHandler('fieldkey')->getList()); + $form->addElement(new TDMCreateFormLabel('<td class="center">'.$field_key_select->render().'</td>')); + // Field Void + $table_autoincrement = $this->tdmcreate->getHandler('tables')->get($field_tid); + if( ($id == 1) && ($table_autoincrement->getVar('table_autoincrement') == 1)) { + $form->addElement(new TDMCreateFormLabel('<td> </td></tr>')); + } else { + // Box header row + $parameters_tray = new XoopsFormElementTray('', '<br />'); + // Field Elements + $criteria_element = new CriteriaCompo(); + $criteria_element->add(new Criteria('fieldelement_tid', 0)); + $criteria_table = new CriteriaCompo(); + $criteria_table->add(new Criteria('fieldelement_mid', $field_mid)); + $field_elements_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$field_id.']', $field->getVar('field_element')); + $field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_element)); + $field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_table)); + unset($criteria_element); unset($criteria_table); + $parameters_tray->addElement($field_elements_select); + + $check_field_parent = new XoopsFormCheckBox(' ', 'field_parent['.$field_id.']', $field->getVar('field_parent')); + $check_field_parent->addOption(1, _AM_TDMCREATE_FIELD_PARENT ); + $parameters_tray->addElement($check_field_parent); + + $check_field_inlist = new XoopsFormCheckBox(' ', 'field_inlist['.$field_id.']', $field->getVar('field_inlist')); + $check_field_inlist->addOption(1, _AM_TDMCREATE_FIELD_INLIST); + $parameters_tray->addElement($check_field_inlist); + + $check_field_inform = new XoopsFormCheckBox(' ', 'field_inform['.$field_id.']', $field->getVar('field_inform')); + $check_field_inform->addOption(1, _AM_TDMCREATE_FIELD_INFORM); + $parameters_tray->addElement($check_field_inform); - $check_field_user = new XoopsFormCheckBox(' ', 'field_user['.$field_id.']', $field->getVar('field_user')); - $check_field_user->addOption(1, _AM_TDMCREATE_FIELD_USER); - $parameters_tray->addElement($check_field_user); + $check_field_admin = new XoopsFormCheckBox(' ', 'field_admin['.$field_id.']', $field->getVar('field_admin')); + $check_field_admin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN); + $parameters_tray->addElement($check_field_admin); - $check_field_block = new XoopsFormCheckBox('', 'field_block['.$field_id.']', $field->getVar('field_block')); - $check_field_block->addOption(1, _AM_TDMCREATE_FIELD_BLOCK); - $parameters_tray->addElement($check_field_block); - - $field_main = $field->getVar('field_main'); - if($field_main == 1) { - $check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']', $field_main); - } else { - $check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']'); - } - $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); - $parameters_tray->addElement($check_field_main); - - $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$field_id.']', $field->getVar('field_search')); - $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH); - $parameters_tray->addElement($check_field_search); + $check_field_user = new XoopsFormCheckBox(' ', 'field_user['.$field_id.']', $field->getVar('field_user')); + $check_field_user->addOption(1, _AM_TDMCREATE_FIELD_USER); + $parameters_tray->addElement($check_field_user); - $check_field_required = new XoopsFormCheckBox(' ', 'field_required['.$field_id.']', $field->getVar('field_required')); - $check_field_required->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED); - $parameters_tray->addElement($check_field_required); - $form->addElement(new TDMCreateFormLabel('<td><div class="portlet"><div class="portlet-header">'._AM_TDMCREATE_FIELD_PARAMETERS_LIST.'</div><div class="portlet-content">'.$parameters_tray->render().'</div></div></td></tr>')); - } - $id++; - } - unset($id); - // Footer form - return $fields_form->getFooterForm($form); - } + $check_field_block = new XoopsFormCheckBox('', 'field_block['.$field_id.']', $field->getVar('field_block')); + $check_field_block->addOption(1, _AM_TDMCREATE_FIELD_BLOCK); + $parameters_tray->addElement($check_field_block); + + $field_main = $field->getVar('field_main'); + if($field_main == 1) { + $check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']', $field_main); + } else { + $check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']'); + } + $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); + $parameters_tray->addElement($check_field_main); + + $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$field_id.']', $field->getVar('field_search')); + $check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH); + $parameters_tray->addElement($check_field_search); + + $check_field_required = new XoopsFormCheckBox(' ', 'field_required['.$field_id.']', $field->getVar('field_required')); + $check_field_required->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED); + $parameters_tray->addElement($check_field_required); + $form->addElement(new TDMCreateFormLabel('<td><div class="portlet"><div class="portlet-header">'._AM_TDMCREATE_FIELD_PARAMETERS_LIST.'</div><div class="portlet-content">'.$parameters_tray->render().'</div></div></td></tr>')); + } + $id++; + } + } + // If you change number fields in tables, + // adding missing fields or delete unnecessary fields + // By goffy + for ($i = $id; $i <= $table_nbfields; $i++) { + $class = ($class == 'even') ? 'odd' : 'even'; + $this->getFormNewLine($form, $class, $i, $field_mid, $field_tid, $f_name, 0); + } + unset($id); + // Footer form + return $fields_form->getFooterForm($form); + } + /* * @private function getFooterForm * @param null Added: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateAbstract.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateAbstract.php (rev 0) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateAbstract.php 2014-11-23 09:41:18 UTC (rev 12867) @@ -0,0 +1,137 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +/** + * tdmcreate module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package tdmcreate + * @since 2.5.0 + * @author Txmod Xoops http://www.txmodxoops.org + * @version $Id: abstract.php 12258 2014-01-02 09:33:29Z timgno $ + */ + +defined('XOOPS_ROOT_PATH') or die('Restricted access'); + +/** + * Abstract base class + */ +abstract class TDMCreateAbstract +{ + /** + * "module" attribute fot files + * + * @var mixed + */ + protected $module = null; + + /** + * "table" attribute fot files + * + * @var mixed + */ + protected $table = null; + + /** + * "tables" attribute fot files + * + * @var mixed + */ + protected $tables = null; + + /** + * "fields" attribute fot files + * + * @var mixed + */ + protected $fields = null; + + /** + * public function setFileName + * @param mixed $module + */ + public function setModule($module) { + if (is_object($module) && ($module instanceof TDMCreateModules)) { + $this->module = $module; + } + } + + /* + * @public function getModule + * @param null + */ + public function getModule() { + return $this->module; + } + + /** + * public function setTable + * @param mixed $table + */ + public function setTable($table) { + if (is_object($table) && ($table instanceof TDMCreateTables)) { + $this->table = $table; + } + } + + /* + * @public function getTable + * @param null + */ + public function getTable() { + return $this->table; + } + + /** + * public function setTables + * @param mixed $tables + */ + public function setTables($tables) { + if (is_array($tables)) { + $this->tables = $tables; + } + } + + /* + * @public function getTables + * @param null + */ + public function getTables() { + return $this->tables; + } + + /** + * @public function setFields + * @param mixed $fields + */ + public function setFields($fields) { + if (is_object($fields) && ($fields instanceof TDMCreateFields)) { + $this->fields = $fields; + } + } + + /* + * @public function getFields + * @param null + */ + public function getFields() { + return $this->fields; + } + + /** + * Generates output for files. + * + * This method is abstract and must be overwritten by the child classes. + * + * @abstract + */ + public function render() {} +} \ No newline at end of file Added: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateArchitecture.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateArchitecture.php (rev 0) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateArchitecture.php 2014-11-23 09:41:18 UTC (rev 12867) @@ -0,0 +1,482 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +/** + * tdmcreate module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package tdmcreate + * @since 2.5.0 + * @author Txmod Xoops http://www.txmodxoops.org + * @version $Id: architecture.php 12258 2014-01-02 09:33:29Z timgno $ + */ +defined('XOOPS_ROOT_PATH') or die('Restricted access'); +require_once 'TDMCreateStructure.php'; + +class TDMCreateArchitecture extends TDMCreateStructure +{ + /* + * @var mixed + */ + private $tdmcreate = null; + /* + * @var mixed + */ + private $structure = null; + /* + * @public function constructor class + * @param null + */ + public function __construct() { + $this->tdmcreate = TDMCreate::getInstance(); + $this->structure = TDMCreateStructure::getInstance(); + } + /* + * @static function &getInstance + * @param null + */ + public static function &getInstance() + { + static $instance = false; + if (!$instance) { + $instance = new self(); + } + return $instance; + } + /* + * @public function getPath + * @param string $path + */ + public function getPath($path) { + $this->path = $path; + } + /* + * @public function getUploadPath + * @param string $path + */ + public function getUploadPath($path) { + $this->uploadPath = $path; + } + /* + * @public function createBaseFoldersFiles + * @param string $module + */ + public function createBaseFoldersFiles( $module ) + { + // Module + $modId = $module->getVar('mod_id'); + $language = $GLOBALS['xoopsConfig']['language']; + // Id of tables + $criteriaTables = new CriteriaCompo(); + $criteriaTables->add(new Criteria('table_mid', $modId)); + $tables = $this->tdmcreate->getHandler('tables')->getObjects($criteriaTables); + unset($criteriaTables); + // + $table = null; + foreach (array_keys($tables) as $t) + { + $tableId = $tables[$t]->getVar('table_id'); + $tableName = $tables[$t]->getVar('table_name'); + $tableAdmin = $tables[$t]->getVar('table_admin'); + $tableUser = $tables[$t]->getVar('table_user'); + $tableBlocks = $tables[$t]->getVar('table_blocks'); + $table = $this->tdmcreate->getHandler('tables')->get($tableId); + } + // + $indexFile = $this->path.'/index.html'; + $docsFolder = $this->path.'/docs'; + $logosFolder = $this->path.'/assets/images/logos'; + $stlModuleDirname = $module->getVar('mod_dirname'); + $stlModuleAuthor = str_replace(' ', '', strtolower($module->getVar('mod_author'))); + // Creation of the Directory in repository + $targetDirectory = $this->uploadPath.'/repository/'. $stlModuleDirname; + $uploadImagesRepository = $this->uploadPath.'/images/repository'; + // Creation of "module" folder + $this->structure->getPath($targetDirectory); + // Creation of "module" folder + $this->structure->makeDir($targetDirectory); + // Copied of index.html file in "root module" folder + $this->structure->copyFile('', $indexFile, 'index.html'); + if ( $module->getVar('mod_admin') == 1) { + // Creation of "admin" folder and index.html file + $this->structure->makeDirAndCopyFile('admin', $indexFile, 'index.html'); + } + if ( $module->getVar('mod_blocks') == 1) { + // Creation of "blocks" folder and index.html file + $this->structure->makeDirAndCopyFile('blocks', $indexFile, 'index.html'); + } + // Creation of "class" folder and index.html file + $this->structure->makeDirAndCopyFile('class', $indexFile, 'index.html'); + // Creation of "assets" folder and index.html file + $this->structure->makeDirAndCopyFile('assets', $indexFile, 'index.html'); + // Creation of "css" folder and index.html file + $this->structure->makeDirAndCopyFile('assets/css', $indexFile, 'index.html'); + // Creation of "images" folder and index.html file + $this->structure->makeDirAndCopyFile('assets/images', $indexFile, 'index.html'); + //Copy the logo of the module + $modImage = str_replace(' ', '', strtolower($module->getVar('mod_image'))); + $this->structure->copyFile('assets/images', $uploadImagesRepository.'/'.$modImage, $modImage); + // Creation of 'images/icons' folder and index.html file - Added in Version 1.15 + $this->structure->makeDirAndCopyFile('assets/images/icons', $indexFile, 'index.html'); + // Creation of "images/icons/16" folder and index.html file + $this->structure->makeDirAndCopyFile('assets/images/icons/16', $indexFile, 'index.html'); + // Creation of "images/icons/32" folder and index.html file + $this->structure->makeDirAndCopyFile('assets/images/icons/32', $indexFile, 'index.html'); + // Copy of 'module_author_logo.gif' file in uploads dir + $logoGifFrom = $uploadImagesRepository.'/'.$stlModuleAuthor.'_logo.gif'; + if (!file_exists($logoGifFrom)) { + copy($logosFolder.'/'.$stlModuleAuthor.'_logo.gif', $logoGifFrom); + } + // Creation of 'module_author_logo.gif' file + $this->structure->copyFile('assets/images', $logoGifFrom, $stlModuleAuthor.'_logo.gif'); + // Creation of "images" folder and index.html file + $this->structure->makeDirAndCopyFile('assets/js', $indexFile, 'index.html'); + // Creation of 'docs' folder and index.html file + $this->structure->makeDirAndCopyFile('docs', $indexFile, 'index.html'); + // Creation of 'credits.txt' file + $this->structure->copyFile('docs', $docsFolder.'/credits.txt', 'credits.txt'); + // Creation of 'install.txt' file + $this->structure->copyFile('docs', $docsFolder.'/install.txt', 'install.txt'); + // Creation of 'lang_diff.txt' file + $this->structure->copyFile('docs', $docsFolder.'/lang_diff.txt', 'lang_diff.txt'); + // Creation of 'license.txt' file + $this->structure->copyFile('docs', $docsFolder.'/license.txt', 'license.txt'); + // Creation of 'readme.txt' file + $this->structure->copyFile('docs', $docsFolder.'/readme.txt', 'readme.txt'); + // Creation of "include" folder and index.html file + $this->structure->makeDirAndCopyFile('include', $indexFile, 'index.html'); + // Creation of "language" folder and index.html file + $this->structure->makeDirAndCopyFile('language', $indexFile, 'index.html'); + // Creation of 'default english' folder + if($language != 'english' ) { + // Creation of "language/local_language" folder and index.html file + $this->structure->makeDirAndCopyFile('language/'.$language, $indexFile, 'index.html'); + // Creation of "language/local_language/help" folder and index.html file + $this->structure->makeDirAndCopyFile('language/'.$language. '/help', $indexFile, 'index.html'); + } + // Creation of "english" folder and index.html file + $this->structure->makeDirAndCopyFile('language/english', $indexFile, 'index.html'); + // Creation of "language/english/help" folder and index.html file + $this->structure->makeDirAndCopyFile('language/english/help', $indexFile, 'index.html'); + if( $module->getVar('mod_admin') == 1 ) { + // Creation of "templates" folder and index.html file + $this->structure->makeDirAndCopyFile('templates', $indexFile, 'index.html'); + } + if( $module->getVar('mod_admin') == 1 ) { + // Creation of "templates/admin" folder and index.html file + $this->structure->makeDirAndCopyFile('templates/admin', $indexFile, 'index.html'); + } + if(is_object($table)) { + if( $table->getVar('table_blocks') == 1 ) { + // Creation of "templates/blocks" folder and index.html file + $this->structure->makeDirAndCopyFile('templates/blocks', $indexFile, 'index.html'); + } + if( $table->getVar('table_name') != null ) { + // Creation of "sql" folder and index.html file + $this->structure->makeDirAndCopyFile('sql', $indexFile, 'index.html'); + } + if( $table->getVar('table_notifications') == 1 ) { + // Creation of "language/english/mail_template" folder and index.html file + $this->structure->makeDirAndCopyFile('language/english/mail_template', $indexFile, 'index.html'); + if($language != 'english' ) { + // Creation of "language/local_language/mail_template" folder and index.html file + $this->structure->makeDirAndCopyFile('language/'.$language.'/mail_template', $indexFile, 'index.html'); + } + } + } + } + + /* + * @public function createFilesToBuilding + * @param string $module + */ + public function createFilesToBuilding( $module ) + { + // Module + $modId = $module->getVar('mod_id'); + $moduleDirname = $module->getVar('mod_dirname'); + $uploadTablesIcons32 = $this->uploadPath.'/images/tables'; + $framePathIcon32 = XOOPS_... [truncated message content] |