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

CRM-21110 Get Total relationships without need for extra table #11009

Merged
merged 1 commit into from
Sep 30, 2017
Merged
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
CRM-21110 Get Total relationships without need for extra table
  • Loading branch information
seamuslee001 committed Sep 29, 2017
commit e729799a8844077aacd4470b00e50ee6d4a1716a
9 changes: 3 additions & 6 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -1279,25 +1279,23 @@ public static function getRelationship(
}

// building the query string
CRM_Core_DAO::executeQuery("CREATE TEMPORARY TABLE civicrm_contact_relationships " . $select1 . $from1 . $where1 . $select2 . $from2 . $where2);
$queryString = "SELECT * FROM civicrm_contact_relationships " . $order . $limit;
$queryString = $select1 . $from1 . $where1 . $select2 . $from2 . $where2;

$relationship = new CRM_Contact_DAO_Relationship();

$relationship->query($queryString);
$relationship->query($queryString . $order . $limit);
$row = array();
if ($count) {
$relationshipCount = 0;
while ($relationship->fetch()) {
$relationshipCount += $relationship->cnt1 + $relationship->cnt2;
}
CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS civicrm_contact_relationships");
return $relationshipCount;
}
else {

if ($includeTotalCount) {
$values['total_relationships'] = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_contact_relationships");
$values['total_relationships'] = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM ({$queryString}) AS r");
}

$mask = NULL;
Expand Down Expand Up @@ -1445,7 +1443,6 @@ public static function getRelationship(
}

$relationship->free();
CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS civicrm_contact_relationships");
return $values;
}
}
Expand Down