Skip to content

Commit

Permalink
Dev: Send purchase request to limesurvey.org (CintLink)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Jul 15, 2016
1 parent 03589f8 commit aa2753d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
29 changes: 21 additions & 8 deletions application/core/plugins/CintLink/CintLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,29 @@ public function login(LSHttpRequest $request)

/**
* When user click "Place order" in the widget,
* this function is called to contact limesurvey.org.
* this function is called to contact limesurvey.org
* and place an order.
*
* @param LSHttpRequest $request
* @return string JSON
*/
public function purchaseRequest(LSHttpRequest $request)
{
return json_encode(array('result' => 'hello'));
$purchaseRequest = $request->getParam('purchaseRequest');
$limesurveyOrgKey = Yii::app()->user->getState('limesurveyOrgKey');

$curl = new Curl();
$response = $curl->post(
$this->baseURL,
array(
'app' => 'cintlinklimesurveyrestapi',
'format' => 'raw',
'resource' => 'order',
'purchaseRequest' => $purchaseRequest,
'key' => $limesurveyOrgKey
)
);
return json_encode(array('result' => $response->body));
}

/**
Expand All @@ -232,21 +247,19 @@ public function getSurvey(LSHttpRequest $request)

$user = $this->api->getCurrentUser();

$link = Yii::app()->createUrl(
$link = Yii::app()->createAbsoluteUrl(
'survey/index',
array(
'sid' => 'sidebody',
'plugin' => 'MassAction',
'method' => 'actionIndex',
'surveyId' => $surveyId
'sid' => $surveyId,
'lang' => $data['surveyls_language']
)
);

return json_encode(array(
'result' => json_encode($data),
'name' => $user->full_name,
'email' => $user->email,
'link' => $this->createAbsoluteUrl("survey/index",array("sid"=>$surveyinfo['sid'],"lang"=>$surveyinfo['language']))
'link' => $link
));
}

Expand Down
7 changes: 6 additions & 1 deletion application/core/plugins/CintLink/js/cintlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ $(document).ready(function() {
locale: getWidgetLanguage(survey.surveyls_language),
introText: "LimeSurvey",
surveyLink: {
value: "http://mysurveycompany.example.com/takesurvey/15",
value: response.link,
readOnly: true
},
surveyTitle: {
Expand All @@ -132,9 +132,14 @@ $(document).ready(function() {
type: "POST",
dataType: "json",
success: function(data) {
console.log(data);

$('#order').text(data.text);

orderUrl = data.id;

$('#release-order').show();

CintLink.close();
}
});
Expand Down

0 comments on commit aa2753d

Please sign in to comment.