예제 #1
0
 protected function _mapSubModelAnnotation(array $mappings, &$result, $result_key, $removeUnchanged, $property)
 {
     if ($mappings['sub_model']['collection']) {
         $result[$result_key] = array();
         if (is_array($this->{$property})) {
             foreach ($this->{$property} as $k => $sub_model) {
                 $sub_model->injectGamineService($this->_gamineservice, $mappings['sub_model']['entity']);
                 $result[$result_key][$k] = $sub_model->toDataArray(false);
             }
             if (empty($result[$result_key])) {
                 $result[$result_key] = null;
             } else {
                 if ($mappings['sub_model']['extract_mode'] == 'min') {
                     $pk = $this->_gamineservice->getPrimaryKeyProperty($mappings['sub_model']['entity']);
                     foreach ($result[$result_key] as $k => $res) {
                         $diff = array_key_exists($k, $this->_original_data) ? array_diff_assoc($this->_original_data[$result_key][$k], $res) : $res;
                         if (!count($diff)) {
                             $result[$result_key][$k] = array($pk => $res[$pk]);
                         } else {
                             if ($res[$pk]) {
                                 $diff[$pk] = $res[$pk];
                             } else {
                                 unset($diff[$pk]);
                             }
                             $result[$result_key][$k] = $diff;
                         }
                     }
                 }
             }
         }
     } else {
         $sub_model->injectGamineService($this->_gamineservice, $mappings['sub_model']['entity']);
         $result[$result_key] = $this->{$property}->toDataArray();
         if ($removeUnchanged && empty($result[$result_key])) {
             unset($result[$result_key]);
         }
     }
 }