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

Added: Webservice for bookings management. #1191

Merged
merged 14 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions classes/webservice/WebserviceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public function __construct()
{
$this->displayName = $this->l('Order from API');
$this->validateOrderAmount = false;
$this->payment_type = OrderPayment::PAYMENT_TYPE_ONLINE;
}
}
41 changes: 39 additions & 2 deletions classes/webservice/WebserviceOutputBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,21 @@ protected function renderAssociations($object, $depth, $associations, $ws_params
}
$output_details = '';
foreach ($objects_assoc as $object_assoc) {
if ($depth == 0 || $class_name === null) {
if (isset($association['only_leaf_nodes']) && $association['only_leaf_nodes']) {
unset($association['only_leaf_nodes']);
unset($association['getter']);
unset($association['setter']);
foreach ($association as $associationKey => $resource) {
$field = array();
$field['sqlId'] = $associationKey;
$field['value'] = null;
if (!is_null($this->schemaToDisplay)) {
$field['synopsis_details'] = $this->getSynopsisDetails($resource);
}

$output_details .= $this->setIndent($depth - 1).$this->objectRender->renderField($field);
}
} elseif ($depth == 0 || $class_name === null) {
$value = null;
if (!empty($object_assoc)) {
$value = $object_assoc;
Expand Down Expand Up @@ -676,7 +690,30 @@ protected function renderFlatAssociation($object, $depth, $assoc_name, $resource
$output .= $this->setIndent($depth - 1).$this->objectRender->renderNodeHeader($resource_name, array(), $more_attr);

foreach ($fields_assoc as $field_name => $field) {
if (!is_array($this->fieldsToDisplay) || in_array($field_name, $this->fieldsToDisplay[$assoc_name])) {
if (isset($field['resource']) && isset($field['fields'])) {
$parent_details = array(
'object_id' => null,
'entity_name' => $field['resource'],
'entities_name' => $field_name,
);
$output_details = '';
$output_details = $this->renderFlatAssociation(
$object,
$depth,
$field_name,
$field['resource'],
$field['fields'],
$object_assoc,
$parent_details
);
if ($output_details != '') {
$output .= $this->setIndent($depth).$this->objectRender->renderNodeHeader($field_name, array());
$output .= $output_details;
$output .= $this->setIndent($depth).$this->objectRender->renderNodeFooter($field_name, array());
} else {
$output .= $this->setIndent($depth).$this->objectRender->renderNodeHeader($field_name, array());
}
} elseif (!is_array($this->fieldsToDisplay) || in_array($field_name, $this->fieldsToDisplay[$assoc_name])) {
if (isset($field['id']) && !isset($field['sqlId'])) {
$field['sqlId'] = 'id';
$field['value'] = isset($object_assoc['id']) ? $object_assoc['id'] : null;
Expand Down
12 changes: 6 additions & 6 deletions classes/webservice/WebserviceOutputJSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function renderField($field)
}
// Case 1 : fields of the current entity (not an association)
if (!$is_association) {
$this->currentEntity[$field['sqlId']] = $field['value'];
$this->currentEntity[$field['sqlId']] = $field['value'];
} else { // Case 2 : fields of an associated entity to the current one
$this->currentAssociatedEntity[] = array('name' => $field['entities_name'], 'key' => $field['sqlId'], 'value' => $field['value']);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public function renderNodeFooter($node_name, $params)
}
$this->currentEntity = array();
}
if (count($this->currentAssociatedEntity)) {
if (is_array($this->currentAssociatedEntity) && count($this->currentAssociatedEntity)) {
$current = array();
foreach ($this->currentAssociatedEntity as $element) {
$current[$element['key']] = $element['value'];
Expand All @@ -159,9 +159,6 @@ public function renderNodeFooter($node_name, $params)

public function overrideContent($content)
{
array_walk($this->content, function (&$item) {
$item = array_filter($item);
});
$content = json_encode($this->content, JSON_UNESCAPED_UNICODE);

return (false !== $content) ? $content : '';
Expand All @@ -187,20 +184,23 @@ public function renderAssociationHeader($obj, $params, $assoc_name, $closed_tags
}
public function renderAssociationFooter($obj, $params, $assoc_name)
{
return;
}

public function renderErrorsHeader()
{
return '';
}

public function renderErrorsFooter()
{
return '';
}

public function renderAssociationField($field)
{
return '';
}

public function renderi18nField($field)
{
return '';
Expand Down
3 changes: 2 additions & 1 deletion classes/webservice/WebserviceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ protected function getOutputObject($type)
public static function getResources()
{
$resources = array(
'addresses' => array('description' => 'The Customer, Manufacturer and Customer addresses','class' => 'Address'),
'addresses' => array('description' => 'The Customer address','class' => 'Address'),
'bookings' => array('description' => 'The Customer bookings', 'specific_management' => 'true','forbidden_method' => array('DELETE')),
'carriers' => array('description' => 'The Carriers','class' => 'Carrier'),
'carts' => array('description' => 'Customer\'s carts', 'class' => 'Cart'),
'cart_rules' => array('description' => 'Cart rules management', 'class' => 'CartRule'),
Expand Down
Loading