diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-05-22 15:37:42 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-05-22 15:37:42 +0100 |
| commit | 6f15bf8dd60491d72f04750433ea8581f54270ab (patch) | |
| tree | ef336e1c1204ddd62d150f39b01351079dc5ef6f | |
| parent | d4521ac7b20ae0edb9e6b823f481b70e7796425d (diff) | |
| download | contact-6f15bf8dd60491d72f04750433ea8581f54270ab.tar.gz contact-6f15bf8dd60491d72f04750433ea8581f54270ab.tar.bz2 contact-6f15bf8dd60491d72f04750433ea8581f54270ab.zip | |
Remove xref methods now in LibertyContent; update callers
Nine methods deleted from Contact (getContactGroupList, getContactSourceList,
getXrefTypeList, getXrefFormatList, loadContentTypeList, loadXrefList,
loadXref, storeXref, stepXref) — all now inherited from LibertyContent.
Contact sets $mXrefTypeKey = 'contact_types' so loadXrefTypeList() continues
to store under the key templates expect. load() updated to call
loadXrefTypeList(). Page files updated: getContactGroupList → getXrefGroupList,
getContactSourceList → getXrefSourceList.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rwxr-xr-x | display_contact.php | 2 | ||||
| -rwxr-xr-x | edit.php | 2 | ||||
| -rwxr-xr-x | edit_notes.php | 2 | ||||
| -rwxr-xr-x | includes/classes/Contact.php | 236 | ||||
| -rwxr-xr-x | index.php | 2 | ||||
| -rwxr-xr-x | load_emails.php | 2 |
6 files changed, 9 insertions, 237 deletions
diff --git a/display_contact.php b/display_contact.php index 749ac98..1d8af5d 100755 --- a/display_contact.php +++ b/display_contact.php @@ -51,7 +51,7 @@ if ($gContent->isCommentable()) { } } -$gContent->mInfo['type'] = $gContent->getContactGroupList(); +$gContent->mInfo['type'] = $gContent->getXrefGroupList(); $gBitSystem->setBrowserTitle("Contact Information"); $gBitSystem->display( 'bitpackage:contact/show_contact.tpl'); @@ -69,7 +69,7 @@ if( empty( $formInfo ) ) { $formInfo = &$gContent->mInfo; } -$formInfo['contact_type_list'] = $gContent->getContactSourceList(); +$formInfo['contact_type_list'] = $gContent->getXrefSourceList(); $gBitSmarty->assign( 'pageInfo', $formInfo ); $gBitSmarty->assign( 'errors', $gContent->mErrors ); diff --git a/edit_notes.php b/edit_notes.php index 8b2e0e4..b449a5a 100755 --- a/edit_notes.php +++ b/edit_notes.php @@ -69,7 +69,7 @@ if( empty( $formInfo ) ) { $formInfo = &$gContent->mInfo; } -$formInfo['contact_type_list'] = $gContent->getContactSourceList(); +$formInfo['contact_type_list'] = $gContent->getXrefSourceList(); $gBitSmarty->assign( 'pageInfo', $formInfo ); $gBitSmarty->assign( 'errors', $gContent->mErrors ); diff --git a/includes/classes/Contact.php b/includes/classes/Contact.php index 399c8e4..3fdbee5 100755 --- a/includes/classes/Contact.php +++ b/includes/classes/Contact.php @@ -30,6 +30,8 @@ class Contact extends LibertyContent { public $mDate; public $mTypes; + protected $mXrefTypeKey = 'contact_types'; + /** * Constructor * @@ -122,8 +124,8 @@ class Contact extends LibertyContent { $this->mInfo['x_coordinate'] = $ll1->lng; } - $this->loadContentTypeList(); - if ( $this->mInfo['contact_types'][2]['content_id'] ) { + $this->loadXrefTypeList(); + if ( !empty( $this->mInfo['contact_types'][2]['content_id'] ) ) { $this->loadClientList(); } $this->loadXrefList(); @@ -458,117 +460,6 @@ class Contact extends LibertyContent { } /** - * Returns titles of the contact type table - * - * @return array List of contact type names from the contact mamager in alphabetical order - */ - public function getContactGroupList() { - global $gBitUser, $gBitSmarty; - - $roles = array_keys($gBitUser->mRoles); - $bindVars = []; - $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] ); - - $query = "SELECT g.*, g.`xref_type` AS source FROM `".BIT_DB_PREFIX."liberty_xref_type` g - LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON ( purm.`user_id`=".$gBitUser->mUserId." ) AND ( purm.`role_id`=g.`role_id` ) - WHERE g.`content_type_guid` = 'contact' AND g.`sort_order` > 0 AND (g.`role_id` IN(". implode(',', array_fill(0, count($roles), '?')) ." ) OR purm.`user_id`=?) - ORDER BY g.`sort_order`"; - $result = $this->mDb->query( $query, $bindVars ); - $ret = []; - while ($res = $result->fetchRow()) { - $ret[] = $res; - } - return $ret; - } - - /** - * Returns titles of the contact type table - * - * @return array List of contact type names from the contact mamager in alphabetical order - */ - public function getContactSourceList() { - global $gBitUser, $gBitSmarty; - - $roles = array_keys($gBitUser->mRoles); - $bindVars = []; - $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] ); - - $query = "SELECT g.`cross_ref_title` AS `type_name`, g.`source` FROM `".BIT_DB_PREFIX."liberty_xref_source` g - JOIN `".BIT_DB_PREFIX."liberty_xref_type` t ON t.`xref_type` = g.`xref_type` AND t.`content_type_guid` = 'contact' - LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON ( purm.`user_id`=".$gBitUser->mUserId." ) AND ( purm.`role_id`=g.`role_id` ) - WHERE g.`content_type_guid` = 'contact' AND t.`sort_order` = 0 AND (g.`role_id` IN(". implode(',', array_fill(0, count($roles), '?')) ." ) OR purm.`user_id`=?) - ORDER BY g.`source`"; - $result = $this->mDb->query( $query, $bindVars ); - $ret = []; - $cnt = 0; - while ($res = $result->fetchRow()) { - $ret[$cnt]['source'] = $res["source"]; - $ret[$cnt++]['name'] = trim($res["type_name"]); - } - return $ret; - } - - /** - * Returns titles of the xref type table - * @param $xrefGroup selects a single group of xref types - * @return array List of xref type names from the contact mamager in alphabetical order - */ - public function getXrefTypeList( $xrefGroup = 0, $xrefTemplate = NULL ) { - if ( $xrefTemplate ) { - $query = "SELECT s.`cross_ref_title` AS `type_name`, s.`source`, s.`template` FROM `".BIT_DB_PREFIX."liberty_xref_source` s - WHERE s.`content_type_guid` = 'contact' AND s.`template` = '$xrefTemplate' - ORDER BY s.`cross_ref_title`"; - $result = $this->mDb->query($query, [] ); - } elseif ( $xrefGroup > -1 ) { - $query = "SELECT s.`cross_ref_title` AS `type_name`, s.`source`, s.`template` FROM `".BIT_DB_PREFIX."liberty_xref_source` s - JOIN `".BIT_DB_PREFIX."liberty_xref_type` t ON t.`xref_type` = s.`xref_type` AND t.`content_type_guid` = 'contact' - LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` x ON x.`source` = s.`source` AND x.`content_id` = ? AND ( x.`end_date` IS NULL OR x.`end_date` > CURRENT_TIMESTAMP ) - WHERE s.`content_type_guid` = 'contact' AND t.`sort_order` = ? AND ( x.`xref_id` IS NULL OR x.`xorder` > 0 ) - ORDER BY s.`cross_ref_title`"; - $result = $this->mDb->query($query, [ $this->mContentId, $xrefGroup ] ); - } else { - $query = "SELECT s.`cross_ref_title` AS `type_name`, s.`source`, s.`template` FROM `".BIT_DB_PREFIX."liberty_xref_source` s - JOIN `".BIT_DB_PREFIX."liberty_xref_type` t ON t.`xref_type` = s.`xref_type` AND t.`content_type_guid` = 'contact' - LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` x ON x.`source` = s.`source` AND x.`content_id` = ? AND ( x.`end_date` IS NULL OR x.`end_date` > CURRENT_TIMESTAMP ) - WHERE s.`content_type_guid` = 'contact' AND t.`sort_order` > 0 AND ( x.`xref_id` IS NULL OR x.`xorder` > 0 ) - ORDER BY s.`cross_ref_title`"; - $result = $this->mDb->query($query, [ $this->mContentId ] ); - } - $ret = []; - - while ($res = $result->fetchRow()) { - $ret['list'][$res["source"]] = trim($res["type_name"]); - $ret['type'][$res["source"]] = trim($res["template"]) <> '' ? trim($res["template"]) : 'generic'; - } - return $ret; - } - - /** - * Returns titles of the contact format templates table - * - * @return array List of contact format templates names from the contact mamager in alphabetical order - */ - public function getXrefFormatList() { - global $gBitUser, $gBitSmarty; - - $roles = array_keys($gBitUser->mRoles); - $bindVars = []; - $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] ); - - $query = "SELECT DISTINCT g.`template` FROM `".BIT_DB_PREFIX."liberty_xref_source` g - LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON ( purm.`user_id`=".$gBitUser->mUserId." ) AND ( purm.`role_id`=g.`role_id` ) - WHERE (g.`role_id` IN(". implode(',', array_fill(0, count($roles), '?')) ." ) OR purm.`user_id`=?) - ORDER BY g.`template`"; - $result = $this->mDb->query( $query, $bindVars ); - $ret = []; - $cnt = 0; - while ($res = $result->fetchRow()) { - $ret[] = trim($res["template"]) <> '' ? trim($res["template"]) : 'generic'; - } - return $ret; - } - - /** * Returns Contract Numbers list * @param $contract selects a single type of contract to list * @return array List of contact numbers in contract number order @@ -602,125 +493,6 @@ class Contact extends LibertyContent { } /** - * getXrefList( &$pParamHash ); - * Get list of xref records for this contact record - */ - public function loadContentTypeList() { - if( $this->isValid() && empty( $this->mInfo['contact_types'] ) ) { - global $gBitUser; - - $roles = array_keys($gBitUser->mRoles); - $bindVars = []; - array_push( $bindVars, $this->mContentId ); - $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] ); - - $sql = "SELECT r.`source`, r.`cross_ref_title`, d.`content_id` - FROM `".BIT_DB_PREFIX."liberty_xref_source` r - JOIN `".BIT_DB_PREFIX."liberty_xref_type` t ON t.`xref_type` = r.`xref_type` AND t.`content_type_guid` = 'contact' - LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` d ON d.`content_id` = ? AND d.`source` = r.`source` - LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON ( purm.`user_id`=".$gBitUser->mUserId." ) AND ( purm.`role_id`=r.`role_id` ) - WHERE r.`content_type_guid` = 'contact' AND t.`sort_order` = 0 AND (r.`role_id` IN(". implode(',', array_fill(0, count($roles), '?')) ." ) OR purm.`user_id`=?) - ORDER BY r.`source`"; - - $result = $this->mDb->query( $sql, $bindVars ); - - while( $res = $result->fetchRow() ) { - $this->mInfo['contact_types'][] = $res; - } - } - } - - /** - * getXrefList( &$pParamHash ); - * Get list of xref records for this contact record - */ - public function loadXrefList() { - if( $this->isValid() && empty( $this->mInfo['xref'] ) ) { - global $gBitUser; - - $roles = array_keys($gBitUser->mRoles); - $bindVars = []; - array_push( $bindVars, $this->mDb->NOW() ); - array_push( $bindVars, $this->mContentId ); - $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] ); - - $sql = "SELECT s.xref_type, x.`xref_id`, x.`last_update_date`, x.`source`, t.`title` AS type_title, - CASE - WHEN x.`end_date` < ? THEN 'history' - ELSE t.`xref_type` END as type_source, - CASE - WHEN x.`xorder` = 0 THEN s.`cross_ref_title` - ELSE s.`cross_ref_title` || '-' || x.`xorder` END - AS source_title, - x.`xref`, x.`xkey`, x.`xkey_ext`, x.`data`, - x.`start_date`, x.`end_date`, s.`template`, - pc.`add1` || ',' || pc.`add2` || ',' || pc.`add4` || ',' || pc.`town` as address - FROM `".BIT_DB_PREFIX."liberty_xref` x - JOIN `".BIT_DB_PREFIX."liberty_xref_source` s ON s.`source` = x.`source` AND s.`content_type_guid` = 'contact' - LEFT JOIN `".BIT_DB_PREFIX."address_postcode` pc ON pc.`postcode` = x.`xkey` - JOIN `".BIT_DB_PREFIX."liberty_xref_type` t ON t.`xref_type` = s.`xref_type` AND t.`content_type_guid` = 'contact' - LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON ( purm.`user_id`=".$gBitUser->mUserId." ) AND ( purm.`role_id`=s.`role_id` ) - WHERE x.content_id = ? AND (s.`role_id` IN(". implode(',', array_fill(0, count($roles), '?')) ." ) OR purm.`user_id`=?) - ORDER BY x.`source`, x.`xorder`"; - - $result = $this->mDb->query( $sql, $bindVars ); - - if($result) { - while( $res = $result->fetchRow() ) { - $this->mInfo[$res['type_source']][] = $res; - } - } - } - } - - /** - * loadXref( &$pParamHash ); - * find contact record that matches the supplied xref record - */ - public function loadXref( $pXrefId = NULL ) { - if( BitBase::verifyId( $pXrefId ) ) { - $xref = new ContactXref( $pXrefId ); - if( $xref->mContentId ) { - $this->load( $xref->mContentId ); - $this->mInfo['xref_title'] = $xref->mContentId; - $this->mInfo['xref_store'] = $xref->mInfo; - $this->mInfo['format_guid'] = 'text'; - } - } - } - - /** - * storeXref( &$pParamHash ); - * store or update xref records for this contact record - */ - public function storeXref( &$pParamHash ) { - $xref = new ContactXref( $pParamHash['xref_id'] ?? NULL ); - if ( $xref->store( $pParamHash ) ) { - $this->mInfo['xref_title'] = $xref->mContentId; - $this->mInfo['xref_store'] = $xref->mInfo; - $pParamHash['xref_id'] = $xref->mXrefId; - $this->load(); - - return true; - } return false; - } - - /** - * stepXref( &$pParamHash ); - * find contact record that matches the supplied xref record - */ - public function stepXref( &$pParamHash ) { - $xref = new ContactXref( $pParamHash['xref_id'] ); - if ( $xref->stepXref( $pParamHash ) ) { - $this->mInfo['xref_title'] = $xref->mContentId; - $this->mInfo['xref_store'] = $xref->mInfo; - $this->load(); - - return true; - } return false; - } - - /** * getClientList( &$pParamHash ); * Get list of client records for this contact record * This is used to list related contact records such as contacts handled by a call center or alarm maintainer @@ -34,6 +34,6 @@ if ($gContent->isCommentable()) { include_once LIBERTY_PKG_PATH . 'comments_inc.php'; } -$gContent->mInfo['type'] = $gContent->getContactGroupList(); +$gContent->mInfo['type'] = $gContent->getXrefGroupList(); $gBitSystem->setBrowserTitle("Contact List Item"); $gBitSystem->display( 'bitpackage:contact/show_contact.tpl', NULL, [ 'display_mode' => 'display' ]); diff --git a/load_emails.php b/load_emails.php index 3ba496f..b421f55 100755 --- a/load_emails.php +++ b/load_emails.php @@ -186,7 +186,7 @@ if ($gContent->isCommentable()) { include_once LIBERTY_PKG_PATH . 'comments_inc.php'; } -$gContent->mInfo['type'] = $gContent->getContactGroupList(); +$gContent->mInfo['type'] = $gContent->getXrefGroupList(); $gBitSystem->setBrowserTitle("Contact Information"); $gBitSystem->display( 'bitpackage:contact/show_contact.tpl'); |
