Xataface 2.0
Xataface Application Framework
actions/single_record_search.php
Go to the documentation of this file.
00001 <?php
00011 class dataface_actions_single_record_search {
00012         function handle(&$params){
00013                 $app =& Dataface_Application::getInstance();
00014                 $record =& $app->getRecord();
00015                 $query =& $app->getQuery();
00016                 if ( !isset($query['--subsearch']) ) $query['--subsearch'] = '';
00017                 
00018                 $results = array();
00019                 
00020                 foreach ( $record->_table->relationships() as $rname=>$r){
00021                         $fields = $r->fields(true);
00022                         $qstr = array();
00023                         foreach ( $fields as $field ){
00024                                 //list($tname, $field) = explode('.', $field);
00025                                 $qstr[] = '`'.str_replace('`','',$field)."` LIKE '%".addslashes($query['--subsearch'])."%'";
00026                         }
00027                         $qstr = implode(' OR ', $qstr);
00028                         $results[$rname] = $record->getRelatedRecordObjects($rname, 0, 10, $qstr);
00029                         unset($r);
00030                         unset($fields);
00031                 }
00032                 
00033                 if ( @$query['--format'] == 'RSS2.0' ){
00034                         $this->handleRSS($results);
00035                 } else {
00036                         df_display(array('results'=>&$results, 'queryString'=>$query['--subsearch']), 'Dataface_single_record_search.html');
00037                 }
00038         }
00039         
00040         function handleRSS($results){
00041                 $app =& Dataface_Application::getInstance();
00042                 $record =& $app->getRecord();
00043                 $query =& $app->getQuery();
00044                 import('feedcreator.class.php');
00045                 import('Dataface/FeedTool.php');
00046                 $ft = new Dataface_FeedTool();
00047                 $rss = new UniversalFeedCreator(); 
00048                 $rss->encoding = $app->_conf['oe'];
00049                 //$rss->useCached(); // use cached version if age<1 hour
00050                 $del =& $record->_table->getDelegate();
00051                 if ( !$del or !method_exists($del, 'getSingleRecordSearchFeed') ){
00052                         $del =& $app->getDelegate();
00053                 }
00054                 if ( $del and method_exists($del, 'getSingleRecordSearchFeed') ){
00055                         $feedInfo = $del->getSingleRecordSearchFeed($record, $query);
00056                         if ( !$feedInfo ) $feedInfo = array();
00057                 }
00058                 if ( isset($feedInfo['title']) ) $rss->title = $feedInfo['title'];
00059                 else $rss->title = $record->getTitle().'[ Search for "'.$query['--subsearch'].'"]';
00060                 
00061                 if ( isset($feedInfo['description']) ) $rss->description = $feedInfo['description'];
00062                 else $rss->description = '';
00063                 
00064                 if ( isset($feedInfo['link']) ) $rss->link = $feedInfo['link'];
00065                 else $rss->link = htmlentities(df_absolute_url($app->url('').'&--subsearch='.urlencode($query['--subsearch'])));
00066                 
00067                 $rss->syndicationURL = $rss->link;
00068                 
00069                 
00070                 $records = array();
00071                 
00072                 foreach ($results as $result){
00073                         foreach ($result as $rec){
00074                                 $records[] = $rec->toRecord();
00075                                 
00076                         }
00077                 }
00078                 
00079                 uasort($records, array($this, 'cmp_last_modified') );
00080                 
00081                 
00082                 
00083                 foreach ($records as $rec){
00084                         if ( $rec->checkPermission('view') and $rec->checkPermission('view in rss') ){
00085                                 $rss->addItem($ft->createFeedItem($rec));
00086                         }
00087                                 
00088                 }
00089                 if ( !$query['--subsearch'] ){
00090                         $rss->addItem($ft->createFeedItem($record));
00091                 }
00092                 
00093                 header("Content-Type: application/xml; charset=".$app->_conf['oe']);
00094                 echo $rss->createFeed('RSS2.0');
00095                 exit;
00096         }
00097         
00098         
00099         function cmp_last_modified($a,$b){
00100                 $amod = $a->getLastModified();
00101                 $bmod = $b->getLastModified();
00102                 if ( $amod == $bmod ) return 0;
00103                 else return ( ($amod < $bmod) ? 1:-1);
00104         }
00105 
00106 }
 All Data Structures Namespaces Files Functions Variables Enumerations