From 0922bedb0d00efe3e9b2a1ff1d1d1b60fbb2ab3f Mon Sep 17 00:00:00 2001
From: Tobias Baden <tobias.baden@stud.hs-hannover.de>
Date: Fri, 24 Aug 2018 11:49:09 +0200
Subject: [PATCH] Updated the course search - Fixed Warnings - Added
 Placeholder - Added Placeholder Settings - Added Placeholder Strings - Added
 help Icon (without function atm) - Updated Version Number

---
 block_hshcourselist.php         | 61 +++++++++++++++++++++++----------
 edit_form.php                   |  6 ++++
 lang/en/block_hshcourselist.php |  7 ++--
 style.css                       |  9 +++++
 version.php                     |  2 +-
 5 files changed, 64 insertions(+), 21 deletions(-)

diff --git a/block_hshcourselist.php b/block_hshcourselist.php
index 49f451e..227cc55 100644
--- a/block_hshcourselist.php
+++ b/block_hshcourselist.php
@@ -25,7 +25,7 @@ class block_hshcourselist extends block_base {
     }
 
     public function get_content() {
-        global $CFG, $DB;
+        global $CFG, $DB, $OUTPUT;
 
         $this->page->requires->js('/blocks/hshcourselist/javascript/jquery-3.2.0.min.js');
         $this->page->requires->js('/blocks/hshcourselist/javascript/listselect.js');
@@ -39,8 +39,14 @@ class block_hshcourselist extends block_base {
         $context_block = context_block::instance($this->instance->id);
         $search = optional_param('hshcoursesearch', '', PARAM_TEXT);
         $hshcoursesubmit = optional_param('hshcoursesubmit', false, PARAM_TEXT);
+        // set placeholder
+        if($this->config->placeholder) {
+            $placeholder = $this->config->placeholder;
+        } else {
+            $placeholder = "";
+        }
         $list_contents = '';
-        $anchor = html_writer::tag('a', '', array('name' => 'hshcourselistanchor')); 
+        $anchor = html_writer::tag('a', '', array('name' => 'hshcourselistanchor'));
 
         $ordercheckbox = html_writer::empty_tag('input', array('type' => 'checkbox', 'name' => 'orderbysemestercheckbox', 'id' => 'orderbysemestercheckbox_id'));
         $ordercheckbox .= html_writer::start_tag('label', array('for' => 'orderbysemestercheckbox_id'));
@@ -56,12 +62,20 @@ class block_hshcourselist extends block_base {
             'name' => 'hshcourselistsearch',
             'id' => 'hshcourselistsearch',
             'class' => 'form-control',
-            'value' => $search
+            'value' => $search,
+            'placeholder' => $placeholder
         );
         $input = html_writer::empty_tag('input', $inputattrs);
 
+        $questionattrs = array(
+            'src' => $OUTPUT->image_url('help', 'moodle'),
+            'class' => 'hshcoursehelpclass',
+            'id' => 'hshcoursehelpid'
+        );
+        $question = html_writer::empty_tag('img', $questionattrs);
+
         $progressattrs = array(
-            'src' => $this->page->theme->pix_url('i/loading_small', 'moodle'),
+            'src' => $OUTPUT->image_url('i/loading_small', 'moodle'),
             'class' => 'hshcourseprogress',
             'id' => 'hshcourseprogress',
             'alt' => get_string('loading', 'block_hshcourselist')
@@ -69,18 +83,18 @@ class block_hshcourselist extends block_base {
         $progress = html_writer::empty_tag('img', $progressattrs);
 
         $formattrs = array(
-                'id' => 'hshcourseform',
-                'method' => 'post',
-                'name' => 'hshcourselistform',
-                //'action' => $this->page->url->out().'#hshcourselistanchor'
-                'action' => new moodle_url('/')
-            );
-
-        $form = html_writer::tag('form', $idSearchinglabel.$ordercheckbox.$input.$progress, $formattrs);
+            'id' => 'hshcourseform',
+            'method' => 'post',
+            'name' => 'hshcourselistform',
+            //'action' => $this->page->url->out().'#hshcourselistanchor'
+            'action' => new moodle_url('/')
+        );
+
+        $form = html_writer::tag('form', $idSearchinglabel.$ordercheckbox.$input.$question.$progress, $formattrs);
         if (!empty($hshcoursesubmit)) {
             $courses = self::get_courses($search, $context_block, $this->globalconf->splitterms,
-                                        $this->globalconf->restrictcontext, $this->page->context,
-                                        $this->globalconf->idSearching, $this->config->orderbysemester);
+                $this->globalconf->restrictcontext, $this->page->context,
+                $this->globalconf->idSearching, $this->config->orderbysemester);
 
             if (!empty($courses)) {
                 foreach ($courses as $course) {
@@ -104,6 +118,17 @@ class block_hshcourselist extends block_base {
             }
         }
 
+        if(!isset($this->config->orderbysemester)) {
+            $orderbysemester = false;
+        } else {
+            $orderbysemester = $this->config->orderbysemester;
+        }
+        if(!isset($this->config->displaymode)) {
+            $displaymode = 2;
+        } else {
+            $displaymode = $this->config->displaymode;
+        }
+
         $list = html_writer::tag('ul', $list_contents, array('id' => 'hshcourselistul'));
         $this->content->text = $anchor.$form.$list;
         $jsmodule = array(
@@ -119,8 +144,8 @@ class block_hshcourselist extends block_base {
 
                 Notice: Trying to get property of non-object in C:\Dev\xampp\htdocs\moodle\blocks\hshcourselist\block_hshcourselist.php on line 118 (123)
             */
-            'displaymode' => $this->config->displaymode,
-            'orderbysemester' => $this->config->orderbysemester,
+            'displaymode' => $displaymode,
+            'orderbysemester' => $orderbysemester,
             'contextid' => $this->page->context->id
         );
         $this->page->requires->js_call_amd('block_hshcourselist/jmodule', 'init', array($jsdata));
@@ -157,7 +182,7 @@ class block_hshcourselist extends block_base {
             if($idSearch) {
                 $params = array_merge($params, array($search));
                 $where .= 'id = ?';
-//                $where .= 'idnumber LIKE ?'; --- Bei Postgres nur "id"
+                //                $where .= 'idnumber LIKE ?'; --- Bei Postgres nur "id"
             } else {
                 $params = array_merge($params, array("%$search%", "%$search%"));
                 $where .= 'shortname ILIKE ? OR fullname ILIKE ?';
@@ -183,6 +208,6 @@ class block_hshcourselist extends block_base {
 
         $fields = 'id, idnumber, shortname, fullname';
         $courses = $DB->get_recordset_select('course', $where, $params, $order, $fields);
-    return $courses;
+        return $courses;
     }
 }
diff --git a/edit_form.php b/edit_form.php
index 82b9703..c0bc59d 100644
--- a/edit_form.php
+++ b/edit_form.php
@@ -11,6 +11,12 @@ class block_hshcourselist_edit_form extends block_edit_form {
         $mform->setDefault('config_title', get_string('default_blocktitle', 'block_hshcourselist'));
         $mform->setType('config_title', PARAM_TEXT);
 
+        //Placeholder Text
+        $mform->addElement('header', 'placeholdersettings',get_string('placeholder_settings', 'block_hshcourselist'));
+        $mform->addElement('text', 'config_placeholder', get_string('placeholder', 'block_hshcourselist'));
+        $mform->setDefault('config_placeholder', "");
+        $mform->setType('config_placeholder', PARAM_TEXT);
+
         // Displaysettings
         $mform->addElement('header', 'displaysettings', get_string('blocksettings_display', 'block_hshcourselist'));
         $selectoptions = array(0 => get_string('displayZero', 'block_hshcourselist'),
diff --git a/lang/en/block_hshcourselist.php b/lang/en/block_hshcourselist.php
index 02572d6..f237bbe 100644
--- a/lang/en/block_hshcourselist.php
+++ b/lang/en/block_hshcourselist.php
@@ -15,7 +15,7 @@ $string['blocksettings_footer'] = 'Footersettings';
 $string['enablefooter'] = 'Enable Footer';
 $string['blockfooter'] = 'Blockfooter';
 
-$string['headerconfig'] = 'Headerconfig';   
+$string['headerconfig'] = 'Headerconfig';
 $string['descconfig'] = 'Descconfig';
 
 $string['displaymode'] = 'Displaymethod';
@@ -27,4 +27,7 @@ $string['orderbysemester'] = 'Order by semester';
 
 $string['loading'] = 'LOADING...';
 
-$string['idSearchingLabel'] = ">> Es wird nur nach Kurs-ID's gesucht. <<";
\ No newline at end of file
+$string['idSearchingLabel'] = ">> Es wird nur nach Kurs-ID's gesucht. <<";
+
+$string['placeholder'] = "Placeholder for the searching field";
+$string['placeholder_settings'] = "Placeholder settings";
\ No newline at end of file
diff --git a/style.css b/style.css
index 2f82d86..9f98cb9 100644
--- a/style.css
+++ b/style.css
@@ -14,6 +14,15 @@
     color: white;
 }
 
+#hshcoursehelpid, .hshcoursehelpclass {
+    margin-top: -61px;
+    margin-left: 98%;
+}
+
+#hshcourselistsearch {
+    width: 97% !important;
+}
+
 /*
  * Aus Bootstrap 4 (Einheitliches Design wird "erzwungen", auch in Bootstrap 3 Themes)
  */
diff --git a/version.php b/version.php
index e15363a..535b56c 100644
--- a/version.php
+++ b/version.php
@@ -1,4 +1,4 @@
 <?php
 $plugin->component = 'block_hshcourselist';
-$plugin->version = 2018081001;  // YYYYMMDDHH
+$plugin->version = 2018082401;  // YYYYMMDDHH
 $plugin->requires = 2016112900; // YYYYMMDDHH
-- 
GitLab