/**
     * Generate code that will be inserted into the ModelConnector to connect a database object with this control.
     * This is called during the codegen process. This is very similar to the QListControl code, but there are
     * some differences. In particular, this control does not support ManyToMany references.
     *
     * @param QCodeGenBase $objCodeGen
     * @param QSqlTable $objTable
     * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
     * @return string
     */
    public function ConnectorCreate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn)
    {
        $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
        $strControlVarName = $objCodeGen->ModelConnectorVariableName($objColumn);
        $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));
        // Read the control type in case we are generating code for a subclass
        $strControlType = $objCodeGen->GetControlCodeGenerator($objColumn)->GetControlClass();
        $strRet = <<<TMPL
\t\t/**
\t\t * Create and setup a {$strControlType} {$strControlVarName}
\t\t * @param string \$strControlId optional ControlId to use
\t\t * @return {$strControlType}
\t\t */
\t\tpublic function {$strControlVarName}_Create(\$strControlId = null) {

TMPL;
        $strControlIdOverride = $objCodeGen->GenerateControlId($objTable, $objColumn);
        if ($strControlIdOverride) {
            $strRet .= <<<TMPL
\t\t\tif (!\$strControlId) {
\t\t\t\t\$strControlId = '{$strControlIdOverride}';
\t\t\t}

TMPL;
        }
        $strRet .= <<<TMPL
\t\t\t\$this->{$strControlVarName} = new {$strControlType}(\$this->objParentObject, \$strControlId);
\t\t\t\$this->{$strControlVarName}->Name = QApplication::Translate('{$strLabelName}');
\t\t\t\$this->{$strControlVarName}->DateTime = \$this->{$strObjectName}->{$objColumn->PropertyName};

TMPL;
        switch ($objColumn->DbType) {
            case QDatabaseFieldType::DateTime:
                $strRet .= "\t\t\t\$this->{$strControlVarName}->DateTimePickerType = QDateTimePickerType::DateTime;\n";
                break;
            case QDatabaseFieldType::Time:
                $strRet .= "\t\t\t\$this->{$strControlVarName}->DateTimePickerType = QDateTimePickerType::Time;\n";
                break;
            default:
                $strRet .= "\t\t\t\$this->{$strControlVarName}->DateTimePickerType = QDateTimePickerType::Date;\n";
        }
        if ($strMethod = QCodeGen::$PreferredRenderMethod) {
            $strRet .= <<<TMPL
\t\t\t\$this->{$strControlVarName}->PreferredRenderMethod = '{$strMethod}';

TMPL;
        }
        $strRet .= $this->ConnectorCreateOptions($objCodeGen, $objTable, $objColumn, $strControlVarName);
        $strRet .= <<<TMPL
\t\t\treturn \$this->{$strControlVarName};
\t\t}


