hc = Modulebuilder\Files\CreateHtmlCode::getInstance(); $this->sc = Modulebuilder\Files\CreateSmartyCode::getInstance(); } /** * @static function getInstance * @return bool|Categories */ public static function getInstance() { static $instance = false; if (!$instance) { $instance = new self(); } return $instance; } /** * @public function write * @param $module * @param $table * @param string $filename */ public function write($module, $table, string $filename): void { $this->setModule($module); $this->setTable($table); $this->setFileName($filename); } /** * @private function getTemplatesUserCategoriesHeader * @param string $moduleDirname * @return string */ private function getTemplatesUserCategoriesHeader(string $moduleDirname): string { return $this->sc->getSmartyIncludeFile($moduleDirname) . PHP_EOL; } /** * @private function getTemplatesUserCategoriesTable * @param string $language * @param $moduleDirname * @param $tableName * @param $tableSoleName * @return string */ private function getTemplatesUserCategoriesTable($moduleDirname, $tableName, $tableSoleName, string $language): string { $single = $this->sc->getSmartySingleVar('table_type'); $table = $this->getTemplatesUserCategoriesThead($tableName, $language); $table .= $this->getTemplatesUserCategoriesTbody($moduleDirname, $tableName, $tableSoleName); return $this->hc->getHtmlTable($table, 'table table-' . $single) . PHP_EOL; } /** * @private function getTemplatesUserCategoriesThead * @param string $language * @param $tableName * @return string */ private function getTemplatesUserCategoriesThead($tableName, string $language): string { $stuTableName = \mb_strtoupper($tableName); $lang = $this->sc->getSmartyConst($language, $stuTableName . '_TITLE'); $single = $this->sc->getSmartySingleVar('numb_col'); $th = $this->hc->getHtmlTableHead($lang, '', $single) . PHP_EOL; $tr = $this->hc->getHtmlTableRow($th, 'head') . PHP_EOL; return $this->hc->getHtmlTableThead($tr) . PHP_EOL; } /** * @private function getTemplatesUserCategoriesTbody * @param string $moduleDirname * @param $tableName * @param $tableSoleName * @return string */ private function getTemplatesUserCategoriesTbody(string $moduleDirname, $tableName, $tableSoleName): string { $single = $this->sc->getSmartySingleVar('panel_type'); $include = $this->sc->getSmartyIncludeFileListForeach($moduleDirname, $tableName, $tableSoleName); $div = $this->hc->getHtmlDiv($include, 'panel panel-' . $single); $cont = $this->hc->getHtmlTableData($div) . PHP_EOL; $html = $this->hc->getHtmlEmpty('') . PHP_EOL; $cont .= $this->sc->getSmartyConditions($tableSoleName . '.count', ' is div by ', '$divideby', $html, false, false, false, '', "\n", true, false) . PHP_EOL; $foreach = $this->sc->getSmartyForeach($tableSoleName, $tableName, $cont) . PHP_EOL; $tr = $this->hc->getHtmlTableRow($foreach) . PHP_EOL; return $this->hc->getHtmlTableTbody($tr) . PHP_EOL; } /** * @private function getTemplatesUserCategoriesTfoot * @return string */ private function getTemplatesUserCategoriesTfoot(): string { $td = $this->hc->getHtmlTableData(' ') . PHP_EOL; $tr = $this->hc->getHtmlTableRow($td) . PHP_EOL; return $this->hc->getHtmlTableTfoot($tr) . PHP_EOL; } /** * @private function getTemplatesUserCategories * @param $moduleDirname * @param $tableName * @param $tableSoleName * @param $language * @return string */ private function getTemplatesUserCategories($moduleDirname, $tableName, $tableSoleName, $language): string { $tab = $this->getTemplatesUserCategoriesTable($moduleDirname, $tableName, $tableSoleName, $language) . PHP_EOL; $div = $this->hc->getHtmlDiv($tab, 'table-responsive') . PHP_EOL; return $this->sc->getSmartyConditions($tableName, ' gt ', '0', $div, false, true, false, '', "\n", true, 'int') . PHP_EOL; } /** * @private function getTemplatesUserCategoriesPanel * @param string $moduleDirname * @param string $tableName * @param $tableSoleName * @param $language * @return string */ private function getTemplatesUserCategoriesPanel(string $moduleDirname, string $tableName, $tableSoleName, $language): string { $stuTableName = \mb_strtoupper($tableName); $incl = $this->sc->getSmartyIncludeFileListForeach($moduleDirname, $tableName, $tableSoleName) . PHP_EOL; $html = $this->hc->getHtmlEmpty('
') . PHP_EOL; $incl .= $this->sc->getSmartyConditions($tableSoleName . '.count', ' is div by ', '$numb_col', $html, false, false, false, '',"\n", true, false) . PHP_EOL; $const = $this->sc->getSmartyConst($language, $stuTableName . '_TITLE'); $div = $this->hc->getHtmlDiv($const, 'panel-heading') . PHP_EOL; $cont = $this->hc->getHtmlDiv($incl, 'panel panel-body') . PHP_EOL; $div .= $this->sc->getSmartyForeach($tableSoleName, $tableName, $cont) . PHP_EOL; $panelType = $this->sc->getSmartySingleVar('panel_type'); return $this->hc->getHtmlDiv($div, 'panel panel-' . $panelType) . PHP_EOL; } /** * @private function getTemplatesUserCategoriesFooter * @param string $moduleDirname * * @return string */ private function getTemplatesUserCategoriesFooter(string $moduleDirname): string { return $this->sc->getSmartyIncludeFile($moduleDirname, 'footer'); } /** * @public function render * @return string */ public function render(): string { $module = $this->getModule(); $table = $this->getTable(); $filename = $this->getFileName(); $moduleDirname = $module->getVar('mod_dirname'); $tableName = $table->getVar('table_name'); $tableSoleName = $table->getVar('table_solename'); $language = $this->getLanguage($moduleDirname, 'MA', '', false); $content = $this->getTemplatesUserCategoriesHeader($moduleDirname); $content .= $this->getTemplatesUserCategoriesPanel($moduleDirname, $tableName, $tableSoleName, $language); $content .= $this->getTemplatesUserCategoriesFooter($moduleDirname); $this->create($moduleDirname, 'templates', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED); return $this->renderFile(); } }