示例#1
0
 /**
  *
  */
 public function prepare_import_content($data, $importsettings, $csvrecord = null, $entryid = null)
 {
     $fieldid = $this->id;
     $data = parent::prepare_import_content($data, $importsettings, $csvrecord, $entryid);
     if (isset($data->{"field_{$fieldid}_{$entryid}"})) {
         $iseditor = $this->is_editor();
         // For editors reformat in editor structure.
         if ($iseditor) {
             $valuearr = explode('##', $data->{"field_{$fieldid}_{$entryid}"});
             $content = array();
             $content['text'] = !empty($valuearr[0]) ? $valuearr[0] : null;
             $content['format'] = !empty($valuearr[1]) ? $valuearr[1] : FORMAT_MOODLE;
             $content['trust'] = !empty($valuearr[2]) ? $valuearr[2] : $this->editoroptions['trusttext'];
             $data->{"field_{$fieldid}_{$entryid}_editor"} = $content;
             unset($data->{"field_{$fieldid}_{$entryid}"});
         }
         // For simple text replace \r\n with new line.
         if (!$iseditor) {
             $data->{"field_{$fieldid}_{$entryid}"} = str_replace('\\r\\n', "\n", $data->{"field_{$fieldid}_{$entryid}"});
         }
     }
     return $data;
 }
示例#2
0
 /**
  *
  */
 public function get_search_sql($search)
 {
     if (!$search) {
         return null;
     }
     // The search value must be found in the field options.
     if (!($search[3] = $this->get_search_value($search[3]))) {
         return null;
     }
     return parent::get_search_sql($search);
 }
示例#3
0
 /**
  *
  */
 public function get_search_sql($search)
 {
     list($element, $not, $operator, $value) = $search;
     // Time list separated by ..
     if (strpos($value, '..') !== false) {
         $value = array_map('strtotime', explode('..', $value));
         // Must have valid timestamps.
         if (in_array(false, $value, true)) {
             $value = '#';
         }
     } else {
         $value = strtotime($value);
         // Must have valid timestamps.
         if ($value === false) {
             $value = '#';
         }
     }
     return parent::get_search_sql(array($element, $not, $operator, $value));
 }
示例#4
0
 /**
  *
  */
 public function __construct($field)
 {
     parent::__construct($field);
     $this->width = $this->param2;
     $this->widthunit = $this->param3;
 }
示例#5
0
 /**
  * Overriding parent to adjust search value. The search value is expected to be
  * a list of strings separated by pipe |. The reserved string for all required is -000-.
  * Searching a value is searching for the index: '#n#'.
  * Equal is simple, e.g. '#1#3#' where the searched options are 1 and 3.
  * Like requires a disjunction of each option. e.g. '%#1#%' OR '%#3#%'
  * or
  */
 public function get_search_sql($search)
 {
     list($element, $not, $operator, $value) = $search;
     // If no options, no search.
     if (!($options = $this->options_menu())) {
         return null;
     }
     $optionkeys = array_keys($options);
     // Search with all required.
     if ($value == '-000-') {
         $value = '#' . implode('#', $optionkeys) . '#';
         $search = array($element, $not, $operator, $value);
         return parent::get_search_sql($search);
     }
     $searchedvalues = array_map('trim', explode('|', $value));
     // Search equal to given list.
     if ($operator == '=') {
         $searchedoptions = array_intersect($options, $searchedvalues);
         // If we are searching for a value that is not in options, search for the impossible.
         if (count($searchedoptions) != count($searchedvalues)) {
             $search = array($element, $not, $operator, '##');
             return parent::get_search_sql($search);
         }
         // All searched values are there.
         $value = '#' . implode('#', array_keys($searchedoptions)) . '#';
         $search = array($element, $not, $operator, $value);
         return parent::get_search_sql($search);
     }
     // Search Like to given list.
     $sql = '';
     $params = array();
     if ($operator == 'LIKE') {
         $searchsqls = array();
         foreach ($searchedvalues as $searched) {
             if ((string) $searched == '') {
                 continue;
             }
             foreach ($options as $key => $option) {
                 if (strpos($option, $searched) !== false) {
                     $value = '#' . $key . '#';
                     $search = array($element, $not, $operator, $value);
                     $searchsqls[$key] = parent::get_search_sql($search);
                 }
             }
         }
         if ($searchsqls) {
             $sqlon = array();
             foreach ($searchsqls as $searchsql) {
                 list($sqlon[], $paramon, ) = $searchsql;
                 $params = array_merge($params, $paramon);
             }
             $sql = '(' . implode(' OR ', $sqlon) . ')';
             return array($sql, $params, $this->is_dataform_content());
         } else {
             // Searched strings not found so search for the impossible to return no entries.
             $search = array($element, '', '=', '##');
             return parent::get_search_sql($search);
         }
     }
     return null;
 }
示例#6
0
 /**
  *
  */
 public function get_search_sql($search)
 {
     if (!$search) {
         return null;
     }
     // Convert the search value to option index.
     $search[3] = $this->get_search_value($search[3]);
     return parent::get_search_sql($search);
 }