/** * Returns code to refresh the control from the saved object. * * @param QCodeGenBase $objCodeGen * @param QSqlTable $objTable * @param QSqlColumn $objColumn * @param bool $blnInit * @return string */ public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) { $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn); $strControlVarName = $this->VarName($strPropName); $strObjectName = $objCodeGen->ModelVariableName($objTable->Name); $strRet = ''; if ($blnInit) { $strRet .= <<<TMPL if (!\$this->str{$strPropName}NullLabel) { \tif (!\$this->{$strControlVarName}->Required) { \t\t\$this->str{$strPropName}NullLabel = '- None -'; \t} \telseif (!\$this->blnEditMode) { \t\t\$this->str{$strPropName}NullLabel = '- Select One -'; \t} } TMPL; } else { $strRet .= "\$this->{$strControlVarName}->RemoveAllItems();\n"; } $strRet .= <<<TMPL \$this->{$strControlVarName}->AddItem(QApplication::Translate(\$this->str{$strPropName}NullLabel), null); TMPL; $options = $objColumn->Options; if (!$options || !isset($options['NoAutoLoad'])) { $strRet .= "\$this->{$strControlVarName}->AddItems(\$this->{$strControlVarName}_GetItems());\n"; } if ($objColumn instanceof QSqlColumn) { $strRet .= "\$this->{$strControlVarName}->SelectedValue = \$this->{$strObjectName}->{$objColumn->PropertyName};\n"; } elseif ($objColumn instanceof QReverseReference && $objColumn->Unique) { $strRet .= "if (\$this->{$strObjectName}->{$objColumn->ObjectPropertyName})\n"; $strRet .= _indent("\$this->{$strControlVarName}->SelectedValue = \$this->{$strObjectName}->{$objColumn->ObjectPropertyName}->{$objCodeGen->GetTable($objColumn->Table)->PrimaryKeyColumnArray[0]->PropertyName};\n"); } elseif ($objColumn instanceof QManyToManyReference) { if ($objColumn->IsTypeAssociation) { $strRet .= "\$this->{$strControlVarName}->SelectedValues = array_keys(\$this->{$strObjectName}->Get{$objColumn->ObjectDescription}Array());\n"; } else { //$strRet .= $strTabs . "\$this->{$strControlVarName}->SelectedValues = \$this->{$strObjectName}->Get{$objColumn->ObjectDescription}Keys();\n"; } } if (!$blnInit) { // wrap it with a test as to whether the control has been created. $strRet = _indent($strRet); $strRet = <<<TMPL if (\$this->{$strControlVarName}) { {$strRet} } TMPL; } $strRet = _indent($strRet, 3); return $strRet; }
/** * Returns code to refresh the control from the saved object. * * @param QCodeGenBase $objCodeGen * @param QSqlTable $objTable * @param QSqlColumn $objColumn * @param bool $blnInit * @return string */ public function ConnectorRefresh(QCodeGenBase $objCodeGen, QSqlTable $objTable, $objColumn, $blnInit = false) { $strPrimaryKey = $objCodeGen->GetTable($objColumn->Reference->Table)->PrimaryKeyColumnArray[0]->PropertyName; $strPropName = QCodeGen::ModelConnectorPropertyName($objColumn); $strControlVarName = $this->VarName($strPropName); $strObjectName = $objCodeGen->ModelVariableName($objTable->Name); $strRet = ''; if (!$blnInit) { $t = "\t"; // inserts an extra tab below $strRet = <<<TMPL \t\t\tif (\$this->{$strControlVarName}) { TMPL; } else { $t = ''; } $options = $objColumn->Options; if (!$options || !isset($options['NoAutoLoad'])) { $strRet .= <<<TMPL {$t}\t\t\t\$this->{$strControlVarName}->Source = \$this->{$strControlVarName}_GetItems(); TMPL; } $strRet .= <<<TMPL {$t}\t\t\tif (\$this->{$strObjectName}->{$strPropName}) { {$t}\t\t\t\t\$this->{$strControlVarName}->Text = \$this->{$strObjectName}->{$strPropName}->__toString(); {$t}\t\t\t\t\$this->{$strControlVarName}->SelectedValue = \$this->{$strObjectName}->{$strPropName}->{$strPrimaryKey}; {$t}\t\t\t} {$t}\t\t\telse { {$t}\t\t\t\t\$this->{$strControlVarName}->Text = ''; {$t}\t\t\t\t\$this->{$strControlVarName}->SelectedValue = null; {$t}\t\t\t} TMPL; if (!$blnInit) { $strRet .= <<<TMPL \t\t\t} TMPL; } return $strRet; }