Changeset 2c1f52d in iPeer


Ignore:
Timestamp:
2012-12-20T17:53:56-08:00 (6 years ago)
Author:
John Hsu <john.hsu@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
169cf4dd
Parents:
b4b7b9f
git-author:
John Hsu <john.hsu@…> (12/18/2012 06:54:09 PM)
git-committer:
John Hsu <john.hsu@…> (12/20/2012 05:53:56 PM)
Message:

Change SurveyInput?'s survey_id to event_id.

Since each survey submission should be paired with the event, not the
template.

I've changed all the SurveyInput? model functions to expect event id
instead of survey id to match. Also removed larged blocks of code that
were calling survey_input model functions. Since those blocks seem to
have been there for a while, I'm assuming people have forgotten what
they do anyways.

Still need to go through all calls to SurveyInput? to see if there are
any lingering manipulations of SurveyInput? data that hard codes
survey_id.

Also need to check that survey submissions are still going through.

Location:
app
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • app/config/sql/ipeer.sql

    rb4b7b9f r2c1f52d  
    952952CREATE TABLE IF NOT EXISTS `survey_inputs` (
    953953  `id` int(11) NOT NULL AUTO_INCREMENT,
    954   `survey_id` int(11) NOT NULL DEFAULT '0',
     954  `event_id` int(11) NOT NULL DEFAULT '0',
    955955  `user_id` int(11) NOT NULL DEFAULT '0',
    956956  `question_id` int(11) NOT NULL DEFAULT '0',
  • app/config/sql/ipeer_samples_data.sql

    rb4b7b9f r2c1f52d  
    14051405CREATE TABLE IF NOT EXISTS `survey_inputs` (
    14061406  `id` int(11) NOT NULL AUTO_INCREMENT,
    1407   `survey_id` int(11) NOT NULL DEFAULT '0',
     1407  `event_id` int(11) NOT NULL DEFAULT '0',
    14081408  `user_id` int(11) NOT NULL DEFAULT '0',
    14091409  `question_id` int(11) NOT NULL DEFAULT '0',
     
    14191419--
    14201420
    1421 INSERT INTO survey_inputs (id, survey_id, user_id, question_id, sub_id, chkbx_id, response_text, response_id) VALUES
    1422 (1, 1, 7, 1, NULL, NULL, '4+', 1),
    1423 (2, 1, 7, 2, NULL, NULL, 'yes', 5),
    1424 (3, 1, 31, 1, NULL, NULL, '3-4', 2),
    1425 (4, 1, 31, 2, NULL, NULL, 'no', 6),
    1426 (5, 2, 17, 3, NULL, NULL, 'B', 8),
    1427 (6, 2, 17, 4, NULL, 0, 'choose me', 11),
    1428 (7, 2, 17, 4, NULL, 1, 'no, me', 12),
    1429 (8, 2, 17, 5, NULL, NULL, 'single line rah rah', 0),
    1430 (9, 2, 17, 6, NULL, NULL, 'long answer what what', 0);
     1421INSERT INTO survey_inputs (id, event_id, user_id, question_id, sub_id, chkbx_id, response_text, response_id) VALUES
     1422(1, 4, 7, 1, NULL, NULL, '4+', 1),
     1423(2, 4, 7, 2, NULL, NULL, 'yes', 5),
     1424(3, 4, 31, 1, NULL, NULL, '3-4', 2),
     1425(4, 4, 31, 2, NULL, NULL, 'no', 6),
     1426(5, 5, 17, 3, NULL, NULL, 'B', 8),
     1427(6, 5, 17, 4, NULL, 0, 'choose me', 11),
     1428(7, 5, 17, 4, NULL, 1, 'no, me', 12),
     1429(8, 5, 17, 5, NULL, NULL, 'single line rah rah', 0),
     1430(9, 5, 17, 6, NULL, NULL, 'long answer what what', 0);
    14311431
    14321432-- --------------------------------------------------------
  • app/controllers/components/evaluation.php

    rb4b7b9f r2c1f52d  
    17791779            return false;
    17801780        }
    1781     /*
    1782     // if no submission exists, create one
    1783     //$surveyInput['SurveyInput']['event_id'] = $params['form']['event_id'];
    1784     // save evaluation submission
    1785     //$surveyInput['SurveyInput']['date_submitted'] = date('Y-m-d H:i:s');
    1786 
    1787     //parse for question id and their response id/text
    1788     //then save
    1789     for ($i=1; $i < $params['form']['question_count']+1; $i++) {
    1790         $questionId = $params['form']['question_id'.$i];
    1791         if (isset($params['form']['answer_'.$i])) {
    1792             if (is_array($params['form']['answer_'.$i])) {
    1793                 if (!$this->SurveyInput->delAllSurveyInputBySurveyIdUserIdQuestionId($surveyId, $userId, $questionId)) {
    1794                     die('delete failed');
    1795                 }
    1796                 //parse answers for 'any choice' type
    1797                 for ($j=0; $j < count($params['form']['answer_'.$i]); $j++) {
    1798                     $surveyInput['SurveyInput']['user_id'] = $userId;
    1799                     $surveyInput['SurveyInput']['survey_id'] = $surveyId;
    1800                     $surveyInput['SurveyInput']['question_id'] = $questionId;
    1801 
    1802                     $answer = explode("_", $params['form']['answer_'.$i][$j]);
    1803                     $surveyInput['SurveyInput']['response_id'] = $answer[1];
    1804                     if (!$this->SurveyInput->save($surveyInput)) {
    1805                         return false;
    1806                     }
    1807                     $this->SurveyInput->id = null;
    1808                 }
    1809             } else {
    1810                 //get existing 'answer' record
    1811                 $surveyInput = $this->SurveyInput->getSurveyInputBySurveyIdUserIdQuestionId($surveyId, $userId, $questionId);
    1812 
    1813                 //if none exists fill in fields
    1814                 if (empty($surveyInput)) {
    1815                     $surveyInput['SurveyInput']['user_id'] = $userId;
    1816                     $surveyInput['SurveyInput']['survey_id'] = $surveyId;
    1817                 }
    1818                 $surveyInput['SurveyInput']['question_id'] = $questionId;
    1819 
    1820                 //check for MC
    1821                 $type = $this->Question->getTypeById($questionId);
    1822                 if ($type == 'M') {
    1823                     $answer = explode("_", $params['form']['answer_'.$i]);
    1824                     $surveyInput['SurveyInput']['response_id'] = $answer[1];
    1825                 } else {
    1826                     $surveyInput['SurveyInput']['response_text'] = $params['form']['answer_'.$i];
    1827                 }
    1828                 if (!$this->SurveyInput->save($surveyInput)) {
    1829                     return false;
    1830                 }
    1831                 $this->SurveyInput->id = null;
    1832             }
    1833         } else {
    1834             if (!$this->SurveyInput->delAllSurveyInputBySurveyIdUserIdQuestionId($surveyId, $userId, $questionId)) {
    1835             die('delete failed');
    1836             } else {
    1837                 if (!$this->SurveyInput->delAllSurveyInputBySurveyIdUserIdQuestionId($surveyId, $userId, $questionId)) {
    1838                     die('delete failed');
    1839                 }
    1840                 //parse answers for 'any choice' type
    1841                 $surveyInput['SurveyInput']['user_id'] = $userId;
    1842                 $surveyInput['SurveyInput']['survey_id'] = $surveyId;
    1843                 $surveyInput['SurveyInput']['question_id'] = $questionId;
    1844                 if (!$this->SurveyInput->save($surveyInput)) {
    1845                     return false;
    1846                 }
    1847                 $this->SurveyInput->id = null;
    1848             }
    1849         }
    1850     }
    1851     if (!$this->EvaluationSubmission->save($evaluationSubmission)) {
    1852         echo "this->EvaluationSubmission->save() returned false";
    1853         return false;
    1854     }
    1855     $this->EvaluationSubmission->id = null;
    1856     return true;
    1857      */
    18581781    }
    18591782
     
    19261849     * @return void
    19271850     */
    1928     function formatSurveyEvaluationResult($event=null, $studentId=null)
     1851    function formatSurveyEvaluationResult($event, $studentId=null)
    19291852    {
    19301853        $this->Survey = ClassRegistry::init('Survey');
     
    19361859        $result = array();
    19371860
    1938         $survey_id = $this->Survey->getSurveyIdByCourseIdTitle($event['Event']['course_id'], $event['Event']['title']);
     1861        $survey_id = $event['Event']['template_id'];
    19391862        $result['survey_id'] = $survey_id;
    19401863
     
    19561879            }
    19571880        }
    1958         $answers = $this->SurveyInput->getAllSurveyInputBySurveyIdUserId($survey_id, $studentId);
     1881        $answers = $this->SurveyInput->getByEventIdUserId(
     1882            $event['Event']['id'], $studentId);
    19591883
    19601884        $result['answers'] = $answers;
     
    19641888        return $result;
    19651889    }
    1966 
    1967 
    1968     /**
    1969      * formatSurveyGroupEvaluationResult
    1970      *
    1971      * @param bool $surveyId      survey id
    1972      * @param bool $surveyGroupId survey group id
    1973      *
    1974      * @access public
    1975      * @return void
    1976      */
    1977     function formatSurveyGroupEvaluationResult($surveyId=null, $surveyGroupId=null)
    1978     {
    1979         $this->Survey = ClassRegistry::init('Survey');
    1980         $this->SurveyQuestion = ClassRegistry::init('SurveyQuestion');
    1981         $this->Question = ClassRegistry::init('Question');
    1982         $this->Response = ClassRegistry::init('Response');
    1983         $this->SurveyInput = ClassRegistry::init('SurveyInput');
    1984         $this->User = ClassRegistry::init('User');
    1985 
    1986         // Get all required data from each table for every question
    1987         $surveyQuestion = new SurveyQuestion();
    1988         $tmp = $surveyQuestion->getQuestionsID($surveyId);
    1989         $tmp = $this->Question->fillQuestion($tmp);
    1990         $tmp = $this->Response->fillResponse($tmp);
    1991         $questions = null;
    1992 
    1993         // Sort the resultant array by question number
    1994         $count = 1;
    1995         for ($i=0; $i<=count($tmp); $i++) {
    1996             for ($j=0; $j<count($tmp); $j++) {
    1997                 if ($i == $tmp[$j]['Question']['number']) {
    1998                     $questions[$count]['Question'] = $tmp[$j]['Question'];
    1999                     $count++;
    2000                 }
    2001             }
    2002         }
    2003 
    2004         for ($i=1; $i < count($questions)+1; $i++) {
    2005             $questionType = $questions[$i]['Question']['type'];
    2006             $questionTypeAllowed = array('C', 'M');
    2007             $questionId = $questions[$i]['Question']['id'];
    2008 
    2009             //count the choice responses
    2010             if (in_array($questionType, $questionTypeAllowed)) {
    2011                 $totalResponsePerQuestion = 0;
    2012                 for ($j=0; $j < count($questions[$i]['Question']['Responses']); $j++) {
    2013                     $responseId = $questions[$i]['Question']['Responses']['response_'.$j]['id'];
    2014                     $answerCount = $this->SurveyInput->findCountInSurveyGroup($surveyId, $questionId, $responseId, $surveyGroupId);
    2015                     //echo $surveyId.';'.$questionId.' '.$responseId.' '.$surveyGroupId;
    2016                     //print_r($answerCount); die;
    2017                     $questions[$i]['Question']['Responses']['response_'.$j]['count'] = $answerCount;
    2018                     $totalResponsePerQuestion += $answerCount;
    2019                 }
    2020                 $questions[$i]['Question']['total_response'] = $totalResponsePerQuestion;
    2021             } else {
    2022                 $responses = $this->SurveyInput->findResponseInSurveyGroup($surveyId, $questionId, $surveyGroupId);
    2023                 $questions[$i]['Question']['Responses'] = array();
    2024                 //sort results by last name
    2025                 $tmpUserResponse = array();
    2026                 for ($j=0; $j < count($responses); $j++) {
    2027                     $responseText = $responses[$j]['SurveyInput']['response_text'];
    2028                     $userId = $responses[$j]['SurveyInput']['user_id'];
    2029                     $userName = $this->User->findById($userId);
    2030                     $userName = $userName['User']['full_name'];
    2031                     $tmpUserResponse[$userName]['response_text'] = $responseText;
    2032                 }
    2033                 ksort($tmpUserResponse);
    2034 
    2035                 $k=1;
    2036                 foreach ($tmpUserResponse as $username => $response) {
    2037                     $questions[$i]['Question']['Responses']['response_'.$k]['response_text'] = $response['response_text'];
    2038                     $questions[$i]['Question']['Responses']['response_'.$k]['user_name'] = $username;
    2039                     $k++;
    2040                 }
    2041             }
    2042         }
    2043 
    2044         return $questions;
    2045     }
    2046 
    20471890
    20481891    /**
  • app/controllers/components/xml_handler.php

    rb4b7b9f r2c1f52d  
    2121     * @return void
    2222     */
    23     function makeTeamMakerXML($survey, $numGroups, $weight)
     23    function makeTeamMakerXML($survey, $numGroups, $weight, $eventId)
    2424    {
    2525        if (phpversion() < 5) {
     
    7272                    $student->$appendChildFunc($response);
    7373
    74                     $responses = $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId($survey['Survey']['id'], $user['id'], $q['id']);
     74                    $responses = $this->SurveyInput->getBySurveyIdUserIdQuestionId($eventId, $user['id'], $q['id']);
    7575                    //print_r($responses);
    7676                    if (count($responses) != 0) {
     
    122122
    123123    /**
    124      * makeTMXml4
    125      *
    126      * @param mixed $survey    survey
    127      * @param mixed $numGroups number of groups
    128      * @param mixed $weight    weight
    129      *
    130      * @access public
    131      * @return void
    132      */
    133     /*function makeTMXml4($survey, $numGroups, $weight)
    134     {
    135         $this->SurveyInput = new SurveyInput;
    136         $this->Response = new Response;
    137         $this->User = new User;
    138 
    139         $doc = domxml_new_doc('1.0');
    140         //docroot
    141         $team_input = $doc->create_element('team_input');
    142         $team_input->set_attribute('num_groups', $numGroups);
    143         $doc->append_child($team_input);
    144         foreach ($survey['Question'] as $q) {
    145             if (in_array($q['type'], array('M', 'C'))) {
    146                 //questions
    147                 $question = $doc->create_element('question');
    148                 $question->set_attribute('id', $q['id']);
    149                 $question->set_attribute('type', ($q['type'] == 'C' ? 'CAO':'MC'));
    150                 $question->set_attribute('title', $q['prompt']);
    151                 $team_input->append_child($question);
    152 
    153                 //weight
    154                 $element_weight = $doc->create_element('weight');
    155                 $element_weight->set_attribute('value', $q['id']);
    156                 $question->append_child($element_weight);
    157             }
    158         }
    159         $courseId = $this->Session->read('ipeerSession.courseId');
    160         $userData = $this->User->getEnrolledStudents($courseId);
    161         //      print_r($userData);
    162         foreach ($userData as $user) {
    163             //students
    164             $student = $doc->create_element('student');
    165             $student->set_attribute('username', $user['User']['student_no']);
    166             $team_input->append_child($student);
    167 
    168             foreach ($survey['Question'] as $q) {
    169                 if (in_array($q['type'], array('M', 'C'))) {
    170                     //response
    171                     $response = $doc->create_element('response');
    172                     $response->set_attribute('q_id', $q['id']);
    173                     $response->set_attribute('type', ($q['type'] == 'C' ? 'CAO':'MC'));
    174                     $student->append_child($response);
    175 
    176                     $responses = $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId($survey['Survey']['id'], $user['User']['id'], $q['id']);
    177                     //print_r($responses);
    178                     if (count($responses) != 0) {
    179                         for ($j=0; $j < count($responses); $j++) {
    180                             $response_tmp = $responses[$j]['SurveyInput'];
    181                             if ($response_tmp['response_text']==null && $response_tmp['response_id']==null) {
    182                                 //response/answer
    183                                 $value = $doc->create_element('value');
    184                                 $value->set_attribute('id', $response_tmp['id']);
    185                                 $value->set_attribute('answer', 0);
    186                                 $response->append_child($value);
    187                             } elseif ($response_tmp['response_text']=='' || $response_tmp['response_text']==null) {
    188                                 //response/answer
    189                                 $value = $doc->create_element('value');
    190                                 $value->set_attribute('id', $response_tmp['id']);
    191                                 $value->set_attribute('answer', 1);
    192                                 $response->append_child($value);
    193                             } else {
    194                                 $mcResponse = explode('_', $response_tmp['response_text']);
    195                                 if (isset($mcResponse[1])) {
    196                                     $mcTmp = $this->Response->find('id='.$mcResponse[1]);
    197                                     if ($mcTmp['Response']['response']==$mcResponse[0]) {
    198                                         //response/answer
    199                                         $value = $doc->create_element('value');
    200                                         $value->set_attribute('id', $response_tmp['id']);
    201                                         //$value->setAttribute('answer',1);
    202                                         $response->append_child($value);
    203                                     }
    204                                 }
    205                             }
    206                         }
    207                     } else {
    208                         if ($type == 'MC') {
    209                             $value = $doc->create_element('value');
    210                             $value->set_attribute('id', '');
    211                             $response->append_child($value);
    212                         }
    213                     }
    214                 }
    215             }
    216         }
    217         return $doc->dump_mem(true);
    218     }*/
    219 
    220 
    221     /**
    222      * makeTMXml5
    223      *
    224      * @param mixed $survey    survey
    225      * @param mixed $numGroups number of groups
    226      * @param mixed $weight    weight
    227      *
    228      * @access public
    229      * @return void
    230      */
    231     /*function makeTMXml5($survey, $numGroups, $weight)
    232     {
    233         $this->SurveyInput = new SurveyInput;
    234         $this->Response = new Response;
    235         $this->User = new User;
    236 
    237         $doc = new DOMDocument('1.0');
    238         //docroot
    239         $team_input = $doc->createElement('team_input');
    240         $team_input->setAttribute('num_groups', $numGroups);
    241         $doc->appendChild($team_input);
    242         foreach ($survey['Question'] as $q) {
    243             if (in_array($q['type'], array('M', 'C'))) {
    244                 //questions
    245                 $question = $doc->createElement('question');
    246                 $question->setAttribute('id', $q['id']);
    247                 $question->setAttribute('type', ($q['type'] == 'C' ? 'CAO':'MC'));
    248                 $question->setAttribute('title', $q['prompt']);
    249                 $team_input->appendChild($question);
    250 
    251                 //weight
    252                 $element_weight = $doc->createElement('weight');
    253                 $element_weight->setAttribute('value', $weight[$question_id]);
    254                 $question->appendChild($element_weight);
    255             }
    256         }
    257         $courseId = $this->Session->read('ipeerSession.courseId');
    258         $userData = $this->User->getEnrolledStudents($courseId);
    259         //      print_r($userData);
    260         foreach ($userData as $user) {
    261             //students
    262             $student = $doc->createElement('student');
    263             $student->setAttribute('username', $user['User']['student_no']);
    264             $team_input->appendChild($student);
    265 
    266             for ($i=1; $i <= count($questions); $i++) {
    267                 if (in_array($questions[$i]['Question']['type'], array('M', 'C'))) {
    268                     $question_id = $questions[$i]['Question']['id'];
    269                     //response
    270                     $type = $questions[$i]['Question']['type'] == 'C' ? 'CAO':'MC';
    271                     $response = $doc->createElement('response');
    272                     $response->setAttribute('q_id', $question_id);
    273                     $response->setAttribute('type', $type);
    274                     $student->appendChild($response);
    275 
    276                     $responses = $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId($survey_id, $user['User']['id'], $question_id);
    277                     //print_r($responses);
    278                     if (count($responses) != 0) {
    279                         for ($j=0; $j < count($responses); $j++) {
    280                             $response_tmp = $responses[$j]['SurveyInput'];
    281                             if ($response_tmp['response_text']==null && $response_tmp['response_id']==null) {
    282                                 //response/answer
    283                                 $value = $doc->createElement('value');
    284                                 $value->setAttribute('id', $response_tmp['id']);
    285                                 $value->setAttribute('answer', 0);
    286                                 $response->appendChild($value);
    287                             } elseif ($response_tmp['response_text']=='' || $response_tmp['response_text']==null) {
    288                                 //response/answer
    289                                 $value = $doc->createElement('value');
    290                                 $value->setAttribute('id', $response_tmp['id']);
    291                                 $value->setAttribute('answer', 1);
    292                                 $response->appendChild($value);
    293                             } else {
    294                                 $mcResponse = explode('_', $response_tmp['response_text']);
    295                                 if (isset($mcResponse[1])) {
    296                                     $mcTmp = $this->Response->find('id='.$mcResponse[1]);
    297                                     if ($mcTmp['Response']['response']==$mcResponse[0]) {
    298                                         //response/answer
    299                                         $value = $doc->createElement('value');
    300                                         $value->setAttribute('id', $response_tmp['id']);
    301                                         //$value->setAttribute('answer',1);
    302                                         $response->appendChild($value);
    303                                     }
    304                                 }
    305                             }
    306                         }
    307                     } else {
    308                         if ($type == 'MC') {
    309                             $value = $doc->createElement('value');
    310                             $value->setAttribute('id', '');
    311                             $response->appendChild($value);
    312                         }
    313                     }
    314                 }
    315             }
    316         }
    317         return $doc->saveXML();
    318     }*/
    319 
    320 
    321     /**
    322124     * readTMXml
    323125     *
  • app/controllers/surveygroups_controller.php

    rb4b7b9f r2c1f52d  
    243243            'recursive' => 2));
    244244        foreach ($survey['Course']['Event'] as $data) {
    245             if ($data['title'] == $survey['Survey']['name']) {
     245            if ($data['event_template_type_id'] == 3 &&
     246               $data['template_id'] == $survey['Survey']['id']) {
    246247                $event_id = $data['id'];
    247248            }
    248249        }
    249250        //make xml for TeamMaker
    250         $doc = $this->XmlHandler->makeTeamMakerXML($survey, $numGroups, $this->params['form']['weight']);
     251        $doc = $this->XmlHandler->makeTeamMakerXML($survey, $numGroups, $this->params['form']['weight'], $event_id);
    251252
    252253        //saves the 'in' file
     
    442443                //if question selected, add responses to data
    443444                if ($question_id != null) {
    444                     $surveyInput = $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId($group_set['Survey']['id'], $surveyGroupMember['id'], $question_id);
     445                    $surveyInput = $this->SurveyInput->getBySurveyIdUserIdQuestionId($event_id, $surveyGroupMember['id'], $question_id);
    445446
    446447                    for ($k=0; $k < count($surveyInput); $k++) {
     
    460461                } else {
    461462                    //links student to survey result if submitted
    462                     $surveyInput = $this->SurveyInput->getAllSurveyInputBySurveyIdUserId($group_set['Survey']['id'], $surveyGroupMember['id']);
     463                    $surveyInput = $this->SurveyInput->getBySurveyIdUserId($event_id, $surveyGroupMember['id']);
    463464                    if (!empty($surveyInput)) {
    464465                        $inputs[$surveyGroupMember['id']] = 'yes';
  • app/models/survey_input.php

    rb4b7b9f r2c1f52d  
    1414
    1515    /**
    16      * getAllSurveyInputBySurveyIdUserId
     16     * getBySurveyIdUserId
    1717     *
    1818     * @param mixed $surveyId survey id
     
    2222     * @return void
    2323     */
    24     function getAllSurveyInputBySurveyIdUserId($surveyId, $userId)
     24    function getByEventIdUserId($eventId, $userId)
    2525    {
    26         return $this->find('all', array('conditions' => array('survey_id' => $surveyId,
    27             'user_id' => $userId),
    28         'order' => 'question_id'));
     26        return $this->find(
     27            'all',
     28            array(
     29                'conditions' => array(
     30                    'event_id' => $eventId,
     31                    'user_id' => $userId
     32                ),
     33                'order' => 'question_id'
     34            )
     35        );
    2936    }
    3037
    3138
    3239    /**
    33      * getAllSurveyInputBySurveyIdUserIdQuestionId
     40     * getBySurveyIdUserIdQuestionId
    3441     *
    3542     * @param mixed $surveyId   survey id
     
    4047     * @return void
    4148     */
    42     function getAllSurveyInputBySurveyIdUserIdQuestionId($surveyId, $userId, $questionId)
     49    function getBySurveyIdUserIdQuestionId($eventId, $userId, $questionId)
    4350    {
    44         return $this->find('all', array('conditions' => array('survey_id' => $surveyId,
    45             'user_id' => $userId,
    46             'question_id' => $questionId)));
     51        return $this->find(
     52            'all',
     53            array(
     54                'conditions' => array(
     55                    'event_id' => $eventId,
     56                    'user_id' => $userId,
     57                    'question_id' => $questionId
     58                )
     59            )
     60        );
    4761    }
    48 
    49     /**
    50      * delAllSurveyInputBySurveyIdUserIdQuestionId
    51      *
    52      * @param mixed $surveyId   survey id
    53      * @param mixed $userId     user id
    54      * @param mixed $questionId question id
    55      *
    56      * @access public
    57      * @return void
    58      */
    59     function delAllSurveyInputBySurveyIdUserIdQuestionId($surveyId, $userId, $questionId)
    60     {
    61         return $this->deleteAll(array('survey_id' => $surveyId,
    62             'user_id' => $userId,
    63             'question_id' => $questionId));
    64     }
    65 
    6662
    6763    /**
     
    9187    }
    9288
    93 
    94     /**
    95      * findCountInSurveyGroup
    96      * SELECT user_id
    97      * FROM survey_inputs
    98      * WHERE survey_id='.$surveyId.'
    99      *     AND question_id='.$questionId.'
    100      *     AND response_id='.$responseId.'
    101      *     AND user_id IN (SELECT user_id FROM survey_group_members WHERE group_id='.$surveyGroupId.');
    102      *
    103      * @param bool $surveyId      survey id
    104      * @param bool $questionId    question id
    105      * @param bool $responseId    response id
    106      * @param bool $surveyGroupId survey group id
    107      *
    108      * @access public
    109      * @return void
    110      */
    111     function findCountInSurveyGroup($surveyId, $questionId, $responseId, $surveyGroupId)
    112     {
    113         $this->SurveyGroupMembers = ClassRegistry::init('SurveyGroupMembers');
    114         $inputs = $this->find(
    115             'all',
    116             array('conditions' => array(
    117                     'survey_id' => $surveyId,
    118                     'question_id' => $questionId,
    119                     'response_id' => $responseId
    120                 )
    121             )
    122         );
    123         $groupMembers = $this->SurveyGroupMembers->find(
    124             'all',
    125             array('conditions' => array('group_id' => $surveyGroupId))
    126         );
    127 
    128         $count = 0;
    129         foreach ($groupMembers as $member) {
    130             foreach ($inputs as $input) {
    131                 if ($member['SurveyGroupMembers']['user_id'] ==
    132                     $input['SurveyInput']['user_id']) {
    133                     $count++;
    134                     break;
    135                 }
    136             }
    137         }
    138         return $count;
    139     }
    140 
    141 
    142     /**
    143      * findResponseInSurveyGroup
    144      * SELECT user_id,response_text
    145      *     FROM survey_inputs
    146      *     WHERE survey_id='.$surveyId.'
    147      *         AND question_id='.$questionId.'
    148      *         AND user_id IN (SELECT user_id FROM survey_group_members WHERE group_id='.$surveyGroupId.')
    149      *
    150      * @param bool $surveyId      survey id
    151      * @param bool $questionId    question id
    152      * @param bool $surveyGroupId survey group id
    153      *
    154      * @access public
    155      * @return void
    156      */
    157     function findResponseInSurveyGroup($surveyId, $questionId, $surveyGroupId)
    158     {
    159         $this->SurveyGroupMembers = ClassRegistry::init('SurveyGroupMembers');
    160 
    161         $conditionSubQuery['`SurveyGroupMembers2`.`group_id`'] = $surveyGroupId;
    162         $dbo = $this->SurveyGroupMembers->getDataSource();
    163         $subQuery = $dbo->buildStatement(
    164             array(
    165                 'fields' => array('`SurveyGroupMembers2`.`user_id`'),
    166                 'table'  => $dbo->fullTableName($this->SurveyGroupMembers),
    167                 'alias'  => 'SurveyGroupMembers2',
    168                 'limit'  => null,
    169                 'offset' => null,
    170                 'joins'  => array(),
    171                 'conditions' => $conditionSubQuery,
    172                 'order'  => null,
    173                 'group'  => null,
    174             ),
    175             $this->SurveyGroupMembers
    176         );
    177         $subQuery = ' user_id IN (' . $subQuery . ') ';
    178         $subQueryExpression = $dbo->expression($subQuery);
    179         $conditions = array(
    180             'survey_id' => $surveyId,
    181             'question_id' => $questionId,
    182         );
    183         $conditions[] = $subQueryExpression;
    184         return $this->find('all',
    185             array(
    186                 'conditions' => $conditions,
    187                 'fields' => array('user_id', 'response_text'),
    188             )
    189         );
    190     }
    19189}
  • app/tests/cases/models/survey_input.test.php

    rb4b7b9f r2c1f52d  
    3737    function testGetAllSurveyInputBySurveyIdUserId()
    3838    {
    39         $result1 = $this->SurveyInput->getAllSurveyInputBySurveyIdUserId(1, 7);
     39        $result1 = $this->SurveyInput->getBySurveyIdUserId(1, 7);
    4040        $expect1 = array(
    4141            '0' => array(
     
    6565
    6666        // Test faulty inputs
    67         $invalid1 = $this->SurveyInput->getAllSurveyInputBySurveyIdUserId(1, 21312);
     67        $invalid1 = $this->SurveyInput->getBySurveyIdUserId(1, 21312);
    6868        $this->assertTrue(empty($invalid1));
    69         $invalid2 = $this->SurveyInput->getAllSurveyInputBySurveyIdUserId(23123, 1);
     69        $invalid2 = $this->SurveyInput->getBySurveyIdUserId(23123, 1);
    7070        $this->assertTrue(empty($invalid2));
    71         $nullInput = $this->SurveyInput->getAllSurveyInputBySurveyIdUserId(null, null);
     71        $nullInput = $this->SurveyInput->getBySurveyIdUserId(null, null);
    7272        $this->assertTrue(empty($nullInput));
    7373    }
     
    7777
    7878        $result1 =
    79             $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId(1, 7, 1);
     79            $this->SurveyInput->getBySurveyIdUserIdQuestionId(1, 7, 1);
    8080        $expect1 = array(
    8181            '0' => array(
     
    9393        $this->assertEqual($result1, $expect1);
    9494
    95         $result2 = $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId(1,7,2);
     95        $result2 = $this->SurveyInput->getBySurveyIdUserIdQuestionId(1,7,2);
    9696        $expect2 = array(
    9797            '0' => array(
     
    110110
    111111        // Test faulty inputs
    112         $invalid1 = $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId(1, 21312, 1);
     112        $invalid1 = $this->SurveyInput->getBySurveyIdUserIdQuestionId(1, 21312, 1);
    113113        $this->assertTrue(empty($invalid1));
    114         $invalid2 = $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId(23123, 1, 1);
     114        $invalid2 = $this->SurveyInput->getBySurveyIdUserIdQuestionId(23123, 1, 1);
    115115        $this->assertTrue(empty($invalid2));
    116         $nullInput = $this->SurveyInput->getAllSurveyInputBySurveyIdUserIdQuestionId(null, null, null);
     116        $nullInput = $this->SurveyInput->getBySurveyIdUserIdQuestionId(null, null, null);
    117117        $this->assertTrue(empty($nullInput));
    118118    }
    119 
    120     function testDelAllSurveyInputBySurveyIdUserIdQuestionId()
    121     {
    122         // Before delete tuple 1
    123         $searchBefore1 = $this->SurveyInput->find('first', array('conditions' => array('survey_id' => 1, 'user_id' => 7, 'question_id' => 1)));
    124         $this->assertTrue(!empty($searchBefore1));
    125         // After delete
    126         $this->SurveyInput->delAllSurveyInputBySurveyIdUserIdQuestionId(1, 7, 1);
    127         $searchAfter1 = $this->SurveyInput->find('first', array('conditions' => array('survey_id' => 1, 'user_id' => 7, 'question_id' => 1)));
    128         $this->assertTrue(empty($searchAfter1));
    129 
    130         // Before delete tuple 2
    131         $searchBefore2 = $this->SurveyInput->find('first', array('conditions' => array('survey_id' => 1, 'user_id' => 31, 'question_id' => 2)));
    132         $this->assertTrue(!empty($searchBefore2));
    133         // After delete
    134         $this->SurveyInput->delAllSurveyInputBySurveyIdUserIdQuestionId(1,31,2);
    135         $searchAfter1 = $this->SurveyInput->find('first', array('conditions' => array('survey_id' => 1, 'user_id' => 31, 'question_id' => 2)));
    136         $this->assertTrue(empty($searchAfter2));
    137     }
    138 
    139     function testFindCountInSurveyGroup()
    140     {
    141         $count = $this->SurveyInput->findCountInSurveyGroup(1, 2, 5, 7);
    142         $this->assertEqual($count, 1);
    143     }
    144119}
Note: See TracChangeset for help on using the changeset viewer.