Skip to content

Commit

Permalink
Fixed issue: various fixes relating to searches of the participants d…
Browse files Browse the repository at this point in the history
…atabase using survey links (ie: qty of surveys)

New feature: search participants database for participants who are linked to a particular survey by name
  • Loading branch information
jcleeland committed Apr 16, 2012
1 parent 52b114a commit 1033109
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 47 deletions.
15 changes: 11 additions & 4 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -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'], '<a href=' . Yii::app()->getController()->createUrl("/admin/tokens/browse/{$row['survey_id']}") . '>' . $row['survey_id'], $row['token_id'], $row['date_created']);
$aData->rows[$i]['cell'] = array($surveyname[0]['surveyls_title'], '<a href=' . Yii::app()->getController()->createUrl("/admin/tokens/browse/surveyid/{$row['survey_id']}") . '>' . $row['survey_id'], $row['token_id'], $row['date_created']);
$i++;
}

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand Down
174 changes: 157 additions & 17 deletions application/models/Participants.php
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
{
Expand All @@ -290,22 +297,56 @@ 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);
}
}
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();
Expand Down Expand Up @@ -369,14 +410,42 @@ 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);
}
}
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();
Expand Down Expand Up @@ -435,14 +504,41 @@ 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);
}
}
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')
{

Expand Down Expand Up @@ -503,14 +599,42 @@ 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);
}
}
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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -689,6 +826,9 @@ function getParticipantsSearch($condition, $page, $limit)
return $data;
}
}
else {
return array();
}
}

function getParticipantsSearchMultiple($condition, $page, $limit)
Expand Down

0 comments on commit 1033109

Please sign in to comment.