/**
     * @param QCodeGenBase $objCodeGen
     * @param QSqlTable $objTable
     * @param QSqlColumn|QReverseReference|QManyToManyReference $objColumn
     * @return string
     */
    public function ConnectorUpdate(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn)
    {
        $strObjectName = $objCodeGen->ModelVariableName($objTable->Name);
        $strPropName = $objColumn->Reference ? $objColumn->Reference->PropertyName : $objColumn->PropertyName;
        $strControlVarName = $this->VarName($strPropName);
        $strRet = <<<TMPL
\t\t\t\tif (\$this->{$strControlVarName}) \$this->{$strObjectName}->{$objColumn->PropertyName} = \$this->{$strControlVarName}->DateTime;

TMPL;
        return $strRet;
    }
    /**
     * @param QCodeGenBase $objCodeGen
     * @param QSqlColumn|QReverseReference| QManyToManyReference $objColumn
     * @return string
     */
    public function ConnectorVariableDeclaration(QCodeGenBase $objCodeGen, $objColumn)
    {
        $strClassName = $this->GetControlClass();
        $strControlVarName = $objCodeGen->ModelConnectorVariableName($objColumn);
        $strRet = <<<TMPL
\t\t/**
\t\t * @var {$strClassName} {$strControlVarName}

\t\t * @access protected
\t\t */
\t\tprotected \${$strControlVarName};


TMPL;
        return $strRet;
    }
    /**
     * @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 = $objColumn->ObjectDescription;
        $strPropNames = $objColumn->ObjectDescriptionPlural;
        $strControlVarName = $objCodeGen->ModelConnectorVariableName($objColumn);
        $strRet = <<<TMPL
\t\tprotected function {$strControlVarName}_Update() {
\t\t\tif (\$this->{$strControlVarName}) {
\t\t\t\t\$this->{$strObjectName}->UnassociateAll{$strPropNames}();
\t\t\t\t\$this->{$strObjectName}->Associate{$strPropName}(\$this->{$strControlVarName}->SelectedValues);
\t\t\t}
\t\t}


TMPL;
        return $strRet;
    }
    protected function DataListParentMakeEditable(QCodeGenBase $objCodeGen, QSqlTable $objTable)
    {
        $strVarName = $objCodeGen->DataListVarName($objTable);
        $strCode = <<<TMPL

\tprotected function {$strVarName}_MakeEditable() {
\t\t\$this->{$strVarName}->AddAction(new QCellClickEvent(), new QAjaxControlAction(\$this, '{$strVarName}_CellClick', null, null, '\$j(this).parent().data("value")'));
\t\t\$this->{$strVarName}->AddCssClass('hover');
\t}

\tprotected function {$strVarName}_CellClick(\$strFormId, \$strControlId, \$strParameter) {
\t\tif (\$strParameter) {
\t\t\t\$this->EditItem(\$strParameter);
\t\t}
\t}

TMPL;
        return $strCode;
    }
 /**
  * QCodeGen::Pluralize()
  * 
  * Example: Overriding the Pluralize method
  * 
  * @param string $strName
  * @return string
  */
 protected function Pluralize($strName)
 {
     // Special Rules go Here
     switch (true) {
         case $strName == 'person':
             return 'people';
         case $strName == 'Person':
             return 'People';
         case $strName == 'PERSON':
             return 'PEOPLE';
             // Trying to be cute here...
         // Trying to be cute here...
         case strtolower($strName) == 'fish':
             return $strName . 'ies';
             // Otherwise, call parent
         // Otherwise, call parent
         default:
             return parent::Pluralize($strName);
     }
 }
    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;
    }
 /**
  * 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";
 }
    /**
     * @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;
    }
    /**
     * 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;
    }