Cameron Ball
Cameron Ball

Reputation: 4128

Yii::app()->lang doesn't work sometimes with LimeSurvey

I am working on a custom script to automatically send out invites and reminders. I have everything working fine up until a point. My function to send invites looks like this:

function sendInvites($iSurveyID) {
    $oSurvey = Survey::model()->findByPk($iSurveyID);

    if (!isset($oSurvey)) {
        die("could not load survey");
    }

    if(!tableExists("{{tokens_$iSurveyID}}")) {
        die("survey has no tokens or something");
    }

    $SQLemailstatuscondition = "emailstatus = 'OK'";
    $SQLremindercountcondition = '';
    $SQLreminderdelaycondition = '';
    $iMaxEmails = (int)Yii::app()->getConfig("maxemails");
    $iMaxReminders = 1;

    if(!is_null($iMaxReminders)) {
        $SQLremindercountcondition = "remindercount < " . $iMaxReminders;
    }

    $oTokens = Tokens_dynamic::model($iSurveyID);
    $aResultTokens = $oTokens->findUninvited(false, $iMaxEmails, true, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);

    if (empty($aResultTokens)) {
        die("No tokens to send invites to");
    }

    $aResult = emailTokens($iSurveyID, $aResultTokens, 'invite');
}

I also have a simple little file that starts up Yii:

Yii::createApplication('LSYii_Application', APPPATH . 'config/config' . EXT);
Yii::app()->loadHelper('admin/token');
Yii::app()->loadHelper('common');

Everything works as expected up until I actually try to send emails to the tokens. I've tracked the problem down to the following, on of the functions called by emailTokens has this in it:

$clang = Yii::app()->lang;

$aBasicTokenFields=array('firstname'=>array(
    'description'=>$clang->gT('First name'),
    'mandatory'=>'N',
    'showregister'=>'Y'
    ),

The Yii::app()->lang part seems to be causing issues because then php is unable to call the gT method. However, when LimeSurvey is running "properly" this never happens. I can't even seem to find where "lang" is in the LimeSurvey source.

What can I do to make it work?

Upvotes: 0

Views: 345

Answers (2)

Denis Chenu
Denis Chenu

Reputation: 821

maybe

Yii::import('application.libraries.Limesurvey_lang');
$clang = new Limesurvey_lang($oTokens->language);

Upvotes: 0

Deckard
Deckard

Reputation: 2450

Why do you make it so hard on yourself and not use the RemoteControl2 API ? See http://manual.limesurvey.org/wiki/RemoteControl_2_API#invite_participants

On that page you will also find a PHP example script.

Upvotes: 0

Related Questions