~bentokitdevs/retromod/traffic

« back to all changes in this revision

Viewing changes to src/private/components/traffic/Contract.php

  • Committer: ken
  • Date: 2012-03-22 06:22:56 UTC
  • Revision ID: svn-v4:8010c1e9-5c09-0410-80af-c3f6856d18d6:branches/traffic:2176
MySQL database optimisations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
188
188
        $container->appendChild($input);
189
189
 
190
190
        if ($id != '') {
191
 
            $query = "SELECT C.name as clientName, I.* FROM ({$this->store->table_traffic_client} C, {$this->store->table_traffic_contract} I) WHERE contractID = '$id' AND C.clientID = I.clientID";
 
191
            $query = "SELECT C.{$this->store->field_client_name} AS clientName, I.* FROM ({$this->store->table_traffic_client} C, {$this->store->table_traffic_contract} I) WHERE contractID = '$id' AND C.clientID = I.clientID";
192
192
            $result = sysdb::query($query);
193
193
            $line = sysdb::fetch_assoc($result);
194
194
 
459
459
                $input->setAttribute('id','contractSalesRepIDList');
460
460
 
461
461
                $query = <<<EOQ
462
 
                        SELECT I.{$this->store->field_salesrep_salesRepID} as salesRepID,
 
462
                        SELECT I.{$this->store->field_salesrep_salesRepID} AS salesRepID,
463
463
                                D.{$this->store->field_detail_firstName} AS firstName,
464
464
                                D.{$this->store->field_detail_lastName} AS lastName
465
465
                        FROM ({$this->store->table_traffic_salesrep} I,
645
645
        $contractID->setAttribute('value',$id);
646
646
        $containerLeft->appendChild($contractID);
647
647
 
648
 
        $query = "SELECT C.name as clientName, I.* FROM ({$this->store->table_traffic_contract} I, {$this->store->table_traffic_client} C) WHERE I.contractID = '$id' AND C.clientID = I.clientID";
 
648
        $query = "SELECT C.{$this->store->field_client_name} AS clientName, I.* FROM ({$this->store->table_traffic_contract} I, {$this->store->table_traffic_client} C) WHERE I.contractID = '$id' AND C.clientID = I.clientID";
649
649
        $result = sysdb::query($query);
650
650
        $line = sysdb::fetch_assoc($result);
651
651
 
915
915
 
916
916
    public function display_list($doc, $ids = '', $sortby = '') {
917
917
        $query = <<<EOQ
918
 
            SELECT C.name AS clientName, I.clientID, I.contractID, I.name, I.contractStatus, I.startDate, I.endDate
 
918
            SELECT C.{$this->store->field_client_name} AS clientName, I.clientID, I.contractID, I.name, I.contractStatus, I.startDate, I.endDate
919
919
            FROM ({$this->store->table_traffic_contract} I, {$this->store->table_traffic_client} C)
920
920
            WHERE C.clientID = I.clientID
921
921
EOQ;
1053
1053
                                        break;
1054
1054
                                default:
1055
1055
                                        $isInclude = false;
1056
 
                                        $warning_message = "Not a valid parent.";
 
1056
                                        state::setMessage('warning', 'Not a valid parent.');
1057
1057
                                        break;
1058
1058
                        }
1059
1059
                        $container->setAttribute('class','module_left');
1076
1076
                                        $column = "I.name";
1077
1077
                                        break;
1078
1078
                                case 'client':
1079
 
                                        $column = "C.name";
 
1079
                                        $column = "C.{$this->store->field_client_name}";
1080
1080
                                        break;
1081
1081
                                case 'status':
1082
1082
                                        $column = "I.contractStatus";
1114
1114
 
1115
1115
    public function display_select($doc, $ids='', $default = -1) {
1116
1116
        $query = <<<EOQ
1117
 
            SELECT {$this->store->field_contract_contractID} as contractID,
1118
 
                                {$this->store->field_contract_name} as name
 
1117
            SELECT {$this->store->field_contract_contractID} AS contractID,
 
1118
                                {$this->store->field_contract_name} AS name
1119
1119
            FROM {$this->store->table_traffic_contract}
1120
1120
EOQ;
1121
1121
        if (is_array($ids) && sizeof($ids) <= 0) { $query .= ' WHERE 0=1'; } else if (is_array($ids) && sizeof($ids) > 0)
1517
1517
                                break;
1518
1518
                        default:
1519
1519
                                $isInclude = false;
1520
 
                                $warning_message = "Not a valid parent.";
 
1520
                                state::setMessage('warning', 'Not a valid parent.');
1521
1521
                                break;
1522
1522
                }
1523
1523
                $item = globalize('item', get_class($this));
1586
1586
                switch ($parentIDType) {
1587
1587
                        case 'Client':
1588
1588
                                $parentFieldName = 'clientID';
 
1589
                                $query = <<<EOQ
 
1590
                                        SELECT C.{$this->store->field_client_name} AS name
 
1591
                                        FROM ({$this->store->table_traffic_client} C)
 
1592
                                        WHERE C.{$this->store->field_client_clientID} = '$parentID'
 
1593
EOQ;
1589
1594
                                break;
1590
1595
                        default:
1591
1596
                                $isInclude = false;
1592
 
                                $warning_message = "Not a valid parent.";
 
1597
                                state::setMessage('warning', 'Not a valid parent.');
1593
1598
                                break;
1594
1599
                }
1595
 
                if ($parentIDType == 'Client')
1596
 
                        $x = 'C';
1597
 
                if ($parentIDType == 'Contract')
1598
 
                        $x = 'T';
1599
 
                if ($parentIDType == 'Campaign')
1600
 
                        $x = 'G';
1601
 
                $query = "SELECT $x.name FROM ({$this->store->table_traffic_client} C, {$this->store->table_traffic_contract} T, {$this->store->table_traffic_campaign} G) WHERE $x.$parentFieldName = '$parentID' AND C.clientID = $x.clientID";
1602
1600
        $result = sysdb::query($query);
1603
1601
                $line = sysdb::fetch_assoc($result);
1604
1602
                $caption_name = utf8_decode($line['name']);