Created
December 12, 2013 19:17
-
-
Save KyleGawryluk/7933748 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Post Relationship | |
* @param string $key API Key | |
* @param string $time API Timestamp | |
* | |
* Required Parameters | |
* 'module1' = (string) Portal Module Name | |
* 'id1' = (string) Record Sugar ID | |
* 'module2' = (string) Portal Module Name | |
* 'id2' = (string) Record Sugar ID | |
* | |
* @return mixed [description] | |
*/ | |
public function postRelate($key, $time) | |
{ | |
if ($this->emptyElementExists(Input::all())) { | |
return Response::make('Required Parameters Not Found', '400'); | |
} | |
$var = (object) Input::all(); | |
$class1 = ucfirst($var->module1); | |
$module1 = new $class1; | |
$relate1 = $module1->where('sugar_id','=',$var->id1)->first(); | |
$class2 = ucfirst($var->module2); | |
$module2 = new $class2; | |
$relate2 = $module2->where('sugar_id','=',$var->id2)->first(); | |
if (!$relate1 || !$relate2) { | |
return Response::make('Relationship Could Not Be Created', '400'); | |
} | |
$relationship = $var->module2.'s'; | |
$relate1->$relationship()->sync([$relate2->id]); | |
return Response::make('Relationship Created', '201'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment