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

add overallcount for addresses #918

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions plugin/AddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class AddressList
/** @var AddressListEnvironment */
private $_pEnvironment = null;

/** @var APIClientActionGeneric */
private $_pApiClientAction = null;

/** @var DataListViewAddress */
private $_pDataViewAddress = null;

Expand All @@ -147,6 +150,9 @@ public function __construct(DataViewAddress $pDataViewAddress = null, AddressLis
{
$this->_pEnvironment = $pEnvironment ?? new AddressListEnvironmentDefault();
$this->_pDataViewAddress = $pDataViewAddress ?? new DataListViewAddress(0, 'default');
$pSDKWrapper = $this->_pEnvironment->getSDKWrapper();
$this->_pApiClientAction = new APIClientActionGeneric
($pSDKWrapper, onOfficeSDK::ACTION_ID_READ, 'address');
}

/**
Expand All @@ -159,28 +165,28 @@ public function __construct(DataViewAddress $pDataViewAddress = null, AddressLis
public function loadAddressesById(array $addressIds, array $fields)
{
$this->_pEnvironment->getFieldnames()->loadLanguage();
$pApiCall = new APIClientActionGeneric
$this->_pApiClientAction = new APIClientActionGeneric
($this->_pEnvironment->getSDKWrapper(), onOfficeSDK::ACTION_ID_READ, 'address');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ist das nicht redundant, wenn das schon im Konstruktor passiert?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ja, definitiv... kann raus

$parameters = [
'recordids' => $addressIds,
'data' => $fields,
'outputlanguage' => Language::getDefault(),
'formatoutput' => true,
];
$parametersRaw = [
'recordids' => $addressIds,
'data' => $this->_addressParametersForImageAlt,
'outputlanguage' => Language::getDefault(),
'formatoutput' => false,
];
$pApiCall->setParameters($parameters);
$pApiCall->addRequestToQueue()->sendRequests();

$records = $pApiCall->getResultRecords();
$parametersRaw = [
'recordids' => $addressIds,
'data' => $this->_addressParametersForImageAlt,
'outputlanguage' => Language::getDefault(),
'formatoutput' => false,
];
$this->_pApiClientAction->setParameters($parameters);
$this->_pApiClientAction->addRequestToQueue()->sendRequests();

$records = $this->_pApiClientAction->getResultRecords();
$this->fillAddressesById($records);
$this->_pDataViewAddress->setFields($fields);

$this->addRawRecordsByAPICall(clone $pApiCall, $parametersRaw);
$this->addRawRecordsByAPICall(clone $this->_pApiClientAction, $parametersRaw);
}

/**
Expand All @@ -205,21 +211,21 @@ public function loadAddresses(int $inputPage = 1)
$apiOnlyFields = $pModifier->getAllAPIFields();
$parameters = $pDataListViewToApi->buildParameters($apiOnlyFields, $this->_pDataViewAddress, $newPage, true);

$pApiCall = new APIClientActionGeneric
$this->_pApiClientAction = new APIClientActionGeneric
($this->_pEnvironment->getSDKWrapper(), onOfficeSDK::ACTION_ID_READ, 'address');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ist das nicht redundant, wenn das schon im Konstruktor passiert?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ja, definitiv... kann raus

$pApiCall->setParameters($parameters);
$pApiCall->addRequestToQueue();
$this->_pApiClientAction->setParameters($parameters);
$this->_pApiClientAction->addRequestToQueue();

$addressParameterRaws = $pDataListViewToApi->buildParameters($this->_addressParametersForImageAlt,
$this->_pDataViewAddress, $newPage);
$this->addRawRecordsByAPICall(clone $pApiCall, $addressParameterRaws);
$this->addRawRecordsByAPICall(clone $this->_pApiClientAction, $addressParameterRaws);

$this->getCountEstateForAddress($this->getAddressIds());

$this->_records = $pApiCall->getResultRecords();
$this->_records = $this->_pApiClientAction->getResultRecords();
$this->fillAddressesById($this->_records);

$resultMeta = $pApiCall->getResultMeta();
$resultMeta = $this->_pApiClientAction->getResultMeta();
$numpages = ceil($resultMeta['cntabsolute']/$this->_pDataViewAddress->getRecordsPerPage());

$multipage = $numpages > 1;
Expand Down Expand Up @@ -339,6 +345,15 @@ public function getAddressById($id): array
return $this->_addressesById[$id] ?? [];
}

/**
* @return int
* @throws API\ApiClientException
*/
public function getAddressOverallCount()
{
return $this->_pApiClientAction->getResultMeta()['cntabsolute'];
}

/**
* @param bool $raw
* @return array
Expand Down
Loading