Changeset 6151


Ignore:
Timestamp:
05/09/12 17:50:59 (12 years ago)
Author:
acoutinho
Message:

Ticket #2709 - Inconsistencias na query de pesquisas de eventos

Location:
trunk/prototype/modules/calendar
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/calendar/interceptors/DBMapping.php

    r6137 r6151  
    111111 
    112112    public function findSchedulable(&$uri, &$params, &$criteria, $original) { 
    113         if (isset($criteria['filter'][3][1]) && $criteria['filter'][3][1] == 'calendar') { 
    114             $start = $criteria['filter'][1][2]; 
    115             $end = $criteria['filter'][2][2]; 
     113        if (isset($criteria['filter'][2][1]) && $criteria['filter'][2][1] == 'calendar') { 
     114            $start = array( $criteria['filter'][1][1][1][2] , $criteria['filter'][1][2][1][2], $criteria['filter'][1][3][1][2] ); 
     115            $end = array( $criteria['filter'][1][1][2][2] , $criteria['filter'][1][2][2][2], $criteria['filter'][1][3][2][2] ); 
    116116 
    117117            $ids = array(); 
    118118            $occ = array(); 
    119119 
    120             if ($occurrences = self::checkOccurrences($start, $end)) 
     120            if ($occurrences = self::checkOccurrences($start[0], $end[0])) 
    121121                foreach ($occurrences as $id => $occurrence) { 
    122122                    $ids[] = $id; 
    123123                    $occ[] = $occurrence; 
    124                 } 
    125  
    126             $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", calendar_object.dtstart as "startTime", calendar_object.summary as "summary", calendar_object.description as "description", calendar_object.dtend as "endTime" , calendar_object.location as "location", calendar_object.allday as "allDay", calendar_object.transp as "transparent", calendar_object.class_id as "class", calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart",calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence",  calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as calendar FROM calendar_to_calendar_object , calendar_object WHERE (range_start >= \'' . $start . '\' AND range_end <= \'' . $end . '\' AND calendar_to_calendar_object.calendar_id IN (\'' . implode('\',\'', $criteria['filter'][3][2]) . '\')) AND calendar_to_calendar_object.calendar_object_id = calendar_object.id' . (!empty($ids) ? ' AND calendar_object.id NOT IN (\'' . implode('\',\'', $ids) . '\')' : ''); 
     124                }        
     125         
     126            $queryRange = '((range_end >= \'' . $start[0] . '\' AND range_end <= \'' . $end[0] . '\') OR ' 
     127                    .'(range_start >= \'' . $start[1] . '\' AND range_start <= \'' . $end[1] . '\') OR ' 
     128                    .'(range_start <= \'' . $start[2] . '\' AND range_end >= \'' . $end[2] . '\')) '; 
     129                 
     130            $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", ' 
     131                .'calendar_object.dtstart as "startTime", calendar_object.summary as "summary", ' 
     132                .'calendar_object.description as "description", calendar_object.dtend as "endTime" , ' 
     133                .'calendar_object.location as "location", calendar_object.allday as "allDay", ' 
     134                .'calendar_object.transp as "transparent", calendar_object.class_id as "class", ' 
     135                .'calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart", ' 
     136                .'calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", ' 
     137                .'calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence", ' 
     138                .'calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as ' 
     139                .'calendar FROM calendar_to_calendar_object , calendar_object ' 
     140                .'WHERE ( '. $queryRange .' ' 
     141                .'AND calendar_to_calendar_object.calendar_id IN (\'' . implode('\',\'', $criteria['filter'][2][2]) . '\')) ' 
     142                .'AND calendar_to_calendar_object.calendar_object_id = calendar_object.id' . (!empty($ids) ? ' ' 
     143                .'AND calendar_object.id NOT IN (\'' . implode('\',\'', $ids) . '\')' : ''); 
    127144 
    128145            $params = Controller::service('PostgreSQL')->execResultSql($sql); 
     
    479496    public function deepnessFindEvent(&$uri, &$result, &$criteria, $original) { 
    480497        if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) { 
    481  
    482498            $Time = new DateTime('now', new DateTimeZone('UTC')); 
    483499            $DayLigth = array(); 
     
    511527 
    512528                if (isset($v['id'])) { 
    513                     $result[$i]['participants'] = Controller::find( array( 'concept' => 'participant' ) , false ,array( 'filter' => array('=', 'schedulable'  ,  $v['id']), 'criteria' => array( 'deepness' => $original['criteria']['deepness'] - 1 )));  
     529                    $result[$i]['participants'] = Controller::find( array( 'concept' => 'participant' ) , false ,array( 'filter' => array('=', 'schedulable'  ,  $v['id']),'deepness' => $original['criteria']['deepness'] - 1 ));  
    514530 
    515531                    $attachmentRelation = Controller::find(array('concept' => 'schedulableToAttachment'), false, array('filter' => array('=', 'schedulable', $v['id']))); 
     
    537553 
    538554//TODO: Remover apos suporte a deepness na api 
    539     public function deepnessReadParticipant( &$uri , &$result , &$criteria , $original ){                
    540         
     555    public function deepnessReadParticipant( &$uri , &$result , &$criteria , $original ){ 
     556 
    541557       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) 
    542558       { 
     
    570586    
    571587    //TODO: Remover apos suporte a deepness na api  
    572     public function deepnessFindParticipant( &$uri , &$result , &$criteria , $original ){                
    573         
     588    public function deepnessFindParticipant( &$uri , &$result , &$criteria , $original ){ 
     589 
    574590       if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) 
    575591       { 
     
    665681 
    666682            $params = array(); 
    667  
    668             $al = Controller::service('PostgreSQL')->execSql( "SELECT distinct co.id as \"id\", co.cal_uid as \"uid\", co.type_id as \"type\", co.dtstart as \"startTime\", co.summary as \"summary\", co.description as \"description\", co.dtend as \"endTime\", co.location as \"location\", co.allday as \"allDay\", co.transp as transparent, co.class_id as class, ". 
    669                                                                 "co.range_start as \"rangeStart\", co.range_end as \"rangeEnd\", co.last_update as \"lastUpdate\", co.dtstamp as \"dtstamp\", co.sequence as \"sequence\", co.tzid as \"timezone\", CASE WHEN rep.object_id = co.id THEN occ.occurrence - al.alarm_offset ELSE co.dtstart - al.alarm_offset END as \"sendTime\" ". 
    670                                                                 "FROM calendar_alarm as al, calendar_object as co, calendar_repeat as rep, calendar_repeat_occurrence as occ, calendar_participant as part WHERE ". 
    671                                                                 "al.action_id = '".ALARM_ALERT."' AND al.sent = '0' AND al.participant_id = part.id AND part.object_id = co.id AND ". 
    672                                                                 "CASE WHEN rep.object_id = co.id ". 
    673                                                                 "THEN rep.id = occ.repeat_id AND occ.occurrence - al.alarm_offset >= '$target' AND occ.occurrence - al.alarm_offset <= '".( $target + 86400000)."' ". 
    674                                                                 "ELSE co.range_start - al.alarm_offset >= '$target' AND co.range_start - al.alarm_offset <= '".( $target + 86400000)."' END"); 
    675  
     683            $notC = array(); 
     684 
     685            $al = Controller::service('PostgreSQL')->execSql("SELECT distinct co.id as \"id\", co.cal_uid as \"uid\", co.type_id as \"type\", co.dtstart as \"startTime\", co.summary as \"summary\", co.description as \"description\", co.dtend as \"endTime\", co.location as \"location\", co.allday as \"allDay\", co.transp as transparent, co.class_id as class, ". 
     686                "co.range_start as \"rangeStart\", co.range_end as \"rangeEnd\", co.last_update as \"lastUpdate\", co.dtstamp as \"dtstamp\", co.sequence as \"sequence\", co.tzid as \"timezone\", CASE WHEN rep.object_id = co.id THEN occ.occurrence - al.alarm_offset ELSE co.dtstart - al.alarm_offset END as \"sendTime\", ". 
     687                "al.unit as \"unit\", al.time as \"time\" FROM calendar_alarm as al, calendar_object as co, calendar_repeat as rep, calendar_repeat_occurrence as occ, calendar_participant as part WHERE ". 
     688                "al.action_id = '".ALARM_ALERT."' AND al.sent = '0' AND ( (al.participant_id = part.id) AND (part.user_info_id = '". Config::me('uidNumber') ."') ) AND part.object_id = co.id AND ". 
     689                "CASE WHEN rep.object_id = co.id ". 
     690                "THEN rep.id = occ.repeat_id AND occ.occurrence - al.alarm_offset >= '$target' AND occ.occurrence - al.alarm_offset <= '".( $target + 86400000)."' ". 
     691                "ELSE (co.range_start - al.alarm_offset) >= '$target' AND (co.range_start - al.alarm_offset) <= '".( $target + 86400000)."' END"); 
     692             
    676693            if(is_array($al)) 
    677               foreach( $al as $v ) 
    678               { 
    679                     $params['sendTime'] = $v['sendTime']; 
    680  
    681                     unset( $v['sendTime'] ); 
    682  
    683                     $params['schedulable'] = $v; 
     694              foreach( $al as $v ){ 
     695                if($notC[$v['id']]) 
     696                    continue; 
     697 
     698                $notC[$v['id']] = true; 
     699                $params[] = array('schedulable' =>  $v); 
    684700              } 
    685701            else 
    686702              $params = false; 
    687  
     703  
    688704            return false; 
    689705        } 
  • trunk/prototype/modules/calendar/js/calendar.codecs.js

    r6097 r6151  
    222222    load: function(){ 
    223223        var eventsDay = DataLayer.get('alarm:schedulable',['=', 'date', Date.today().getTime()]); 
     224        if(eventsDay) 
    224225        for(var i = 0; i < eventsDay.length; i++){ 
    225226            this.addAlarm( eventsDay[i] ); 
     
    405406                 
    406407        }); 
    407          
    408408        return notArray ? res[0] : res; 
    409409    }, 
     
    417417         
    418418    encoder: function (evtObjt){ 
    419          
    420         if(notArray = typeof(evtObjt) == 'array' ) 
     419        if(evtObjt == '') return false; 
     420 
     421        if((notArray = typeof(evtObjt) !== 'array') && (!evtObjt.length)) 
    421422            evtObjt = [evtObjt]; 
    422423                         
     
    426427                                                                                         
    427428            return{ 
    428                 id: objEvent.id, 
     429                id: objEvent.schedulable.id, 
    429430                event_start: new Date( time ).setTimezoneOffset(Timezone.timezones[objEvent.schedulable.timezone]).toString( User.preferences.dateFormat), 
    430                 sendTime: objEvent.sendTime, 
     431                sendTime: parseInt(objEvent.schedulable.sendTime) / 1000, 
    431432                schedulable: { 
    432433                    startTime: dateCalendar.formatDate(Timezone.getDateEvent(new Date(time), objEvent.schedulable.timezone, objEvent.schedulable.DayLigth, 'startTime'), User.preferences.hourFormat), 
    433434                    id: objEvent.schedulable.id, 
    434435                    summary: objEvent.schedulable.summary, 
    435                     time: objEvent.time,         
    436                     unit: dateCalendar.timeunit[objEvent.unit.toLowerCase()] + ( parseInt(objEvent.time) > 1 ? 's' : '' ) 
     436                    time: objEvent.schedulable.time,     
     437                    unit: (dateCalendar.timeunit[objEvent.schedulable.unit.toLowerCase()]) + ( parseInt(objEvent.schedulable.time) > 1 ? 's' : '' ) 
    437438                } 
    438439            } 
    439440        }); 
    440         return notArray ? res[0] : res; 
     441        return res; 
    441442    } 
    442443}); 
     
    11451146        for(var i in Calendar.signatureOf) 
    11461147            timezone[i] = Calendar.signatureOf[i].calendar.timezone; 
    1147                  
     1148         
    11481149        return { 
    1149             filter: ["AND",  
    1150  
    1151             [ ">=", "rangeStart", filter.start.getTime() ], 
    1152             [ "<=", "rangeEnd", filter.end.getTime() ], 
    1153             [ "IN", "calendar", Calendar.calendarIds ] 
    1154  
    1155             ],  
     1150            filter: ['AND',  
     1151                        ['OR',  
     1152                            ['AND',  
     1153                                ['>=', 'rangeEnd', filter.start.getTime()],  
     1154                                ['<=', 'rangeEnd', filter.end.getTime()] ,  
     1155                            ], 
     1156                            ['AND',  
     1157                                ['>=', 'rangeStart', filter.start.getTime()],  
     1158                                ['<=', 'rangeStart', filter.end.getTime()] ,  
     1159                            ], 
     1160                            ['AND',  
     1161                                ['<=', 'rangeStart', filter.start.getTime()],  
     1162                                ['>=', 'rangeEnd', filter.end.getTime()] ,  
     1163                            ] 
     1164                        ], 
     1165                        ['IN', 'calendar',  Calendar.calendarIds] 
     1166                ],  
    11561167            criteria: { 
    11571168                deepness: 2,  
  • trunk/prototype/modules/calendar/js/helpers.js

    r6103 r6151  
    6262        if (!eventInterval.length) 
    6363            return 'Por favor, informe o intervalo'; 
    64         else if (parseInt(eventInterval,10) <=0 || parseInt(eventInterval,10).toString() == "NaN") 
     64        else if (parseInt(eventInterval,10) < 0 || parseInt(eventInterval,10).toString() == "NaN") 
    6565            return 'Por favor informe um valor válido para o intervalo'; 
    6666    }     
     
    23962396         
    23972397    return { 
    2398         filter: ['AND', ['>=', 'rangeStart', rangeStart], ['<=', 'rangeEnd', rangeEnd] , ['IN', 'calendar',  calerdars_selecteds]],  
     2398         filter: ['AND',  
     2399                    ['OR',  
     2400                        ['AND',  
     2401                            ['>=', 'rangeEnd', rangeStart],  
     2402                            ['<=', 'rangeEnd', rangeEnd] ,  
     2403                        ], 
     2404                        ['AND',  
     2405                            ['>=', 'rangeStart', rangeStart],  
     2406                            ['<=', 'rangeStart', rangeEnd] ,  
     2407                        ], 
     2408                        ['AND',  
     2409                            ['<=', 'rangeStart', rangeStart],  
     2410                            ['>=', 'rangeEnd', rangeEnd] ,  
     2411                        ] 
     2412                    ], 
     2413                    ['IN', 'calendar',  calerdars_selecteds] 
     2414                ],  
    23992415        criteria: { 
    24002416            deepness: 2,  
Note: See TracChangeset for help on using the changeset viewer.