public function __set($strName, $mixValue) { // These are included here because this class is constructed before code generation // include_once(__INCLUDES__ . '/qcodo/_core/codegen/QConvertNotationBase.class.php'); include_once __INCLUDES__ . '/qcodo/codegen/QConvertNotation.class.php'; switch ($strName) { /////////////////// // Member Variables /////////////////// default: try { $objAdminSetting = AdminSetting::LoadByShortDescription(QConvertNotation::UnderscoreFromCamelCase($strName)); $objAdminSetting->Value = $mixValue; return $objAdminSetting->Save(); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }
/** * Similar to MetaAddColumn, except it creates a column for a Type-based Id. You MUST specify * the name of the Type class that this will attempt to use $NameArray against. * * Also, $mixContent cannot be an array. Only a single field can be specified. * * @param mixed $mixContent string or QQNode from Country * @param string $strTypeClassName the name of the TypeClass to use $NameArray against * @param mixed $objOverrideParameters */ public function MetaAddTypeColumn($mixContent, $strTypeClassName, $objOverrideParameters = null) { // Validate TypeClassName if (!class_exists($strTypeClassName) || !property_exists($strTypeClassName, 'NameArray')) { throw new QCallerException('Invalid TypeClass Name: ' . $strTypeClassName); } // Validate Node try { $objNode = $this->ResolveContentItem($mixContent); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } // Create the Column $strName = QConvertNotation::WordsFromCamelCase($objNode->_PropertyName); if (strtolower(substr($strName, strlen($strName) - 3)) == ' id') { $strName = substr($strName, 0, strlen($strName) - 3); } $strProperty = $objNode->GetDataGridHtml(); $objNewColumn = new QDataGridColumn(QApplication::Translate($strName), sprintf('<?=(%s) ? %s::$NameArray[%s] : null;?>', $strProperty, $strTypeClassName, $strProperty), array('OrderByClause' => QQ::OrderBy($objNode), 'ReverseOrderByClause' => QQ::OrderBy($objNode, false))); // Perform Overrides $objOverrideArray = func_get_args(); if (count($objOverrideArray) > 2) { try { unset($objOverrideArray[0]); unset($objOverrideArray[1]); $objNewColumn->OverrideAttributes($objOverrideArray); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } $this->AddColumn($objNewColumn); return $objNewColumn; }
protected function AnalyzeTable(QTable $objTable) { // Setup the Table Object $strTableName = $objTable->Name; $objTable->ClassName = $this->ClassNameFromTableName($strTableName); $objTable->ClassNamePlural = $this->Pluralize($objTable->ClassName); // Get the List of Columns $objFieldArray = $this->objDb->GetFieldsForTable($strTableName); // Iterate through the list of Columns to create objColumnArray $objColumnArray = array(); if ($objFieldArray) { foreach ($objFieldArray as $objField) { $objColumn = $this->AnalyzeTableColumn($objField, $objTable); $objColumnArray[strtolower($objColumn->Name)] = $objColumn; } } $objTable->ColumnArray = $objColumnArray; // Get the List of Indexes $objTable->IndexArray = $this->objDb->GetIndexesForTable($objTable->Name); // Create an Index array $objIndexArray = array(); // Create our Index for Primary Key (if applicable) $strPrimaryKeyArray = array(); foreach ($objColumnArray as $objColumn) { if ($objColumn->PrimaryKey) { $objPkColumn = $objColumn; array_push($strPrimaryKeyArray, $objColumn->Name); } } if (count($strPrimaryKeyArray)) { $objIndex = new QIndex(); $objIndex->KeyName = 'pk_' . $strTableName; $objIndex->PrimaryKey = true; $objIndex->Unique = true; $objIndex->ColumnNameArray = $strPrimaryKeyArray; array_push($objIndexArray, $objIndex); if (count($strPrimaryKeyArray) == 1) { $objPkColumn->Unique = true; $objPkColumn->Indexed = true; } } //if ($strTableName == 'campus_job') exit(var_dump($objPkColumn)); // Iterate though each Index that exists in this table, set any Columns's "Index" property // to TRUE if they are a single-column index if ($objTable->IndexArray) { foreach ($objArray = $objTable->IndexArray as $objDatabaseIndex) { // Make sure the columns are defined if (count($objDatabaseIndex->ColumnNameArray) == 0) { $this->strErrors .= sprintf("Index %s in table %s indexes on no columns.\n", $objDatabaseIndex->KeyName, $strTableName); } else { // Ensure every column exist in the DbIndex's ColumnNameArray $blnFailed = false; foreach ($objArray = $objDatabaseIndex->ColumnNameArray as $strColumnName) { if (array_key_exists(strtolower($strColumnName), $objTable->ColumnArray) && $objTable->ColumnArray[strtolower($strColumnName)]) { // It exists -- do nothing } else { // Otherwise, add a warning $this->strErrors .= sprintf("Index %s in table %s indexes on the column %s, which does not appear to exist.\n", $objDatabaseIndex->KeyName, $strTableName, $strColumnName); $blnFailed = true; } } if (!$blnFailed) { // Let's make sure if this is a single-column index, we haven't already created a single-column index for this column $blnAlreadyCreated = false; foreach ($objIndexArray as $objIndex) { if (count($objIndex->ColumnNameArray) == count($objDatabaseIndex->ColumnNameArray)) { if (implode(',', $objIndex->ColumnNameArray) == implode(',', $objDatabaseIndex->ColumnNameArray)) { $blnAlreadyCreated = true; } } } if (!$blnAlreadyCreated) { // Create the Index Object $objIndex = new QIndex(); $objIndex->KeyName = $objDatabaseIndex->KeyName; $objIndex->PrimaryKey = $objDatabaseIndex->PrimaryKey; $objIndex->Unique = $objDatabaseIndex->Unique; if ($objDatabaseIndex->PrimaryKey) { $objIndex->Unique = true; } $objIndex->ColumnNameArray = $objDatabaseIndex->ColumnNameArray; // Add the new index object to the index array array_push($objIndexArray, $objIndex); // Lastly, if it's a single-column index, update the Column in the table to reflect this if (count($objDatabaseIndex->ColumnNameArray) == 1) { $strColumnName = $objDatabaseIndex->ColumnNameArray[0]; $objColumn = $objTable->ColumnArray[strtolower($strColumnName)]; $objColumn->Indexed = true; if ($objIndex->Unique) { $objColumn->Unique = true; } } } } } } } // Add the IndexArray to the table $objTable->IndexArray = $objIndexArray; // Get the List of Foreign Keys from the database $objForeignKeys = $this->objDb->GetForeignKeysForTable($objTable->Name); // Add to it, the list of Foreign Keys from any Relationships Script $objForeignKeys = $this->GetForeignKeysFromRelationshipsScript($strTableName, $objForeignKeys); // Iterate through each foreign key that exists in this table if ($objForeignKeys) { foreach ($objForeignKeys as $objForeignKey) { // Make sure it's a single-column FK if (count($objForeignKey->ColumnNameArray) != 1) { $this->strErrors .= sprintf("Foreign Key %s in table %s keys on multiple columns. Multiple-columned FKs are not supported by the code generator.\n", $objForeignKey->KeyName, $strTableName); } else { // Make sure the column in the FK definition actually exists in this table $strColumnName = $objForeignKey->ColumnNameArray[0]; if (array_key_exists(strtolower($strColumnName), $objTable->ColumnArray) && ($objColumn = $objTable->ColumnArray[strtolower($strColumnName)])) { // Now, we make sure there is a single-column index for this FK that exists $blnFound = false; if ($objIndexArray = $objTable->IndexArray) { foreach ($objIndexArray as $objIndex) { if (count($objIndex->ColumnNameArray) == 1 && strtolower($objIndex->ColumnNameArray[0]) == strtolower($strColumnName)) { $blnFound = true; } } } if (!$blnFound) { // Single Column Index for this FK does not exist. Let's create a virtual one and warn $objIndex = new QIndex(); $objIndex->KeyName = sprintf('virtualix_%s_%s', $objTable->Name, $objColumn->Name); $objIndex->Unique = $objColumn->Unique; $objIndex->ColumnNameArray = array($objColumn->Name); $objIndexArray = $objTable->IndexArray; $objIndexArray[] = $objIndex; $objTable->IndexArray = $objIndexArray; if ($objIndex->Unique) { $this->strErrors .= sprintf("Notice: It is recommended that you add a single-column UNIQUE index on \"%s.%s\" for the Foreign Key %s\r\n", $strTableName, $strColumnName, $objForeignKey->KeyName); } else { $this->strErrors .= sprintf("Notice: It is recommended that you add a single-column index on \"%s.%s\" for the Foreign Key %s\r\n", $strTableName, $strColumnName, $objForeignKey->KeyName); } } // Make sure the table being referenced actually exists if (array_key_exists(strtolower($objForeignKey->ReferenceTableName), $this->objTableArray) || array_key_exists(strtolower($objForeignKey->ReferenceTableName), $this->objTypeTableArray)) { // STEP 1: Create the New Reference $objReference = new QReference(); // Retrieve the Column object $objColumn = $objTable->ColumnArray[strtolower($strColumnName)]; // Setup Key Name $objReference->KeyName = $objForeignKey->KeyName; $strReferencedTableName = $objForeignKey->ReferenceTableName; // Setup IsType flag if (array_key_exists(strtolower($strReferencedTableName), $this->objTypeTableArray)) { $objReference->IsType = true; } else { $objReference->IsType = false; } // Setup Table and Column names $objReference->Table = $strReferencedTableName; $objReference->Column = $objForeignKey->ReferenceColumnNameArray[0]; // Setup VariableType $objReference->VariableType = $this->ClassNameFromTableName($strReferencedTableName); // Setup PropertyName and VariableName $objReference->PropertyName = $this->ReferencePropertyNameFromColumn($objColumn); $objReference->VariableName = $this->ReferenceVariableNameFromColumn($objColumn); // Add this reference to the column $objColumn->Reference = $objReference; // STEP 2: Setup the REVERSE Reference for Non Type-based References if (!$objReference->IsType) { // Retrieve the ReferencedTable object // $objReferencedTable = $this->objTableArray[strtolower($objReference->Table)]; $objReferencedTable = $this->GetTable($objReference->Table); $objReverseReference = new QReverseReference(); $objReverseReference->KeyName = $objReference->KeyName; $objReverseReference->Table = $strTableName; $objReverseReference->Column = $strColumnName; $objReverseReference->NotNull = $objColumn->NotNull; $objReverseReference->Unique = $objColumn->Unique; $objReverseReference->PropertyName = $this->PropertyNameFromColumn($this->GetColumn($strTableName, $strColumnName)); $objReverseReference->ObjectDescription = $this->CalculateObjectDescription($strTableName, $strColumnName, $strReferencedTableName, false); $objReverseReference->ObjectDescriptionPlural = $this->CalculateObjectDescription($strTableName, $strColumnName, $strReferencedTableName, true); $objReverseReference->VariableName = $this->ReverseReferenceVariableNameFromTable($objTable->Name); $objReverseReference->VariableType = $this->ReverseReferenceVariableTypeFromTable($objTable->Name); // For Special Case ReverseReferences, calculate Associated MemberVariableName and PropertyName... // See if ReverseReference is due to an ORM-based Class Inheritence Chain if (count($objTable->PrimaryKeyColumnArray) == 1 && $objColumn->PrimaryKey) { $objReverseReference->ObjectMemberVariable = QConvertNotation::PrefixFromType(QType::Object) . $objReverseReference->VariableType; $objReverseReference->ObjectPropertyName = $objReverseReference->VariableType; $objReverseReference->ObjectDescription = $objReverseReference->VariableType; $objReverseReference->ObjectDescriptionPlural = $this->Pluralize($objReverseReference->VariableType); // Otherwise, see if it's just plain ol' unique } else { if ($objColumn->Unique) { $objReverseReference->ObjectMemberVariable = $this->CalculateObjectMemberVariable($strTableName, $strColumnName, $strReferencedTableName); $objReverseReference->ObjectPropertyName = $this->CalculateObjectPropertyName($strTableName, $strColumnName, $strReferencedTableName); } } // Add this ReverseReference to the referenced table's ReverseReferenceArray $objArray = $objReferencedTable->ReverseReferenceArray; array_push($objArray, $objReverseReference); $objReferencedTable->ReverseReferenceArray = $objArray; } } else { $this->strErrors .= sprintf("Foreign Key %s in table %s references a table %s that does not appear to exist.\n", $objForeignKey->KeyName, $strTableName, $objForeignKey->ReferenceTableName); } } else { $this->strErrors .= sprintf("Foreign Key %s in table %s indexes on a column that does not appear to exist.\n", $objForeignKey->KeyName, $strTableName); } } } } // Verify: Table Name is valid (alphanumeric + "_" characters only, must not start with a number) // and NOT a PHP Reserved Word $strMatches = array(); preg_match('/' . $this->strPatternTableName . '/', $strTableName, $strMatches); if (count($strMatches) && $strMatches[0] == $strTableName && $strTableName != '_') { // Setup Reserved Words $strReservedWords = explode(',', QCodeGen::PhpReservedWords); for ($intIndex = 0; $intIndex < count($strReservedWords); $intIndex++) { $strReservedWords[$intIndex] = strtolower(trim($strReservedWords[$intIndex])); } $strTableNameToTest = trim(strtolower($strTableName)); foreach ($strReservedWords as $strReservedWord) { if ($strTableNameToTest == $strReservedWord) { $this->strErrors .= sprintf("Table '%s' has a table name which is a PHP reserved word.\r\n", $strTableName); unset($this->objTableArray[strtolower($strTableName)]); return; } } } else { $this->strErrors .= sprintf("Table '%s' can only contain characters that are alphanumeric or _, and must not begin with a number.\r\n", $strTableName); unset($this->objTableArray[strtolower($strTableName)]); return; } // Verify: Column Names are all valid names $objColumnArray = $objTable->ColumnArray; foreach ($objColumnArray as $objColumn) { $strColumnName = $objColumn->Name; $strMatches = array(); preg_match('/' . $this->strPatternColumnName . '/', $strColumnName, $strMatches); if (count($strMatches) && $strMatches[0] == $strColumnName && $strColumnName != '_') { } else { $this->strErrors .= sprintf("Table '%s' has an invalid column name: '%s'\r\n", $strTableName, $strColumnName); unset($this->objTableArray[strtolower($strTableName)]); return; } } // Verify: Table has at least one PK $blnFoundPk = false; $objColumnArray = $objTable->ColumnArray; foreach ($objColumnArray as $objColumn) { if ($objColumn->PrimaryKey) { $blnFoundPk = true; } } if (!$blnFoundPk) { $this->strErrors .= sprintf("Table %s does not have any defined primary keys.\n", $strTableName); unset($this->objTableArray[strtolower($strTableName)]); return; } }
protected function CalculateObjectDescriptionForAssociation($strAssociationTableName, $strTableName, $strReferencedTableName, $blnPluralize) { // Strip Prefixes (if applicable) $strTableName = $this->StripPrefixFromTable($strTableName); $strAssociationTableName = $this->StripPrefixFromTable($strAssociationTableName); $strReferencedTableName = $this->StripPrefixFromTable($strReferencedTableName); // Starting Point $strToReturn = QConvertNotation::CamelCaseFromUnderscore($strReferencedTableName); if ($blnPluralize) { $strToReturn = $this->Pluralize($strToReturn); } // Let's start with strAssociationTableName // Rip out trailing "_assn" if applicable $strAssociationTableName = str_replace($this->strAssociationTableSuffix, '', $strAssociationTableName); // Take out strTableName if applicable (both with and without underscores) $strAssociationTableName = str_replace($strTableName, '', $strAssociationTableName); $strTableName = str_replace('_', '', $strTableName); $strAssociationTableName = str_replace($strTableName, '', $strAssociationTableName); // Take out strReferencedTableName if applicable (both with and without underscores) $strAssociationTableName = str_replace($strReferencedTableName, '', $strAssociationTableName); $strReferencedTableName = str_replace('_', '', $strReferencedTableName); $strAssociationTableName = str_replace($strReferencedTableName, '', $strAssociationTableName); // Change any double "__" to single "_" $strAssociationTableName = str_replace("__", "_", $strAssociationTableName); $strAssociationTableName = str_replace("__", "_", $strAssociationTableName); $strAssociationTableName = str_replace("__", "_", $strAssociationTableName); // If we have nothing left or just a single "_" in AssociationTableName, return "Starting Point" if ($strAssociationTableName == "_" || $strAssociationTableName == "") { return sprintf("%s%s%s", $this->strAssociatedObjectPrefix, $strToReturn, $this->strAssociatedObjectSuffix); } // Otherwise, add "As" and the predicate return sprintf("%s%sAs%s%s", $this->strAssociatedObjectPrefix, $strToReturn, QConvertNotation::CamelCaseFromUnderscore($strAssociationTableName), $this->strAssociatedObjectSuffix); }
} protected function btnDelete_Click($strFormId, $strControlId, $strParameter) { // Delegate "Delete" processing to the <?php echo $objTable->ClassName; ?> MetaControl $this->mct<?php echo $objTable->ClassName; ?> ->Delete<?php echo $objTable->ClassName; ?> (); $this->RedirectToListPage(); } protected function btnCancel_Click($strFormId, $strControlId, $strParameter) { $this->RedirectToListPage(); } // Other Methods protected function RedirectToListPage() { QApplication::Redirect(__VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/<?php echo QConvertNotation::UnderscoreFromCamelCase($objTable->ClassName); ?> _list.php'); } } ?>
public static function JavaCaseFromUnderscore($strName) { $strToReturn = QConvertNotation::CamelCaseFromUnderscore($strName); return strtolower(substr($strToReturn, 0, 1)) . substr($strToReturn, 1); }
* @param string $strControlId optional ControlId to use * @return QLabel */ public function <?php echo $strLabelId; ?> _Create($strControlId = null) { $this-><?php echo $strLabelId; ?> = new QLabel($this->objParentObject, $strControlId); $this-><?php echo $strLabelId; ?> ->Name = QApplication::Translate('<?php echo QConvertNotation::WordsFromCamelCase($objReverseReference->ObjectPropertyName); ?> '); $this-><?php echo $strLabelId; ?> ->Text = ($this-><?php echo $strObjectName; ?> -><?php echo $objReverseReference->ObjectPropertyName; ?> ) ? $this-><?php echo $strObjectName; ?> -><?php
* @param string $strControlId optional ControlId to use * @return QLabel */ public function <?php echo $strLabelId; ?> _Create($strControlId = null) { $this-><?php echo $strLabelId; ?> = new QLabel($this->objParentObject, $strControlId); $this-><?php echo $strLabelId; ?> ->Name = QApplication::Translate('<?php echo QConvertNotation::WordsFromCamelCase($objManyToManyReference->ObjectDescriptionPlural); ?> '); $aSelection = $this-><?php echo $strObjectName; ?> ->Get<?php echo $objManyToManyReference->ObjectDescription; ?> Array(); $this-><?php echo $strLabelId; ?> ->Text = implode($this->str<?php echo $objManyToManyReference->ObjectDescription;
protected function CalculateObjectDescriptionForAssociation($strAssociationTableName, $strTableName, $strReferencedTableName, $blnPluralize) { // Strip Prefixes (if applicable) $strTableName = $this->StripPrefixFromTable($strTableName); $strAssociationTableName = $this->StripPrefixFromTable($strAssociationTableName); $strReferencedTableName = $this->StripPrefixFromTable($strReferencedTableName); // Starting Point $strToReturn = QConvertNotation::CamelCaseFromUnderscore($strReferencedTableName); if ($blnPluralize) { $strToReturn = $this->Pluralize($strToReturn); } // Let's start with strAssociationTableName // Rip out trailing "_assn" if applicable $strAssociationTableName = str_replace($this->strAssociationTableSuffix, '', $strAssociationTableName); // remove instances of the table names in the association table name $strTableName2 = str_replace('_', '', $strTableName); // remove underscores if they are there $strReferencedTableName2 = str_replace('_', '', $strReferencedTableName); // remove underscores if they are there if (beginsWith($strAssociationTableName, $strTableName . '_')) { $strAssociationTableName = trimOffFront($strTableName . '_', $strAssociationTableName); } elseif (beginsWith($strAssociationTableName, $strTableName2 . '_')) { $strAssociationTableName = trimOffFront($strTableName2 . '_', $strAssociationTableName); } elseif (beginsWith($strAssociationTableName, $strReferencedTableName . '_')) { $strAssociationTableName = trimOffFront($strReferencedTableName . '_', $strAssociationTableName); } elseif (beginsWith($strAssociationTableName, $strReferencedTableName2 . '_')) { $strAssociationTableName = trimOffFront($strReferencedTableName2 . '_', $strAssociationTableName); } elseif ($strAssociationTableName == $strTableName || $strAssociationTableName == $strTableName2 || $strAssociationTableName == $strReferencedTableName || $strAssociationTableName == $strReferencedTableName2) { $strAssociationTableName = ""; } if (endsWith($strAssociationTableName, '_' . $strTableName)) { $strAssociationTableName = trimOffEnd('_' . $strTableName, $strAssociationTableName); } elseif (endsWith($strAssociationTableName, '_' . $strTableName2)) { $strAssociationTableName = trimOffEnd('_' . $strTableName2, $strAssociationTableName); } elseif (endsWith($strAssociationTableName, '_' . $strReferencedTableName)) { $strAssociationTableName = trimOffEnd('_' . $strReferencedTableName, $strAssociationTableName); } elseif (endsWith($strAssociationTableName, '_' . $strReferencedTableName2)) { $strAssociationTableName = trimOffEnd('_' . $strReferencedTableName2, $strAssociationTableName); } elseif ($strAssociationTableName == $strTableName || $strAssociationTableName == $strTableName2 || $strAssociationTableName == $strReferencedTableName || $strAssociationTableName == $strReferencedTableName2) { $strAssociationTableName = ""; } // Change any double "__" to single "_" $strAssociationTableName = str_replace("__", "_", $strAssociationTableName); $strAssociationTableName = str_replace("__", "_", $strAssociationTableName); $strAssociationTableName = str_replace("__", "_", $strAssociationTableName); // If we have nothing left or just a single "_" in AssociationTableName, return "Starting Point" if ($strAssociationTableName == "_" || $strAssociationTableName == "") { return sprintf("%s%s%s", $this->strAssociatedObjectPrefix, $strToReturn, $this->strAssociatedObjectSuffix); } // Otherwise, add "As" and the predicate return sprintf("%s%sAs%s%s", $this->strAssociatedObjectPrefix, $strToReturn, QConvertNotation::CamelCaseFromUnderscore($strAssociationTableName), $this->strAssociatedObjectSuffix); }
} // protected function Form_Load() {} <?php include 'edit_form_create.tpl.php'; ?> <?php include 'edit_create_buttons.tpl.php'; ?> <?php include 'edit_button_click.tpl.php'; ?> } // Go ahead and run this form object to render the page and its event handlers, implicitly using // <?php echo QConvertNotation::UnderscoreFromCamelCase($strPropertyName); ?> _edit.tpl.php as the included HTML template file <?php echo $strPropertyName; ?> EditForm::Run('<?php echo $strPropertyName; ?> EditForm');
* @param string $strControlId optional ControlId to use * @return QLabel */ public function <?php echo $strLabelId; ?> _Create($strControlId = null) { $this-><?php echo $strLabelId; ?> = new QLabel($this->objParentObject, $strControlId); $this-><?php echo $strLabelId; ?> ->Name = QApplication::Translate('<?php echo QConvertNotation::WordsFromCamelCase($objColumn->Reference->PropertyName); ?> '); $this-><?php echo $strLabelId; ?> ->Text = ($this-><?php echo $strObjectName; ?> -><?php echo $objColumn->Reference->PropertyName; ?> ) ? $this-><?php echo $strObjectName; ?> -><?php