Esempio n. 1
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;
 }