1 | <?php
|
---|
2 |
|
---|
3 | class TypePointerOneToOne extends TypeBase
|
---|
4 | {
|
---|
5 | function GetTablePointerName($Type, $Item)
|
---|
6 | {
|
---|
7 | global $Database;
|
---|
8 |
|
---|
9 | //print_r($Item);
|
---|
10 | $Columns = '';
|
---|
11 | $List = GetListDefinition($Type['Parameters'][0]);
|
---|
12 | $TargetTable = $List['TableName'];
|
---|
13 | //echo($TargetTable.'<');
|
---|
14 | //print_r($List);
|
---|
15 | foreach($List['Items'] as $Index => $ListItem)
|
---|
16 | {
|
---|
17 | //echo('ListItem');
|
---|
18 | //print_r($ListItem);
|
---|
19 | $Type = GetTypeDefinition($ListItem['Type']);
|
---|
20 | if($ListItem['VisibleInPointer'] == 1)
|
---|
21 | {
|
---|
22 | if($Type['ParentType'] == TypePointerOneToOneId)
|
---|
23 | {
|
---|
24 | //print_r($Type);
|
---|
25 | $DbResult = $Database->select(array('Database' => $List['Database'], 'Table' => $List['TableName'], 'Condition' => $List['IdName'].'='.$Item['Value']));
|
---|
26 | $DbRow = $DbResult->fetch_assoc();
|
---|
27 | $DefinitionItem = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'], 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
|
---|
28 | $SubTarget = $this->GetTablePointerName($Type, $DefinitionItem);
|
---|
29 | $Columns .= '"'.$SubTarget['Name'].' ",';
|
---|
30 | } else $Columns .= '`'.$ListItem['Name'].'`," ",';
|
---|
31 | }
|
---|
32 | }
|
---|
33 | $Columns = substr($Columns, 0, -1);
|
---|
34 | if($Columns == '') $Columns = '`'.$List['IdName'].'` AS `Name`, `'.$List['IdName'].'`';
|
---|
35 | else $Columns = 'CONCAT('.$Columns.') AS `Name`, `'.$List['IdName'].'`';
|
---|
36 | $DbResult = $Database->select(array('Database' => $List['Database'], 'Table' => $TargetTable, 'Columns' => $Columns, 'Condition' => $List['IdName'].'='.$Item['Value']));
|
---|
37 | //echo($Database->LastQuery);
|
---|
38 | if($DbResult->num_rows > 0)
|
---|
39 | {
|
---|
40 | return($DbResult->fetch_assoc());
|
---|
41 | } else return('');
|
---|
42 | }
|
---|
43 |
|
---|
44 | function GetTablePointerNameList($Type, $Item)
|
---|
45 | {
|
---|
46 | global $Database;
|
---|
47 |
|
---|
48 | $Columns = '';
|
---|
49 | $List = GetListDefinition($Type['Parameters'][0]);
|
---|
50 | $TargetTable = $List['TableName'];
|
---|
51 | foreach($List['Items'] as $ListItem)
|
---|
52 | if($ListItem['VisibleInPointer'] == 1) $Columns .= '`'.$ListItem['Name'].'`," ",';
|
---|
53 | $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, `'.$List['IdName'].'`';
|
---|
54 | $DbResult = $Database->select(array('Database' => $List['Database'], 'Table' => $TargetTable, 'Columns' => $Columns));
|
---|
55 | //echo($Database->LastQuery);
|
---|
56 | if($DbResult->num_rows > 0)
|
---|
57 | {
|
---|
58 |
|
---|
59 | $Result = array(array('Name' => 'Žádný', 'Id' => 0));
|
---|
60 | while($DbRow = $DbResult->fetch_assoc())
|
---|
61 | $Result[] = $DbRow;
|
---|
62 | return($Result);
|
---|
63 | } else return(array());
|
---|
64 | }
|
---|
65 |
|
---|
66 | function OnView($Item)
|
---|
67 | {
|
---|
68 | global $Database;
|
---|
69 |
|
---|
70 | $Type = GetTypeDefinition($Item['Type']);
|
---|
71 | $List = GetListDefinition($Type['Parameters'][0]);
|
---|
72 | $TargetTable = $Type['Parameters'][0];
|
---|
73 | $TargetName = $this->GetTablePointerName($Type, $Item);
|
---|
74 | if($TargetName != '') $Output = '<a href="?Action=ViewItem&Table='.$TargetTable.'&Item='.$TargetName[$List['IdName']].'">'.$TargetName['Name'].'</a>';
|
---|
75 | else $Output = '';
|
---|
76 | return($Output);
|
---|
77 | }
|
---|
78 |
|
---|
79 | function OnEdit($Item)
|
---|
80 | {
|
---|
81 | global $Database, $Types;
|
---|
82 |
|
---|
83 | $Type = $Types[$Item['Type']];
|
---|
84 | $List = GetListDefinition($Type['Parameters'][0]);
|
---|
85 | $Output = '<select name="'.$Item['Name'].'">';
|
---|
86 | $TargetNameList = $this->GetTablePointerNameList($Type, $Item);
|
---|
87 | //echo($Database->LastQuery);
|
---|
88 | foreach($TargetNameList as $TargetName)
|
---|
89 | {
|
---|
90 | if($Item['Value'] == $TargetName[$List['IdName']]) $Selected = ' selected="1"'; else $Selected = '';
|
---|
91 | $Output .= '<option value="'.$TargetName[$List['IdName']].'"'.$Selected.'>'.$TargetName['Name'].'</option>';
|
---|
92 | }
|
---|
93 | $Output .= '</select>';
|
---|
94 | return($Output);
|
---|
95 | }
|
---|
96 |
|
---|
97 | function OnLoad($Item)
|
---|
98 | {
|
---|
99 | return($_POST[$Item['Name']]);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | ?>
|
---|