Skip to content

Commit

Permalink
MDL-25275 - mod/data - Added a check box to eliminate date searches i…
Browse files Browse the repository at this point in the history
…f desired.
  • Loading branch information
abgreeve committed Oct 11, 2012
1 parent ccd90e7 commit c0e98e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
26 changes: 14 additions & 12 deletions mod/data/field/date/field.class.php
Expand Up @@ -55,12 +55,13 @@ function display_add_field($recordid=0) {

//Enable the following three functions once core API issues have been addressed.
function display_search_field($value=0) {
$selectors = html_writer::select_time('days', 'f_'.$this->field->id.'_d', $value)
. html_writer::select_time('months', 'f_'.$this->field->id.'_m', $value)
. html_writer::select_time('years', 'f_'.$this->field->id.'_y', $value);
return $selectors;
$selectors = html_writer::select_time('days', 'f_'.$this->field->id.'_d', $value['timestamp'])
. html_writer::select_time('months', 'f_'.$this->field->id.'_m', $value['timestamp'])
. html_writer::select_time('years', 'f_'.$this->field->id.'_y', $value['timestamp']);
$datecheck = html_writer::checkbox('f_'.$this->field->id.'_z', 1, $value['usedate']);
$str = $selectors . ' ' . $datecheck . ' ' . get_string('usedate', 'data');

//return print_date_selector('f_'.$this->field->id.'_d', 'f_'.$this->field->id.'_m', 'f_'.$this->field->id.'_y', $value, true);
return $str;
}

function generate_sql($tablealias, $value) {
Expand All @@ -70,21 +71,22 @@ function generate_sql($tablealias, $value) {
$i++;
$name = "df_date_$i";
$varcharcontent = $DB->sql_compare_text("{$tablealias}.content");
return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name=>$value));
return array(" ({$tablealias}.fieldid = {$this->field->id} AND $varcharcontent = :$name) ", array($name => $value['timestamp']));
}

function parse_search_field() {

$day = optional_param('f_'.$this->field->id.'_d', 0, PARAM_INT);
$month = optional_param('f_'.$this->field->id.'_m', 0, PARAM_INT);
$year = optional_param('f_'.$this->field->id.'_y', 0, PARAM_INT);
if (!empty($day) && !empty($month) && !empty($year)) {
return make_timestamp($year, $month, $day, 12, 0, 0, 0, false);
}
else {
$usedate = optional_param('f_'.$this->field->id.'_z', 0, PARAM_INT);
$data = array();
if (!empty($day) && !empty($month) && !empty($year) && $usedate == 1) {
$data['timestamp'] = make_timestamp($year, $month, $day, 12, 0, 0, 0, false);
$data['usedate'] = 1;
return $data;
} else {
return 0;
}

}

function update_content($recordid, $value, $name='') {
Expand Down
1 change: 1 addition & 0 deletions mod/data/lang/en/data.php
Expand Up @@ -342,6 +342,7 @@
The field enclosure is a character that surrounds each field in each record. It can normally be left unset.';
$string['uploadrecords_link'] = 'mod/data/import';
$string['url'] = 'Url';
$string['usedate'] = 'Include in search.';
$string['usestandard'] = 'Use a preset';
$string['usestandard_help'] = 'To use a preset available to the whole site, select it from the list. (If you have added a preset to the list using the save as preset feature then you have the option of deleting it.)';
$string['viewfromdate'] = 'Read only from';
Expand Down

0 comments on commit c0e98e8

Please sign in to comment.