Xataface Tagger Module 0.3
Tagging Widget & Tag Cloud component for Xataface
|
00001 <?php 00002 /* 00003 * Xataface Tagger Module v 0.1 00004 * Copyright (C) 2011 Steve Hannah <steve@weblite.ca> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library 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 GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public 00017 * License along with this library; if not, write to the 00018 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00034 class Dataface_FormTool_tagger { 00035 00047 function &buildWidget($record, &$field, $form, $formFieldName, $new=false){ 00048 $widget =& $field['widget']; 00049 $factory =& Dataface_FormTool::factory(); 00050 $atts = array( 00051 'class' => 'xf-tagger', 00052 'data-xf-tagger-field'=> $field['name'], 00053 'data-xf-tagger-table' => $field['tablename'] 00054 ); 00055 if ( $new ){ 00056 $table = Dataface_Table::loadTable($field['tablename']); 00057 $fperms = $table->getPermissions(array('field'=>$field['name'])); 00058 00059 $rperms = $table->getPermissions(array('relationship'=>$field['relationship'])); 00060 00061 00062 if ( !@$fperms['new'] or !@$rperms['add new related record'] ){ 00063 $atts['data-xf-tagger-no-add-new'] = 1; 00064 } 00065 if ( !@$fperms['new'] or !@$rperms['add existing related record'] ){ 00066 $atts['data-xf-tagger-no-add-existing'] = 1; 00067 } 00068 if ( !@$fperms['new'] or !@$rperms['remove related record'] ){ 00069 $atts['data-xf-tagger-no-remove'] = 1; 00070 } 00071 00072 $atts['data-new'] = 1; 00073 } else { 00074 $fperms = $record->getPermissions(array('field'=>$field['name'])); 00075 $rperms = $record->getPermissions(array('relationship'=>$field['relationship'])); 00076 00077 if ( !@$fperms['edit'] or !@$rperms['add new related record'] ){ 00078 $atts['data-xf-tagger-no-add-new'] = 1; 00079 } 00080 if ( !@$fperms['edit'] or !@$rperms['add existing related record'] ){ 00081 $atts['data-xf-tagger-no-add-existing'] = 1; 00082 00083 } 00084 if ( !@$fperms['edit'] or !@$rperms['remove related record'] ){ 00085 //echo "Cannot remove";exit; 00086 $atts['data-xf-tagger-no-remove'] = 1; 00087 } 00088 00089 00090 $atts['data-record-id'] = $record->getId(); 00091 00092 00093 } 00094 $el =& $factory->addElement('textarea', $formFieldName, $widget['label'], $atts); 00095 if ( PEAR::isError($el) ) return $el; 00096 $el->setProperties($widget); 00097 $el->setFreezeWithAttribute(true); // we still want the textarea to show up 00098 // even if it's read only. 00099 00100 if ( $new ){ 00101 00102 $table = Dataface_Table::loadTable($field['tablename']); 00103 $fperms = $table->getPermissions(array('field'=>$field['name'])); 00104 00105 $rperms = $table->getPermissions(array('relationship'=>$field['relationship'])); 00106 if ( !$rperms['add existing related record'] ){ 00107 // If the user doesn't have permission to add existing related records 00108 // to this relationship then there's no point giving them edit permission 00109 // to this field at all. 00110 $el->freeze(); 00111 } 00112 00113 00114 00115 00116 } else { 00117 $fperms = $record->getPermissions(array('field'=>$field['name'])); 00118 $rperms = $record->getPermissions(array('relationship'=>$field['relationship'])); 00119 00120 if ( !@$fperms['edit'] or !@$rperms['add existing related record'] ){ 00121 $el->freeze(); 00122 } 00123 00124 00125 } 00126 00127 return $el; 00128 } 00129 00130 00131 }