• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/easy/FormRenderer.php

00001 <?php
00002 
00026 class FormRenderer
00027 {
00028 
00035     static public function render ($formObj)
00036     {
00037         $tplEngine = $formObj->m_TemplateEngine;
00038         $tplAttributes = FormRenderer::buildTemplateAttributes($formObj);
00039         
00040         if (isset($formObj->m_jsClass)) {
00041             $subForms = ($formObj->m_SubForms) ? implode(";", $formObj->m_SubForms) : "";
00042             if ($formObj->m_StaticOutput != true) {
00043                 $formScript = "\n<script>Openbiz.newFormObject('$formObj->m_Name','$formObj->m_jsClass','$subForms'); </script>\n";
00044             }
00045             if ($formObj->m_AutoRefresh > 0) {
00046                 $formScript .= "\n<script>setTimeout(\"Openbiz.CallFunction('$formObj->m_Name.UpdateForm()');\",\"" . ($formObj->m_AutoRefresh * 1000) . "\") </script>\n";
00047             }
00048         }
00049         
00050         if ($tplEngine == "Smarty" || $tplEngine == null)
00051             return FormRenderer::renderSmarty($formObj, $tplAttributes) . $formScript;
00052         else
00053             return FormRenderer::renderPHP($formObj, $tplAttributes) . $formScript;
00054     }
00055 
00062     static public function buildTemplateAttributes ($formObj)
00063     {
00064         // Assocative Array to hold all Template Values
00065         // Fill with default viewobj attributes
00066         $tplAttributes = $formObj->outputAttrs(); //jixian: we still need this function 
00067         
00068         $tplAttributes['title'] = $formObj->m_Title;
00069         $tplAttributes['errors'] = $formObj->m_Errors;
00070         $tplAttributes['notices'] = $formObj->m_Notices;
00071         $tplAttributes['formname'] = $formObj->m_Name;
00072         $tplAttributes['module'] = $formObj->getModuleName($formObj->m_Name);
00073         
00074         // if the $formobj form type is list render table, otherwise render record
00075         if (strtoupper($formObj->m_FormType) == 'LIST') {
00076             $recordSet = $formObj->fetchDataSet();
00077             $tplAttributes['dataPanel'] = $formObj->m_DataPanel->renderTable($recordSet);
00078         } else {
00079             $record = $formObj->fetchData();
00080             $tplAttributes['dataPanel'] = $formObj->m_DataPanel->renderRecord($record);
00081         }
00082         
00083         if (isset($formObj->m_SearchPanel)) {
00084             $search_record = $formObj->m_SearchPanelValues;
00085             foreach ($formObj->m_SearchPanel as $elem) {
00086                 if (! $elem->m_FieldName)
00087                     continue;
00088                 $post_value = BizSystem::clientProxy()->getFormInputs($elem->m_Name);
00089                 if ($post_value) {
00090                     $search_record[$elem->m_FieldName] = $post_value;
00091                 }
00092             }
00093             $tplAttributes['searchPanel'] = $formObj->m_SearchPanel->renderRecord($search_record);
00094         } else {
00095             $tplAttributes['searchPanel'] = $formObj->m_SearchPanel->render();
00096         }
00097         $tplAttributes['actionPanel'] = $formObj->m_ActionPanel->render();
00098         $tplAttributes['navPanel'] = $formObj->m_NavPanel->render();
00099         
00100         return $tplAttributes;
00101     }
00102 
00110     static protected function renderSmarty ($formObj, $tplAttributes = Array())
00111     {
00112         $smarty = BizSystem::getSmartyTemplate();
00113         $tplFile = BizSystem::getTplFileWithPath($formObj->m_TemplateFile, $formObj->m_Package);
00114         
00115         $formOutput = $formObj->outputAttrs();
00116         foreach ($formOutput as $k=>$v) {
00117             $smarty->assign($k, $v);
00118         }
00119         // render the formobj attributes
00120         $smarty->assign("form", $formOutput);
00121         
00122         //Translate Array of template variables to Zend template object
00123         foreach ($tplAttributes as $key => $value) {
00124             $smarty->assign($key, $value);
00125         }
00126         
00127         return $smarty->fetch($tplFile);
00128     }
00129 
00137     static protected function renderPHP ($formObj, $tplAttributes = Array())
00138     {
00139         $form = BizSystem::getZendTemplate();
00140         $tplFile = BizSystem::getTplFileWithPath($formObj->m_TemplateFile, $formObj->m_Package);
00141         $form->addScriptPath(dirname($tplFile));
00142         
00143         $formOutput = $formObj->outputAttrs();
00144         foreach ($formOutput as $k=>$v) {
00145             $form->$k = $v;
00146         }
00147 
00148         foreach ($tplAttributes as $key => $value) {
00149             if ($value == NULL) {
00150                 $form->$key = '';
00151             } else {
00152                 $form->$key = $value;
00153             }
00154         }
00155         
00156         // render the formobj attributes
00157         $form->form = $formOutput;
00158 
00159         return $form->render($formObj->m_TemplateFile);
00160     }
00161 }
00162 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2