Ver código fonte

Merge pull request #438 from danbarretodev/1.9.x

Fix for personal and admin events from my agenda event list view - refs CT#7381
Yannick Warnier 10 anos atrás
pai
commit
a572afa673

+ 26 - 6
main/calendar/agenda.lib.php

@@ -1092,12 +1092,23 @@ class Agenda
      */
     public function get_personal_events($start, $end)
     {
-        $start = api_get_utc_datetime(intval($start));
-        $end = api_get_utc_datetime(intval($end));
+        $start = intval($start);
+        $end = intval($end);
+        $startCondition = '';
+        $endCondition = '';
+
+        if ($start !== 0) {
+            $start = api_get_utc_datetime($start);
+            $startCondition = "AND date >= '".$start."'";
+        }
+        if ($start !== 0) {
+            $end = api_get_utc_datetime($end);
+            $endCondition = "AND (enddate <= '".$end."' OR enddate IS NULL)";
+        }
         $user_id = api_get_user_id();
 
         $sql = "SELECT * FROM ".$this->tbl_personal_agenda."
-                WHERE date >= '".$start."' AND (enddate <='".$end."' OR enddate IS NULL) AND user = $user_id";
+                WHERE user = $user_id $startCondition $endCondition";
 
         $result = Database::query($sql);
         $my_events = array();
@@ -1434,13 +1445,22 @@ class Agenda
         $start = intval($start);
         $end = intval($end);
 
-        $start = api_get_utc_datetime($start);
-        $end = api_get_utc_datetime($end);
+        $startCondition = '';
+        $endCondition = '';
+
+        if ($start !== 0) {
+            $start = api_get_utc_datetime($start);
+            $startCondition = "AND start_date >= '".$start."'";
+        }
+        if ($start !== 0) {
+            $end = api_get_utc_datetime($end);
+            $endCondition = "AND end_date <= '".$end."'";
+        }
 
         $access_url_id = api_get_current_access_url_id();
 
         $sql = "SELECT * FROM ".$this->tbl_global_agenda."
-               WHERE start_date >= '".$start."' AND end_date <= '".$end."' AND access_url_id = $access_url_id ";
+               WHERE access_url_id = $access_url_id $startCondition $endCondition";
 
         $result = Database::query($sql);
         $my_events = array();

+ 7 - 2
main/calendar/agenda_list.php

@@ -40,7 +40,8 @@ if (!empty($GLOBALS['_cid']) && $GLOBALS['_cid'] != -1) {
     // Agenda is out of the course tool (e.g personal agenda)
     $url = false;
     foreach ($events as &$event) {
-        $event['url'] = api_get_self() . '?cid=' . $event['course_id'];
+        $event['url'] = api_get_self() . '?cid=' . $event['course_id'] .
+        '&type=' . $event['type'];
     }
 }
 
@@ -59,14 +60,18 @@ if (api_is_allowed_to_edit()) {
         if (empty($courseInfo)) {
             // This happens when list agenda is not inside a course
             if (
+                ($type == 'course' || $type == 'session') &&
                 isset($_GET['cid']) &&
                 intval($_GET['cid']) !== 0
             ) {
+                // For course and session event types
                 // Just needs course ID
                 $courseInfo = array('real_id' => intval($_GET['cid']));
+                $agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);
+            } else {
+                // personal and admin do not have visibility property
             }
         }
-        $agenda->changeVisibility($_GET['id'], $_GET['visibility'], $courseInfo);
         header('Location: '. api_get_self());
         exit;
     }

+ 5 - 3
main/template/default/agenda/event_list.tpl

@@ -40,9 +40,11 @@
                             <img title="{{ 'Invisible' }}" src="{{'visible.png'|icon(32)}} ">
                         </a>
                     {% else %}
-                        <a class="btn" href="{% if url %}{{ url }}{% else %}{{ event.url }}{% endif %}&action=change_visibility&visibility=1&id={{ event.real_id }}">
-                            <img title="{{ 'Visible' }}" src="{{'invisible.png'|icon(32)}} ">
-                        </a>
+                        {% if event.type == 'course' or event.type == 'session' %}
+                            <a class="btn" href="{% if url %}{{ url }}{% else %}{{ event.url }}{% endif %}&action=change_visibility&visibility=1&id={{ event.real_id }}">
+                                <img title="{{ 'Visible' }}" src="{{'invisible.png'|icon(32)}} ">
+                            </a>
+                        {% endif %}
                     {% endif %}
                 </td>
             {% endif %}