Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
TableTool.php
Go to the documentation of this file.
1 <?php
2 /*-------------------------------------------------------------------------------
3  * Xataface Web Application Framework
4  * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *-------------------------------------------------------------------------------
20  */
38 require_once 'Dataface/Application.php';
39 require_once 'Dataface/Table.php';
40 
42 
43  var $_table;
44  var $_app;
45 
47  $this->_table =& Dataface_Table::loadTable($tablename);
48  $this->_app =& Dataface_Application::getInstance();
49  }
50 
51  public static function &getInstance($tablename){
52  static $instances = array();
53  if ( !isset($instances[$tablename]) ){
54  $instances[$tablename] = new Dataface_TableTool($tablename);
55  }
56  return $instances[$tablename];
57  }
58 
59 
66  function resolveLink($fieldname, &$record){
67  if ( !is_a($record, 'Dataface_Record') ){
68  throw new Exception("Dataface_TableTool::resolveLink() expects an object of type 'Dataface_Record' as the second argument, but received '".get_class($record));
69  }
70  $link = $record->getLink($fieldname);
71 
72  if ( is_array($link) ){
73  return Dataface_LinkTool::buildLink($link);
74  } else if ( $link ){
75  return $this->_app->filterUrl($link);
76  } else {
77  return null;
78  }
79 
80  }
81 
82 
83 }