Ignore:
Timestamp:
03/05/13 18:13:47 (11 years ago)
Author:
douglas
Message:

Ticket #3370 - Corrigido duplicacao de repeticao em compartilhamento de eventos

File:
1 edited

Legend:

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

    r7962 r7965  
    340340        $repeat = Controller::read(array('concept' => 'repeat', 'id' => $id)); 
    341341 
    342         unset($repeat['schedulable']); 
    343342        unset($repeat['id']); 
    344343 
     
    347346        if (isset($original['properties']['exceptions'])) { 
    348347            $exceptions = explode(',', $original['properties']['exceptions']); 
    349             unset($repeat['exceptions']); 
    350         } 
    351  
    352         $lastExceptions = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('AND', array('=', 'repeat', $id), array('=', 'exception', 1)))); 
     348            $event = Controller::read(array('concept' => 'schedulable', 'id' => $repeat['schedulable']));  
     349  
     350        if(array_key_exists(0, $event)) $event = $event[0];  
     351  
     352        $date = new DateTime('now', new DateTimeZone('UTC'));  
     353  
     354        foreach($exceptions as &$e){  
     355            $date->setTimestamp((int) ($e / 1000));  
     356            $date->setTimezone( new DateTimeZone( $event['timezone'] ));  
     357            $e = ($date->getTimestamp() - $date->getOffset()).'000';  
     358        }  
     359  
     360        unset($repeat['exceptions']);  
     361        } 
     362 
     363    unset($repeat['schedulable']);  
     364  
     365    $lastExceptions = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('AND', array('=', 'repeat', $id), array('=', 'exception', 1))));  
    353366 
    354367        //Recurepa as execeções anteriores caso exista 
     
    365378        else if(!empty($exceptions)) 
    366379            Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,exception,occurrence)VALUES ('" . $id . "','1','" . implode("'),('" . $id . "','1','", $exceptions) . "')" ); 
    367     }       
     380    }  
    368381 
    369382    public function checkOccurrences($start, $end, $calendarIds) { 
     
    414427 
    415428            foreach ($result as $id => $res){ 
    416                  
    417                 $ocurrences = array_unique($res); 
     429  
     430            $ocurrences = array_unique($res);  
     431  
     432            /*  
     433             * Check current range decoded  
     434             * */  
     435            $current = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('=', 'repeat', $id)));  
     436            $toDiff = array();  
     437  
     438            if(!empty($current))  
     439                foreach($current as $c) $toDiff[] = $c['occurrence'];  
     440  
     441            $ocurrences = array_diff($ocurrences, $toDiff);  
     442  
     443            if(!empty($ocurrences))  
    418444                Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,occurrence)VALUES('" . $id . "','" . implode("'),('" . $id . "', '", $ocurrences) . "')"); 
    419             } 
     445  
     446        }  
    420447            $data = array(); 
    421448 
     
    436463//      $return = Controller::find( array( 'concept' => 'repeatOccurrence' ), false, array( 'filter' => array( 'AND', array( '>=', 'occurrence', $origStart ), array( '<=', 'occurrence', $origEnd ), array( 'IN', 'repeat', $ids ) ), 'deepness' => $deep ) ); 
    437464 
    438         $return = Controller::service('PostgreSQL')->execResultSql('SELECT calendar_repeat_occurrence.occurrence as "occurrence", calendar_repeat.object_id as "schedulable" FROM calendar_repeat, calendar_repeat_occurrence WHERE calendar_repeat_occurrence.occurrence >= \'' . $origStart . '\' AND calendar_repeat_occurrence.occurrence <= \'' . $origEnd . '\' AND calendar_repeat_occurrence.repeat_id IN (\'' . implode('\',\'', $ids) . '\') AND calendar_repeat.id = calendar_repeat_occurrence.repeat_id AND calendar_repeat_occurrence.exception != 1'); 
     465        $return = Controller::service('PostgreSQL')->execResultSql('SELECT calendar_repeat_occurrence.occurrence as "occurrence", calendar_repeat.object_id as "schedulable" FROM calendar_repeat, calendar_repeat_occurrence WHERE calendar_repeat_occurrence.occurrence >= \'' . $origStart . '\' AND calendar_repeat_occurrence.occurrence <= \'' . $origEnd . '\' AND calendar_repeat_occurrence.repeat_id IN (\'' . implode('\',\'', $ids) . '\') AND calendar_repeat.id = calendar_repeat_occurrence.repeat_id AND calendar_repeat_occurrence.exception != 1 order by calendar_repeat_occurrence.occurrence'); 
    439466 
    440467        if (!is_array($return)) 
Note: See TracChangeset for help on using the changeset viewer.