public function fill_release($dispatch_id = false, $ignore_redirect = false) { $iDispId = $dispatch_id ? $dispatch_id : getRequest('param0'); $oDispatch = umiObjectsCollection::getInstance()->getObject($iDispId); if ($oDispatch instanceof umiObject) { $iReleaseId = $this->getNewReleaseInstanceId($iDispId); $iNewsRelation = $oDispatch->getValue("news_relation"); $arrNewsLents = umiHierarchy::getInstance()->getObjectInstances($iNewsRelation, false, true); // get all releases $iHierarchyTypeId = umiHierarchyTypesCollection::getInstance()->getTypeByName("dispatches", "release")->getId(); $iReleaseTypeId = umiObjectTypesCollection::getInstance()->getTypeByHierarchyTypeId($iHierarchyTypeId); $oReleaseType = umiObjectTypesCollection::getInstance()->getType($iReleaseTypeId); $sel = new umiSelection(); $sel->setObjectTypeFilter(); $sel->addObjectType($iReleaseTypeId); $sel->setPropertyFilter(); $sel->addPropertyFilterEqual($oReleaseType->getFieldId('disp_reference'), $iDispId); $arrReleases = umiSelectionsParser::runSelection($sel); if (count($arrNewsLents)) { $iElementId = (int) $arrNewsLents[0]; $hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("news", "item")->getId(); $object_type_id = umiObjectTypesCollection::getInstance()->getBaseType("news", "item"); $object_type = umiObjectTypesCollection::getInstance()->getType($object_type_id); $publish_time_field_id = $object_type->getFieldId('publish_time'); $sel = new umiSelection(); $sel->setElementTypeFilter(); $sel->addElementType($hierarchy_type_id); $sel->setOrderFilter(); $sel->setOrderByProperty($publish_time_field_id, false); $sel->setHierarchyFilter(); $sel->addHierarchyFilter($iElementId, 0, true); $sel->setLimitFilter(); $sel->addLimit(50); $sel->setIsLangIgnored(true); /* $sel->setPropertyFilter(); $sel->addPropertyFilterBetween($publish_time_field_id, $date1, $date2); */ $result = umiSelectionsParser::runSelection($sel); for ($iI = 0; $iI < count($result); $iI++) { $iNextNewId = $result[$iI]; $oNextNew = umiHierarchy::getInstance()->getElement($iNextNewId); if ($oNextNew instanceof umiHierarchyElement) { $sName = $oNextNew->getName(); $sHeader = $oNextNew->getValue('h1'); $sShortBody = $oNextNew->getValue('anons'); $sBody = $oNextNew->getValue('content'); $oPubTime = $oNextNew->getValue('publish_time'); if (!strlen($sBody)) { $sBody = $sShortBody; } // add message $iHierarchyTypeId = umiHierarchyTypesCollection::getInstance()->getTypeByName("dispatches", "message")->getId(); $iMsgTypeId = umiObjectTypesCollection::getInstance()->getTypeByHierarchyTypeId($iHierarchyTypeId); $oMsgType = umiObjectTypesCollection::getInstance()->getType($iMsgTypeId); // check if new exists $oSel = new umiSelection(); $oSel->setObjectTypeFilter(); $oSel->addObjectType($iMsgTypeId); $oSel->setPropertyFilter(); $oSel->addPropertyFilterEqual($oMsgType->getFieldId('new_relation'), $iNextNewId); $oSel->setPropertyFilter(); $oSel->addPropertyFilterEqual($oMsgType->getFieldId('release_reference'), $arrReleases); $oSel->setLimitFilter(); $oSel->addLimit(1); $iCount = umiSelectionsParser::runSelectionCounts($oSel); if ($iCount > 0) { continue; } //add new message $iMsgObjId = umiObjectsCollection::getInstance()->addObject($sName, $iMsgTypeId); // try get object $oMsgObj = umiObjectsCollection::getInstance()->getObject($iMsgObjId); if ($oMsgObj instanceof umiObject) { $oMsgObj->setValue('release_reference', $iReleaseId); $oMsgObj->setValue('header', $sHeader); $oMsgObj->setValue('body', $sBody); $oMsgObj->setValue('short_body', $sShortBody); $oMsgObj->setValue('new_relation', array($iNextNewId)); if ($oPubTime instanceof umiDate) { $oMsgObj->setValue('msg_date', $oPubTime); } $oMsgObj->commit(); } } } } } // WTF? IE7 does not send the HTTP_REFERER header, so we should set the redirect string manually if (!$ignore_redirect) { $this->chooseRedirect('/admin/dispatches/edit/' . $iDispId . '/'); } }