-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #65: Add custom endpoint to get Online Applications Campaign
Remove entrypoint code and add tests Update Application Form to use REST endpoint Update Exception type
- Loading branch information
1 parent
68f3840
commit a3bb8fc
Showing
7 changed files
with
316 additions
and
268 deletions.
There are no files selected for viewing
6 changes: 0 additions & 6 deletions
6
package/src/custom/Extension/application/Ext/EntryPointRegistry/getCampaign.php
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
package/src/custom/modules/Campaigns/clients/base/api/OnlineApplicationsAPI.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); | ||
|
||
class OnlineApplicationsAPI extends SugarApi | ||
{ | ||
/** | ||
* Registers a custom API endpoint at /Campaigns/GetOnlineApplicationsCampaignId. | ||
* The endpoint returns ID of the most recently updated Campaign with the name 'Online Applications' | ||
* @return array The definition of the custom endpoint | ||
*/ | ||
public function registerApiRest() | ||
{ | ||
return array( | ||
//GET | ||
'onlineApplicationsGet' => array( | ||
|
||
//request type | ||
'reqType' => 'GET', | ||
|
||
//set authentication | ||
'noLoginRequired' => true, | ||
|
||
//endpoint path | ||
'path' => array('Campaigns', 'getOnlineApplicationsCampaignId'), | ||
|
||
//method to call | ||
'method' => 'getOnlineApplicationsCampaignId', | ||
|
||
//short help string to be displayed in the help documentation | ||
'shortHelp' => 'Get the ID of the most recently updated Campaign with the name \'Online Applications\'', | ||
|
||
//long help to be displayed in the help documentation | ||
'longHelp' => 'custom/modules/Campaigns/clients/base/api/help/GetOnlineApplicationsCampaignId.html', | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Get the ID of the most recently updated Campaign with the name 'Online Applications' | ||
* | ||
* @return an array containing the ID of the most recently updated Campaign with the name 'Online Applications' | ||
*/ | ||
public function getOnlineApplicationsCampaignId() | ||
{ | ||
// Get the most recently updated Campaign with the name 'Online Applications' | ||
$q = $this->getSugarQuery(); | ||
$q->select(array('id', 'name')); | ||
$q->from($this->getNewCampaignBean(), array('team_security' => false)); | ||
$q->where()->equals('name', 'Online Applications'); | ||
$q->orderBy('date_modified', 'desc'); | ||
$q->limit(1); | ||
|
||
$results = $q->execute(); | ||
|
||
if(sizeof($results) != 1 || !$results[0]['id']){ | ||
throw new \SugarApiExceptionError("Unable to find ID for the Campaign named Online Applications"); | ||
} | ||
|
||
return array('id' => $results[0]['id']); | ||
} | ||
|
||
/** | ||
* Get Sugar Query. | ||
* This function exists so we can mock the SugarQuery in automated tests. | ||
* | ||
* @return \SugarQuery | ||
*/ | ||
protected function getSugarQuery() | ||
{ | ||
return new \SugarQuery(); | ||
} | ||
|
||
/** | ||
* Get a new Campaign Bean. | ||
* This function exists so we can mock the Campaigns Bean in automated tests. | ||
* | ||
* @return null|\SugarBean | ||
*/ | ||
protected function getNewCampaignBean() | ||
{ | ||
return \BeanFactory::newBean('Campaigns'); | ||
} | ||
|
||
} | ||
|
||
?> |
35 changes: 35 additions & 0 deletions
35
...e/src/custom/modules/Campaigns/clients/base/api/help/GetOnlineApplicationsCampaignId.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<h2>Overview</h2> | ||
<span class="lead"> | ||
A custom GET endpoint. Returns the ID of the most recently updated Campaign with the name 'Online Applications'. | ||
</span> | ||
|
||
<h2>Result</h2> | ||
<table class="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
id | ||
</td> | ||
<td> | ||
String | ||
</td> | ||
<td> | ||
The ID of the most recently updated Campaign with the name 'Online Applications'. | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<h3>Output Example</h3> | ||
<pre class="pre-scrollable"> | ||
{ | ||
"id": "f56b6d18-52e1-11e8-a080-34363bc46900" | ||
} | ||
</pre> |
Oops, something went wrong.