break; } } default: if (isset($object_type_id) and isset($object_id)) { $mlf = new MessageListFactory(); $mlf->getByObjectTypeAndObject($object_type_id, $object_id); $i = 0; foreach ($mlf as $message) { //Get user info $ulf = new UserListFactory(); $messages[] = array('id' => $message->getId(), 'parent_id' => $message->getParent(), 'object_type' => $message->getObjectType(), 'object_id' => $message->getObject(), 'priority' => $message->getPriority(), 'status' => $message->getStatus(), 'subject' => $message->getSubject(), 'body' => $message->getBody(), 'created_date' => $message->getCreatedDate(), 'created_by' => $message->getCreatedBy(), 'created_by_full_name' => $ulf->getById($message->getCreatedBy())->getCurrent()->getFullName(), 'updated_date' => $message->getUpdatedDate(), 'updated_by' => $message->getUpdatedBy(), 'deleted_date' => $message->getDeletedDate(), 'deleted_by' => $message->getDeletedBy()); //Mark own messages as read. if ($message->getCreatedBy() != $current_user->getId()) { $mlf_b = new MessageListFactory(); $message_obj = $mlf_b->getById($message->getId())->getCurrent(); $message_obj->setStatus(20); $message_obj->Save(); } if ($i == 0) { $parent_id = $message->getId(); $default_subject = TTi18n::gettext('Re:') . ' ' . $message->getSubject(); } $i++; } //Get object data $object_name_options = $mlf->getOptions('object_name'); $smarty->assign_by_ref('object_name', $object_name_options[$object_type_id]); $smarty->assign_by_ref('messages', $messages); $smarty->assign_by_ref('message_data', $message_data); $smarty->assign_by_ref('default_subject', $default_subject);
function getEmailMessageAddresses() { $olf = $this->getObjectHandler(); if (is_object($olf)) { $olf->getById($this->getObject()); if ($olf->getRecordCount() > 0) { $obj = $olf->getCurrent(); switch ($this->getObjectType()) { case 5: case 100: Debug::Text('Email Object Type... Parent ID: ' . $this->getParent(), __FILE__, __LINE__, __METHOD__, 10); if ($this->getParent() == 0) { $user_ids[] = $obj->getId(); } else { $mlf = new MessageListFactory(); $mlf->getById($this->getParent()); if ($mlf->getRecordCount() > 0) { $m_obj = $mlf->getCurrent(); $user_ids[] = $m_obj->getCreatedBy(); } Debug::Text('cEmail Object Type... Parent ID: ' . $this->getParent(), __FILE__, __LINE__, __METHOD__, 10); } break; case 40: $user_ids[] = $obj->getId(); break; case 50: //Request //Get all users who have contributed to the thread. $mlf = new MessageListFactory(); $mlf->getMessagesInThreadById($this->getId()); Debug::Text(' Messages In Thread: ' . $mlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($mlf->getRecordCount() > 0) { foreach ($mlf as $m_obj) { $user_ids[] = $m_obj->getCreatedBy(); } } unset($mlf, $m_obj); //Debug::Arr($user_ids, 'User IDs in Thread: ', __FILE__, __LINE__, __METHOD__,10); //Only alert direct supervisor to request at this point. Because we need to take into account //if the request was authorized or not to determine if we should email the next higher level in the hierarchy. if ($this->getParent() == 0) { //Get direct parent in hierarchy. $u_obj = $obj->getUserObject(); //Find proper hierarchy to use for this object $hotlf = new HierarchyObjectTypeListFactory(); $control_id = $hotlf->getByCompanyIdAndObjectTypeId($u_obj->getCompany(), $this->getObjectType())->getCurrent()->getHierarchyControl(); Debug::Text(' Hierarchy Control ID: ' . $control_id, __FILE__, __LINE__, __METHOD__, 10); $hlf = new HierarchyListFactory(); $node_data = $hlf->getByHierarchyControlIdAndUserId($control_id, $u_obj->getId()); if ($node_data['parent_id'] != 0) { $user_ids[] = $node_data['parent_id']; } unset($hotlf, $control_id, $hlf, $node_data); } global $current_user; if (isset($current_user) and is_object($current_user) and isset($user_ids) and is_array($user_ids)) { $user_ids = array_unique($user_ids); $current_user_key = array_search($current_user->getId(), $user_ids); Debug::Text(' Current User Key: ' . $current_user_key, __FILE__, __LINE__, __METHOD__, 10); if ($current_user_key !== FALSE) { Debug::Text(' Removing Current User From Recipient List...' . $current_user->getId(), __FILE__, __LINE__, __METHOD__, 10); unset($user_ids[$current_user_key]); } } else { Debug::Text(' Current User Object not available...', __FILE__, __LINE__, __METHOD__, 10); } unset($current_user, $current_user_key); break; case 90: $user_ids[] = $obj->getUser(); break; } } if (isset($user_ids) and is_array($user_ids)) { //Get user preferences and determine if they accept email notifications. Debug::Arr($user_ids, 'Recipient User Ids: ', __FILE__, __LINE__, __METHOD__, 10); $uplf = new UserPreferenceListFactory(); $uplf->getByUserId($user_ids); if ($uplf->getRecordCount() > 0) { foreach ($uplf as $up_obj) { if ($up_obj->getEnableEmailNotificationMessage() == TRUE and $up_obj->getUserObject()->getStatus() == 10) { if ($up_obj->getUserObject()->getWorkEmail() != '') { $retarr[] = $up_obj->getUserObject()->getWorkEmail(); } if ($up_obj->getEnableEmailNotificationHome() and $up_obj->getUserObject()->getHomeEmail() != '') { $retarr[] = $up_obj->getUserObject()->getHomeEmail(); } } } if (isset($retarr)) { Debug::Arr($retarr, 'Recipient Email Addresses: ', __FILE__, __LINE__, __METHOD__, 10); return $retarr; } } } } return FALSE; }