<?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";
    /**
     * 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;
    }