Ejemplo n.º 1
1
 protected function getElementFields($iblockId, $elementId)
 {
     $totalResult = array();
     $list = new CList($iblockId);
     $listFields = $list->getFields();
     foreach ($listFields as $fieldId => $field) {
         $totalResult[$fieldId] = $field;
     }
     $elementQuery = CIBlockElement::getList(array(), array("IBLOCK_ID" => $iblockId, "=ID" => $elementId), false, false, array('*'));
     $elementObject = $elementQuery->getNextElement();
     $elementNewData = $elementObject->getFields();
     if (is_array($elementNewData)) {
         foreach ($elementNewData as $fieldId => $fieldValue) {
             if (!$list->is_field($fieldId)) {
                 continue;
             }
             if (isset($totalResult[$fieldId]["NAME"])) {
                 $totalResult[$fieldId]["VALUE"] = $fieldValue;
             }
         }
     }
     $query = \CIblockElement::getPropertyValues($iblockId, array('ID' => $elementId));
     if ($propertyValues = $query->fetch()) {
         foreach ($propertyValues as $id => $values) {
             if ($id == "IBLOCK_ELEMENT_ID") {
                 continue;
             }
             $fieldId = "PROPERTY_" . $id;
             $totalResult[$fieldId]["VALUE"] = $values;
         }
     }
     return $totalResult;
 }
Ejemplo n.º 2
0
 public static function convertToDB($property, $value)
 {
     $listId = self::prepareValue($value);
     if (empty($property['ELEMENT_ID'])) {
         $value['VALUE'] = implode(',', $listId);
         return $value;
     }
     global $USER;
     if ($USER instanceof \CUser && $USER->getId()) {
         $userId = $USER->getId();
     } else {
         $userId = SystemUser::SYSTEM_USER_ID;
     }
     if (isset($value['DESCRIPTION']) && $value['DESCRIPTION'] == 'workflow') {
         $workFlow = true;
     } else {
         $workFlow = false;
     }
     $value['VALUE'] = array();
     $userFieldManager = Driver::getInstance()->getUserFieldManager();
     list($connectorClass, $moduleId) = $userFieldManager->getConnectorDataByEntityType("iblock_element");
     foreach ($listId as $id) {
         list($type, $realId) = FileUserType::detectType($id);
         if ($type == FileUserType::TYPE_NEW_OBJECT) {
             $errorCollection = new ErrorCollection();
             $fileModel = File::loadById($realId, array('STORAGE'));
             if (!$fileModel) {
                 continue;
             }
             if ($workFlow) {
                 $canUpdate = true;
             } else {
                 $securityContext = $fileModel->getStorage()->getSecurityContext($userId);
                 if (!$fileModel->canRead($securityContext)) {
                     continue;
                 }
                 $canUpdate = $fileModel->canUpdate($securityContext);
             }
             $attachedModel = AttachedObject::add(array('MODULE_ID' => $moduleId, 'OBJECT_ID' => $fileModel->getId(), 'ENTITY_ID' => $property['ELEMENT_ID'], 'ENTITY_TYPE' => $connectorClass, 'IS_EDITABLE' => (int) $canUpdate, 'ALLOW_EDIT' => (int) ($canUpdate && (int) Application::getInstance()->getContext()->getRequest()->getPost('DISK_FILE_' . $property['IBLOCK_ID'] . '_DISK_ATTACHED_OBJECT_ALLOW_EDIT')), 'CREATED_BY' => $userId), $errorCollection);
             if (!$attachedModel || $errorCollection->hasErrors()) {
                 continue;
             }
             $value['VALUE'][] = $attachedModel->getId();
         } else {
             $value['VALUE'][] = $realId;
         }
     }
     $query = \CIblockElement::getPropertyValues($property['IBLOCK_ID'], array('ID' => $property['ELEMENT_ID']));
     $oldPropertyValues = array();
     if ($propertyValues = $query->fetch()) {
         if (is_array($propertyValues[$property['ID']]) && !empty($propertyValues[$property['ID']])) {
             $oldValues = current($propertyValues[$property['ID']]);
         } else {
             $oldValues = $propertyValues[$property['ID']];
         }
         if (!empty($oldValues)) {
             $oldPropertyValues = explode(',', $oldValues);
         }
     }
     $attachedIdForDelete = array_diff($oldPropertyValues, $value['VALUE']);
     if (!empty($attachedIdForDelete)) {
         foreach ($attachedIdForDelete as $idAttached) {
             list($type, $realId) = FileUserType::detectType($idAttached);
             if ($type == FileUserType::TYPE_ALREADY_ATTACHED) {
                 $attachedModel = AttachedObject::loadById($realId);
                 if (!$attachedModel) {
                     continue;
                 }
                 if ($userFieldManager->belongsToEntity($attachedModel, "iblock_element", $property['ELEMENT_ID'])) {
                     $attachedModel->delete();
                 }
             }
         }
     }
     $value['VALUE'] = implode(',', $value['VALUE']);
     return $value;
 }