예제 #1
0
 protected function loadFromDatabase()
 {
     if (!isset($this->fields) && $this->iblock_id > 0 && is_array($this->id)) {
         $this->fields = array();
         foreach ($this->id as $id) {
             if ($id > 0) {
                 $propertyList = \CIBlockElement::getProperty($this->iblock_id, $id, array("sort" => "asc"), array("EMPTY" => "N"));
                 while ($property = $propertyList->fetch()) {
                     if ($property["VALUE_ENUM"] != "") {
                         $value = $property["VALUE_ENUM"];
                     } elseif ($property["PROPERTY_TYPE"] === "E") {
                         $value = new ElementPropertyElement($property["VALUE"]);
                     } elseif ($property["PROPERTY_TYPE"] === "G") {
                         $value = new ElementPropertySection($property["VALUE"]);
                     } else {
                         if (strlen($property["USER_TYPE"])) {
                             $value = new ElementPropertyUserField($property["VALUE"], $property);
                         } else {
                             $value = $property["VALUE"];
                         }
                     }
                     $this->fields[$property["ID"]][] = $value;
                     $this->fieldMap[$property["ID"]] = $property["ID"];
                     if ($property["CODE"] != "") {
                         $this->fieldMap[strtolower($property["CODE"])] = $property["ID"];
                     }
                 }
             }
         }
     }
     return is_array($this->fields);
 }
예제 #2
0
 /**
  * ћетод публикует документ. “о есть делает его доступным в публичной части сайта.
  *
  * @param string $documentId - код документа.
  */
 public function PublishDocument($documentId)
 {
     global $DB;
     $ID = intval($documentId);
     $db_element = CIBlockElement::getList(array(), array("ID" => $ID, "SHOW_HISTORY" => "Y"), false, false, array("ID", "TIMESTAMP_X", "MODIFIED_BY", "DATE_CREATE", "CREATED_BY", "IBLOCK_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "SORT", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_TEXT", "DETAIL_TEXT_TYPE", "WF_STATUS_ID", "WF_PARENT_ELEMENT_ID", "WF_NEW", "WF_COMMENTS", "IN_SECTIONS", "CODE", "TAGS", "XML_ID", "TMP_ID"));
     if ($element = $db_element->fetch()) {
         $parentId = intval($element["WF_PARENT_ELEMENT_ID"]);
         if ($parentId) {
             $elementObject = new CIBlockElement();
             $element["WF_PARENT_ELEMENT_ID"] = false;
             if ($element["PREVIEW_PICTURE"]) {
                 $element["PREVIEW_PICTURE"] = CFile::makeFileArray($element["PREVIEW_PICTURE"]);
             } else {
                 $element["PREVIEW_PICTURE"] = array("tmp_name" => "", "del" => "Y");
             }
             if ($element["DETAIL_PICTURE"]) {
                 $element["DETAIL_PICTURE"] = CFile::makeFileArray($element["DETAIL_PICTURE"]);
             } else {
                 $element["DETAIL_PICTURE"] = array("tmp_name" => "", "del" => "Y");
             }
             $element["IBLOCK_SECTION"] = array();
             if ($element["IN_SECTIONS"] == "Y") {
                 $sectionsQuery = CIBlockElement::getElementGroups($element["ID"], true, array('ID', 'IBLOCK_ELEMENT_ID'));
                 while ($section = $sectionsQuery->fetch()) {
                     $element["IBLOCK_SECTION"][] = $section["ID"];
                 }
             }
             $element["PROPERTY_VALUES"] = array();
             $props =& $element["PROPERTY_VALUES"];
             //Delete old files
             $propsQuery = CIBlockElement::getProperty($element["IBLOCK_ID"], $parentId, array("value_id" => "asc"), array("PROPERTY_TYPE" => "F", "EMPTY" => "N"));
             while ($prop = $propsQuery->fetch()) {
                 if (!array_key_exists($prop["ID"], $props)) {
                     $props[$prop["ID"]] = array();
                 }
                 $props[$prop["ID"]][$prop["PROPERTY_VALUE_ID"]] = array("VALUE" => array("tmp_name" => "", "del" => "Y"), "DESCRIPTION" => false);
             }
             //Add new proiperty values
             $propsQuery = CIBlockElement::getProperty($element["IBLOCK_ID"], $element["ID"], array("value_id" => "asc"));
             $i = 0;
             while ($prop = $propsQuery->fetch()) {
                 $i++;
                 if (!array_key_exists($prop["ID"], $props)) {
                     $props[$prop["ID"]] = array();
                 }
                 if ($prop["PROPERTY_VALUE_ID"]) {
                     if ($prop["PROPERTY_TYPE"] == "F") {
                         $props[$prop["ID"]]["n" . $i] = array("VALUE" => CFile::makeFileArray($prop["VALUE"]), "DESCRIPTION" => $prop["DESCRIPTION"]);
                     } else {
                         $props[$prop["ID"]]["n" . $i] = array("VALUE" => $prop["VALUE"], "DESCRIPTION" => $prop["DESCRIPTION"]);
                     }
                 }
             }
             $elementObject->update($parentId, $element);
             CBPDocument::mergeDocuments(array("lists", get_called_class(), $parentId), array("lists", get_called_class(), $documentId));
             CIBlockElement::delete($ID);
             CIBlockElement::wF_CleanUpHistoryCopies($parentId, 0);
             $strSql = "update b_iblock_element set WF_STATUS_ID='1', WF_NEW=NULL WHERE ID=" . $parentId . " AND WF_PARENT_ELEMENT_ID IS NULL";
             $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br>LINE: " . __LINE__);
             CIBlockElement::updateSearch($parentId);
             return $parentId;
         } else {
             CIBlockElement::wF_CleanUpHistoryCopies($ID, 0);
             $strSql = "update b_iblock_element set WF_STATUS_ID='1', WF_NEW=NULL WHERE ID=" . $ID . " AND WF_PARENT_ELEMENT_ID IS NULL";
             $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br>LINE: " . __LINE__);
             CIBlockElement::updateSearch($ID);
             return $ID;
         }
     }
     return false;
 }