TMPL;
        return $strRet;
    }
 public function __set($strName, $mixValue)
 {
     try {
         switch ($strName) {
             default:
                 return parent::__set($strName, $mixValue);
         }
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
     }
 }
    /**
     * Generate code that will be inserted into the ModelConnector to connect a database object with this control.
     * This is called during the codegen process. This is very similar to the QListControl code, but there are
     * some differences. In particular, this control does not support ManyToMany references.
     *
     * @param QCodeGenBase $objCodeGen
     * @param QSqlTable $objTable
     * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
     * @return string
     */
    public function ConnectorCreate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn)
    {
        $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
        $strClassName = $objTable->ClassName;
        $strControlVarName = $objCodeGen->ModelConnectorVariableName($objColumn);
        $strLabelName = addslashes(QCodeGen::ModelConnectorControlName($objColumn));
        // Read the control type in case we are generating code for a subclass of QTextBox
        $strControlType = $objCodeGen->GetControlCodeGenerator($objColumn)->GetControlClass();
        $strRet = <<<TMPL
\t\t/**
\t\t * Create and setup a {$strControlType} {$strControlVarName}
\t\t * @param string \$strControlId optional ControlId to use
\t\t * @return {$strControlType}
\t\t */
\t\tpublic function {$strControlVarName}_Create(\$strControlId = null) {

TMPL;
        $strControlIdOverride = $objCodeGen->GenerateControlId($objTable, $objColumn);
        if ($strControlIdOverride) {
            $strRet .= <<<TMPL
\t\t\tif (!\$strControlId) {
\t\t\t\t\$strControlId = '{$strControlIdOverride}';
\t\t\t}

TMPL;
        }
        $strRet .= <<<TMPL
\t\t\t\$this->{$strControlVarName} = new {$strControlType}(\$this->objParentObject, \$strControlId);
\t\t\t\$this->{$strControlVarName}->Name = QApplication::Translate('{$strLabelName}');

TMPL;
        if ($strMethod = QCodeGen::$PreferredRenderMethod) {
            $strRet .= <<<TMPL
\t\t\t\$this->{$strControlVarName}->PreferredRenderMethod = '{$strMethod}';

TMPL;
        }
        $strRet .= $this->ConnectorCreateOptions($objCodeGen, $objTable, $objColumn, $strControlVarName);
        $strRet .= $this->ConnectorRefresh($objCodeGen, $objTable, $objColumn, true);
        $strRet .= <<<TMPL
\t\t\treturn \$this->{$strControlVarName};
\t\t}


TMPL;
        return $strRet;
    }
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function <?php 
echo $strLabelId;
?>
_Create($strControlId = null, $strDateTimeFormat = null) {
			$this-><?php 
echo $strLabelId;
?>
 = new QLabel($this->objParentObject, $strControlId);
			$this-><?php 
echo $strLabelId;
?>
->Name = QApplication::Translate('<?php 
echo QCodeGen::MetaControlLabelNameFromColumn($objColumn);
?>
');
			$this->str<?php 
echo $objColumn->PropertyName;
?>
DateTimeFormat = $strDateTimeFormat;
			$this-><?php 
echo $strLabelId;
?>
->Text = sprintf($this-><?php 
echo $strObjectName;
?>
-><?php 
echo $objColumn->PropertyName;
?>
    public function ConnectorGet(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn)
    {
        $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
        $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
        $strControlVarName = $this->VarName($strPropName);
        $strRet = <<<TMPL
\t\t\t\tcase '{$strPropName}NullLabel':
\t\t\t\t\treturn \$this->str{$strPropName}NullLabel;

TMPL;
        return $strRet;
    }
<?php

/** @var QSqlTable $objTable */
/** @var QDatabaseCodeGen $objCodeGen */
global $_TEMPLATE_SETTINGS;
$strPropertyName = QCodeGen::DataListPropertyName($objTable);
$_TEMPLATE_SETTINGS = array('OverwriteFlag' => true, 'DocrootFlag' => false, 'DirectorySuffix' => '', 'TargetDirectory' => __PANEL_GEN__, 'TargetFileName' => $strPropertyName . 'ListPanel.tpl.php');
$listCodegenerator = $objCodeGen->GetDataListCodeGenerator($objTable);
$strListVarName = $objCodeGen->DataListVarName($objTable);
print "<?php\n";
?>
	/**
	 * This is a draft template file for the <?php 
echo $strPropertyName;
?>
ListPanel.
	 * This file will be overwritten every time you do a code generation. If you would like to make manual modifications
	 * to this file, you should move it out of this directory and into another location, and then modify the
     * Template property of the <?php 
echo $strPropertyName;
?>
ListPanel to point to the new location.
	 **/
?>

<?php 
if (!isset($objTable->Options['CreateFilter']) || $objTable->Options['CreateFilter'] !== false) {
    print '<?= _r($this->pnlFilter); ?>' . "\n";
}
print '<?= _r($this->' . $strListVarName . '); ?>' . "\n";
print '<?= _r($this->pnlButtons); ?>' . "\n";
Ejemplo n.º 7
0
 public function __construct()
 {
     QCodeGen::$TemplateEscapeBegin = '<%';
     QCodeGen::$TemplateEscapeEnd = '%>';
     QCodeGen::$TemplateEscapeBeginLength = strlen(QCodeGen::$TemplateEscapeBegin);
     QCodeGen::$TemplateEscapeEndLength = strlen(QCodeGen::$TemplateEscapeEnd);
 }
Ejemplo n.º 8
0
Where CODEGEN_SETTINGS is the absolute filepath of the codegen_settings.xml
file, containing the code generator settings.

For more information, please go to http://qcu.be
';
    exit;
}
if ($_SERVER['argc'] != 2) {
    PrintInstructions();
}
/////////////////////
// Run Code Gen
QCodeGen::Run($_SERVER['argv'][1]);
/////////////////////
if ($strErrors == QCodeGen::$RootErrors) {
    printf("The following ROOT ERRORS were reported:\r\n%s\r\n\r\n", $strErrors);
} else {
    printf("CodeGen settings (as evaluted from %s):\r\n%s\r\n\r\n", $_SERVER['argv'][1], QCodeGen::GetSettingsXml());
}
foreach (QCodeGen::$CodeGenArray as $objCodeGen) {
    printf("%s\r\n---------------------------------------------------------------------\r\n", $objCodeGen->GetTitle());
    printf("%s\r\n", $objCodeGen->GetReportLabel());
    printf("%s\r\n", $objCodeGen->GenerateAll());
    if ($strErrors = $objCodeGen->Errors) {
        printf("The following errors were reported:\r\n%s\r\n", $strErrors);
    }
    print "\r\n";
}
foreach (QCodeGen::GenerateAggregate() as $strMessage) {
    printf("%s\r\n\r\n", $strMessage);
}
 /**
  * Returns code to refresh the control from the saved object.
  *
  * @param QCodeGenBase $objCodeGen
  * @param QSqlTable $objTable
  * @param QSqlColumn|QReverseReference $objColumn
  * @param bool $blnInit
  * @throws Exception
  * @return string
  */
 public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false)
 {
     $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
     $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
     $strControlVarName = $this->VarName($strPropName);
     // Preamble with an if test if not initializing
     $strRet = '';
     if ($objColumn instanceof QSqlColumn) {
         if ($objColumn->Identity || $objColumn->Timestamp) {
             $strRet = "\$this->{$strControlVarName}->Text =  \$this->blnEditMode ? \$this->{$strObjectName}->{$strPropName} : QApplication::Translate('N\\A');";
         } else {
             if ($objColumn->Reference) {
                 if ($objColumn->Reference->IsType) {
                     $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$objColumn->PropertyName} ? {$objColumn->Reference->VariableType}::\$NameArray[\$this->{$strObjectName}->{$objColumn->PropertyName}] : null;";
                 } else {
                     $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName} ? \$this->{$strObjectName}->{$strPropName}->__toString() : null;";
                 }
             } else {
                 switch ($objColumn->VariableType) {
                     case "boolean":
                         $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName} ? QApplication::Translate('Yes') : QApplication::Translate('No');";
                         break;
                     case "QDateTime":
                         $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName} ? \$this->{$strObjectName}->{$strPropName}->qFormat(\$this->str{$strPropName}DateTimeFormat) : null;";
                         break;
                     default:
                         $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName};";
                 }
             }
         }
     } elseif ($objColumn instanceof QReverseReference) {
         if ($objColumn->Unique) {
             $strRet = "\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$objColumn->ObjectPropertyName} ? \$this->{$strObjectName}->{$objColumn->ObjectPropertyName}->__toString() : null;";
         }
     } elseif ($objColumn instanceof QManyToManyReference) {
         $strRet = "\$this->{$strControlVarName}->Text = implode(\$this->str{$objColumn->ObjectDescription}Glue, \$this->{$strObjectName}->Get{$objColumn->ObjectDescription}Array());";
     } else {
         throw new Exception('Unknown column type.');
     }
     if (!$blnInit) {
         $strRet = "\t\t\tif (\$this->{$strControlVarName}) " . $strRet;
     } else {
         $strRet = "\t\t\t" . $strRet;
     }
     return $strRet . "\n";
 }
