コード例 #1
0
/**
 * Marks a tokens as completed and sends a confirmation email to the participiant.
 * If $quotaexit is set to true then the user exited the survey due to a quota
 * restriction and the according token is only marked as 'Q'
 *
 * @param mixed $quotaexit
 */
function submittokens($quotaexit = false)
{
    $surveyid = Yii::app()->getConfig('surveyID');
    if (isset($_SESSION['survey_' . $surveyid]['s_lang'])) {
        $thissurvey = getSurveyInfo($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
    } else {
        $thissurvey = getSurveyInfo($surveyid);
    }
    $clienttoken = $_SESSION['survey_' . $surveyid]['thistoken']['token'];
    $clang = Yii::app()->lang;
    $sitename = Yii::app()->getConfig("sitename");
    $emailcharset = Yii::app()->getConfig("emailcharset");
    // Shift the date due to global timeadjust setting
    $today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
    // check how many uses the token has left
    $oTokenInformation = Tokens_dynamic::model($surveyid)->findByAttributes(array('token' => $clienttoken));
    if ($oTokenInformation) {
        $usesleft = $oTokenInformation->usesleft;
        $participant_id = isset($oTokenInformation->participant_id) ? $oTokenInformation->participant_id : '';
    }
    if ($quotaexit == true) {
        $oTokenInformation->completed = 'Q';
        $oTokenInformation->usesleft = $oTokenInformation->usesleft - 1;
    } else {
        if (isset($usesleft) && $usesleft <= 1) {
            // Finish the token
            if (isTokenCompletedDatestamped($thissurvey)) {
                $oTokenInformation->completed = $today;
            } else {
                $oTokenInformation->completed = 'Y';
            }
            if (!empty($participant_id)) {
                $slquery = Survey_links::model()->find('participant_id = :pid AND survey_id = :sid AND token_id = :tid', array(':pid' => $participant_id, ':sid' => $surveyid, ':tid' => $oTokenInformation->tid));
                if (isTokenCompletedDatestamped($thissurvey)) {
                    $slquery->date_completed = $today;
                } else {
                    // Update the survey_links table if necessary, to protect anonymity, use the date_created field date
                    $slquery->date_completed = $slquery->date_created;
                }
                $slquery->save();
            }
        }
        $oTokenInformation->usesleft = $oTokenInformation->usesleft - 1;
    }
    $oTokenInformation->save();
    if ($quotaexit == false) {
        if ($oTokenInformation && trim(strip_tags($thissurvey['email_confirm'])) != "" && $thissurvey['sendconfirmation'] == "Y") {
            if ($oTokenInformation->completed == "Y" || $oTokenInformation->completed == $today) {
                $from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
                $to = $oTokenInformation->email;
                $subject = $thissurvey['email_confirm_subj'];
                $aReplacementVars = array();
                $aReplacementVars["ADMINNAME"] = $thissurvey['admin'];
                $aReplacementVars["ADMINEMAIL"] = $thissurvey['adminemail'];
                $aReplacementVars['ADMINEMAIL'] = $thissurvey['adminemail'];
                //Fill with token info, because user can have his information with anonimity control
                $aReplacementVars["FIRSTNAME"] = $oTokenInformation->firstname;
                $aReplacementVars["LASTNAME"] = $oTokenInformation->lastname;
                $aReplacementVars["TOKEN"] = $clienttoken;
                // added survey url in replacement vars
                $surveylink = Yii::app()->createAbsoluteUrl("/survey/index/sid/{$surveyid}", array('lang' => $_SESSION['survey_' . $surveyid]['s_lang'], 'token' => $clienttoken));
                $aReplacementVars['SURVEYURL'] = $surveylink;
                $attrfieldnames = getAttributeFieldNames($surveyid);
                foreach ($attrfieldnames as $attr_name) {
                    $aReplacementVars[strtoupper($attr_name)] = $oTokenInformation->{$attr_name};
                }
                $dateformatdatat = getDateFormatData($thissurvey['surveyls_dateformat']);
                $numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']);
                $redata = array('thissurvey' => $thissurvey);
                $subject = templatereplace($subject, $aReplacementVars, $redata);
                $subject = html_entity_decode($subject, ENT_QUOTES, $emailcharset);
                if (getEmailFormat($surveyid) == 'html') {
                    $ishtml = true;
                } else {
                    $ishtml = false;
                }
                $message = $thissurvey['email_confirm'];
                //$message=ReplaceFields($message, $fieldsarray, true);
                $message = templatereplace($message, $aReplacementVars, $redata);
                if (!$ishtml) {
                    $message = strip_tags(breakToNewline(html_entity_decode($message, ENT_QUOTES, $emailcharset)));
                } else {
                    $message = html_entity_decode($message, ENT_QUOTES, $emailcharset);
                }
                //Only send confirmation email if there is a valid email address
                if (validateEmailAddress($to)) {
                    SendEmailMessage($message, $subject, $to, $from, $sitename, $ishtml);
                }
            } else {
                // Leave it to send optional confirmation at closed token
            }
        }
    }
}
コード例 #2
0
ファイル: Participants.php プロジェクト: rawaludin/LimeSurvey
 function deleteParticipantTokenAnswer($rows)
 {
     /* This function deletes the participant from the participants table,
        the participant from any tokens table they're in (using the survey_links table to find them),
        all responses in surveys they've been linked to,
        and then all the participants attributes. */
     $rowid = explode(",", $rows);
     foreach ($rowid as $row) {
         //ORIGINAL LINE: $tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = "' . $row . '"')->queryAll();
         $tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = :row')->bindParam(":row", $row, PDO::PARAM_INT)->queryAll();
         foreach ($tokens as $key => $value) {
             $tokentable = '{{tokens_' . intval($value['survey_id']) . '}}';
             if (Yii::app()->db->schema->getTable($tokentable)) {
                 $tokenid = Yii::app()->db->createCommand()->select('token')->from('{{tokens_' . intval($value['survey_id']) . '}}')->where('participant_id = "' . $value['participant_id'] . '"')->queryAll();
                 $token = $tokenid[0];
                 $surveytable = '{{survey_' . intval($value['survey_id']) . '}}';
                 if ($datas = Yii::app()->db->schema->getTable($surveytable)) {
                     if (!empty($token['token']) && isset($datas->columns['token'])) {
                         $gettoken = Yii::app()->db->createCommand()->select('*')->from('{{survey_' . intval($value['survey_id']) . '}}')->where('token = :token')->bindParam(":token", $token['token'], PDO::PARAM_STR)->queryAll();
                         $gettoken = $gettoken[0];
                         Yii::app()->db->createCommand()->delete('{{survey_' . intval($value['survey_id']) . '}}', 'token = :token')->bindParam(":token", $gettoken['token'], PDO::PARAM_STR);
                         // Deletes matching responses from surveys
                     }
                 }
                 Yii::app()->db->createCommand()->delete('{{tokens_' . intval($value['survey_id']) . '}}', 'participant_id = "' . $value['participant_id'] . '"');
                 // Deletes matching token table entries
             }
         }
         Yii::app()->db->createCommand()->delete(Participants::model()->tableName(), array('in', 'participant_id', $row));
         Yii::app()->db->createCommand()->delete(Survey_links::model()->tableName(), array('in', 'participant_id', $row));
         Yii::app()->db->createCommand()->delete(Participant_attribute::model()->tableName(), array('in', 'participant_id', $row));
     }
 }
コード例 #3
0
 /**
  * Receives an ajax call containing the participant id in the fourth segment of the url
  * Supplies list of survey links - surveys of which this participant is on the tokens table
  * URL: [localurl]/limesurvey/admin/participants/getSurveyInfo_json/pid/[participant_id]
  * RETURNS: json data containing linked survey information (Survey name, survey id, token_id and date_added)
  */
 function getSurveyInfo_json()
 {
     $participantid = Yii::app()->request->getQuery('pid');
     $records = Survey_links::model()->findAllByAttributes(array('participant_id' => $participantid));
     $aData = new stdClass();
     $aData->page = 1;
     $aData->records = count($records);
     $aData->total = ceil($aData->records / 10);
     $i = 0;
     foreach ($records as $row) {
         $oSurvey = Survey::model()->with(array('languagesettings' => array('condition' => 'surveyls_language=language')))->findByAttributes(array('sid' => $row['survey_id']));
         foreach ($oSurvey->languagesettings as $oLanguageSetting) {
             $surveyname = $oLanguageSetting->surveyls_title;
         }
         $surveylink = "";
         /* Check permissions of each survey before creating a link*/
         if (!hasSurveyPermission($row['survey_id'], 'tokens', 'read')) {
             $surveylink = $row['survey_id'];
         } else {
             $surveylink = '<a href=' . Yii::app()->getController()->createUrl("/admin/tokens/sa/browse/surveyid/{$row['survey_id']}") . '>' . $row['survey_id'] . '</a>';
         }
         $aData->rows[$i]['cell'] = array($surveyname, $surveylink, $row['token_id'], $row['date_created'], $row['date_invited'], $row['date_completed']);
         $i++;
     }
     echo ls_json_encode($aData);
 }
コード例 #4
0
 /**
  * Function responsible to deactivate a survey.
  *
  * @access public
  * @param int $iSurveyID
  * @return void
  */
 public function deactivate($iSurveyID = null)
 {
     $iSurveyID = Yii::app()->request->getPost('sid', $iSurveyID);
     $iSurveyID = sanitize_int($iSurveyID);
     $clang = $this->getController()->lang;
     $date = date('YmdHis');
     //'His' adds 24hours+minutes to name to allow multiple deactiviations in a day
     if (empty($_POST['ok'])) {
         $aData['surveyid'] = $iSurveyID;
         $aData['date'] = $date;
         $aData['dbprefix'] = Yii::app()->db->tablePrefix;
         $aData['step1'] = true;
     } else {
         //See if there is a tokens table for this survey
         if (tableExists("{{tokens_{$iSurveyID}}}")) {
             if (Yii::app()->db->getDriverName() == 'postgre') {
                 $deactivateresult = Yii::app()->db->createCommand()->renameTable($toldtable . '_tid_seq', $tnewtable . '_tid_seq');
                 $setsequence = "ALTER TABLE " . Yii::app()->db->quoteTableName($tnewtable) . " ALTER COLUMN tid SET DEFAULT nextval('{{{$tnewtable}}}_tid_seq'::regclass);";
                 $deactivateresult = Yii::app()->db->createCommand($setsequence)->query();
                 $setidx = "ALTER INDEX {{{$toldtable}}}_idx RENAME TO {{{$tnewtable}}}_idx;";
                 $deactivateresult = Yii::app()->db->createCommand($setidx)->query();
             }
             $toldtable = "{{tokens_{$iSurveyID}}}";
             $tnewtable = "{{old_tokens_{$iSurveyID}_{$date}}}";
             $tdeactivateresult = Yii::app()->db->createCommand()->renameTable($toldtable, $tnewtable);
             $aData['tnewtable'] = $tnewtable;
             $aData['toldtable'] = $toldtable;
         }
         //Remove any survey_links to the CPDB
         Survey_links::model()->deleteLinksBySurvey($iSurveyID);
         // IF there are any records in the saved_control table related to this survey, they have to be deleted
         $result = Saved_control::model()->deleteSomeRecords(array('sid' => $iSurveyID));
         //Yii::app()->db->createCommand($query)->query();
         $sOldSurveyTableName = Yii::app()->db->tablePrefix . "survey_{$iSurveyID}";
         $sNewSurveyTableName = Yii::app()->db->tablePrefix . "old_survey_{$iSurveyID}_{$date}";
         $aData['sNewSurveyTableName'] = $sNewSurveyTableName;
         //Update the auto_increment value from the table before renaming
         $new_autonumber_start = 0;
         $query = "SELECT id FROM " . Yii::app()->db->quoteTableName($sOldSurveyTableName) . " ORDER BY id desc";
         $result = Yii::app()->db->createCommand($query)->limit(1)->query();
         foreach ($result->readAll() as $row) {
             if (strlen($row['id']) > 12) {
                 $part1 = substr($row['id'], 0, 12);
                 $part2len = strlen($row['id']) - 12;
                 $part2 = sprintf("%0{$part2len}d", substr($row['id'], 12, strlen($row['id']) - 12) + 1);
                 $new_autonumber_start = "{$part1}{$part2}";
             } else {
                 $new_autonumber_start = $row['id'] + 1;
             }
         }
         $condn = array('sid' => $iSurveyID);
         $insertdata = array('autonumber_start' => $new_autonumber_start);
         $survey = Survey::model()->findByAttributes($condn);
         $survey->autonumber_start = $new_autonumber_start;
         $survey->save();
         if (Yii::app()->db->getDrivername() == 'postgre') {
             $deactivateresult = Yii::app()->db->createCommand()->renameTable($sOldSurveyTableName . '_id_seq', $sNewSurveyTableName . '_id_seq');
             $setsequence = "ALTER TABLE {$newtable} ALTER COLUMN id SET DEFAULT nextval('{$sNewSurveyTableName}_id_seq'::regclass);";
             $deactivateresult = Yii::app()->db->createCommand($setsequence)->execute();
         }
         $deactivateresult = Yii::app()->db->createCommand()->renameTable($sOldSurveyTableName, $sNewSurveyTableName);
         $insertdata = array('active' => 'N');
         $survey->active = 'N';
         $survey->save();
         $prow = Survey::model()->find('sid = :sid', array(':sid' => $iSurveyID));
         if ($prow->savetimings == "Y") {
             $sOldTimingsTableName = Yii::app()->db->tablePrefix . "survey_{$iSurveyID}_timings";
             $sNewTimingsTableName = Yii::app()->db->tablePrefix . "old_survey_{$iSurveyID}_timings_{$date}";
             $deactivateresult2 = Yii::app()->db->createCommand()->renameTable($sOldTimingsTableName, $sNewTimingsTableName);
             $deactivateresult = $deactivateresult && $deactivateresult2;
             $aData['sNewTimingsTableName'] = $sNewTimingsTableName;
         }
         $aData['surveyid'] = $iSurveyID;
     }
     $this->_renderWrappedTemplate('survey', 'deactivateSurvey_view', $aData);
 }
コード例 #5
0
/**
 * Marks a tokens as completed and sends a confirmation email to the participiant.
 * If $quotaexit is set to true then the user exited the survey due to a quota
 * restriction and the according token is only marked as 'Q'
 *
 * @param mixed $quotaexit
 */
function submittokens($quotaexit = false)
{
    global $thissurvey;
    global $surveyid;
    global $clienttoken;
    $clang = Yii::app()->lang;
    $sitename = Yii::app()->getConfig("sitename");
    $emailcharset = Yii::app()->getConfig("emailcharset");
    // Shift the date due to global timeadjust setting
    $today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
    // check how many uses the token has left
    $usesquery = "SELECT usesleft, participant_id, tid FROM {{tokens_{$surveyid}}} WHERE token='" . $clienttoken . "'";
    $usesresult = dbExecuteAssoc($usesquery);
    $usesrow = $usesresult->read();
    if (isset($usesrow)) {
        $usesleft = $usesrow['usesleft'];
        $participant_id = $usesrow['participant_id'];
        $token_id = $usesrow['tid'];
    }
    $utquery = "UPDATE {{tokens_{$surveyid}}}\n";
    if ($quotaexit == true) {
        $utquery .= "SET completed='Q', usesleft=usesleft-1\n";
    } elseif (isTokenCompletedDatestamped($thissurvey)) {
        if (isset($usesleft) && $usesleft <= 1) {
            $utquery .= "SET usesleft=usesleft-1, completed='{$today}'\n";
            if (!empty($participant_id)) {
                //Update the survey_links table if necessary
                $slquery = Survey_links::model()->find('participant_id = "' . $participant_id . '" AND survey_id = ' . $surveyid . ' AND token_id = ' . $token_id);
                $slquery->date_completed = $today;
                $slquery->save();
            }
        } else {
            $utquery .= "SET usesleft=usesleft-1\n";
        }
    } else {
        if (isset($usesleft) && $usesleft <= 1) {
            $utquery .= "SET usesleft=usesleft-1, completed='Y'\n";
            if (!empty($participant_id)) {
                //Update the survey_links table if necessary, to protect anonymity, use the date_created field date
                $slquery = Survey_links::model()->find('participant_id = "' . $participant_id . '" AND survey_id = ' . $surveyid . ' AND token_id = ' . $token_id);
                $slquery->date_completed = $slquery->date_created;
                $slquery->save();
            }
        } else {
            $utquery .= "SET usesleft=usesleft-1\n";
        }
    }
    $utquery .= "WHERE token='" . $clienttoken . "'";
    $utresult = dbExecuteAssoc($utquery) or safeDie("Couldn't update tokens table!<br />\n{$utquery}<br />\n");
    //Checked
    if ($quotaexit == false) {
        // TLR change to put date into sent and completed
        $cnfquery = "SELECT * FROM {{tokens_{$surveyid}}} WHERE token='" . $clienttoken . "' AND completed!='N' AND completed!=''";
        $cnfresult = dbExecuteAssoc($cnfquery);
        //Checked
        $cnfrow = $cnfresult->read();
        if (isset($cnfrow)) {
            $from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
            $to = $cnfrow['email'];
            $subject = $thissurvey['email_confirm_subj'];
            $fieldsarray["{ADMINNAME}"] = $thissurvey['adminname'];
            $fieldsarray["{ADMINEMAIL}"] = $thissurvey['adminemail'];
            $fieldsarray["{SURVEYNAME}"] = $thissurvey['name'];
            $fieldsarray["{SURVEYDESCRIPTION}"] = $thissurvey['description'];
            $fieldsarray["{FIRSTNAME}"] = $cnfrow['firstname'];
            $fieldsarray["{LASTNAME}"] = $cnfrow['lastname'];
            $fieldsarray["{TOKEN}"] = $clienttoken;
            $attrfieldnames = getAttributeFieldNames($surveyid);
            foreach ($attrfieldnames as $attr_name) {
                $fieldsarray["{" . strtoupper($attr_name) . "}"] = $cnfrow[$attr_name];
            }
            $dateformatdatat = getDateFormatData($thissurvey['surveyls_dateformat']);
            $numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']);
            $fieldsarray["{EXPIRY}"] = convertDateTimeFormat($thissurvey["expiry"], 'Y-m-d H:i:s', $dateformatdatat['phpdate']);
            $subject = ReplaceFields($subject, $fieldsarray, true);
            $subject = html_entity_decode($subject, ENT_QUOTES, $emailcharset);
            if (getEmailFormat($surveyid) == 'html') {
                $ishtml = true;
            } else {
                $ishtml = false;
            }
            if (trim(strip_tags($thissurvey['email_confirm'])) != "" && $thissurvey['sendconfirmation'] == "Y") {
                $message = $thissurvey['email_confirm'];
                $message = ReplaceFields($message, $fieldsarray, true);
                if (!$ishtml) {
                    $message = strip_tags(breakToNewline(html_entity_decode($message, ENT_QUOTES, $emailcharset)));
                } else {
                    $message = html_entity_decode($message, ENT_QUOTES, $emailcharset);
                }
                //Only send confirmation email if there is a valid email address
                if (validateEmailAddress($cnfrow['email'])) {
                    SendEmailMessage($message, $subject, $to, $from, $sitename, $ishtml);
                }
            } else {
                //There is nothing in the message or "Send confirmation emails" is set to "No" , so don't send a confirmation email
                //This section only here as placeholder to indicate new feature :-)
            }
        }
    }
}
コード例 #6
0
ファイル: tokens.php プロジェクト: rawaludin/LimeSurvey
 /**
  * Show dialogs and create a new tokens table
  */
 function _newtokentable($iSurveyId)
 {
     $clang = $this->getController()->lang;
     Yii::import('application.helpers.admin.token_helper', true);
     if (Yii::app()->request->getPost('createtable') == "Y" && hasSurveyPermission($iSurveyId, 'surveyactivation', 'update')) {
         createTokenTable($iSurveyId);
         $this->_renderWrappedTemplate('token', array('message' => array('title' => $clang->gT("Token control"), 'message' => $clang->gT("A token table has been created for this survey.") . " (\"" . Yii::app()->db->tablePrefix . "tokens_{$iSurveyId}\")<br /><br />\n" . "<input type='submit' value='" . $clang->gT("Continue") . "' onclick=\"window.open('" . $this->getController()->createUrl("admin/tokens/index/surveyid/{$iSurveyId}") . "', '_top')\" />\n")));
     } elseif (returnGlobal('restoretable') == "Y" && Yii::app()->request->getPost('oldtable') && hasSurveyPermission($iSurveyId, 'surveyactivation', 'update')) {
         //Rebuild attributedescription value for the surveys table
         $table = Yii::app()->db->schema->getTable(Yii::app()->request->getPost('oldtable'));
         $fields = array_filter(array_keys($table->columns), 'filterForAttributes');
         foreach ($fields as $fieldname) {
             $name = $fieldname;
             if ($fieldname[10] == 'c') {
                 //This belongs to a cpdb attribute
                 $cpdbattid = substr($fieldname, 15);
                 $data = ParticipantAttributeNames::model()->getAttributeName($cpdbattid, Yii::app()->session['adminlang']);
                 $name = $data['attribute_name'];
             }
             $fieldcontents[$fieldname] = array('description' => $name, 'mandatory' => 'N', 'show_register' => 'N');
         }
         Survey::model()->updateByPk($iSurveyId, array('attributedescriptions' => serialize($fieldcontents)));
         Yii::app()->db->createCommand()->renameTable(Yii::app()->request->getPost('oldtable'), Yii::app()->db->tablePrefix . "tokens_" . intval($iSurveyId));
         //Add any survey_links from the renamed table
         Survey_links::model()->rebuildLinksFromTokenTable($iSurveyId);
         $this->_renderWrappedTemplate('token', array('message' => array('title' => $clang->gT("Import old tokens"), 'message' => $clang->gT("A token table has been created for this survey and the old tokens were imported.") . " (\"" . Yii::app()->db->tablePrefix . "tokens_{$iSurveyId}" . "\")<br /><br />\n" . "<input type='submit' value='" . $clang->gT("Continue") . "' onclick=\"window.open('" . $this->getController()->createUrl("admin/tokens/index/surveyid/{$iSurveyId}") . "', '_top')\" />\n")));
         LimeExpressionManager::SetDirtyFlag();
         // so that knows that token tables have changed
     } else {
         $this->getController()->loadHelper('database');
         $result = Yii::app()->db->createCommand(dbSelectTablesLike("{{old_tokens_" . intval($iSurveyId) . "_%}}"))->queryAll();
         $tcount = count($result);
         if ($tcount > 0) {
             foreach ($result as $rows) {
                 $oldlist[] = reset($rows);
             }
             $aData['oldlist'] = $oldlist;
         }
         $thissurvey = getSurveyInfo($iSurveyId);
         $aData['thissurvey'] = $thissurvey;
         $aData['surveyid'] = $iSurveyId;
         $aData['tcount'] = $tcount;
         $aData['databasetype'] = Yii::app()->db->getDriverName();
         $this->_renderWrappedTemplate('token', 'tokenwarning', $aData);
     }
 }
コード例 #7
0
 /**
  * Deletes a survey and all its data
  *
  * @access public
  * @param int $iSurveyID
  * @param bool @recursive
  * @return void
  */
 public function deleteSurvey($iSurveyID, $recursive = true)
 {
     Survey::model()->deleteByPk($iSurveyID);
     if ($recursive == true) {
         if (tableExists("{{survey_" . intval($iSurveyID) . "}}")) {
             Yii::app()->db->createCommand()->dropTable("{{survey_" . intval($iSurveyID) . "}}");
         }
         if (tableExists("{{survey_" . intval($iSurveyID) . "_timings}}")) {
             Yii::app()->db->createCommand()->dropTable("{{survey_" . intval($iSurveyID) . "_timings}}");
         }
         if (tableExists("{{tokens_" . intval($iSurveyID) . "}}")) {
             Yii::app()->db->createCommand()->dropTable("{{tokens_" . intval($iSurveyID) . "}}");
         }
         $oResult = Questions::model()->findAllByAttributes(array('sid' => $iSurveyID));
         foreach ($oResult as $aRow) {
             Answers::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
             Conditions::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
             Question_attributes::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
             Defaultvalues::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
         }
         Questions::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         Assessment::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         Groups::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         Surveys_languagesettings::model()->deleteAllByAttributes(array('surveyls_survey_id' => $iSurveyID));
         Survey_permissions::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         Saved_control::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         Survey_url_parameters::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
         //Remove any survey_links to the CPDB
         Survey_links::model()->deleteLinksBySurvey($iSurveyID);
         Quota::model()->deleteQuota(array('sid' => $iSurveyID), true);
     }
 }
コード例 #8
0
 /**
  * This function deletes the participant from the participants table,           
  * references in the survey_links table (but not in matching tokens tables)
  * and then all the participants attributes.
  * @param $rows Participants ID separated by comma
  * @return void
  **/
 function deleteParticipants($rows, $bFilter = true)
 {
     // Converting the comma separated IDs to an array and assign chunks of 100 entries to have a reasonable query size
     $aParticipantsIDChunks = array_chunk(explode(",", $rows), 100);
     foreach ($aParticipantsIDChunks as $aParticipantsIDs) {
         if ($bFilter) {
             $aParticipantsIDs = $this->filterParticipantIDs($aParticipantsIDs);
         }
         Yii::app()->db->createCommand()->delete(Participants::model()->tableName(), array('in', 'participant_id', $aParticipantsIDs));
         // Delete survey links
         Yii::app()->db->createCommand()->delete(Survey_links::model()->tableName(), array('in', 'participant_id', $aParticipantsIDs));
         // Delete participant attributes
         Yii::app()->db->createCommand()->delete(Participant_attribute::model()->tableName(), array('in', 'participant_id', $aParticipantsIDs));
     }
 }