예제 #3
0
 public function OnAfterIBlockElementDelete($fields)
 {
     if (CModule::includeModule('bizproc')) {
         $errors = array();
         $iblockType = COption::getOptionString("lists", "livefeed_iblock_type_id");
         $iblockQuery = CIBlock::getList(array(), array('ID' => $fields['IBLOCK_ID']));
         if ($iblock = $iblockQuery->fetch()) {
             $iblockType = $iblock["IBLOCK_TYPE_ID"];
         }
         $states = CBPStateService::getDocumentStates(BizprocDocument::getDocumentComplexId($iblockType, $fields['ID']));
         $listWorkflowId = array();
         foreach ($states as $workflowId => $state) {
             $listWorkflowId[] = $workflowId;
         }
         self::deleteSocnetLog($listWorkflowId);
         CBPDocument::onDocumentDelete(BizprocDocument::getDocumentComplexId($iblockType, $fields['ID']), $errors);
     }
     $propertyQuery = CIBlockElement::getProperty($fields['IBLOCK_ID'], $fields['ID'], 'sort', 'asc', array('ACTIVE' => 'Y'));
     while ($property = $propertyQuery->fetch()) {
         $userType = \CIBlockProperty::getUserType($property['USER_TYPE']);
         if (array_key_exists('DeleteAllAttachedFiles', $userType)) {
             call_user_func_array($userType['DeleteAllAttachedFiles'], array($fields['ID']));
         }
     }
 }