Ejemplo n.º 10
0
 public static function Run($strSettingsXmlFilePath)
 {
     QCodeGen::$CodeGenArray = array();
     QCodeGen::$SettingsFilePath = $strSettingsXmlFilePath;
     if (!file_exists($strSettingsXmlFilePath)) {
         QCodeGen::$RootErrors = 'FATAL ERROR: CodeGen Settings XML File (' . $strSettingsXmlFilePath . ') was not found.';
         return;
     }
     if (!is_file($strSettingsXmlFilePath)) {
         QCodeGen::$RootErrors = 'FATAL ERROR: CodeGen Settings XML File (' . $strSettingsXmlFilePath . ') was not found.';
         return;
     }
     // Try Parsing the Xml Settings File
     try {
         QApplication::SetErrorHandler('QcodoHandleCodeGenParseError', E_ALL);
         QCodeGen::$SettingsXml = new SimpleXMLElement(file_get_contents($strSettingsXmlFilePath));
         QApplication::RestoreErrorHandler();
     } catch (Exception $objExc) {
         QCodeGen::$RootErrors .= 'FATAL ERROR: Unable to parse CodeGenSettings XML File: ' . $strSettingsXmlFilePath;
         QCodeGen::$RootErrors .= "\r\n";
         QCodeGen::$RootErrors .= $objExc->getMessage();
         return;
     }
     // Set the Template Escaping
     QCodeGen::$TemplateEscapeBegin = QCodeGen::LookupSetting(QCodeGen::$SettingsXml, 'templateEscape', 'begin');
     QCodeGen::$TemplateEscapeEnd = QCOdeGen::LookupSetting(QCodeGen::$SettingsXml, 'templateEscape', 'end');
     QCodeGen::$TemplateEscapeBeginLength = strlen(QCodeGen::$TemplateEscapeBegin);
     QCodeGen::$TemplateEscapeEndLength = strlen(QCodeGen::$TemplateEscapeEnd);
     if (!QCodeGen::$TemplateEscapeBeginLength || !QCodeGen::$TemplateEscapeEndLength) {
         QCodeGen::$RootErrors .= "CodeGen Settings XML Fatal Error: templateEscape begin and/or end was not defined\r\n";
         return;
     }
     // Application Name
     QCodeGen::$ApplicationName = QCodeGen::LookupSetting(QCodeGen::$SettingsXml, 'name', 'application');
     // Iterate Through DataSources
     if (QCodeGen::$SettingsXml->dataSources->asXML()) {
         foreach (QCodeGen::$SettingsXml->dataSources->children() as $objChildNode) {
             switch (dom_import_simplexml($objChildNode)->nodeName) {
                 case 'database':
                     QCodeGen::$CodeGenArray[] = new QDatabaseCodeGen($objChildNode);
                     break;
                 case 'restService':
                     QCodeGen::$CodeGenArray[] = new QRestServiceCodeGen($objChildNode);
                     break;
                 default:
                     QCodeGen::$RootErrors .= sprintf("Invalid Data Source Type in CodeGen Settings XML File (%s): %s\r\n", $strSettingsXmlFilePath, dom_import_simplexml($objChildNode)->nodeName);
                     break;
             }
         }
     }
 }
    /**
     * @param QCodeGenBase $objCodeGen
     * @param QSqlTable $objTable
     * @param QSqlColumn|QReverseReference $objColumn
     * @return string
     */
    public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn)
    {
        $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
        $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn);
        $strControlVarName = $this->VarName($strPropName);
        $strRet = '';
        if ($objColumn instanceof QSqlColumn) {
            $strRet = <<<TMPL
\t\t\t\tif (\$this->{$strControlVarName}) \$this->{$strObjectName}->{$objColumn->PropertyName} = \$this->{$strControlVarName}->SelectedValue;

TMPL;
        } elseif ($objColumn instanceof QReverseReference) {
            $strRet = <<<TMPL
\t\t\t\tif (\$this->{$strControlVarName}) \$this->{$strObjectName}->{$objColumn->ObjectPropertyName} = {$objColumn->VariableType}::Load(\$this->{$strControlVarName}->SelectedValue);

TMPL;
        }
        return $strRet;
    }
 /**
  * Returns the control label name as used in the ModelConnector corresponding to this column or table.
  *
  * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
  *
  * @return string
  */
 public static function ModelConnectorControlName($objColumn)
 {
     if (($o = $objColumn->Options) && isset($o['Name'])) {
         // Did developer default?
         return $o['Name'];
     }
     return QConvertNotation::WordsFromCamelCase(QCodeGen::ModelConnectorPropertyName($objColumn));
 }
    /**
     * Generates an alternate create columns function that could be used by the list panel to create the columns directly.
     * This is designed to be added as commented out code in the list panel override class that the user can choose to use.
     *
     * @param QCodeGenBase $objCodeGen
     * @param QSqlTable $objTable
     * @return string
     */
    public function DataListSubclassOverrides(QCodeGenBase $objCodeGen, QSqlTable $objTable)
    {
        $strVarName = $objCodeGen->DataListVarName($objTable);
        $strPropertyName = QCodeGen::DataListPropertyName($objTable);
        $strCode = <<<TMPL
/*
\t Uncomment this block to directly create the columns here, rather than creating them in the {$strPropertyName}List connector.
\t You can then modify the column creation process by editing the function below. Or, you can instead call the parent function 
\t and modify the columns after the {$strPropertyName}List creates the default columns.

\tprotected function {$strVarName}_CreateColumns() {

TMPL;
        foreach ($objTable->ColumnArray as $objColumn) {
            if (isset($objColumn->Options['FormGen']) && $objColumn->Options['FormGen'] == QFormGen::None) {
                continue;
            }
            if (isset($objColumn->Options['NoColumn']) && $objColumn->Options['NoColumn']) {
                continue;
            }
            $strCode .= <<<TMPL
\t\t\$col = \$this->{$strVarName}->CreateNodeColumn("{$objCodeGen->ModelConnectorControlName($objColumn)}", QQN::{$objTable->ClassName}()->{$objCodeGen->ModelConnectorPropertyName($objColumn)});

TMPL;
        }
        foreach ($objTable->ReverseReferenceArray as $objReverseReference) {
            if ($objReverseReference->Unique) {
                $strCode .= <<<TMPL
\t\t\$col = \$this->{$strVarName}->CreateNodeColumn("{$objCodeGen->ModelConnectorControlName($objReverseReference)}", QQN::{$objTable->ClassName}()->{$objReverseReference->ObjectDescription});

TMPL;
            }
        }
        $strCode .= <<<TMPL
\t}

*/\t

TMPL;
        $strCode .= <<<TMPL
\t\t
/*
\t Uncomment this block to use an Edit column instead of clicking on a highlighted row in order to edit an item.

\t\tprotected \$pxyEditRow;

\t\tprotected function {$strVarName}_MakeEditable () {
\t\t\t\$pxyEditRow = new QControlProxy(\$this);
\t\t\t\$pxyEditRow->AddAction(new QClickEvent(), new QAjaxControlAction(\$this, '{$strVarName}_EditClick'));
\t\t\t\$this->{$strVarName}->CreateLinkColumn(QApplication::Translate('Edit'), QApplication::Translate('Edit'), \$pxyEditRow, QQN::{$objTable->ClassName}()->Id, null, false, 0);
\t\t}

\t\tprotected function {$strVarName}_EditClick(\$strFormId, \$strControlId, \$param) {
\t\t\t\$this->EditItem(\$param);
\t\t}
*/\t

TMPL;
        return $strCode;
    }
