ImportModel::getCountSQL PHP Method

getCountSQL() public method

Return SQL for updating a count.
public getCountSQL ( string $Aggregate, string $ParentTable, string $ChildTable, string $ParentColumnName = '', string $ChildColumnName = '', string $ParentJoinColumn = '', string $ChildJoinColumn = '' ) : Gdn_DataSet
$Aggregate string count, max, min, etc.
$ParentTable string The name of the parent table.
$ChildTable string The name of the child table
$ParentColumnName string
$ChildColumnName string
$ParentJoinColumn string
$ChildJoinColumn string
return Gdn_DataSet
    public function getCountSQL($Aggregate, $ParentTable, $ChildTable, $ParentColumnName = '', $ChildColumnName = '', $ParentJoinColumn = '', $ChildJoinColumn = '')
    {
        if (!$ParentColumnName) {
            switch (strtolower($Aggregate)) {
                case 'count':
                    $ParentColumnName = "Count{$ChildTable}s";
                    break;
                case 'max':
                    $ParentColumnName = "Last{$ChildTable}ID";
                    break;
                case 'min':
                    $ParentColumnName = "First{$ChildTable}ID";
                    break;
                case 'sum':
                    $ParentColumnName = "Sum{$ChildTable}s";
                    break;
            }
        }
        if (!$ChildColumnName) {
            $ChildColumnName = $ChildTable . 'ID';
        }
        if (!$ParentJoinColumn) {
            $ParentJoinColumn = $ParentTable . 'ID';
        }
        if (!$ChildJoinColumn) {
            $ChildJoinColumn = $ParentJoinColumn;
        }
        $Result = "update :_{$ParentTable} p\n                  set p.{$ParentColumnName} = (\n                     select {$Aggregate}(c.{$ChildColumnName})\n                     from :_{$ChildTable} c\n                     where p.{$ParentJoinColumn} = c.{$ChildJoinColumn})";
        return $Result;
    }