Changeset 19 for types/PointerOneToOne.php
- Timestamp:
- Oct 22, 2008, 9:12:20 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
types/PointerOneToOne.php
r18 r19 1 1 <?php 2 2 3 function GetTablePointerName($Type, $Item) 3 class TypePointerOneToOne 4 4 { 5 global $Database, $Lists; 5 function GetTablePointerName($Type, $Item) 6 { 7 global $Database, $Lists; 6 8 7 //print_r($Item);8 $Columns = '';9 $TargetTable = $Type['Parameters'][0];9 //print_r($Item); 10 $Columns = ''; 11 $TargetTable = $Type['Parameters'][0]; 10 12 11 foreach($Lists[$TargetTable]['Items'] as $ListItem) 12 if($ListItem['VisibleInPointer'] == 1) $Columns .= '`'.$ListItem['Name'].'`," ",'; 13 $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, ItemId, Id'; 14 $DbResult = $Database->select($TargetTable, $Columns, 'ItemId='.$Item['Value'].' AND (DeletionTime IS NULL) ORDER BY Id DESC LIMIT 1'); 15 //echo($Database->LastQuery); 16 if($DbResult->num_rows > 0) 13 foreach($Lists[$TargetTable]['Items'] as $ListItem) 14 if($ListItem['VisibleInPointer'] == 1) $Columns .= '`'.$ListItem['Name'].'`," ",'; 15 $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, ItemId, Id'; 16 $DbResult = $Database->select($TargetTable, $Columns, 'ItemId='.$Item['Value'].' AND (DeletionTime IS NULL) ORDER BY Id DESC LIMIT 1'); 17 //echo($Database->LastQuery); 18 if($DbResult->num_rows > 0) 19 { 20 return($DbResult->fetch_assoc()); 21 } else return(''); 22 } 23 24 function GetTablePointerNameList($Type, $Item) 17 25 { 18 return($DbResult->fetch_assoc()); 19 } else return(''); 26 global $Database, $Lists; 27 28 $Columns = ''; 29 $TargetTable = $Type['Parameters'][0]; 30 31 foreach($Lists[$TargetTable]['Items'] as $ListItem) 32 if($ListItem['VisibleInPointer'] == 1) $Columns .= 't1.`'.$ListItem['Name'].'`," ",'; 33 $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, t1.Id, t1.ItemId, t1.DeletionTime'; 34 $DbResult = $Database->query('SELECT t3.* FROM (SELECT '.$Columns.' FROM `'.$TargetTable.'` AS t1 LEFT JOIN `'.$TargetTable.'` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL)) AS t3 WHERE t3.DeletionTime IS NULL'); 35 //echo($Database->LastQuery); 36 if($DbResult->num_rows > 0) 37 { 38 $Result = array(array('Name' => 'Žádný', 'Id' => 0, 'ItemId' => 0)); 39 while($DbRow = $DbResult->fetch_assoc()) 40 $Result[] = $DbRow; 41 return($Result); 42 } else return(array()); 43 } 44 45 function OnView($Item) 46 { 47 global $Database, $Lists, $Types; 48 49 $Type = $Types[$Item['Type']]; 50 $TargetTable = $Type['Parameters'][0]; 51 $TargetName = $this->GetTablePointerName($Type, $Item); 52 $Output = '<a href="?Action=ViewItem&Table='.$TargetTable.'&Item='.$TargetName['ItemId'].'">'.$TargetName['Name'].'</a>'; 53 return($Output); 54 } 55 56 function OnEdit($Item) 57 { 58 global $Database, $Lists, $Types; 59 60 $Type = $Types[$Item['Type']]; 61 $Output = '<select name="'.$Item['Name'].'">'; 62 $TargetNameList = $this->GetTablePointerNameList($Type, $Item); 63 //echo($Database->LastQuery); 64 foreach($TargetNameList as $TargetName) 65 { 66 if($Item['Value'] == $TargetName['ItemId']) $Selected = ' selected="1"'; else $Selected = ''; 67 $Output .= '<option value="'.$TargetName['ItemId'].'"'.$Selected.'>'.$TargetName['Name'].'</option>'; 68 } 69 $Output .= '</select>'; 70 return($Output); 71 } 72 73 function OnLoad($Item) 74 { 75 return($_POST[$Item['Name']]); 76 } 20 77 } 21 78 22 function GetTablePointerNameList($Type, $Item) 23 { 24 global $Database, $Lists; 25 26 $Columns = ''; 27 $TargetTable = $Type['Parameters'][0]; 28 29 foreach($Lists[$TargetTable]['Items'] as $ListItem) 30 if($ListItem['VisibleInPointer'] == 1) $Columns .= 't1.`'.$ListItem['Name'].'`," ",'; 31 $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, t1.Id, t1.ItemId, t1.DeletionTime'; 32 $DbResult = $Database->query('SELECT t3.* FROM (SELECT '.$Columns.' FROM `'.$TargetTable.'` AS t1 LEFT JOIN `'.$TargetTable.'` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL)) AS t3 WHERE t3.DeletionTime IS NULL'); 33 //echo($Database->LastQuery); 34 if($DbResult->num_rows > 0) 35 { 36 $Result = array(array('Name' => 'Žádný', 'Id' => 0, 'ItemId' => 0)); 37 while($DbRow = $DbResult->fetch_assoc()) 38 $Result[] = $DbRow; 39 return($Result); 40 } else return(array()); 41 } 42 43 function TypePointerOneToOneOnView($Item) 44 { 45 global $Database, $Lists, $Types; 46 47 $Type = $Types[$Item['Type']]; 48 $TargetTable = $Type['Parameters'][0]; 49 $TargetName = GetTablePointerName($Type, $Item); 50 $Output = '<a href="?Action=ViewItem&Table='.$TargetTable.'&Item='.$TargetName['ItemId'].'">'.$TargetName['Name'].'</a>'; 51 return($Output); 52 } 53 54 function TypePointerOneToOneOnEdit($Item) 55 { 56 global $Database, $Lists, $Types; 57 58 $Type = $Types[$Item['Type']]; 59 $Output = '<select name="'.$Item['Name'].'">'; 60 $TargetNameList = GetTablePointerNameList($Type, $Item); 61 //echo($Database->LastQuery); 62 foreach($TargetNameList as $TargetName) 63 { 64 if($Item['Value'] == $TargetName['ItemId']) $Selected = ' selected="1"'; else $Selected = ''; 65 $Output .= '<option value="'.$TargetName['ItemId'].'"'.$Selected.'>'.$TargetName['Name'].'</option>'; 66 } 67 $Output .= '</select>'; 68 return($Output); 69 } 70 71 function TypePointerOneToOneOnLoad($Item) 72 { 73 return($_POST[$Item['Name']]); 74 } 79 $TypeDefinitionList['PointerOneToOne'] = new TypePointerOneToOne; 75 80 76 81 ?>
Note:
See TracChangeset
for help on using the changeset viewer.