Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
ajax_nav_tree_node.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  */
68 
69  function handle(&$params){
70 
72  $record =& $app->getRecord();
73  if ( !$record ){
74  echo '{}';
75  }
76 
77  $relationships = $record->_table->getRelationshipsAsActions();
78  if ( isset($_GET['-relationship']) ){
79  $relationships = array($relationships[$_GET['-relationship']]);
80  }
81  $outerOut = array();
82  foreach ($relationships as $relationship){
83  $innerOut = array();
84  $relatedRecords = $record->getRelatedRecordObjects($relationship['name'],0,60);
85  foreach ($relatedRecords as $relatedRecord){
86  $domainRecord = $relatedRecord->toRecord();
87  $override = array('__title__'=>$relatedRecord->getTitle());
88 
89  $innerOut[] = "'".$domainRecord->getId()."': ".$domainRecord->toJS(array(), $override);
90  }
91  if ( count($relationships) > 1 ){
92  $outerOut[] = "'".$relationship['name']."': {'__title__': '".$relationship['label']."', '__url__': '".$record->getURL('-action=related_records_list&-relationship='.urlencode($relationship['name']))."','records': {".implode(',',$innerOut)."}}";
93  } else {
94  $outerOut[] = implode(',',$innerOut);
95  }
96 
97  }
98  echo '{'.implode(',',$outerOut).'}';
99  exit;
100 
101  }
102 }