Changeset 22 for trunk/www/types/PointerOneToOne.php
- Timestamp:
- Jun 12, 2009, 8:56:03 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/types/PointerOneToOne.php
r11 r22 3 3 class TypePointerOneToOne extends TypeBase 4 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 5 function OnView($Item) 67 6 { 68 global $Database ;7 global $Database, $TypeDefinitionList; 69 8 70 $Type = GetTypeDefinition($Item['Type']); 9 $Type = $TypeDefinitionList[$Item['Type']]; 10 $DbResult = $Database->query('SELECT '.$Type['Parameters']['Name'].' AS Name FROM `'.$Type['Parameters']['Table'].'` WHERE `'.$Type['Parameters']['Id'].'`='.$Item['Value']); 11 $DbRow = $DbResult->fetch_assoc(); 12 $Output = $DbRow['Name']; 13 14 /* $Type = GetTypeDefinition($Item['Type']); 71 15 $List = GetListDefinition($Type['Parameters'][0]); 72 16 $TargetTable = $Type['Parameters'][0]; … … 74 18 if($TargetName != '') $Output = '<a href="?Action=ViewItem&Table='.$TargetTable.'&Item='.$TargetName[$List['IdName']].'">'.$TargetName['Name'].'</a>'; 75 19 else $Output = ''; 20 */ 76 21 return($Output); 77 22 } … … 79 24 function OnEdit($Item) 80 25 { 81 global $Database, $Type s;26 global $Database, $TypeDefinitionList; 82 27 83 $Type = $Types[$Item['Type']];84 $List = GetListDefinition($Type['Parameters'][0]);85 28 $Output = '<select name="'.$Item['Name'].'">'; 86 $T argetNameList = $this->GetTablePointerNameList($Type, $Item);87 //echo($Database->LastQuery);88 foreach($TargetNameList as $TargetName)29 $Type = $TypeDefinitionList[$Item['Type']]; 30 $DbResult = $Database->query('SELECT '.$Type['Parameters']['Name'].' AS Name,'.$Type['Parameters']['Id'].' AS Id FROM `'.$Type['Parameters']['Table'].'`'); 31 while($DbRow = $DbResult->fetch_assoc()) 89 32 { 90 if($Item['Value'] == $ TargetName[$List['IdName']]) $Selected = ' selected="1"'; else $Selected = '';91 $Output .= '<option value="'.$ TargetName[$List['IdName']].'"'.$Selected.'>'.$TargetName['Name'].'</option>';33 if($Item['Value'] == $DbRow['Id']) $Selected = ' selected="1"'; else $Selected = ''; 34 $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Name'].'</option>'; 92 35 } 93 36 $Output .= '</select>';
Note:
See TracChangeset
for help on using the changeset viewer.