Permalink
Browse files

[MDL-8407] Add new function text_export_supported() or export_text_va…

…lue() to those "mod/data/field/*/field.class.php" files which need them. The existing code formatting has been cleaned up, too.
  • Loading branch information...
1 parent 775a5f4 commit 22cceb0cc998d1f073290a5c3ae461164edc123f robertall committed May 30, 2008
@@ -23,7 +23,6 @@
///////////////////////////////////////////////////////////////////////////
class data_field_file extends data_field_base {
-
var $type = 'file';
function data_field_file($field=0, $data=0) {
@@ -32,7 +31,6 @@ function data_field_file($field=0, $data=0) {
function display_add_field($recordid=0) {
global $CFG;
-
if ($recordid){
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
$contents[0] = $content->content;
@@ -41,13 +39,10 @@ function display_add_field($recordid=0) {
$contents[0] = '';
$contents[1] = '';
}
-
$src = empty($contents[0]) ? '' : $contents[0];
$name = empty($contents[1]) ? $src : $contents[1];
$displayname = empty($contents[1]) ? '' : $contents[1];
-
$path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
-
if ($CFG->slasharguments) {
$source = $CFG->wwwroot.'/file.php/'.$path;
} else {
@@ -59,7 +54,6 @@ function display_add_field($recordid=0) {
$displayname = '';
$source = '';
}
-
$str = '<div title="' . s($this->field->description) . '">';
$str .= '<fieldset><legend><span class="accesshide">'.$this->field->name.'</span></legend>';
$str .= '<input type="hidden" name ="field_'.$this->field->id.'_file" value="fakevalue" />';
@@ -70,8 +64,8 @@ function display_add_field($recordid=0) {
$str .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.s($this->field->param3).'" />';
$str .= '</fieldset>';
$str .= '</div>';
-
- if ($recordid and isset($content) and !empty($content->content)){ // Print icon
+ if ($recordid and isset($content) and !empty($content->content)) {
+ // Print icon
require_once($CFG->libdir.'/filelib.php');
$icon = mimeinfo('icon', $src);
$str .= '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.
@@ -81,78 +75,64 @@ function display_add_field($recordid=0) {
}
function display_search_field($value = '') {
- return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
+ return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
}
-
+
function generate_sql($tablealias, $value) {
- return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') ";
+ return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') ";
}
-
function parse_search_field() {
return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
}
function display_browse_field($recordid, $template) {
-
global $CFG;
-
if (!$content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
return false;
}
-
$width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
$height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
-
if (empty($content->content)) {
return '';
}
-
require_once($CFG->libdir.'/filelib.php');
-
$src = $content->content;
$name = empty($content->content1) ? $src : $content->content1;
-
$source = get_file_url($this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid);
-
$icon = mimeinfo('icon', $src);
$str = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" height="16" width="16" alt="'.$icon.'" />&nbsp;'.
'<a href="'.$source.'/'.$src.'" >'.$name.'</a>';
-
return $str;
}
-/// content = a ## b where a is the filename, b is the display file name
+ // content: "a##b" where a is the file name, b is the display name
function update_content($recordid, $value, $name) {
global $CFG;
-
if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
- /// Quickly make one now!
+ // Quickly make one now!
$oldcontent = new object;
$oldcontent->fieldid = $this->field->id;
$oldcontent->recordid = $recordid;
if ($oldcontent->id = insert_record('data_content', $oldcontent)) {
error('Could not make an empty record!');
}
}
-
$content = new object;
$content->id = $oldcontent->id;
-
$names = explode('_',$name);
switch ($names[2]) {
- case 'file': //file just uploaded
- //$course = get_course('course', 'id', $this->data->course);
-
+ case 'file':
+ // file just uploaded
+# $course = get_course('course', 'id', $this->data->course);
$filename = $_FILES[$names[0].'_'.$names[1]];
$filename = $filename['name'];
$dir = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
-
- //only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg
+ // only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg
if ($filename){
require_once($CFG->libdir.'/uploadlib.php');
- //FIX ME: $course not defined heer!!
+ // FIX ME: $course not defined here
$um = new upload_manager($names[0].'_'.$names[1],true,false,$this->data->course,false,$this->field->param3);
if ($um->process_file_uploads($dir)) {
$newfile_name = $um->get_new_filename();
@@ -162,7 +142,8 @@ function update_content($recordid, $value, $name) {
}
break;
- case 'filename': //only changing alt tag
+ case 'filename':
+ // only changing alt tag
$content->content1 = clean_param($value, PARAM_NOTAGS);
update_record('data_content', $content);
break;
@@ -172,15 +153,20 @@ function update_content($recordid, $value, $name) {
}
}
- function notemptyfield($value, $name){
+ function notemptyfield($value, $name) {
$names = explode('_',$name);
- if ($names[2] == 'file'){
+ if ($names[2] == 'file') {
$filename = $_FILES[$names[0].'_'.$names[1]];
- return !empty($filename['name']); //if there's a file in $_FILES, not empty
+ return !empty($filename['name']);
+ // if there's a file in $_FILES, not empty
}
return false;
}
+ function text_export_supported() {
+ return false;
+ }
+
}
?>
@@ -1,4 +1,4 @@
-<?php
+<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
@@ -23,47 +23,40 @@
///////////////////////////////////////////////////////////////////////////
class data_field_latlong extends data_field_base {
-
var $type = 'latlong';
// This is an array of URL schemes for linking out to services, using the float values of lat and long.
// In each scheme, the special markers @lat@ and @long@ will be replaced by the float values.
// The config options for the field store each service name that should be displayed, in a comma-separated
// field. Therefore please DO NOT include commas in the service names if you are adding extra services.
+
+ // Parameter data used:
+ // "param1" is a comma-separated list of the linkout service names that are enabled for this instance
+ // "param2" indicates the label that will be used in generating Google Earth KML files: -1 for item #, -2 for lat/long, positive number for the (text) field to use.
+
var $linkoutservices = array(
"Google Maps" => "http://maps.google.com/maps?q=@lat@,+@long@&iwloc=A&hl=en",
"Google Earth" => "@wwwroot@/mod/data/field/latlong/kml.php?d=@dataid@&fieldid=@fieldid@&rid=@recordid@",
"Geabios" => "http://www.geabios.com/html/services/maps/PublicMap.htm?lat=@lat@&lon=@long@&fov=0.3&title=Moodle%20data%20item",
"OpenStreetMap" => "http://www.openstreetmap.org/index.html?lat=@lat@&lon=@long@&zoom=11",
"Multimap" => "http://www.multimap.com/map/browse.cgi?scale=200000&lon=@long@&lat=@lat@&icon=x"
- );
+ );
// Other map sources listed at http://kvaleberg.com/extensions/mapsources/index.php?params=51_30.4167_N_0_7.65_W_region:earth
-
-
- // Parameter data used:
- // "param1" is a comma-separated list of the linkout service names that are enabled for this instance
- // "param2" indicates the label that will be used in generating Google Earth KML files: -1 for item #, -2 for lat/long, positive number for the (text) field to use.
-
-
-
function data_field_latlong($field=0, $data=0) {
parent::data_field_base($field, $data);
}
- function display_add_field($recordid=0){
+ function display_add_field($recordid=0) {
global $CFG;
-
$lat = '';
$long = '';
-
- if ($recordid){
+ if ($recordid) {
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
$lat = $content->content;
$long = $content->content1;
}
}
-
$str = '<div title="'.s($this->field->description).'">';
$str .= '<fieldset><legend><span class="accesshide">'.$this->field->name.'</span></legend>';
$str .= '<table><tr><td align="right">';
@@ -72,60 +65,56 @@ function display_add_field($recordid=0){
$str .= '</table>';
$str .= '</fieldset>';
$str .= '</div>';
-
return $str;
}
-
+
function display_search_field($value = '') {
global $CFG;
$lats = get_records_sql_menu('SELECT id, content from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
$longs = get_records_sql_menu('SELECT id, content1 from '.$CFG->prefix.'data_content WHERE fieldid='.$this->field->id.' GROUP BY content ORDER BY content');
$options = array();
if(!empty($lats) && !empty($longs)) {
- $options[''] = ''; //Make first index blank.
+ $options[''] = '';
+ // Make first index blank.
foreach($lats as $key => $temp) {
$options[$temp.','.$longs[$key]] = $temp.','.$longs[$key];
}
}
return choose_from_menu($options, 'f_'.$this->field->id, $value, 'choose', '', 0, true);
}
-
+
function parse_search_field() {
return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
}
-
+
function generate_sql($tablealias, $value) {
$latlong[0] = '';
$latlong[1] = '';
$latlong = explode (',', $value, 2);
- return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$latlong[0]' AND {$tablealias}.content1 = '$latlong[1]') ";
+ return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content = '$latlong[0]' AND {$tablealias}.content1 = '$latlong[1]') ";
}
function display_browse_field($recordid, $template) {
global $CFG;
- if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
+ if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
$lat = empty($content->content)? '':$content->content;
$long = empty($content->content1)? '':$content->content1;
-
if (empty($lat) or empty($long)) {
return '';
}
-
- if($lat < 0) {
- $compasslat = "" . sprintf('%01.4f', 0 - $lat) . '°S';
- } else {
- $compasslat = "" . sprintf('%01.4f', $lat) . "°N";
- }
- if($long < 0) {
- $compasslong = "" . sprintf('%01.4f', 0 - $long) . '°W';
- } else {
- $compasslong = "" . sprintf('%01.4f', $long) . "°E";
- }
-
+ if($lat < 0) {
+ $compasslat = "" . sprintf('%01.4f', 0 - $lat) . '°S';
+ } else {
+ $compasslat = "" . sprintf('%01.4f', $lat) . "°N";
+ }
+ if($long < 0) {
+ $compasslong = "" . sprintf('%01.4f', 0 - $long) . '°W';
+ } else {
+ $compasslong = "" . sprintf('%01.4f', $long) . "°E";
+ }
$str = '<form style="display:inline;">';
$str.= "$compasslat, $compasslong";
-
// Now let's create the jump-to-services link
$servicesshown = explode(',', $this->field->param1);
@@ -139,15 +128,14 @@ function display_browse_field($recordid, $template) {
'@courseid@'=> $this->data->course,
'@fieldid@'=> $content->fieldid,
'@recordid@'=> $content->recordid,
- );
+ );
if(sizeof($servicesshown)==1 && $servicesshown[0]) {
$str .= " <a href='"
. str_replace(array_keys($urlreplacements), array_values($urlreplacements), $this->linkoutservices[$servicesshown[0]])
."'>$servicesshown[0]</a> ";
} elseif (sizeof($servicesshown)>1) {
$str .= "\n<select name='jumpto'>";
-
foreach($servicesshown as $servicename){
// Add a link to a service
$str .= "\n <option value='"
@@ -158,9 +146,7 @@ function display_browse_field($recordid, $template) {
// which allows the "Go" button to refer to the drop-down selector.
$str .= "\n</select><input type='button' value='" . get_string('go') . "' onclick='if(previousSibling.value){self.location=previousSibling.value}'/>";
}
-
$str.= '</form>';
-
return $str;
}
return false;
@@ -170,19 +156,19 @@ function update_content($recordid, $value, $name='') {
$content = new object;
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
-
$names = explode('_', $name);
- switch ($names[2]){
- case 0: // update lat
+ switch ($names[2]) {
+ case 0:
+ // update lat
$content->content = (float)$value;
break;
- case 1: // update long
+ case 1:
+ // update long
$content->content1 = (float)$value;
break;
default:
break;
}
-
if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
$content->id = $oldcontent->id;
return update_record('data_content', $content);
@@ -193,16 +179,23 @@ function update_content($recordid, $value, $name='') {
function get_sort_sql($fieldname) {
global $CFG;
-
switch ($CFG->dbfamily) {
- case 'mysql': // string in an arithmetic operation is converted to a floating-point number
+ case 'mysql':
+ // string in an arithmetic operation is converted to a floating-point number
return '('.$fieldname.'+0.0)';
- case 'postgres': //cast is for PG
+ case 'postgres':
+ //cast is for PG
return 'CAST('.$fieldname.' AS REAL)';
- default: //Return just the fieldname. TODO: Look behaviour under MSSQL and Oracle
+ default:
+ //Return just the fieldname. TODO: Look behaviour under MSSQL and Oracle
return $fieldname;
}
}
+
+ function export_text_value($record) {
+ return sprintf('%01.4f', $record->content) . " " . sprintf('%01.4f', $record->content1);
+ }
+
}
?>
Oops, something went wrong.

0 comments on commit 22cceb0

Please sign in to comment.