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

Multiple portal #25

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
34 changes: 30 additions & 4 deletions site/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ function create() {

if(isset($_REQUEST['sug']) && $_REQUEST['sug'] != ''){

$contacts = $restClient->getEntry('Contacts',$_REQUEST['sug'],array('name','email1'));
$module = $this->getRequestModule();

$sug = $this->getRequestSugarId();

$contacts = $restClient->getEntry($module, $sug,array('name','email1'));
if(!empty($contacts['entry_list'])){

$contact = $contacts['entry_list'][0]['name_value_list'];
Expand Down Expand Up @@ -214,7 +218,7 @@ function create() {
$user->set('tmp_user', true);
}

$restClient->setEntry('Contacts',array('id'=>$_REQUEST['sug'], 'joomla_account_id' => $user->id,'joomla_account_access' => $pass, ));
$restClient->setEntry($module, array('id'=>$sug, 'joomla_account_id' => $user->id,'joomla_account_access' => $pass, ));
echo json_encode(array("success"=>true));
}
}else{
Expand All @@ -231,7 +235,11 @@ function update_e(){

if(isset($_REQUEST['sug']) && $_REQUEST['sug'] != ''){

$contacts = $restClient->getEntry('Contacts',$_REQUEST['sug'],array('name','email1','joomla_account_id'));
$module = $this->getRequestModule();

$sug = $this->getRequestSugarId();

$contacts = $restClient->getEntry($module, $sug,array('name','email1','joomla_account_id'));

if(!empty($contacts['entry_list'])){
$contact = $contacts['entry_list'][0]['name_value_list'];
Expand Down Expand Up @@ -273,7 +281,12 @@ private function setUserDisabled($disable){
include_once 'components/com_advancedopenportal/sugarRestClient.php';
$restClient = new sugarRestClient();
$restClient->login();
$contacts = $restClient->getEntry('Contacts',$_REQUEST['sug'],array('joomla_account_id'));

$module = $this->getRequestModule();

$sug = $this->getRequestSugarId();

$contacts = $restClient->getEntry($module, $sug,array('joomla_account_id'));
if(!empty($contacts['entry_list'])){
$contact = $contacts['entry_list'][0]['name_value_list'];
$userId = (int) $_REQUEST['uid'];
Expand All @@ -292,5 +305,18 @@ private function setUserDisabled($disable){
JFactory::getApplication()->close();
}

private function getRequestModule() {
$module = 'Contacts';
if(isset($_REQUEST['m'])) {
$module = $_REQUEST['m'];
}
return $module;
}

private function getRequestSugarId() {
$split = explode('::', $_REQUEST['sug']);
$sug = $split[0];
return $sug;
}

}
39 changes: 35 additions & 4 deletions site/models/SugarCasesConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public function getCaseStatusDisplay($status){

public function addFiles($caseId, $caseUpdateId, $contactId, $files){
$results = array();

self::resolveAccountContactId($contactId);

//For every file, create a new note. Add an attachment and link the note to the
foreach($files as $file_name => $file_location){
$note_data = array(
Expand All @@ -99,6 +102,7 @@ public function addFiles($caseId, $caseUpdateId, $contactId, $files){
$new_note = $this->restClient->setEntry('Notes',$note_data);
$note_id = $new_note['id'];
$this->restClient->set_note_attachment($note_id, $file_name, $file_location);

$this->restClient->setRelationship("Notes",$note_id,"contact",$contactId);
$results[] = array('id'=>$note_id,'file_name'=>$file_name);
}
Expand All @@ -107,6 +111,8 @@ public function addFiles($caseId, $caseUpdateId, $contactId, $files){

public function newCase($contact_id,$subject, $description,$type,$priority,$files){

self::resolveAccountContactId($contact_id);

$data = array("contact_id"=>$contact_id,
"contact_created_by_id"=>$contact_id,
"name" => $subject,
Expand All @@ -115,6 +121,7 @@ public function newCase($contact_id,$subject, $description,$type,$priority,$file
"type" => $type,
"priority" => $priority,
'update_date_entered' => true,
'aop_creator_portal' => JUri::base(),
);
//TODO: Check call results
//Create the actual case.
Expand All @@ -137,6 +144,9 @@ public function newCase($contact_id,$subject, $description,$type,$priority,$file
public function postUpdate($case_id,$update_text, $contact_id){
$data = array();
//TODO: Add validation that this user can update this case.

self::resolveAccountContactId($contact_id);

$data['name'] = $update_text;
$data['description'] = $update_text;
$data['contact_id'] = $contact_id;
Expand All @@ -147,6 +157,9 @@ public function postUpdate($case_id,$update_text, $contact_id){
}

public function getUpdate($update_id){

self::resolveAccountContactId($this->case_update_fields['contact_id']);

$sugarupdate = $this->restClient->getEntry("AOP_Case_Updates",$update_id,$this->case_update_fields,
array(
array('name'=>'contact',
Expand Down Expand Up @@ -252,22 +265,28 @@ public function getCase($case_id,$contact_id){
}

public function getContact($contactId){
$sugarcontact = $this->restClient->getEntry("Contacts",$contactId,$this->contact_fields);

self::resolveAccountContactId($contactId);

$sugarcontact = $this->restClient->getEntry('Contacts', $contactId,$this->contact_fields);
$contact = new SugarUpdate($sugarcontact['entry_list'][0],$sugarcontact['relationship_list'][0]);
return $contact;
}

public function getCases($contact_id){
$contact = $this->getContact($contact_id);

$contact = $this->getContact(self::resolveAccountContactId($contact_id));
switch($contact->portal_user_type){
case 'Account':
$contact = $this->getContact($contact_id);
$cases = $this->fromSugarCases($this->restClient->getRelationships('Accounts', $contact->account_id,'cases','',$this->case_fields));
break;
case 'Single':
default:
$cases = $this->fromSugarCases($this->restClient->getRelationships('Contacts', $contact_id,'cases','',$this->case_fields));
$cases = $this->fromSugarCases($this->restClient->getRelationships('Contacts', $contact_id, 'cases','',$this->case_fields));
break;
}

return $cases;
}

Expand Down Expand Up @@ -303,9 +322,21 @@ private function getContactData($sugarId,$user){
}

public function updateOrCreateContact($sugarId,$user){

self::resolveAccountContactId($sugarId);

$contactData = $this->getContactData($sugarId, $user);
$res = $this->restClient->setEntry('Contacts',$contactData);
$res = $this->restClient->setEntry('Contacts', $contactData);
return $res;
}

protected static function resolveAccountContactId(&$contactId) {
$split = explode('::', $contactId);
$accountId = $contactId = $split[0];
if(count($split) > 1) {
$contactId = $split[1];
}
return $accountId;
}

}