Skip to content

Commit

Permalink
Dev: Disable participants if user has any Cint orders
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 9, 2016
1 parent 72793a1 commit 1061813
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
23 changes: 13 additions & 10 deletions application/core/plugins/CintLink/CintLink.php
Expand Up @@ -332,25 +332,28 @@ protected function userIsActivatingSurvey()
protected function disableTokens($surveyId)
{
list($contr, $action, $subaction) = $this->getControllerAction();
if ($contr == 'admin' && $action == 'tokens')
$isTokenAction = $contr == 'admin' && $action == 'tokens';

// If user has any Cint order, forbid access to participants
if ($isTokenAction)
{

// End if survey has no Cint orders
if (!CintLinkOrder::hasAnyOrders($surveyId))
{
return;
}

$not = new Notification(array(
'user_id' => Yii::app()->user->id,
'title' => $this->gT('Participants disabled'),
'message' => '<span class="fa fa-exclamation-circle text-warning"></span>&nbsp;' .
$this->gT('Participants are disabled since you have an active Cint order.'),
$this->gT('Participants are disabled since you have a Cint order.'),
'importance' => Notification::HIGH_IMPORTANCE,
));
$not->save();

// Redirect back
//Yii::app()->end();
$url = Yii::app()->createUrl(
'admin/survey/sa/view',
array(
'surveyid' => $surveyId
)
);
$url = Yii::app()->request->getOriginalUrlReferrer();
Yii::app()->getController()->redirect($url);
}
}
Expand Down
22 changes: 21 additions & 1 deletion application/core/plugins/CintLink/model/CintLinkOrder.php
Expand Up @@ -276,7 +276,7 @@ public function getCompletes()
* Used in grid view
* @return string
*/
protected function getAge()
public function getAge()
{
$minAge = null;
$maxAge = null;
Expand All @@ -301,4 +301,24 @@ protected function getAge()

return $result;
}

/**
* Returns true if survey has any Cint orders, no matter the state.
* @param int $surveyId
* @return boolean
*/
public static function hasAnyOrders($surveyId)
{
if (empty($surveyId))
{
throw new InvalidArgumentException('surveyId cannot be null or empty');
}

$criteria = new CDbCriteria();
$criteria->addCondition('deleted = false');
$criteria->addCondition('sid = ' . $surveyId); // TODO: Escape
$count = CintLinkOrder::model()->count($criteria);
return $count > 0;
}

}

0 comments on commit 1061813

Please sign in to comment.