Beispiel #1
0
 /**
  * @param array $fields		Item fields.
  * @return array
  */
 public static function onBeforeIndex($fields)
 {
     if (!isset($fields['MODULE_ID']) || $fields['MODULE_ID'] != 'iblock') {
         return $fields;
     }
     if (empty($fields['PARAM2'])) {
         return $fields;
     }
     if (!isset(self::$catalogList[$fields['PARAM2']])) {
         self::$catalogList[$fields['PARAM2']] = false;
         $catalogIterator = CatalogIblockTable::getList(array('select' => array('IBLOCK_ID'), 'filter' => array('=IBLOCK_ID' => $fields['PARAM2'])));
         $catalog = $catalogIterator->fetch();
         if (!empty($catalog)) {
             self::$catalogList[$fields['PARAM2']] = $catalog['IBLOCK_ID'];
         }
         unset($catalog, $catalogIterator);
     }
     if (!empty(self::$catalogList[$fields['PARAM2']])) {
         $fields["PARAMS"]["iblock_section"] = array();
         if (strpos($fields['ITEM_ID'], 'S') === false) {
             $sections = \CIBlockElement::getElementGroups($fields["ITEM_ID"], true, array('ID'));
             while ($section = $sections->fetch()) {
                 $nav = \CIBlockSection::getNavChain($fields['PARAM2'], $section["ID"], array('ID'));
                 while ($chain = $nav->fetch()) {
                     $fields["PARAMS"]["iblock_section"][] = $chain['ID'];
                 }
                 unset($chain, $nav);
             }
             unset($section, $sections);
         } else {
             $nav = \CIBlockSection::getNavChain($fields['PARAM2'], preg_replace('#[^0-9]+#', '', $fields["ITEM_ID"]), array('ID'));
             while ($chain = $nav->fetch()) {
                 $fields["PARAMS"]["iblock_section"][] = $chain['ID'];
             }
             unset($chain, $nav);
         }
     }
     return $fields;
 }
Beispiel #2
0
 /**
  * @param array $fields		Item fields.
  * @return array
  */
 public function onBeforeIndex($fields)
 {
     if ($fields["MODULE_ID"] == "iblock") {
         $catalogs = \CCatalog::getList(array(), array('IBLOCK_ID' => $fields['PARAM2']), false, false, array('IBLOCK_ID'));
         if ($catalogs->fetch()) {
             $fields["PARAMS"]["iblock_section"] = array();
             if (strpos($fields['ITEM_ID'], 'S') === false) {
                 $sections = \CIBlockElement::getElementGroups($fields["ITEM_ID"], true, array('ID'));
                 while ($section = $sections->fetch()) {
                     $nav = \CIBlockSection::getNavChain($fields['PARAM2'], $section["ID"], array('ID'));
                     while ($chain = $nav->fetch()) {
                         $fields["PARAMS"]["iblock_section"][] = $chain['ID'];
                     }
                 }
             } else {
                 $nav = \CIBlockSection::getNavChain($fields['PARAM2'], preg_replace('#[^0-9]+#', '', $fields["ITEM_ID"]), array('ID'));
                 while ($chain = $nav->fetch()) {
                     $fields["PARAMS"]["iblock_section"][] = $chain['ID'];
                 }
             }
         }
     }
     return $fields;
 }
Beispiel #3
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;
 }
Beispiel #4
0
 /**
  * Fills member elementSections member with sections identifiers of the element.
  *
  * @param integer $elementId Identifier of the element.
  *
  * @return void
  */
 protected function loadElementSections($elementId)
 {
     $sectionList = \CIBlockElement::getElementGroups($elementId, true, array("ID"));
     while ($section = $sectionList->fetch()) {
         $this->elementSections[] = $section["ID"];
     }
 }