[Vtigercrm-commits] [Vtiger development] #8638: Get_dependents_list of Account bug
Vtiger development
vtiger-tickets at trac.vtiger.com
Mon Oct 12 15:34:05 GMT 2015
#8638: Get_dependents_list of Account bug
------------------------+------------------------
Reporter: oleg.a | Owner: developer
Type: defect | Status: new
Priority: unassigned | Milestone: Unassigned
Component: vtigercrm | Version: 6.3.0
Severity: Medium | Keywords:
------------------------+------------------------
If you want to relate, for example, Account - Leads with 1:m relation with
field UItype 10 (like cf550), you add Custom Field to the vtiger_leadscf
table and run vtlib to make relation. All works fine, but you can't see
related records in Account related tab!
The issue is in get_dependents_list, it point to custom field (cf550) in
main module table instead of actual table. Actual table name stored in
vtiger_field table. There is solution:
OLD CODE
{{{
/**
1455 * Function to handle the dependents list for the module.
1456 * NOTE: UI type '10' is used to stored the references to
other modules for a given record.
1457 * These dependent records can be retrieved through this
function.
1458 * For eg: A trouble ticket can be related to an Account
or a Contact.
1459 * From a given Contact/Account if we need to fetch all
such dependent trouble tickets, get_dependents_list function can be used.
1460 */
1461 function get_dependents_list($id, $cur_tab_id,
$rel_tab_id, $actions = false) {
1462
1463 global $currentModule, $app_strings,
$singlepane_view, $current_user;
1464
1465 $parenttab = getParentTab();
1466
1467 $related_module =
vtlib_getModuleNameById($rel_tab_id);
1468 $other = CRMEntity::getInstance($related_module);
1469
1470 // Some standard module class doesn't have
required variables
1471 // that are used in the query, they are defined in
this generic API
1472 vtlib_setup_modulevars($currentModule, $this);
1473 vtlib_setup_modulevars($related_module, $other);
1474
1475 $singular_modname = 'SINGLE_' . $related_module;
1476 $button = '';
1477
1478 // To make the edit or del link actions to return
back to same view.
1479 if ($singlepane_view == 'true')
1480 $returnset =
"&return_module=$currentModule&return_action=DetailView&return_id=$id";
1481 else
1482 $returnset =
"&return_module=$currentModule&return_action=CallRelatedList&return_id=$id";
1483
1484 $return_value = null;
1485 $dependentFieldSql = $this->db->pquery("SELECT
tabid, fieldname, columnname FROM vtiger_field WHERE uitype='10' AND" .
1486 " fieldid IN (SELECT fieldid FROM
vtiger_fieldmodulerel WHERE relmodule=? AND module=?)",
array($currentModule, $related_module));
1487 $numOfFields =
$this->db->num_rows($dependentFieldSql);
1488
1489 if ($numOfFields > 0) {
1490 $dependentColumn =
$this->db->query_result($dependentFieldSql, 0, 'columnname');
1491 $dependentField =
$this->db->query_result($dependentFieldSql, 0, 'fieldname');
1492
1493 $button .= '<input type="hidden" name="' .
$dependentColumn . '" id="' . $dependentColumn . '" value="' . $id . '">';
1494 $button .= '<input type="hidden" name="' .
$dependentColumn . '_type" id="' . $dependentColumn . '_type" value="' .
$currentModule . '">';
1495 if ($actions) {
1496 if (is_string($actions))
1497 $actions = explode(',',
strtoupper($actions));
1498 if (in_array('ADD', $actions) &&
isPermitted($related_module, 1, '') == 'yes'
1499 &&
getFieldVisibilityPermission($related_module, $current_user->id,
$dependentField, 'readwrite') == '0') {
1500 $button .= "<input
title='" . getTranslatedString('LBL_ADD_NEW') . " " .
getTranslatedString($singular_modname, $related_module) . "'
class='crmbutton small create'" .
1501 "
onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"'
type='submit' name='button'" .
1502 " value='"
. getTranslatedString('LBL_ADD_NEW') . " " .
getTranslatedString($singular_modname, $related_module) . "'> ";
1503 }
1504 }
1505
1506 $entityIds =
$this->getRelatedContactsIds();
1507 array_push($entityIds, $id);
1508 $entityIds = implode(',', $entityIds);
1509
1510 $userNameSql =
getSqlForNameInDisplayFormat(array('first_name'=>'vtiger_users.first_name','last_name'
=> 'vtiger_users.last_name'), 'Users');
1511
1512 $query = "SELECT vtiger_crmentity.*,
$other->table_name.*";
1513 $query .= ", CASE WHEN
(vtiger_users.user_name NOT LIKE '') THEN $userNameSql ELSE
vtiger_groups.groupname END AS user_name";
1514
1515 $more_relation = '';
1516 if (!empty($other->related_tables)) {
1517 foreach ($other->related_tables as
$tname => $relmap) {
1518 $query .= ", $tname.*";
1519
1520 // Setup the default JOIN
conditions if not specified
1521 if (empty($relmap[1]))
1522 $relmap[1] =
$other->table_name;
1523 if (empty($relmap[2]))
1524 $relmap[2] =
$relmap[0];
1525 $more_relation .= " LEFT
JOIN $tname ON $tname.$relmap[0] = $relmap[1].$relmap[2]";
1526 }
1527 }
1528
1529 $query .= " FROM $other->table_name";
1530 $query .= " INNER JOIN vtiger_crmentity ON
vtiger_crmentity.crmid = $other->table_name.$other->table_index";
1531 $query .= $more_relation;
1532 $query .= " LEFT JOIN vtiger_users ON
vtiger_users.id = vtiger_crmentity.smownerid";
1533 $query .= " LEFT JOIN vtiger_groups ON
vtiger_groups.groupid = vtiger_crmentity.smownerid";
1534 $query .= " WHERE vtiger_crmentity.deleted
= 0 AND $other->table_name.$dependentColumn IN (".$entityIds.")";
1535
1536 $return_value =
GetRelatedList($currentModule, $related_module, $other, $query, $button,
$returnset);
1537 }
1538 if ($return_value == null)
1539 $return_value = Array();
1540 $return_value['CUSTOM_BUTTON'] = $button;
1541
1542 return $return_value;
1543 }
}}}
NEW CODE
{{{
/**
1455 * Function to handle the dependents list for the module.
1456 * NOTE: UI type '10' is used to stored the references to
other modules for a given record.
1457 * These dependent records can be retrieved through this
function.
1458 * For eg: A trouble ticket can be related to an Account
or a Contact.
1459 * From a given Contact/Account if we need to fetch all
such dependent trouble tickets, get_dependents_list function can be used.
1460 */
1461 function get_dependents_list($id, $cur_tab_id,
$rel_tab_id, $actions = false) {
1462
1463 global $currentModule, $app_strings,
$singlepane_view, $current_user;
1464
1465 $parenttab = getParentTab();
1466
1467 $related_module =
vtlib_getModuleNameById($rel_tab_id);
1468 $other = CRMEntity::getInstance($related_module);
1469
1470 // Some standard module class doesn't have
required variables
1471 // that are used in the query, they are defined in
this generic API
1472 vtlib_setup_modulevars($currentModule, $this);
1473 vtlib_setup_modulevars($related_module, $other);
1474
1475 $singular_modname = 'SINGLE_' . $related_module;
1476 $button = '';
1477
1478 // To make the edit or del link actions to return
back to same view.
1479 if ($singlepane_view == 'true')
1480 $returnset =
"&return_module=$currentModule&return_action=DetailView&return_id=$id";
1481 else
1482 $returnset =
"&return_module=$currentModule&return_action=CallRelatedList&return_id=$id";
1483
1484 $return_value = null;
1485 $dependentFieldSql = $this->db->pquery("SELECT
tabid, fieldname, columnname , tablename FROM vtiger_field WHERE
uitype='10' AND" .
1486 " fieldid IN (SELECT fieldid FROM
vtiger_fieldmodulerel WHERE relmodule=? AND module=?)",
array($currentModule, $related_module));
1487 $numOfFields =
$this->db->num_rows($dependentFieldSql);
1488
1489 if ($numOfFields > 0) {
1490 $dependentColumn =
$this->db->query_result($dependentFieldSql, 0, 'columnname');
1491 $dependentField =
$this->db->query_result($dependentFieldSql, 0, 'fieldname');
1492 $dependentTable =
$this->db->query_result($dependentFieldSql, 0, 'tablename');
1493 $button .= '<input type="hidden" name="' .
$dependentColumn . '" id="' . $dependentColumn . '" value="' . $id . '">';
1494 $button .= '<input type="hidden" name="' .
$dependentColumn . '_type" id="' . $dependentColumn . '_type" value="' .
$currentModule . '">';
1495 if ($actions) {
1496 if (is_string($actions))
1497 $actions = explode(',',
strtoupper($actions));
1498 if (in_array('ADD', $actions) &&
isPermitted($related_module, 1, '') == 'yes'
1499 &&
getFieldVisibilityPermission($related_module, $current_user->id,
$dependentField, 'readwrite') == '0') {
1500 $button .= "<input
title='" . getTranslatedString('LBL_ADD_NEW') . " " .
getTranslatedString($singular_modname, $related_module) . "'
class='crmbutton small create'" .
1501 "
onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\"'
type='submit' name='button'" .
1502 " value='"
. getTranslatedString('LBL_ADD_NEW') . " " .
getTranslatedString($singular_modname, $related_module) . "'> ";
1503 }
1504 }
1505
1506 $entityIds =
$this->getRelatedContactsIds();
1507 array_push($entityIds, $id);
1508 $entityIds = implode(',', $entityIds);
1509
1510 $userNameSql =
getSqlForNameInDisplayFormat(array('first_name'=>'vtiger_users.first_name','last_name'
=> 'vtiger_users.last_name'), 'Users');
1511
1512 $query = "SELECT vtiger_crmentity.*,
$other->table_name.*";
1513 $query .= ", CASE WHEN
(vtiger_users.user_name NOT LIKE '') THEN $userNameSql ELSE
vtiger_groups.groupname END AS user_name";
1514
1515 $more_relation = '';
1516 if (!empty($other->related_tables)) {
1517 foreach ($other->related_tables as
$tname => $relmap) {
1518 $query .= ", $tname.*";
1519
1520 // Setup the default JOIN
conditions if not specified
1521 if (empty($relmap[1]))
1522 $relmap[1] =
$other->table_name;
1523 if (empty($relmap[2]))
1524 $relmap[2] =
$relmap[0];
1525 $more_relation .= " LEFT
JOIN $tname ON $tname.$relmap[0] = $relmap[1].$relmap[2]";
1526 }
1527 }
1528
1529 $query .= " FROM $other->table_name";
1530 $query .= " INNER JOIN vtiger_crmentity ON
vtiger_crmentity.crmid = $other->table_name.$other->table_index";
1531 $query .= $more_relation;
1532 $query .= " LEFT JOIN vtiger_users ON
vtiger_users.id = vtiger_crmentity.smownerid";
1533 $query .= " LEFT JOIN vtiger_groups ON
vtiger_groups.groupid = vtiger_crmentity.smownerid";
1534 $query .= " WHERE vtiger_crmentity.deleted
= 0 AND $dependentTable.$dependentColumn IN (".$entityIds.")";
1535
1536 $return_value =
GetRelatedList($currentModule, $related_module, $other, $query, $button,
$returnset);
1537 }
1538 if ($return_value == null)
1539 $return_value = Array();
1540 $return_value['CUSTOM_BUTTON'] = $button;
1541
1542 return $return_value;
1543 }
}}}
Changes in lines 1485,1492,1534
--
Ticket URL: <http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/8638>
Vtiger development <http://trac.vtiger.com/>
Vtiger CRM
More information about the vtigercrm-commits
mailing list