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

#1093 [Control] add: LinkedObject with parent info in selector #1309

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions class/dolibarrobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// Load Dolibarr libraries.
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
require_once DOL_DOCUMENT_ROOT . '/supplier_proposal/class/supplier_proposal.class.php';
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';

/**
* Class for DoliSMQExpedition.
Expand Down Expand Up @@ -163,3 +164,21 @@ class DoliSMQSupplierProposal extends SupplierProposal
'entity' => ['type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => -1, 'index' => 1]
];
}

/**
* Class for DoliSMQContact.
*/
class DoliSMQContact extends Contact
{
/**
* Constructor.
*
* @param DoliDb $db Database handler.
*/
public function __construct(DoliDB $db)
{
parent::__construct($db);

$this->fields['fk_soc']['enabled'] = 1;
}
}
83 changes: 44 additions & 39 deletions lib/dolismq_sheet.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function get_sheet_linkable_objects(): array
// 'post_name' => Name of post sent retrieved by GETPOST() function
// 'link_name' => Name of object sourcetype in llx_element_element
// 'tab_type' => Tab type element for prepare_head function
// 'parent_object' => OPTIONAL : $linkableObjectTypes Key of parent (Use for objects as productlot, contact, task)
// 'fk_parent' => OPTIONAL : Name of parent for objects as productlot, contact, task
// 'parent_post' => OPTIONAL : Name of parent post (retrieved by GETPOST() function, it can be different from fk_parent
// 'create_url' => Path to creation card, no need to add "?action=create"
Expand All @@ -86,18 +87,19 @@ function get_sheet_linkable_objects(): array

if (isModEnabled('productbatch')) {
$linkableObjectTypes['productlot'] = [
'langs' => 'Batch',
'langfile' => 'products',
'picto' => 'lot',
'className' => 'ProductLot',
'post_name' => 'fk_productlot',
'link_name' => 'productbatch',
'tab_type' => 'productlot',
'name_field' => 'batch',
'fk_parent' => 'fk_product',
'parent_post' => 'fk_product',
'create_url' => 'product/stock/productlot_card.php',
'class_path' => 'product/stock/class/productlot.class.php',
'langs' => 'Batch',
'langfile' => 'products',
'picto' => 'lot',
'className' => 'ProductLot',
'post_name' => 'fk_productlot',
'link_name' => 'productbatch',
'tab_type' => 'productlot',
'name_field' => 'fk_product, batch',
'parent_object' => 'product',
'fk_parent' => 'fk_product',
'parent_post' => 'fk_product',
'create_url' => 'product/stock/productlot_card.php',
'class_path' => 'product/stock/class/productlot.class.php',
];
}

Expand Down Expand Up @@ -129,18 +131,19 @@ function get_sheet_linkable_objects(): array
'class_path' => 'societe/class/societe.class.php',
];
$linkableObjectTypes['contact'] = [
'langs' => 'Contact',
'langfile' => 'companies',
'picto' => 'address',
'className' => 'Contact',
'post_name' => 'fk_contact',
'link_name' => 'contact',
'tab_type' => 'contact',
'name_field' => 'lastname, firstname',
'fk_parent' => 'fk_soc',
'parent_post' => 'fk_soc',
'create_url' => 'contact/card.php',
'class_path' => 'contact/class/contact.class.php',
'langs' => 'Contact',
'langfile' => 'companies',
'picto' => 'address',
'className' => 'DoliSMQContact',
'post_name' => 'fk_contact',
'link_name' => 'contact',
'tab_type' => 'contact',
'name_field' => 'fk_soc, lastname, firstname',
'parent_object' => 'thirdparty',
'fk_parent' => 'fk_soc',
'parent_post' => 'fk_soc',
'create_url' => 'contact/card.php',
'class_path' => 'contact/class/contact.class.php',
];
}

Expand All @@ -158,18 +161,19 @@ function get_sheet_linkable_objects(): array
'class_path' => 'projet/class/project.class.php',
];
$linkableObjectTypes['task'] = [
'langs' => 'Task',
'langfile' => 'projects',
'picto' => 'projecttask',
'className' => 'SaturneTask',
'post_name' => 'fk_task',
'link_name' => 'project_task',
'tab_type' => 'task',
'name_field' => 'label',
'fk_parent' => 'fk_projet',
'parent_post' => 'fk_project',
'create_url' => 'projet/tasks.php',
'class_path' => 'projet/class/task.class.php',
'langs' => 'Task',
'langfile' => 'projects',
'picto' => 'projecttask',
'className' => 'SaturneTask',
'post_name' => 'fk_task',
'link_name' => 'project_task',
'tab_type' => 'task',
'name_field' => 'fk_projet, label',
'parent_object' => 'project',
'fk_parent' => 'fk_projet',
'parent_post' => 'fk_project',
'create_url' => 'projet/tasks.php',
'class_path' => 'projet/class/task.class.php',
];
}

Expand Down Expand Up @@ -348,9 +352,10 @@ function get_sheet_linkable_objects(): array
'className' => $linkableObjectInformations['className'] ?? '',
'name_field' => $linkableObjectInformations['name_field'] ?? '',
'post_name' => $linkableObjectInformations['post_name'] ?? '',
'link_name' => $linkableObjectInformations['link_name'] ?? '',
'tab_type' => $linkableObjectInformations['tab_type'] ?? '',
'fk_parent' => $linkableObjectInformations['fk_parent'] ?? '',
'link_name' => $linkableObjectInformations['link_name'] ?? '',
'tab_type' => $linkableObjectInformations['tab_type'] ?? '',
'parent_object' => $linkableObjectInformations['parent_object'] ?? '',
'fk_parent' => $linkableObjectInformations['fk_parent'] ?? '',
'parent_post' => $linkableObjectInformations['parent_post'] ?? '',
'create_url' => $linkableObjectInformations['create_url'] ?? '',
'class_path' => $linkableObjectInformations['class_path'] ?? '',
Expand Down
21 changes: 19 additions & 2 deletions view/control/control_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@
} else {
$objectFilter = [];
}

$objectList = saturne_fetch_all_object_type($linkableElement['className'], '', '', 0, 0, $objectFilter);

if (is_array($objectList) && !empty($objectList)) {
Expand All @@ -585,8 +586,24 @@
$nameFields = explode(', ', $nameField);
if (is_array($nameFields) && !empty($nameFields)) {
foreach($nameFields as $subnameField) {
$objectName .= $objectSingle->$subnameField . ' ';
}
if ($subnameField == $linkableElement['fk_parent']) {
$parentObject = new $elementArray[$linkableElement['parent_object']]['className']($db);
$parentObject->fetch($objectSingle->$subnameField);
$parentNameField = $elementArray[$linkableElement['parent_object']]['name_field'];
if (strstr($parentNameField, ',')) {
$parentNameFields = explode(', ', $parentNameField);
if (is_array($parentNameFields) && !empty($parentNameFields)) {
foreach($parentNameFields as $subParentNameField) {
$objectName .= $parentObject->$subParentNameField . ' - ';
}
}
} else {
$objectName .= $parentObject->$parentNameField . ' - ';
}
} else {
$objectName .= $objectSingle->$subnameField . ' ';
}
}
}
} else {
$objectName = $objectSingle->$nameField;
Expand Down