예제 #4
0
 if ($ELEMENT_ID && $templatesOnStartup) {
     $modifiedFields = array();
     /* We get the new data element. */
     $elementNewData = array();
     $elementOldData = array();
     $elementQuery = CIBlockElement::getList(array(), array("IBLOCK_ID" => $arResult["IBLOCK_ID"], "=ID" => $arResult["ELEMENT_ID"]), false, false, $arSelect);
     $elementObject = $elementQuery->getNextElement();
     if (is_object($elementObject)) {
         $elementNewData = $elementObject->getFields();
     }
     $elementOldData = $arResult["ELEMENT_FIELDS"];
     unset($elementNewData["TIMESTAMP_X"]);
     unset($elementOldData["TIMESTAMP_X"]);
     $elementNewData["PROPERTY_VALUES"] = array();
     if (is_object($elementObject)) {
         $propertyQuery = CIBlockElement::getProperty($arResult["IBLOCK_ID"], $arResult["ELEMENT_ID"], array("sort" => "asc", "id" => "asc", "enum_sort" => "asc", "value_id" => "asc"), array("ACTIVE" => "Y", "EMPTY" => "N"));
         while ($property = $propertyQuery->fetch()) {
             $propertyId = $property["ID"];
             if (!array_key_exists($propertyId, $elementNewData["PROPERTY_VALUES"])) {
                 $elementNewData["PROPERTY_VALUES"][$propertyId] = $property;
                 unset($elementNewData["PROPERTY_VALUES"][$propertyId]["DESCRIPTION"]);
                 unset($elementNewData["PROPERTY_VALUES"][$propertyId]["VALUE_ENUM_ID"]);
                 unset($elementNewData["PROPERTY_VALUES"][$propertyId]["VALUE_ENUM"]);
                 unset($elementNewData["PROPERTY_VALUES"][$propertyId]["VALUE_XML_ID"]);
                 $elementNewData["PROPERTY_VALUES"][$propertyId]["FULL_VALUES"] = array();
                 $elementNewData["PROPERTY_VALUES"][$propertyId]["VALUES_LIST"] = array();
             }
             $elementNewData["PROPERTY_VALUES"][$propertyId]["FULL_VALUES"][$property["PROPERTY_VALUE_ID"]] = array("VALUE" => $property["VALUE"], "DESCRIPTION" => $property["DESCRIPTION"]);
             $elementNewData["PROPERTY_VALUES"][$propertyId]["VALUES_LIST"][$property["PROPERTY_VALUE_ID"]] = $property["VALUE"];
         }
     }
예제 #5
0
 public function UpdateDocument($documentId, $arFields)
 {
     $documentId = intval($documentId);
     if ($documentId <= 0) {
         throw new CBPArgumentNullException("documentId");
     }
     CIBlockElement::WF_CleanUpHistoryCopies($documentId, 0);
     $arFieldsPropertyValues = array();
     $dbResult = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"), false, false, array("ID", "IBLOCK_ID"));
     $arResult = $dbResult->Fetch();
     if (!$arResult) {
         throw new Exception("Element is not found");
     }
     $arDocumentFields = self::GetDocumentFields("iblock_" . $arResult["IBLOCK_ID"]);
     $arKeys = array_keys($arFields);
     foreach ($arKeys as $key) {
         if (!array_key_exists($key, $arDocumentFields)) {
             continue;
         }
         $arFields[$key] = is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]) ? $arFields[$key] : array($arFields[$key]);
         $realKey = substr($key, 0, strlen("PROPERTY_")) == "PROPERTY_" ? substr($key, strlen("PROPERTY_")) : $key;
         if ($arDocumentFields[$key]["Type"] == "user") {
             $ar = array();
             foreach ($arFields[$key] as $v1) {
                 if (substr($v1, 0, strlen("user_")) == "user_") {
                     $ar[] = substr($v1, strlen("user_"));
                 } else {
                     $a1 = self::GetUsersFromUserGroup($v1, $documentId);
                     foreach ($a1 as $a11) {
                         $ar[] = $a11;
                     }
                 }
             }
             $arFields[$key] = $ar;
         } elseif ($arDocumentFields[$key]["Type"] == "select") {
             $arV = array();
             $db = CIBlockProperty::GetPropertyEnum($realKey, false, array("IBLOCK_ID" => $arResult["IBLOCK_ID"]));
             while ($ar = $db->GetNext()) {
                 $arV[$ar["XML_ID"]] = $ar["ID"];
             }
             $listValue = array();
             foreach ($arFields[$key] as &$value) {
                 if (CBPHelper::isAssociativeArray($value)) {
                     $listXmlId = array_keys($value);
                     foreach ($listXmlId as $xmlId) {
                         $listValue[] = $arV[$xmlId];
                     }
                 } else {
                     if (array_key_exists($value, $arV)) {
                         $value = $arV[$value];
                     }
                 }
             }
             if (!empty($listValue)) {
                 $arFields[$key] = $listValue;
             }
         } elseif ($arDocumentFields[$key]["Type"] == "file") {
             foreach ($arFields[$key] as &$value) {
                 $value = CFile::MakeFileArray($value);
             }
         } elseif ($arDocumentFields[$key]["Type"] == "S:DiskFile") {
             $listFileId = array();
             foreach ($arFields[$key] as $value) {
                 if (is_array($value)) {
                     foreach ($value as $fileId) {
                         if (!empty($fileId)) {
                             $listFileId[] = $fileId;
                         }
                     }
                 } else {
                     if (!empty($value)) {
                         $listFileId[] = $value;
                     }
                 }
             }
             /* Attaching files from the disk to the iblock element */
             if (!empty($listFileId)) {
                 $arFields[$key] = array();
                 $propertyQuery = CIBlockElement::getProperty($arResult["IBLOCK_ID"], $documentId, "sort", "asc", array("ACTIVE" => "Y", "CODE" => $realKey));
                 $property = $propertyQuery->fetch();
                 $currentValues["VALUE"] = $property["VALUE"];
                 $attachedId = array();
                 foreach ($listFileId as $fileId) {
                     $attachId = self::attachFileDisk($arResult["IBLOCK_ID"], $documentId, $fileId, $currentValues["VALUE"]);
                     if (!empty($attachId)) {
                         $attachedId["VALUE"][] = $attachId;
                     }
                 }
                 if (!empty($attachedId)) {
                     $arFields[$key][] = $attachedId;
                     $listAttachedId = array();
                     foreach ($currentValues["VALUE"] as $attachId) {
                         if (!in_array($attachId, $attachedId["VALUE"])) {
                             $listAttachedId[] = $attachId;
                         }
                     }
                     if (!empty($listAttachedId)) {
                         self::deleteAttachedFileDisk($listAttachedId, $documentId);
                     }
                 } else {
                     $arFields[$key][] = $currentValues;
                 }
             }
         } elseif ($arDocumentFields[$key]["Type"] == "S:HTML") {
             foreach ($arFields[$key] as &$value) {
                 $value = array("VALUE" => $value);
             }
         }
         if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key])) {
             if (count($arFields[$key]) > 0) {
                 $a = array_values($arFields[$key]);
                 $arFields[$key] = $a[0];
             } else {
                 $arFields[$key] = null;
             }
         }
         if (substr($key, 0, strlen("PROPERTY_")) == "PROPERTY_") {
             $realKey = substr($key, strlen("PROPERTY_"));
             $arFieldsPropertyValues[$realKey] = is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]) ? $arFields[$key] : array($arFields[$key]);
             unset($arFields[$key]);
         }
     }
     if (count($arFieldsPropertyValues) > 0) {
         $arFields["PROPERTY_VALUES"] = $arFieldsPropertyValues;
     }
     $iblockElement = new CIBlockElement();
     if (count($arFields["PROPERTY_VALUES"]) > 0) {
         $iblockElement->SetPropertyValuesEx($documentId, $arResult["IBLOCK_ID"], $arFields["PROPERTY_VALUES"]);
     }
     unset($arFields["PROPERTY_VALUES"]);
     $res = $iblockElement->Update($documentId, $arFields, false, true, true);
     if (!$res) {
         throw new Exception($iblockElement->LAST_ERROR);
     }
 }