grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 'accounts',
'bug_id' => 'bugs',
'task_id' => 'tasks',
'note_id' => 'notes',
'meeting_id' => 'meetings',
'call_id' => 'calls',
'email_id' => 'emails',
);
/**
* aCase constructor.
*/
public function __construct()
{
parent::__construct();
global $sugar_config;
if (!$sugar_config['require_accounts']) {
unset($this->required_fields['account_name']);
}
$this->setupCustomFields('Cases');
foreach ($this->field_defs as $name => $field) {
$this->field_name_map[$name] = $field;
}
}
/**
* @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8,
* please update your code, use __construct instead
*/
public function aCase()
{
$deprecatedMessage =
'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
if (isset($GLOBALS['log'])) {
$GLOBALS['log']->deprecated($deprecatedMessage);
} else {
trigger_error($deprecatedMessage, E_USER_DEPRECATED);
}
self::__construct();
}
/**
* @return string
*/
public function get_summary_text()
{
return "$this->name";
}
/**
* @return string[]
*/
public function listviewACLHelper()
{
$array_assign = parent::listviewACLHelper();
$is_owner = false;
$in_group = false; //SECURITY GROUPS
if (!empty($this->account_id)) {
if (!empty($this->account_id_owner)) {
global $current_user;
$is_owner = $current_user->id === $this->account_id_owner;
} else {
global $current_user;
$parent_bean = BeanFactory::getBean('Accounts', $this->account_id);
if ($parent_bean !== false) {
$is_owner = $current_user->id === $parent_bean->assigned_user_id;
}
}
require_once 'modules/SecurityGroups/SecurityGroup.php';
$in_group = SecurityGroup::groupHasAccess('Accounts', $this->account_id, 'view');
}
if (!ACLController::moduleSupportsACL('Accounts') ||
ACLController::checkAccess('Accounts', 'view', $is_owner, 'module', $in_group)
) {
$array_assign['ACCOUNT'] = 'a';
} else {
$array_assign['ACCOUNT'] = 'span';
}
return $array_assign;
}
/**
* @param bool $is_update
* @param array $exclude
*/
public function save_relationship_changes($is_update, $exclude = array())
{
parent::save_relationship_changes($is_update, $exclude);
if (!empty($this->contact_id)) {
$this->set_case_contact_relationship($this->contact_id);
}
}
/**
* @param $contact_id
*/
public function set_case_contact_relationship($contact_id)
{
global $app_list_strings;
$default = $app_list_strings['case_relationship_type_default_key'];
$this->load_relationship('contacts');
$this->contacts->add($contact_id, array('contact_role' => $default));
}
public function fill_in_additional_detail_fields()
{
parent::fill_in_additional_detail_fields();
// Fill in the assigned_user_name
$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
$this->created_by_name = get_assigned_user_name($this->created_by);
$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
if (!empty($this->id)) {
$account_info = $this->getAccount($this->id);
if (!empty($account_info)) {
$this->account_name = $account_info['account_name'];
$this->account_id = $account_info['account_id'];
}
}
}
/** Returns a list of the associated contacts
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
* All Rights Reserved..
* Contributor(s): ______________________________________..
*/
public function get_contacts()
{
$this->load_relationship('contacts');
$query_array=$this->contacts->getQuery();
//update the select clause in the returned query.
if (!is_array($query_array)) {
LoggerManager::getLogger()->fatal('Building database selection for contacts but the query information format is not an array.');
return false;
}
$query_array['select'] =
'SELECT contacts.id, contacts.first_name, contacts.last_name, contacts.title, contacts.email1, contacts.phone_work, contacts_cases.contact_role as case_role, contacts_cases.id as case_rel_id ';
$query = '';
foreach ($query_array as $qString) {
$query .= ' ' . $qString;
}
$temp = array('id', 'first_name', 'last_name', 'title', 'email1', 'phone_work', 'case_role', 'case_rel_id');
return $this->build_related_list2($query, new Contact(), $temp);
}
/**
* @return array
*/
public function get_list_view_data()
{
global $current_language;
$app_list_strings = return_app_list_strings_language($current_language);
$temp_array = $this->get_list_view_array();
$temp_array['NAME'] = empty($this->name) ? 'blank' : $this->name;
$temp_array['PRIORITY'] =
empty($this->priority) ? '' :
(!isset($app_list_strings[$this->field_name_map['priority']['options']][$this->priority]) ?
$this->priority : $app_list_strings[$this->field_name_map['priority']['options']][$this->priority]);
$temp_array['STATUS'] =
empty($this->status) ? '' :
(!isset($app_list_strings[$this->field_name_map['status']['options']][$this->status]) ? $this->status :
$app_list_strings[$this->field_name_map['status']['options']][$this->status]);
$temp_array['ENCODED_NAME'] = $this->name;
$temp_array['CASE_NUMBER'] = $this->case_number;
$temp_array['SET_COMPLETE'] =
"" .
SugarThemeRegistry::current()->getImage(
'close_inline',
'title=' . translate('LBL_LIST_CLOSE', 'Cases') . " border='0'",
null,
null,
'.gif',
translate('LBL_LIST_CLOSE', 'Cases')
) .
'';
//$temp_array['ACCOUNT_NAME'] = $this->account_name; //overwrites the account_name value returned from the cases table.
return $temp_array;
}
/**
* builds a generic search based on the query string using or
* do not include any $this-> because this is called on without having the class instantiated.
*
* @param $the_query_string
*
* @return string|void
*/
public function build_generic_where_clause($the_query_string)
{
$where_clauses = array();
$the_query_string = $this->db->quote($the_query_string);
$where_clauses[] = "cases.name like '$the_query_string%'";
$where_clauses[] = "accounts.name like '$the_query_string%'";
if (is_numeric($the_query_string)) {
$where_clauses[] = "cases.case_number like '$the_query_string%'";
}
$the_where = '';
foreach ($where_clauses as $clause) {
if ($the_where !== '') {
$the_where .= ' or ';
}
$the_where .= $clause;
}
if ($the_where !== '') {
$the_where = '(' . $the_where . ')';
}
return $the_where;
}
/**
* @param Sugar_Smarty $xtpl
* @param aCase $case
*
* @return mixed
*/
public function set_notification_body($xtpl, $case)
{
global $app_list_strings;
$xtpl->assign('CASE_NUMBER', $case->case_number);
$xtpl->assign('CASE_SUBJECT', $case->name);
$xtpl->assign(
'CASE_PRIORITY',
(isset($case->priority) ? $app_list_strings['case_priority_dom'][$case->priority] : '')
);
$xtpl->assign('CASE_STATUS', (isset($case->status) ? $app_list_strings['case_status_dom'][$case->status] : ''));
$xtpl->assign('CASE_DESCRIPTION', $case->description);
return $xtpl;
}
/**
* @param $interface
*
* @return bool
*/
public function bean_implements($interface)
{
switch ($interface) {
case 'ACL':
return true;
}
return false;
}
/**
* retrieves the Subject line macro for InboundEmail parsing.
*
* @return string
*/
public function getEmailSubjectMacro()
{
global $sugar_config;
return (isset($sugar_config['inbound_email_case_subject_macro']) &&
!empty($sugar_config['inbound_email_case_subject_macro'])) ?
$sugar_config['inbound_email_case_subject_macro'] : $this->emailSubjectMacro;
}
/**
* @param $case_id
*
* @return array
*/
public function getAccount($case_id)
{
if (empty($case_id)) {
return array();
}
$ret_array = array();
$query =
"SELECT acc.id, acc.name FROM accounts acc, cases WHERE acc.id = cases.account_id AND cases.id = '" .
$case_id .
"' AND cases.deleted=0 AND acc.deleted=0";
$result = $this->db->query($query, true, ' Error filling in additional detail fields: ');
// Get the id and the name.
$row = $this->db->fetchByAssoc($result);
if ($row !== null) {
$ret_array['account_name'] = stripslashes($row['name']);
$ret_array['account_id'] = $row['id'];
} else {
$ret_array['account_name'] = '';
$ret_array['account_id'] = '';
}
return $ret_array;
}
}