![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00002 /*------------------------------------------------------------------------------- 00003 * Xataface Web Application Framework 00004 * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca) 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 *------------------------------------------------------------------------------- 00020 */ 00038 require_once 'Dataface/Application.php'; 00039 require_once 'Dataface/Table.php'; 00040 00041 class Dataface_TableTool { 00042 00043 var $_table; 00044 var $_app; 00045 00046 function Dataface_TableTool($tablename){ 00047 $this->_table =& Dataface_Table::loadTable($tablename); 00048 $this->_app =& Dataface_Application::getInstance(); 00049 } 00050 00051 public static function &getInstance($tablename){ 00052 static $instances = array(); 00053 if ( !isset($instances[$tablename]) ){ 00054 $instances[$tablename] = new Dataface_TableTool($tablename); 00055 } 00056 return $instances[$tablename]; 00057 } 00058 00059 00066 function resolveLink($fieldname, &$record){ 00067 if ( !is_a($record, 'Dataface_Record') ){ 00068 throw new Exception("Dataface_TableTool::resolveLink() expects an object of type 'Dataface_Record' as the second argument, but received '".get_class($record)); 00069 } 00070 $link = $record->getLink($fieldname); 00071 00072 if ( is_array($link) ){ 00073 return Dataface_LinkTool::buildLink($link); 00074 } else if ( $link ){ 00075 return $this->_app->filterUrl($link); 00076 } else { 00077 return null; 00078 } 00079 00080 } 00081 00082 00083 }