public static function getDocument($documentId) { $documentId = (int) $documentId; if ($documentId <= 0) { throw new CBPArgumentNullException("documentId"); } $file = File::loadById($documentId); if (!$file) { return null; } $ufFields = Driver::getInstance()->getUserFieldManager()->getFieldsForObject($file); $ufFileRow = array(); if (!empty($ufFields)) { foreach ($ufFields as $fieldKey => $fieldData) { $ufFileRow[$fieldKey] = $fieldData['VALUE']; $ufFileRow[$fieldData['XML_ID']] = $fieldData['VALUE']; } } $fileRow = File::getList(array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => array('ID' => $documentId)))->fetch(); if (!$fileRow) { return null; } if (empty($fileRow["CODE"])) { $fileRow["CODE"] = Loc::getMessage("DISK_BZ_D_NAME_NOT_CODE"); } return array_merge(array("ID" => $fileRow["ID"], "CREATE_TIME" => $fileRow["CREATE_TIME"], "CREATED_BY" => $fileRow["CREATED_BY"], "CREATED_BY_PRINTABLE" => $fileRow['CREATE_USERREF_NAME'] . ' ' . $fileRow['CREATE_USERREF_LAST_NAME'], "UPDATE_TIME" => $fileRow["UPDATE_TIME"], "UPDATED_BY" => $fileRow["UPDATED_BY"], "UPDATED_BY_PRINTABLE" => $fileRow['UPDATE_USERREF_NAME'] . ' ' . $fileRow['UPDATE_USERREF_LAST_NAME'], "DELETE_TIME" => $fileRow["DELETE_TIME"], "DELETED_BY" => $fileRow["DELETED_BY"], "DELETED_BY_PRINTABLE" => $fileRow['DELETE_USERREF_NAME'] . ' ' . $fileRow['DELETE_USERREF_LAST_NAME'], "STORAGE_ID" => $fileRow["STORAGE_ID"], "NAME" => $fileRow["NAME"], "SIZE" => $fileRow["SIZE"], "CODE" => $fileRow["CODE"], "TIMESTAMP_X" => $fileRow["UPDATE_TIME"], "MODIFIED_BY" => $fileRow["CREATED_BY"], "MODIFIED_BY_PRINTABLE" => $fileRow['UPDATE_USERREF_NAME'] . ' ' . $fileRow['UPDATE_USERREF_LAST_NAME'], "DATE_CREATE" => $fileRow["CREATE_TIME"], "FILE_SIZE" => $fileRow["SIZE"]), $ufFileRow); }
/** * Search re-index handler. * @param array $nextStepData Array with data about step. * @param null $searchObject Search object. * @param string $method Method. * @return array|bool */ public static function onSearchReindex($nextStepData = array(), $searchObject = null, $method = "") { $result = array(); $filter = array('TYPE' => ObjectTable::TYPE_FILE); if (isset($nextStepData['MODULE']) && $nextStepData['MODULE'] === 'disk' && !empty($nextStepData['ID'])) { $filter['>ID'] = self::getObjectIdFromItemId($nextStepData['ID']); } else { $filter['>ID'] = 0; } static $self = null; if ($self === null) { $self = Driver::getInstance()->getIndexManager(); } $query = File::getList(array('filter' => $filter, 'order' => array('ID' => 'ASC'))); while ($fileData = $query->fetch()) { /** @var File $file */ $file = File::buildFromArray($fileData); $detailUrl = Driver::getInstance()->getUrlManager()->getPathFileDetail($file); $searchData = array('ID' => self::getItemId($file), 'LAST_MODIFIED' => $file->getUpdateTime() ?: $file->getCreateTime(), 'TITLE' => $file->getName(), 'PARAM1' => $file->getStorageId(), 'PARAM2' => $file->getParentId(), 'SITE_ID' => $file->getStorage()->getSiteId() ?: SITE_ID, 'URL' => $detailUrl, 'PERMISSIONS' => $self->getSimpleRights($file), 'BODY' => $self->getFileContent($file)); if ($searchObject) { $indexResult = call_user_func(array($searchObject, $method), $searchData); if (!$indexResult) { return $searchData["ID"]; } } else { $result[] = $searchData; } } if ($searchObject) { return false; } return $result; }
public static function onSearchIndex($userField) { $values = $userField['VALUE']; if (!is_array($values)) { $values = array($userField['VALUE']); } $searchData = array(); $fileIdsForLoad = array(); $attachedIdsForLoad = array(); foreach ($values as $value) { list($type, $realValue) = self::detectType($value); if ($type == self::TYPE_NEW_OBJECT) { if (self::isLoadedFile($realValue)) { $searchData[] = self::getFileById($realValue)->getName(); } else { $fileIdsForLoad[] = $realValue; } } else { $attachedIdsForLoad[] = $realValue; } } unset($value); if ($attachedIdsForLoad) { $query = AttachedObject::getList(array('select' => array('NAME' => 'OBJECT.NAME'), 'filter' => array('ID' => $attachedIdsForLoad))); while ($attachedItem = $query->fetch()) { $searchData[] = Ui\Text::cleanTrashCanSuffix($attachedItem['NAME']); } unset($attachedItem, $attachedIdsForLoad); } if ($fileIdsForLoad) { $query = File::getList(array('select' => array('NAME'), 'filter' => array('ID' => $fileIdsForLoad))); while ($fileItem = $query->fetch()) { $searchData[] = Ui\Text::cleanTrashCanSuffix($fileItem['NAME']); } unset($fileItem, $fileIdsForLoad); } return implode("\r\n", $searchData); }
public static function getDocumentType($documentId) { if (substr($documentId, 0, strlen(self::DOCUMENT_TYPE_PREFIX)) == self::DOCUMENT_TYPE_PREFIX) { return $documentId; } $documentId = intval($documentId); if ($documentId <= 0) { throw new CBPArgumentNullException("documentId"); } $fileRow = File::getList(array('select' => array('ID', 'STORAGE_ID'), 'filter' => array('ID' => $documentId)))->fetch(); if (!$fileRow || empty($fileRow['STORAGE_ID'])) { throw new SystemException("Element is not found"); } return self::generateDocumentType($fileRow['STORAGE_ID']); }