Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

52977 Query and display of media information in the property list #915

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
90 changes: 90 additions & 0 deletions plugin/EstateFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,29 @@

class EstateFiles
{
/** */
const FILE_TYPES = [
ImageTypes::TITLE,
ImageTypes::PHOTO,
ImageTypes::PHOTO_BIG,
ImageTypes::GROUNDPLAN,
ImageTypes::LOCATION_MAP,
ImageTypes::PANORAMA,
LinksTypes::FILE_TYPE_LINK,
MovieLinkTypes::FILE_TYPE_MOVIE_LINK,
LinksTypes::FILE_TYPE_OGULO_LINK,
LinksTypes::EXPOSE,
];

/** @var array */
private $_estateFiles = array();

/** @var array */
private $_pictureCategories = array();

/** @var array */
private $_estateAllFiles = array();

/**
* EstateFiles constructor.
*
Expand Down Expand Up @@ -81,6 +98,66 @@ public function getAllFiles(array $pictureCategories, array $estateIds, SDKWrapp
}
}

/**
* @param array $estateIds
* @param SDKWrapper $pSDKWrapper
* @return void
*/
public function getFilesByEstateIds(array $estateIds, SDKWrapper $pSDKWrapper)
{
$listRequestInQueue = [];
$pAPIClientAction = new APIClientActionGeneric($pSDKWrapper, onOfficeSDK::ACTION_ID_GET, 'file');
$pAPIClientActionClone = null;

foreach ($estateIds as $mainId => $estateId) {
$pAPIClientActionClone = clone $pAPIClientAction;
$pAPIClientActionClone->setParameters([
'estateid' => $mainId,
'showispublishedonhomepage' => true,
'listlimit' => 100
]);
$pAPIClientActionClone->setResourceId('estate');
$pAPIClientActionClone->addRequestToQueue();
$listRequestInQueue[$mainId] = $pAPIClientActionClone;
}
$pAPIClientActionClone->sendRequests();

$data = [];
foreach ($listRequestInQueue as $key => $value) {
if ($value->getResultStatus()) {
$data[$key] = $value->getResultRecords();
}
}

$this->collectEstateFilesForSingleRecord($data);
}

/**
* @param array $responseArray
* @return void
*/
private function collectEstateFilesForSingleRecord(array $responseArray)
{
foreach ($responseArray as $estateId => $value) {
foreach ($value as $fileEntry) {
$fileId = $fileEntry['id'];
$url = !empty($fileEntry['elements']['url']) ? $fileEntry['elements']['url'] : "";
$title = !empty($fileEntry['elements']['title']) ? $fileEntry['elements']['title'] : "";
$type = !empty($fileEntry['elements']['type']) ? $fileEntry['elements']['type'] : "";
$file = array(
'id' => $fileId,
'url' => $this->correctUrl($url),
'title' => $title,
'type' => $type
);
if (!in_array($type, self::FILE_TYPES)) {
continue;
}

$this->_estateAllFiles[$estateId][$fileId] = $file;
}
}
}

/**
*
Expand Down Expand Up @@ -299,4 +376,17 @@ public function getEstatePictureValues($imageId, $estateId)
{
return $this->_estateFiles[$estateId][$imageId] ?? [];
}


/**
*
* @param int $estateId
* @return array
*
*/

public function getEstateAllFilesById(int $estateId): array
{
return $this->_estateAllFiles[$estateId] ?? [];
}
}
19 changes: 19 additions & 0 deletions plugin/EstateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public function loadEstates(int $currentPage = 1, DataView $pDataListView = null

$this->_pEstateFiles = $this->_pEnvironment->getEstateFiles();
$this->_pEstateFiles->getAllFiles($fileCategories, $estateIds, $this->_pEnvironment->getSDKWrapper());
$this->_pEstateFiles->getFilesByEstateIds($estateIds, $this->_pEnvironment->getSDKWrapper());
}

if ($pDataListView->getRandom()) {
Expand Down Expand Up @@ -854,6 +855,24 @@ public function getEstatePictureUrl($imageId, array $options = null)
return $this->_pEstateFiles->getEstateFileUrl($imageId, $currentEstate, $options);
}

/**
* @return array
*/
public function getEstateFilesInfo(): array
{
$currentEstate = $this->_currentEstate['mainId'];
return $this->_pEstateFiles->getEstateAllFilesById($currentEstate);
}

/**
* @return int
*/
public function getEstateFilesCount(): int
{
$currentEstate = $this->_currentEstate['mainId'];
return count($this->_pEstateFiles->getEstateAllFilesById($currentEstate));
}

/**
* @param int $imageId
* @return string
Expand Down
3 changes: 3 additions & 0 deletions plugin/Types/LinksTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ abstract class LinksTypes
const FILE_TYPE_OBJECT_LINK = 'Objekt-Link';
const FILE_TYPE_LINK = 'Link';

/** */
const EXPOSE = 'Expose';

/**
*
* @param string $type
Expand Down
14 changes: 14 additions & 0 deletions tests/TestClassEstateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,20 @@ public function prepareEstateList()
'language' => 'ENG'
], null, $responseGetEstatePictures);

$dataGetEstateFiles = json_decode
(file_get_contents(__DIR__.'/resources/ApiResponseGetEstatesFiles.json'), true);

$estateIds = [15,1051,1082,1193,1071];
$parameters = [];
foreach ($estateIds as $estateId) {
$parameters['estateid'] = $estateId;
$parameters['showispublishedonhomepage'] = true;
$parameters['listlimit'] = 100;
$responseGetEstateFiles = $dataGetEstateFiles['response'];
$this->_pSDKWrapperMocker->addResponseByParameters
(onOfficeSDK::ACTION_ID_GET, 'file', 'estate', $parameters, null, $responseGetEstateFiles);
}

$pContainerBuilder = new ContainerBuilder;
$pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
$this->_pContainer = $pContainerBuilder->build();
Expand Down
29 changes: 29 additions & 0 deletions tests/resources/ApiResponseGetEstatesFiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"response": {
"actionid": "urn:onoffice-de-ns:smart:2.5:smartml:action:get",
"resourceid": "estate",
"resourcetype": "file",
"cacheable": true,
"identifier": "",
"data": {
"meta": {
"cntabsolute": 9
},
"records": [
{
"id": 15,
"type": "estate",
"elements": {
"url" : "https://test.url/image/2.jpg",
"title" : "Titelbild",
"type" : "Titelbild"
}
}
]
},
"status": {
"errorcode": 0,
"message": "OK"
}
}
}
Loading