<?php

/** @var QSqlTable $objTable */
/** @var QDatabaseCodeGen $objCodeGen */
global $_TEMPLATE_SETTINGS;
$strPropertyName = QCodeGen::DataListPropertyName($objTable);
$strPropertyNamePlural = QCodeGen::DataListPropertyNamePlural($objTable);
$_TEMPLATE_SETTINGS = array('OverwriteFlag' => true, 'DocrootFlag' => true, 'DirectorySuffix' => '', 'TargetDirectory' => __FORMS__, 'TargetFileName' => QConvertNotation::UnderscoreFromCamelCase($objTable->ClassName) . '_edit.tpl.php');
print "<?php\n";
?>
	// This is the HTML template include file (.tpl.php) for the <?php 
echo QConvertNotation::UnderscoreFromCamelCase($strPropertyName);
?>
_edit.php
	// Feel free to edit this as needed.
	global $gObjectName;
	global $gObjectNamePlural;

	$gObjectName =  QApplication::Translate('<?php 
echo $strPropertyName;
?>
');
	$gObjectNamePlural =  QApplication::Translate('<?php 
echo $strPropertyNamePlural;
?>
');

	$strPageTitle = QApplication::Translate('<?php 
echo $strPropertyName;
?>
');
Ejemplo n.º 15
0
<?php

/** @var QSqlTable $objTable */
/** @var QDatabaseCodeGen $objCodeGen */
global $_TEMPLATE_SETTINGS;
$strPropertyName = QCodeGen::DataListPropertyName($objTable);
$strClassName = QCodeGen::DataListControlClass($objTable);
$listCodegenerator = $objCodeGen->GetDataListCodeGenerator($objTable);
$strListVarName = $objCodeGen->DataListVarName($objTable);
$options = $objTable->Options;
$_TEMPLATE_SETTINGS = array('OverwriteFlag' => true, 'DocrootFlag' => false, 'DirectorySuffix' => '', 'TargetDirectory' => __MODEL_CONNECTOR_GEN__, 'TargetFileName' => $objTable->ClassName . 'ListGen.class.php');
print "<?php\n";
?>
/**
 * This is the generated connector class for the List functionality
 * of the <?php 
echo $objTable->ClassName;
?>
 class.  This code-generated class
 * subclasses a <?php 
echo $strPropertyName;
?>
 class and can be used to display
 * a collection of <?php 
echo $objTable->ClassName;
?>
 objects.
 *
 * To take advantage of some (or all) of these control objects, you
 * must create an instance of this object in a QForm or QPanel.
 *
 /**
  * Dialog button has been clicked. Save the options, or Save, codegen, and then reload.
  *
  * @param $strFormId
  * @param $strControlId
  * @param $mixParam
  */
 public function ButtonClick($strFormId, $strControlId, $mixParam)
 {
     if ($mixParam == 'save') {
         $this->UpdateControlInfo();
         $this->WriteParams();
     } elseif ($mixParam == 'saveRefresh') {
         $this->UpdateControlInfo();
         $this->WriteParams();
         QCodeGen::Run(__CONFIGURATION__ . '/codegen_settings.xml');
         foreach (QCodeGen::$CodeGenArray as $objCodeGen) {
             $objCodeGen->GenerateAll();
             // silently codegen
         }
         QApplication::Redirect($_SERVER['PHP_SELF']);
     }
     $this->Close();
 }