Ejemplo n.º 1
0
 private static function reverseOperation($operation)
 {
     $reversedOperation = array();
     if (count($operation) > 0) {
         if ($operation['type'] == 'modifyCellValue') {
             $reversedOperation['type'] = $operation['type'];
             $reversedOperation['gridX'] = $operation['gridX'];
             $reversedOperation['gridY'] = $operation['gridY'];
             $reversedOperation['oldValue'] = $operation['newValue'];
             $reversedOperation['newValue'] = $operation['oldValue'];
         } else {
             if ($operation['type'] == 'applySuggestion') {
                 $reversedOperation['type'] = $operation['type'];
                 $modifications = array();
                 foreach ($operation['modifications'] as $modification) {
                     array_push($modifications, History::reverseOperation($modification));
                 }
                 $reversedOperation['modifications'] = $modifications;
             } else {
                 if ($operation['type'] == 'markPostposition') {
                     $reversedOperation['type'] = 'unmarkPostposition';
                     $reversedOperation['documentId'] = $operation['documentId'];
                     $reversedOperation['documentOffset'] = $operation['documentOffset'];
                     $reversedOperation['sentenceId'] = $operation['sentenceId'];
                     $reversedOperation['position'] = $operation['position'];
                 } else {
                     if ($operation['type'] == 'unmarkPostposition') {
                         $reversedOperation['type'] = 'markPostposition';
                         $reversedOperation['documentId'] = $operation['documentId'];
                         $reversedOperation['documentOffset'] = $operation['documentOffset'];
                         $reversedOperation['sentenceId'] = $operation['sentenceId'];
                         $reversedOperation['position'] = $operation['position'];
                     } else {
                         if ($operation['type'] == 'insertWord') {
                             $reversedOperation['type'] = 'deleteWord';
                             $reversedOperation['documentId'] = $operation['documentId'];
                             $reversedOperation['documentOffset'] = $operation['documentOffset'];
                             $reversedOperation['sentenceId'] = $operation['sentenceId'];
                             $reversedOperation['position'] = $operation['position'];
                         } else {
                             if ($operation['type'] == 'deleteWord') {
                                 $reversedOperation['type'] = 'insertWord';
                                 $reversedOperation['documentId'] = $operation['documentId'];
                                 $reversedOperation['documentOffset'] = $operation['documentOffset'];
                                 $reversedOperation['sentenceId'] = $operation['sentenceId'];
                                 $reversedOperation['position'] = $operation['position'];
                             }
                         }
                     }
                 }
             }
         }
     }
     /*
     CakeLog::write('debug', 'operation: '.print_r($operation,true));
     CakeLog::write('debug', 'reversed: '.print_r($reversedOperation,true));
     */
     return $reversedOperation;
 }