From 1033109b1642ede8bc23397b33f67360a56c274f Mon Sep 17 00:00:00 2001 From: jcleeland Date: Mon, 16 Apr 2012 16:13:48 +1000 Subject: [PATCH] Fixed issue: various fixes relating to searches of the participants database using survey links (ie: qty of surveys) New feature: search participants database for participants who are linked to a particular survey by name --- .../controllers/admin/participantsaction.php | 15 +- application/models/Participants.php | 174 ++++++++++++++++-- .../participants/displayParticipants_view.php | 56 +++--- scripts/admin/displayParticipant.js | 6 +- 4 files changed, 204 insertions(+), 47 deletions(-) diff --git a/application/controllers/admin/participantsaction.php b/application/controllers/admin/participantsaction.php index 4ab28aa4f72..0f8668f4588 100644 --- a/application/controllers/admin/participantsaction.php +++ b/application/controllers/admin/participantsaction.php @@ -469,7 +469,7 @@ function getSurveyInfo_json() foreach ($records as $row) { $surveyname = Surveys_languagesettings::getSurveyNames($row['survey_id']); - $aData->rows[$i]['cell'] = array($surveyname[0]['surveyls_title'], '' . $row['survey_id'], $row['token_id'], $row['date_created']); + $aData->rows[$i]['cell'] = array($surveyname[0]['surveyls_title'], '' . $row['survey_id'], $row['token_id'], $row['date_created']); $i++; } @@ -658,15 +658,20 @@ function getaddtosurveymsg() } /** - * Gets the ids of participants to be copied to the indivisual survey + * Gets the ids of participants to be copied to the individual survey */ function getSearchIDs() { $searchcondition = basename(Yii::app()->request->getPost('searchcondition')); // get the search condition from the URL + /* a search contains posted data inside $_POST['searchcondition']. + * Each seperate query is made up of 3 fields, seperated by double-pipes ("|") + * EG: fname||eq||jason||lname||ct||c + * + */ if ($searchcondition != 'getParticipants_json') // if there is a search condition present { $participantid = ""; - $condition = explode("||", $searchcondition); // explode the condition to teh array + $condition = explode("||", $searchcondition); // explode the condition to the array // format for the condition is field||condition||value if (count($condition) == 3) // if count is 3 , then it's a single search { @@ -808,7 +813,8 @@ function exporttocsv() function getParticipantsResults_json() { - ///admin/participants/getParticipantsResults_json/search/email||contain||com + ///admin/participants/getParticipantsResults_json/search/email||contains||com + //Possible methods: equal,contains,notequal,notcontains,greaterthan,lessthan //First entry is field to search, second method, third value, seperated by double pipe "||" $page = Yii::app()->request->getPost('page'); $limit = Yii::app()->request->getPost('rows'); @@ -822,6 +828,7 @@ function getParticipantsResults_json() if (Yii::app()->session['USER_RIGHT_SUPERADMIN']) { $searchcondition = Yii::app()->request->getQuery('search'); + $searchcondition = urldecode($searchcondition); $finalcondition = array(); $condition = explode("||", $searchcondition); diff --git a/application/models/Participants.php b/application/models/Participants.php index effe9fbe983..d0f270e472d 100644 --- a/application/models/Participants.php +++ b/application/models/Participants.php @@ -160,7 +160,13 @@ function updateRow($data) function getParticipantsOwner($userid) { - return Yii::app()->db->createCommand()->select('{{participants}}.*,{{participant_shares}}.can_edit')->from('{{participants}}')->leftJoin('{{participant_shares}}', ' {{participants}}.participant_id={{participant_shares}}.participant_id')->where('owner_uid = :userid OR share_uid = ' . $userid)->group('{{participants}}.participant_id')->bindParam(":userid", $userid, PDO::PARAM_INT)->queryAll(); + return Yii::app()->db->createCommand() + ->select('{{participants}}.*,{{participant_shares}}.can_edit') + ->from('{{participants}}')->leftJoin('{{participant_shares}}', ' {{participants}}.participant_id={{participant_shares}}.participant_id') + ->where('owner_uid = :userid OR share_uid = ' . $userid) + ->group('{{participants}}.participant_id') + ->bindParam(":userid", $userid, PDO::PARAM_INT) + ->queryAll(); } function getParticipantsOwnerCount($userid) @@ -282,6 +288,7 @@ function deleteParticipantTokenAnswer($rows) function getParticipantsSearch($condition, $page, $limit) { + $lang = Yii::app()->session['adminlang']; $start = $limit * $page - $limit; if ($condition[1] == 'equal') { @@ -290,15 +297,22 @@ function getParticipantsSearch($condition, $page, $limit) $resultarray = array(); if ($page == 0 && $limit == 0) { - $data = Yii::app()->db->createCommand()->select('*')->from('{{participants}}')->queryAll(); + $data = Yii::app()->db->createCommand() + ->select('*') + ->from('{{participants}}') + ->queryAll(); } else { - $data = Yii::app()->db->createCommand()->select('*')->from('{{participants}}')->limit(intval($limit), $start)->queryAll(); + $data = Yii::app()->db->createCommand() + ->select('*') + ->from('{{participants}}') + ->limit(intval($limit), $start) + ->queryAll(); } foreach ($data as $key => $value) { - $count = count(Yii::app()->db->createCommand()->where('participant_id = :participant_id')->from('{{survey_links}}')->select('*')->bindParam(":participant_id", $value['participant_id'], PDO::PARAM_INT)->queryAll()); + $count = Participants::getSurveyCount($value['participant_id']); if ($count == $condition[2]) { array_push($resultarray, $value); @@ -306,6 +320,33 @@ function getParticipantsSearch($condition, $page, $limit) } return $resultarray; } + else if ($condition[0] == 'survey') //Searching survey by name or SID + { + if($page ==0 && $limit == 0) + { + $data = Yii::app()->db->createCommand() + ->select('{{participants}}.*, {{surveys_languagesettings}}.surveyls_title') + ->from('{{participants}}') + ->join('{{survey_links}}', '{{participants}}.participant_id={{survey_links}}.participant_id') + ->join('{{surveys_languagesettings}}', '{{survey_links}}.survey_id={{surveys_languagesettings}}.surveyls_survey_id') + ->where('{{surveys_languagesettings}}.surveyls_language=:lang AND {{surveys_languagesettings}}.surveyls_title = :param2') + ->bindParam(":lang", $lang, PDO::PARAM_STR) + ->bindParam(":param2", $condition[2], PDO::PARAM_STR) + ->queryAll(); + } else { + $data = Yii::app()->db->createCommand() + ->select('{{participants}}.*, {{surveys_languagesettings}}.surveyls_title') + ->from('{{participants}}') + ->join('{{survey_links}}', '{{participants}}.participant_id={{survey_links}}.participant_id') + ->join('{{surveys_languagesettings}}', '{{survey_links}}.survey_id={{surveys_languagesettings}}.surveyls_survey_id') + ->where('{{surveys_languagesettings}}.surveyls_language=:lang AND {{surveys_languagesettings}}.surveyls_title = :param2') + ->limit(intval($limit), $start) + ->bindParam(":lang", $lang, PDO::PARAM_STR) + ->bindParam(":param2", $condition[2], PDO::PARAM_STR) + ->queryAll(); + } + return $data; + } else if ($condition[0] == 'owner_name') { $userid = Yii::app()->db->createCommand()->select('uid')->where('full_name = :condition_2')->from('{{users}}')->bindParam("condition_2", $condition[2], PDO::PARAM_STR)->queryAll(); @@ -369,7 +410,7 @@ function getParticipantsSearch($condition, $page, $limit) } foreach ($data as $key => $value) { - $count = count(Yii::app()->db->createCommand()->where('participant_id = :participiant_id')->from('{{survey_links}}')->bindParam(":participant_id", $value['participant_id'], PDO::PARAM_INT)->queryAll()); + $count = Participants::getSurveyCount($value['participant_id']); if ($count == $condition[2]) { array_push($resultarray, $value); @@ -377,6 +418,34 @@ function getParticipantsSearch($condition, $page, $limit) } return $resultarray; } + else if ($condition[0] == 'survey') //Searching survey by name or SID + { + $param2="%".$condition[2]."%"; + if($page ==0 && $limit == 0) + { + $data = Yii::app()->db->createCommand() + ->select('{{participants}}.*, {{surveys_languagesettings}}.surveyls_title') + ->from('{{participants}}') + ->join('{{survey_links}}', '{{participants}}.participant_id={{survey_links}}.participant_id') + ->join('{{surveys_languagesettings}}', '{{survey_links}}.survey_id={{surveys_languagesettings}}.surveyls_survey_id') + ->where('{{surveys_languagesettings}}.surveyls_language=:lang AND ({{surveys_languagesettings}}.surveyls_title LIKE :param2 OR {{survey_links}}.survey_id LIKE :param2)') + ->bindParam(":lang", $lang, PDO::PARAM_STR) + ->bindParam(":param2", $param2, PDO::PARAM_STR) + ->queryAll(); + } else { + $data = Yii::app()->db->createCommand() + ->select('{{participants}}.*, {{surveys_languagesettings}}.surveyls_title') + ->from('{{participants}}') + ->join('{{survey_links}}', '{{participants}}.participant_id={{survey_links}}.participant_id') + ->join('{{surveys_languagesettings}}', '{{survey_links}}.survey_id={{surveys_languagesettings}}.surveyls_survey_id') + ->where('{{surveys_languagesettings}}.surveyls_language=:lang AND ({{surveys_languagesettings}}.surveyls_title LIKE :param2 OR {{survey_links}}.survey_id LIKE :param2)') + ->limit(intval($limit), $start) + ->bindParam(":lang", $lang, PDO::PARAM_STR) + ->bindParam(":param2", $param2, PDO::PARAM_STR) + ->queryAll(); + } + return $data; + } else if ($condition[0] == 'owner_name') { $userid = $command = Yii::app()->db->createCommand()->select('uid')->where(array('like', 'full_name', $condition[2]))->from('{{users}}')->queryAll(); @@ -435,7 +504,7 @@ function getParticipantsSearch($condition, $page, $limit) } foreach ($data as $key => $value) { - $count = count(Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = :participant_id')->bindParam(":participant_id", $value['participant_id'], PDO::PARAM_INT)->queryAll()); + $count = Participants::getSurveyCount($value['participant_id']); if ($count != $condition[2]) { array_push($resultarray, $value); @@ -443,6 +512,33 @@ function getParticipantsSearch($condition, $page, $limit) } return $resultarray; } + else if ($condition[0] == 'survey') //Searching survey by name or SID + { + if($page ==0 && $limit == 0) + { + $data = Yii::app()->db->createCommand() + ->select('{{participants}}.*, {{surveys_languagesettings}}.surveyls_title') + ->from('{{participants}}') + ->join('{{survey_links}}', '{{participants}}.participant_id={{survey_links}}.participant_id') + ->join('{{surveys_languagesettings}}', '{{survey_links}}.survey_id={{surveys_languagesettings}}.surveyls_survey_id') + ->where('{{surveys_languagesettings}}.surveyls_language=:lang AND {{surveys_languagesettings}}.surveyls_title != :param2') + ->bindParam(":lang", $lang, PDO::PARAM_STR) + ->bindParam(":param2", $condition[2], PDO::PARAM_STR) + ->queryAll(); + } else { + $data = Yii::app()->db->createCommand() + ->select('{{participants}}.*, {{surveys_languagesettings}}.surveyls_title') + ->from('{{participants}}') + ->join('{{survey_links}}', '{{participants}}.participant_id={{survey_links}}.participant_id') + ->join('{{surveys_languagesettings}}', '{{survey_links}}.survey_id={{surveys_languagesettings}}.surveyls_survey_id') + ->where('{{surveys_languagesettings}}.surveyls_language=:lang AND {{surveys_languagesettings}}.surveyls_title != :param2') + ->limit(intval($limit), $start) + ->bindParam(":lang", $lang, PDO::PARAM_STR) + ->bindParam(":param2", $condition[2], PDO::PARAM_STR) + ->queryAll(); + } + return $data; + } else if ($condition[0] == 'owner_name') { @@ -503,7 +599,7 @@ function getParticipantsSearch($condition, $page, $limit) } foreach ($data as $key => $value) { - $count = count(Yii::app()->db->createCommand()->where('participant_id = :participant_id')->from('{{survey_links}}')->select('*')->bindParam(":participant_id", $value['participant_id'], PDO::PARAM_INT)->queryAll()); + $count = Participants::getSurveyCount($value['participant_id']); if ($count != $condition[2]) { array_push($resultarray, $value); @@ -511,6 +607,34 @@ function getParticipantsSearch($condition, $page, $limit) } return $resultarray; } + else if ($condition[0] == 'survey') //Searching survey by name or SID + { + $param2="%".$condition[2]."%"; + if($page ==0 && $limit == 0) + { + $data = Yii::app()->db->createCommand() + ->select('{{participants}}.*, {{surveys_languagesettings}}.surveyls_title') + ->from('{{participants}}') + ->join('{{survey_links}}', '{{participants}}.participant_id={{survey_links}}.participant_id') + ->join('{{surveys_languagesettings}}', '{{survey_links}}.survey_id={{surveys_languagesettings}}.surveyls_survey_id') + ->where('{{surveys_languagesettings}}.surveyls_language=:lang AND {{surveys_languagesettings}}.surveyls_title NOT LIKE :param2') + ->bindParam(":lang", $lang, PDO::PARAM_STR) + ->bindParam(":param2", $param2, PDO::PARAM_STR) + ->queryAll(); + } else { + $data = Yii::app()->db->createCommand() + ->select('{{participants}}.*, {{surveys_languagesettings}}.surveyls_title') + ->from('{{participants}}') + ->join('{{survey_links}}', '{{participants}}.participant_id={{survey_links}}.participant_id') + ->join('{{surveys_languagesettings}}', '{{survey_links}}.survey_id={{surveys_languagesettings}}.surveyls_survey_id') + ->where('{{surveys_languagesettings}}.surveyls_languages=:lang AND {{surveys_languagesettings}}.surveyls_title NOT LIKE :param2') + ->limit(intval($limit), $start) + ->bindParam(":lang", $lang, PDO::PARAM_STR) + ->bindParam(":param2", $param2, PDO::PARAM_STR) + ->queryAll(); + } + return $data; + } else if ($condition[0] == 'owner_name') { $userid = Yii::app()->db->createCommand()->select('uid')->where(array('not like', 'full_name', $condition[2]))->from('{{users}}')->queryAll(); @@ -555,22 +679,29 @@ function getParticipantsSearch($condition, $page, $limit) } else if ($condition[1] == 'greaterthan') { - if ($condition[0] == 'surveys') + if ($condition[0] == 'surveys') //This is a search using a count of surveys, not the name or SID { $resultarray = array(); + if ($page == 0 && $limit == 0) { - $data = $this->db->get('participants'); + $data = Yii::app()->db->createCommand() + ->select('{{participants.participant_id}}, count(*) as surveycount') + ->from('{{participants}}') + ->queryAll(); } else { - $data = $this->db->get('participants', $limit, $start); + $data = Yii::app()->db->createCommand() + ->select('*') + ->from('{{participants}}') + ->limit($limit, $start) + ->queryAll(); + } - foreach ($data->result_array() as $key => $value) + foreach ($data as $key => $value) { - $this->db->where('participant_id=:participant_id')->bindParam(":participant_id", $value['participant_id'], PDO::PARAM_INT); - $this->db->from('survey_links'); - $count = $this->db->count_all_results(); + $count = Participants::getSurveyCount($value['participant_id']); if ($count > $condition[2]) { array_push($resultarray, $value); @@ -628,15 +759,21 @@ function getParticipantsSearch($condition, $page, $limit) if ($page == 0 && $limit == 0) { - $data = Yii::app()->db->createCommand()->select('*')->from('{{participants}}')->queryAll(); + $data = Yii::app()->db->createCommand() + ->select('*') + ->from('{{participants}}') + ->queryAll(); } else { - $data = Yii::app()->db->createCommand()->select('*')->from('{{participants}}')->limit($limit, $start)->queryAll(); + $data = Yii::app()->db->createCommand()->select('*') + ->from('{{participants}}') + ->limit($limit, $start) + ->queryAll(); } foreach ($data as $key => $value) { - $count = count(Yii::app()->db->createCommand()->where('participant_id = :participant_id')->bindParam(":participant_id", $value['participant_id'], PDO::PARAM_INT)->from('{{survey_links}}')->select('*')->queryAll()); + $count = Participants::getSurveyCount($value['participant_id']); if ($count < $condition[2]) { array_push($resultarray, $value); @@ -689,6 +826,9 @@ function getParticipantsSearch($condition, $page, $limit) return $data; } } + else { + return array(); + } } function getParticipantsSearchMultiple($condition, $page, $limit) diff --git a/application/views/admin/participants/displayParticipants_view.php b/application/views/admin/participants/displayParticipants_view.php index 97a347121d7..f3a9f58d484 100644 --- a/application/views/admin/participants/displayParticipants_view.php +++ b/application/views/admin/participants/displayParticipants_view.php @@ -62,7 +62,8 @@ var firstnameTxt="eT("First name") ?>"; var lastnameTxt="eT("Last name") ?>"; var blacklistedTxt="eT("Blacklisted") ?>"; - var surveysTxt="et("Surveys") ?>"; + var surveysTxt="eT("Survey Links") ?>"; + var surveyTxt="eT("Survey Name") ?>"; var languageTxt="eT("Language") ?>"; var owneridTxt="eT("Owner ID") ?>"; var ownernameTxt="eT("Owner name") ?>"; @@ -82,6 +83,7 @@ var surveyIdColTxt="eT("Survey ID") ?>"; var tokenIdColTxt="eT("Token ID") ?>"; var dateAddedColTxt="eT("Date added") ?>"; + var surveylinkUrl = "getController()->createUrl("admin/participants/getSurveyInfo_json/pid/"); ?>"; /* Colnames and heading for attributes subgrid */ var attributesHeadingTxt="eT("Participant's attribute information") ?>"; @@ -129,7 +131,6 @@ var minusbutton = "getRequest()->getBaseUrl() . "/images/deleteanswer.png" ?>"; var addbutton = "getRequest()->getBaseUrl() . "/images/plus.png" ?>"; var delparticipantUrl = "getController()->createUrl("admin/participants/delParticipant"); ?>"; - var surveylinkUrl = "getController()->createUrl("admin/participants/getSurveyInfo_json/pid/"); ?>"; var getAttribute_json = "getController()->createUrl("admin/participants/getAttribute_json/pid/"); ?>"; var exporttocsv = "getController()->createUrl("admin/participants/exporttocsv/id"); ?>"; var exporttocsvcount = "getController()->createUrl("admin/participants/exporttocsvcount"); ?>"; @@ -164,7 +165,8 @@ 'lastname' => $clang->gT("Last name"), 'email' => $clang->gT("Email"), 'blacklisted' => $clang->gT("Blacklisted"), - 'surveys' => $clang->gT("Surveys"), + 'surveys' => $clang->gT("Survey Links"), + 'survey' => $clang->gT("Survey Name"), 'language' => $clang->gT("Language"), 'owner_uid' => $clang->gT("Owner ID"), 'owner_name' => $clang->gT("Owner name")); @@ -260,38 +262,40 @@
-

- eT("Select the survey to which participants are to be added"); ?> -

+

+ eT("Survey:"); ?> +

gT("Select..."); + //$option[''] = $clang->gT("Select..."); foreach ($surveynames as $row) { $option[$row['surveyls_survey_id']] = $row['surveyls_title']; } - echo CHtml::dropDownList('survey_id', 'id="survey_id"', $option); + echo CHtml::listBox('survey_id', 'id="survey_id"', $option, array('style'=>'width: 350px', 'size'=>3)); } ?>

-

- eT("Select which participants to add to the selected survey"); ?> -

+

+ eT("Participants to add:"); ?> +

    -
  1. eT("all participants in current search") ?>
  2. -
  3. eT("all participants") ?>
  4. -
  5. eT("only the participants I have selected") ?>
  6. +
  7. eT("all participants in current search") ?>
  8. +
  9. eT("all participants") ?>
  10. +
  11. eT("only the participants I have selected") ?>
+

+ eT("Options:") ?> +

- eT("Display survey token table after adding participants?"); ?> 'redirect', @@ -301,6 +305,7 @@ echo CHtml::checkBox('redirect', TRUE, $data); ?> +

@@ -311,13 +316,16 @@ + diff --git a/scripts/admin/displayParticipant.js b/scripts/admin/displayParticipant.js index d61f3b55698..c0c26aad8bc 100644 --- a/scripts/admin/displayParticipant.js +++ b/scripts/admin/displayParticipant.js @@ -15,6 +15,7 @@ function addcondition(newcid) \n\ \n\ \n\ + \n\ \n\ \n\ "+optionstring+"\n\ @@ -73,6 +74,7 @@ $(document).ready(function() { \n\ \n\ \n\ + \n\ \n\ \n\ "+optionstring+"\n\ @@ -341,7 +343,7 @@ $(document).ready(function() { caption:"", title: fullSearchTitle, buttonicon:'searchicon', - onClickButton:function(){ + onClickButton:function(){ var dialog_buttons={}; dialog_buttons[searchBtn]=function(){ searchconditions=""; @@ -392,7 +394,7 @@ $(document).ready(function() { }); } }}).trigger("reloadGrid"); - + $(this).dialog("close"); } }; dialog_buttons[cancelBtn]=function(){