protected function saveFields() { $referencedObjectTypesCount = array(); foreach ($this->properties['fieldIds'] as $item) { array_key_exists($item->type, $referencedObjectTypesCount) ? ++$referencedObjectTypesCount[$item->type] : ($referencedObjectTypesCount[$item->type] = 1); } if (array_key_exists(BM_RT_MAIN, $referencedObjectTypesCount) && $referencedObjectTypesCount[BM_RT_MAIN] > 1 || array_key_exists(BM_RT_REFERRED, $referencedObjectTypesCount) && $referencedObjectTypesCount[BM_RT_REFERRED] > 1) { echo '<b>Ошибка уровня ядра:</b> в связи не может быть двух главных или двух зависимых объектов'; exit; } $dataLink = $this->application->dataLink; $cacheLink = $this->application->cacheLink; $sql = "DELETE FROM `link_referenceMap_referenceField` WHERE `referenceMapId` = " . $this->properties['identifier'] . ";"; $dataLink->query($sql); $this->application->log->add($sql); if (count($this->droppedFields) > 0) { foreach ($this->droppedFields as $fieldId => $fieldName) { $field = new bmReferenceField($this->application, array('identifier' => $fieldId)); $field->delete(); } } $insertStrings = array(); $insertObjectStrings = array(); foreach ($this->properties['fieldIds'] as $item) { $fieldId = $item->referenceFieldId; $type = $item->type; $droppedFieldIds = array_keys($this->droppedFields); if (!in_array($fieldId, $droppedFieldIds)) { $insertStrings[] = "(" . $dataLink->formatInput($this->properties['identifier'], BM_VT_INTEGER) . ", " . $dataLink->formatInput($fieldId, BM_VT_INTEGER) . ", " . $dataLink->formatInput($type, BM_VT_INTEGER) . ")"; } } if (count($insertStrings) > 0) { $sql = "INSERT IGNORE INTO\n `link_referenceMap_referenceField`\n (`referenceMapId`, `referenceFieldId`, `referenceFieldType`)\n VALUES\n " . implode(', ', $insertStrings) . ";"; $dataLink->query($sql); $this->application->log->add($sql); } $this->dirty['saveFields'] = false; }