Changeset a419b84 in iPeer


Ignore:
Timestamp:
2012-12-17T19:23:25-08:00 (6 years ago)
Author:
Compass <pan.luo@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
b9de53f
Parents:
8d18ab4
git-author:
Compass <pan.luo@…> (12/17/2012 06:43:01 PM)
git-committer:
Compass <pan.luo@…> (12/17/2012 07:23:25 PM)
Message:

Separate survey with event in survey template

Location:
app
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/evaltools_controller.php

    r8d18ab4 ra419b84  
    4646    function index($evaltool = null)
    4747    {
    48         if (!User::hasPermission('controllers/evaltools')) {
    49             $this->Session->setFlash(__('You do not have permission to view evaluation tools.', true));
    50             $this->redirect('/home');
    51         }
    5248        //Disable the autorender, base the role to render the custom home
    5349        $this->autoRender = false;
     
    9894
    9995        $surveyData = $this->Survey->find('all', array('conditions' => array('Survey.creator_id' => $this->Auth->user('id')),
    100             'contain' => array('Course')));
     96            'contain' => false));
    10197        $this->set('surveyData', $surveyData);
    10298
  • app/controllers/simpleevaluations_controller.php

    r8d18ab4 ra419b84  
    124124            // grab all instructors that have access to the courses above
    125125            $instructors = $this->UserCourse->find(
    126                 'all', 
     126                'all',
    127127                array(
    128128                    'conditions' => array('UserCourse.course_id' => $courseIds)
     
    156156            }
    157157        }
    158        
     158
    159159        empty($basicRestrictions) ? $restrictions = $basicRestrictions :
    160160            $restrictions['SimpleEvaluation.creator_id'] = $basicRestrictions;
     
    225225            $this->redirect('/home');
    226226        }
    227        
     227
    228228        $eval = $this->SimpleEvaluation->find(
    229             'first', 
     229            'first',
    230230            array(
    231                 'conditions' => array('id' => $id), 
     231                'conditions' => array('id' => $id),
    232232                'contain' => array('Event' => 'EvaluationSubmission')
    233233            )
    234234        );
    235        
     235
    236236        // check to see if $id is valid - numeric & is a simple evaluation
    237237        if (!is_numeric($id) || empty($eval)) {
     
    239239            $this->redirect('index');
    240240        }
    241        
     241
    242242        // check whether the user has access to the evaluation if the eval is not public
    243243        if ($eval['SimpleEvaluation']['availability'] != 'public' && !User::hasPermission('functions/superadmin')) {
     
    262262                array_push($instructorIds, $this->Auth->user('id'));
    263263            }
    264            
     264
    265265            // creator's id must be in the array of accessible user ids
    266266            if (!(in_array($eval['SimpleEvaluation']['creator_id'], $instructorIds))) {
     
    269269            }
    270270        }
    271        
     271
    272272        if ($layout != '') {
    273273            $this->layout = $layout;
     
    343343    function edit($id = null)
    344344    {
    345         if (!User::hasPermission('controllers/simpleevaluations')) {
    346             $this->Session->setFlash(__('You do not have permission to edit simple evaluations', true));
    347             $this->redirect('/home');
    348         }
    349 
    350345        // retrieving the requested simple evaluation
    351346        $eval = $this->SimpleEvaluation->find(
    352             'first', 
     347            'first',
    353348            array(
    354                 'conditions' => array('id' => $id), 
     349                'conditions' => array('id' => $id),
    355350                'contain' => array('Event' => 'EvaluationSubmission')
    356351            )
     
    358353        // for storing submissions - for checking if there are any submissions
    359354        $submissions = array();
    360        
     355
    361356        // check to see if $id is valid - numeric & is a simple evaluation
    362357        if (!is_numeric($id) || empty($eval)) {
     
    364359            $this->redirect('index');
    365360        }
    366        
     361
    367362        if (!User::hasPermission('functions/superadmin')) {
    368363            // instructor
     
    386381                array_push($instructorIds, $this->Auth->user('id'));
    387382            }
    388            
     383
    389384            // creator's id be in the array of accessible user ids
    390385            if (!(in_array($eval['SimpleEvaluation']['creator_id'], $instructorIds))) {
     
    393388            }
    394389        }
    395        
     390
    396391        foreach ($eval['Event'] as $event) {
    397392            if (!empty($event['EvaluationSubmission'])) {
     
    399394            }
    400395        }
    401        
     396
    402397        // check to see if submissions had been made - if yes - simple evaluation can't be edited
    403398        if (!empty($submissions)) {
     
    419414            $this->Output->br2nl($this->data);
    420415        }
    421        
     416
    422417        $this->set('title_for_layout', __('Simple Evaluations > Edit Template', true));
    423418    }
     
    437432            $this->redirect('/home');
    438433        }
    439        
     434
    440435        $eval = $this->SimpleEvaluation->find(
    441             'first', 
     436            'first',
    442437            array(
    443                 'conditions' => array('id' => $id), 
     438                'conditions' => array('id' => $id),
    444439                'contain' => array('Event' => 'EvaluationSubmission')
    445440            )
    446441        );
    447        
     442
    448443        // check to see if $id is valid - numeric & is a simple evaluation
    449444        if (!is_numeric($id) || empty($eval)) {
     
    451446            $this->redirect('index');
    452447        }
    453        
     448
    454449        // can be copied if eval is public
    455450        if ($eval['SimpleEvaluation']['availability'] != 'public' && !User::hasPermission('functions/superadmin')) {
     
    474469                array_push($instructorIds, $this->Auth->user('id'));
    475470            }
    476                
     471
    477472            // creator's id be in the array of accessible user ids
    478473            if (!(in_array($eval['SimpleEvaluation']['creator_id'], $instructorIds))) {
     
    481476            }
    482477        }
    483        
     478
    484479        $this->render = false;
    485480        $this->data = $this->SimpleEvaluation->read(null, $id);
     
    508503        // retrieving the requested simple evaluation
    509504        $eval = $this->SimpleEvaluation->find(
    510             'first', 
     505            'first',
    511506            array(
    512                 'conditions' => array('id' => $id), 
     507                'conditions' => array('id' => $id),
    513508                'contain' => array('Event' => 'EvaluationSubmission')
    514509            )
    515510        );
    516        
     511
    517512        // check to see if $id is valid - numeric & is a simple evaluation
    518513        if (!is_numeric($id) || empty($eval)) {
     
    542537                array_push($instructorIds, $this->Auth->user('id'));
    543538            }
    544            
     539
    545540            // creator's id be in the array of accessible user ids
    546541            if (!(in_array($eval['SimpleEvaluation']['creator_id'], $instructorIds))) {
  • app/controllers/surveys_controller.php

    r8d18ab4 ra419b84  
    5050                // Put in the custom inUse column
    5151                $data[$key]['!Custom']['inUse'] = $inUse ? __("Yes", true) : __("No", true);
    52 
    53                 // Decide whether the course is release or not ->
    54                 // (from the events controller postProcess function)
    55                 $releaseDate = strtotime($entry["Survey"]["release_date_begin"]);
    56                 $endDate = strtotime($entry["Survey"]["release_date_end"]);
    57                 $timeNow = strtotime($entry[0]["now()"]);
    58 
    59                 if (!$releaseDate) {
    60                     $releaseDate = 0;
    61                 }
    62                 if (!$endDate) {
    63                     $endDate = 0;
    64                 }
    65 
    66                 $isReleased = "";
    67                 if ($timeNow < $releaseDate) {
    68                     $isReleased = __("Not Yet Open", true);
    69                 } else if ($timeNow > $endDate) {
    70                     $isReleased = __("Already Closed", true);
    71                 } else {
    72                     $isReleased = __("Open Now", true);
    73                 }
    74 
    75                 // Put in the custom isReleased string
    76                 $data[$key]['!Custom']['isReleased'] = $isReleased;
    7752            }
    7853        }
     
    10075        $columns = array(
    10176            array("Survey.id",          __("ID", true),         "4em",   "hidden"),
    102             array("Course.id",          "",             "",     "hidden"),
    103             array("Course.course",      __("Course", true),      "15em",  "action", "View Course"),
    104             array("Survey.name",        __("Name", true),        "auto",  "action", "View Event"),
     77            array("Survey.name",        __("Name", true),        "auto",  "action", "Edit Survey"),
     78            array("Survey.question_count", __("Questions", true),        "6em",  "action", "View Questions"),
    10579            array("!Custom.inUse",      __("In Use", true),      "4em",   "number"),
    106             array("Survey.due_date",    __("Due Date", true),   "10em",  "date"),
    107             // The release window columns
    108             array("now()",   "", "", "hidden"),
    109             array("Survey.release_date_begin", "", "", "hidden"),
    110             array("Survey.release_date_end",   "", "", "hidden"),
    111             array("!Custom.isReleased", __("Released ?", true),   "  4em",   "string"),
    11280            array("Survey.creator_id",   "", "", "hidden"),
    11381            array("Survey.creator",  __("Created By", true),    "8em", "action", "View Creator"),
     
    11684        // Just list all and my evaluations for selections
    11785        $userList = array($myID => "My Surveys");
    118 
    119         // Join in the course name
    120         $joinTableCourse =
    121             array("id"        => "Survey.course_id",
    122                 "localKey"  => "course_id",
    123                 "description" => "Course:",
    124                 "list" => $courses,
    125                 "default"   => $this->Session->read('ipeerSession.courseId'),
    126                 "joinTable" => "courses",
    127                 "joinModel" => "Course");
    12886
    12987        $joinTableCreator =
     
    13694
    13795        // Add the join table into the array
    138         $joinTables = array($joinTableCreator, $joinTableCourse);
     96        $joinTables = array($joinTableCreator);
    13997
    14098        if (User::hasPermission('functions/superadmin')) {
     
    143101            // For instructors: only list their own course events (surveys)
    144102            $extraFilters = $conditions;
    145             $extraFilters = " ( ";
    146             $courseIds = array_keys($courses);
    147             foreach ($courseIds as $id) {
    148                 $extraFilters .= "course_id=$id or ";
    149             }
    150             $extraFilters .= "1=0 ) "; // just terminates the or condition chain with "false"
    151103        }
    152104
    153105        // Set up actions
    154         $warning = __("Are you sure you want to delete this evaluation permanently?", true);
     106        $warning = __("Are you sure you want to delete this survey permanently?", true);
    155107        $actions = array(
    156             array(__("View Event", true), "", "", "", "view", "Survey.id"),
    157             array(__("Edit Event", true), "", "", "", "edit", "Survey.id"),
    158             array(__("Edit Questions", true), "", "", "", "questionsSummary", "Survey.id"),
     108            array(__("View Survey", true), "", "", "", "view", "Survey.id"),
     109            array(__("Edit Survey", true), "", "", "", "edit", "Survey.id"),
     110            array(__("View Questions", true), "", "", "", "questionsSummary", "Survey.id"),
    159111            array(__("Copy Survey", true), "", "", "", "copy", "Survey.id"),
    160112            array(__("Delete Survey", true), $warning, "", "", "delete", "Survey.id"),
    161             array(__("View Course", true), "",    "", "courses", "home", "Course.id"),
    162113            array(__("View Creator", true), "",    "", "users", "view", "Survey.creator_id"));
    163114
     
    167118        // Set up the list itself
    168119        $this->AjaxList->setUp($this->Survey, $columns, $actions,
    169             "Course.course", "Survey.name", $joinTables, $extraFilters, $recursive, "__postProcess");
     120            "Survey.name", "Survey.name", $joinTables, $extraFilters, $recursive, "__postProcess");
    170121    }
    171122
     
    223174    function view($id)
    224175    {
    225         $eval = $this->Survey->find(
     176        $survey = $this->Survey->find(
    226177            'first',
    227178            array(
     
    232183
    233184        // check to see if $id is valid - numeric & is a survey
    234         if (!is_numeric($id) || empty($eval)) {
     185        if (!is_numeric($id) || empty($survey)) {
    235186            $this->Session->setFlash(__('Error: Invalid ID.', true));
    236187            $this->redirect('index');
    237         }
    238 
    239         $course = $this->Course->getAccessibleCourseById($eval['Survey']['course_id'], User::get('id'), User::getCourseFilterPermission());
    240         if (!$course) {
    241             $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    242             $this->redirect('index');
    243         }
    244 
    245         $data = $this->Survey->read(null, $id);
    246         $this->set('data', $data);
     188            return;
     189        }
     190
     191        $this->set('data', $survey);
    247192    }
    248193
     
    267212                }
    268213
    269                 //$this->questionsSummary($this->Survey->id);
    270 
    271                 //$this->params['data']['Survey']['released'] = 1;
    272                 $eventArray = array();
    273 
    274                 //add survey to events
    275                 $eventArray['Event']['title'] = $this->data['Survey']['name'];
    276                 $eventArray['Event']['course_id'] = $this->data['Survey']['course_id'];
    277                 $eventArray['Event']['event_template_type_id'] = 3;
    278                 $eventArray['Event']['template_id'] = $this->data['Survey']['id'];
    279                 $eventArray['Event']['self_eval'] = 1;
    280                 $eventArray['Event']['com_req'] = 1;
    281                 $eventArray['Event']['due_date'] = $this->data['Survey']['due_date'];
    282                 $eventArray['Event']['release_date_begin'] = $this->data['Survey']['release_date_begin'];
    283                 $eventArray['Event']['release_date_end'] = $this->data['Survey']['release_date_end'];
    284 
    285                 //Save Data
    286                 $this->Event->save($eventArray);
    287214                $this->Session->setFlash(__('Survey is saved!', true), 'good');
    288215                $this->redirect('index');
     216                return;
    289217            } else {
    290                 //$this->set('errmsg', $this->Survey->errorMessage);
    291218                $this->Session->setFlash(__('Error on saving survey.', true));
    292219            }
     
    294221
    295222        // Get the course data
    296         $courses = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list');
    297         $templates = $this->Survey->find('list', array('conditions' => array('course_id' => array_keys($courses))));
     223        $templates = $this->Survey->find('list');
    298224        $this->set('templates', $templates);
    299         $this->set('courses', $courses);
    300225        $this->render('edit');
    301226    }
     
    313238    {
    314239        // retrieving the requested survey
    315         $eval = $this->Survey->find(
     240        $survey = $this->Survey->find(
    316241            'first',
    317242            array(
     
    324249
    325250        // check to see if $id is valid - numeric & is a survey
    326         if (!is_numeric($id) || empty($eval)) {
     251        if (!is_numeric($id) || empty($survey)) {
    327252            $this->Session->setFlash(__('Error: Invalid ID.', true));
    328253            $this->redirect('index');
    329254        }
    330255
    331         $course = $this->Course->getAccessibleCourseById($eval['Survey']['course_id'], User::get('id'), User::getCourseFilterPermission());
    332         if (!$course) {
    333             $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    334             $this->redirect('index');
    335         }
    336 
    337         foreach ($eval['Event'] as $event) {
    338             if (!empty($event['EvaluationSubmission'])) {
    339                 $submissions[] = $event['EvaluationSubmission'];
    340             }
    341         }
    342 
    343256        // check to see if submissions had been made - if yes - survey can't be edited
    344         if (!empty($submissions)) {
    345             $this->Session->setFlash(__('Submissions had been made. '.$eval['Survey']['name'].' cannot be edited. Please make a copy.', true));
    346             $this->redirect('index');
    347         }
    348 
    349         $data = $this->Survey->find('first', array('conditions' => array('id' => $id),
    350             'contain' => array('Event')));
     257        if (isset($survey['Event'])) {
     258            foreach ($survey['Event'] as $event) {
     259                if (!empty($event['EvaluationSubmission'])) {
     260                    $submissions[] = $event['EvaluationSubmission'];
     261                }
     262            }
     263            if (!empty($submissions)) {
     264                $this->Session->setFlash(__('Submissions had been made. '.$survey['Survey']['name'].' cannot be edited. Please make a copy.', true));
     265                $this->redirect('index');
     266            }
     267        }
     268
    351269        if (!empty($this->data)) {
    352             //alter dates for the event
    353             //TODO: separate date from survey
    354             $data['Survey'] = $this->data['Survey'];
    355             $data['Event'][0]['title'] = $this->data['Survey']['name'];
    356             $data['Event'][0]['course_id'] = $this->data['Survey']['course_id'];
    357             $data['Event'][0]['due_date'] = $this->data['Survey']['due_date'];
    358             $data['Event'][0]['release_date_begin'] = $this->data['Survey']['release_date_begin'];
    359             $data['Event'][0]['release_date_end'] = $this->data['Survey']['release_date_end'];
    360 
    361             if ($this->Survey->save($data)) {
     270            if ($this->Survey->save($this->data)) {
    362271                $this->Session->setFlash(__('The Survey was edited successfully.', true), 'good');
    363272                $this->redirect('index');
     273                return;
    364274            } else {
    365275                $this->Session->setFlash($this->Survey->errorMessage);
    366276            }
    367277        } else {
    368             $this->data = $data;
    369         }
    370 
    371         // Get the course data
    372         $courses = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list');
    373         $this->set('courses', $courses);
     278            $this->data = $survey;
     279        }
    374280    }
    375281
     
    385291    function copy($id)
    386292    {
    387         $eval = $this->Survey->find(
     293        $survey = $this->Survey->find(
    388294            'first',
    389295            array(
     
    394300
    395301        // check to see if $id is valid - numeric & is a survey
    396         if (!is_numeric($id) || empty($eval)) {
     302        if (!is_numeric($id) || empty($survey)) {
    397303            $this->Session->setFlash(__('Error: Invalid ID.', true));
    398304            $this->redirect('index');
    399         }
    400 
    401         $course = $this->Course->getAccessibleCourseById($eval['Survey']['course_id'], User::get('id'), User::getCourseFilterPermission());
    402         if (!$course) {
    403             $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    404             $this->redirect('index');
    405         }
    406 
    407         $courses = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list');
    408 
    409         $this->data = $this->Survey->read(null, $id);
     305            return;
     306        }
     307
     308        $this->data = $survey;
    410309        unset($this->data['Survey']['id']);
    411310        $this->data['Survey']['name'] = 'Copy of '.$this->data['Survey']['name'];
    412         //converting nl2br back so it looks better
    413         $this->Output->br2nl($this->data);
    414 
     311
     312        $this->set('action', 'copy');
    415313        $this->set('template_id', $id);
    416         $this->set('courses', $courses);
    417314        $this->set('breadcrumb', $this->breadcrumb->push('surveys')->push(__('Copy', true)));
    418315        $this->render('edit');
     
    431328    {
    432329        // retrieving the requested survey
    433         $eval = $this->Survey->find(
     330        $survey = $this->Survey->find(
    434331            'first',
    435332            array(
     
    440337
    441338        // check to see if $id is valid - numeric & is a survey
    442         if (!is_numeric($id) || empty($eval)) {
     339        if (!is_numeric($id) || empty($survey)) {
    443340            $this->Session->setFlash(__('Error: Invalid ID.', true));
    444341            $this->redirect('index');
    445342        }
    446343
    447         $course = $this->Course->getAccessibleCourseById($eval['Survey']['course_id'], User::get('id'), User::getCourseFilterPermission());
    448         if (!$course) {
    449             $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    450             $this->redirect('index');
    451         }
    452 
    453         foreach ($eval['Event'] as $event) {
    454             if (!empty($event['EvaluationSubmission'])) {
    455                 $submissions[] = $event['EvaluationSubmission'];
    456             }
    457         }
    458 
    459344        // check to see if submissions had been made - if yes - survey can't be edited
    460         if (!empty($submissions)) {
    461             $this->Session->setFlash(__('Submissions had been made. '.$eval['Survey']['name'].' cannot be deleted', true));
    462             $this->redirect('index');
     345        if (isset($survey['Event'])) {
     346            $submissions = array();
     347            foreach ($survey['Event'] as $event) {
     348                if (!empty($event['EvaluationSubmission'])) {
     349                    $submissions[] = $event['EvaluationSubmission'];
     350                }
     351            }
     352            if (!empty($submissions)) {
     353                $this->Session->setFlash(__('Submissions had been made. '.$survey['Survey']['name'].' cannot be edited. Please make a copy.', true));
     354                $this->redirect('index');
     355            }
    463356        }
    464357
     
    471364    }
    472365
    473   /**
    474    * releaseSurvey
    475    * called to change survey status to release
    476    *
    477    * @param bool $id
    478    *
    479    * @access public
    480    * @return void
    481    */
    482   function releaseSurvey($id=null)
    483   {//deprecated, this function is not used
    484       $eventArray = array();
    485 
    486       $this->Survey->id = $id;
    487       $this->params['data'] = $this->Survey->read();
    488       $this->params['data']['Survey']['released'] = 1;
    489 
    490       //add survey to eventsx();
    491       //set up Event params
    492       $eventArray['Event']['title'] = $this->params['data']['Survey']['name'];
    493       $eventArray['Event']['course_id'] = $this->params['data']['Survey']['course_id'];
    494       $eventArray['Event']['event_template_type_id'] = 3;
    495       $eventArray['Event']['template_id'] = $this->params['data']['Survey']['id'];
    496       $eventArray['Event']['self_eval'] = 0;
    497       $eventArray['Event']['com_req'] = 0;
    498       $eventArray['Event']['due_date'] = $this->params['data']['Survey']['due_date'];
    499       $eventArray['Event']['release_date_begin'] = $this->params['data']['Survey']['release_date_begin'];
    500       $eventArray['Event']['release_date_end'] = $this->params['data']['Survey']['release_date_end'];
    501       $eventArray['Event']['creator_id'] = $this->params['data']['Survey']['creator_id'];
    502       $eventArray['Event']['created'] = $this->params['data']['Survey']['created'];
    503 
    504       //Save Data
    505       if ($this->Event->save($eventArray)) {
    506           //Save Groups for the Event
    507           //$this->GroupEvent->insertGroups($this->Event->id, $this->params['data']['Event']);
    508 
    509           //$this->redirect('/events/index/The event is added successfully.');
    510       }
    511 
    512       $this->Survey->save($this->params['data']);
    513 
    514 
    515       $this->set('data', $this->Survey->find('all', null, null, 'id'));
    516       $this->set('message', __('The survey was released.', true));
    517       $this->index();
    518       $this->render('index');
    519   }
    520 
    521 
    522366  /************ Question Functions ***********/
    523367
     
    534378    {
    535379        // retrieving the requested survey
    536         $eval = $this->Survey->find('first',
     380        $survey = $this->Survey->find('first',
    537381            array(
    538382                'conditions' => array('id' => $survey_id),
     
    540384            )
    541385        );
    542         // for storing submissions - for checking if there are any submissions
    543         $submissions = array();
    544386
    545387        // check to see if $id is valid - numeric & is a survey
    546         if (!is_numeric($survey_id) || empty($eval)) {
     388        if (!is_numeric($survey_id) || empty($survey)) {
    547389            $this->Session->setFlash(__('Invalid ID.', true));
    548390            $this->redirect('index');
    549         }
    550 
    551         $course = $this->Course->getAccessibleCourseById($eval['Survey']['course_id'], User::get('id'), User::getCourseFilterPermission());
    552         if (!$course) {
    553             $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    554             $this->redirect('index');
    555         }
    556 
    557         foreach ($eval['Event'] as $event) {
    558             if (!empty($event['EvaluationSubmission'])) {
    559                 $submissions[] = $event['EvaluationSubmission'];
    560             }
    561         }
    562 
     391            return;
     392        }
     393
     394        // for storing submissions - for checking if there are any submissions
     395        $hasSubmission = false;
    563396        // check to see if submissions had been made - if yes - survey can't be edited
    564         if (!empty($submissions)) {
    565             $this->Session->setFlash(__('Submissions had been made. Questions for "'.$eval['Survey']['name'].'" cannot be edited.', true));
    566             $this->redirect('index');
     397        if (isset($survey['Event'])) {
     398            foreach ($survey['Event'] as $event) {
     399                if (!empty($event['EvaluationSubmission'])) {
     400                    $hasSubmission = true;
     401                }
     402            }
    567403        }
    568404
     
    574410            'recursive' => 1));
    575411
    576         $this->set('breadcrumb', $this->breadcrumb->push('surveys')->push(__('Edit Question', true)));
     412        $this->set('breadcrumb', $this->breadcrumb->push('surveys')->push(__('View Questions', true)));
    577413        $this->set('survey_id', $survey_id);
    578414        $this->set('questions', $questions);
    579         $this->set('is_editable', true);
     415        $this->set('is_editable', !$hasSubmission);
    580416        $this->render('questionssummary');
    581417    }
  • app/models/survey.php

    r8d18ab4 ra419b84  
    7171
    7272    /**
     73     * __construct
     74     *
     75     * @param bool $id    id
     76     * @param bool $table table
     77     * @param bool $ds    data source
     78     *
     79     * @access protected
     80     * @return void
     81     */
     82    function __construct($id = false, $table = null, $ds = null)
     83    {
     84        parent::__construct($id, $table, $ds);
     85        $this->virtualFields['question_count'] = sprintf('SELECT count(*) as question_count FROM survey_questions as q WHERE q.survey_id = %s.id', $this->alias);
     86    }
     87
     88    /**
    7389     * getSurveyIdByCourseIdTitle
    7490     *
  • app/tests/cases/controllers/surveys_controller.test.php

    r8d18ab4 ra419b84  
    7575    function testIndex() {
    7676        $result = $this->testAction('/surveys/index', array('return' => 'vars'));
    77 
    78         $this->assertEqual($result['paramsForList']['data']['entries'][0]['Survey']['name'], 'Team Creation Survey');
    79         $this->assertEqual($result['paramsForList']['data']['entries'][0]['Course']['course'], 'MECH 328');
    80         $this->assertEqual($result['paramsForList']['data']['entries'][1]['Survey']['name'], 'Survey, all Q types');
    81         $this->assertEqual($result['paramsForList']['data']['entries'][1]['Course']['course'], 'MECH 328');
     77        $surveys = Set::sort($result['paramsForList']['data']['entries'], '{n}.Survey.id', 'asc');
     78        $this->assertEqual($surveys[0]['Survey']['name'], 'Team Creation Survey');
     79        $this->assertEqual($surveys[0]['Survey']['question_count'], 2);
     80        $this->assertEqual($surveys[1]['Survey']['name'], 'Survey, all Q types');
     81        $this->assertEqual($surveys[1]['Survey']['question_count'], 4);
    8282    }
    8383
     
    8585        $result = $this->testAction('/surveys/view/1', array('return' => 'vars'));
    8686        $this->assertEqual($result['data']['Survey']['name'], 'Team Creation Survey');
    87         $this->assertEqual($result['data']['Survey']['due_date'], '2012-07-31 11:20:00');
    88         $this->assertEqual($result['data']['Survey']['release_date_begin'], '2012-07-01 11:20:00');
    89         $this->assertEqual($result['data']['Survey']['release_date_end'], '2013-12-31 11:20:00');
    90         $this->assertEqual($result['data']['Course']['course'], 'MECH 328');
    91         $this->assertEqual($result['data']['Course']['title'], 'Mechanical Engineering Design Project');
    9287    }
    9388
     
    109104
    110105    //TODO redirect
    111     function testReleaseSurvey() {
     106    function testQuestionSummary() {
    112107        $result = $this->testAction('surveys/questionsSummary/1', array('return' => 'vars'));
    113108        $this->assertEqual($result['questions'][0]['Question']['prompt'], 'What was your GPA last term?');
  • app/views/evaltools/index.ctp

    r8d18ab4 ra419b84  
    1 <?php 
     1<?php
    22// data processing for simple eval, create arrays to generate the entry tables
    33$simpleevalheaders = array(
    44    __('Name', true),
    5     __('In Use', true), 
    6     __('Public', true), 
     5    __('In Use', true),
     6    __('Public', true),
    77    __('Base Point Per Member', true)
    88);
     
    3333$rubricscells = array();
    3434foreach($rubricData as $data) {
    35     $rubric = $data['Rubric']; 
     35    $rubric = $data['Rubric'];
    3636    $row = array();
    3737    $row[] = $html->link($rubric['name'], '/rubrics/view/'.$rubric['id']);
     
    5858);
    5959$mixevalcells = array();
    60 foreach ($mixevalData as $data) { 
     60foreach ($mixevalData as $data) {
    6161    $mixeval = $data['Mixeval'];
    6262    $row = array();
     
    7878    __('Name', true),
    7979    __('In Use', true),
    80     __('Course', true),
    81     __('Due Date', true),
    82     __('Released?', true)
     80    __('Questions', true),
    8381);
    8482$surveycells = array();
     
    9088        $html->image('icons/green_check.gif', array('alt'=>'green_check')) :
    9189        $html->image('icons/red_x.gif', array('alt'=>'red_x'));
    92     $row[] = $survey['course_id'] == '-1' ? 'N/A' : $data['Course']['course'];
    93     $row[] = Toolkit::formatDate(date('Y-m-d H:i:s',
    94         strtotime($survey['due_date'])));
    95     $row[] = date('Y-m-d H:i:s',time()) > $survey['release_date_begin'] ?
    96         $html->image('icons/green_check.gif', array('alt'=>'green_check')) :
    97         $html->image('icons/red_x.gif', array('alt'=>'red_x'));
     90    $row[] = $survey['question_count'];
    9891    $surveycells[] = $row;
    9992}
     
    109102    $emailTemplate = $data['EmailTemplate'];
    110103    $row = array();
    111     $row[] = $html->link($emailTemplate['name'], 
     104    $row[] = $html->link($emailTemplate['name'],
    112105        '/emailtemplates/view/'.$emailTemplate['id']);
    113106    $row[] = $emailTemplate['subject'];
     
    124117<div class='evaltoolsadd'><?php echo $html->link(__('Add Simple Evaluation', true), '/simpleevaluations/add', array('class' => 'add-button')); ?></div>
    125118<table class='standardtable'>
    126 <?php 
     119<?php
    127120echo $html->tableHeaders($simpleevalheaders);
    128121echo $html->tableCells($simpleevalcells);
  • app/views/surveys/edit.ctp

    r8d18ab4 ra419b84  
    1111<?php echo $this->Form->input('name', array('size'=>'50', 'class'=>'input',
    1212    'readonly' => $readonly)) ?>
    13 <div id="surveyErr"></div>
    1413
    1514<?php if('add' == $this->action):?>
     
    1716<?php elseif('copy' == $this->action):?>
    1817    <?php echo $this->Form->input('template_id', array('type' => 'hidden', 'value' => $template_id))?>
    19 <?php endif;
    20 
    21 echo $this->Form->input('course_id', array(
    22     'label' => __('Assigned Course:', true).'<font color="red">*</font>'));
    23 echo $form->input('Survey.due_date', array(
    24     'label'=> __('Due Date', true).':<font color="red">*</font>',
    25     'type'=>'text',
    26     'size'=>'40',
    27     'class'=>'input',
    28     ));
    29 
    30 echo $form->input('Survey.release_date_begin', array(
    31     'label'=>__('Release From:<font color="red">*</font>', true),
    32     'type'=>'text',
    33     'size'=>'40',
    34     'class'=>'input',
    35     ));
    36 
    37 echo $form->input('Survey.release_date_end', array(
    38     'label'=> __('Release Until:<font color="red">*</font>', true),
    39     'type'=>'text',
    40     'size'=>'40',
    41     'class'=>'input',
    42     )) ?>
     18<?php endif;?>
    4319
    4420    <div style="text-align: center">
  • app/views/surveys/questionssummary.ctp

    r8d18ab4 ra419b84  
    1616                    array('escape' => false, 'class' => 'delete-button'),
    1717                    __('Are you sure to delete question', true).' &ldquo;'.$question['prompt'].'&rdquo;?')?>
     18                <?php endif; ?>
    1819                </div>
     20                <?php if ($is_editable):?>
    1921                <div style="float: right">
    2022                <?php echo $this->Html->link(__('Top', true),
     
    3133                    array('escape' => false, 'class' => 'bottom-button small-font'))?>
    3234                </div>
     35                <?php endif;?>
    3336                <div style="clear: both;"></div>
    34                 <?php endif;?>
    3537            </div>
    3638            <div class="survey-response">
  • app/views/surveys/view.ctp

    r8d18ab4 ra419b84  
    66    </tr>
    77    <tr>
    8       <td><?php __('Assigned Course')?>:&nbsp;</td>
    9       <td><?php echo $this->Html->link($data['Course']['course'], '/courses/view/'.$data['Survey']['course_id'])?></td>
    10     </tr>
    11     <tr>
    128      <td><?php __('Creator')?>:</td>
    139      <td><?php echo $this->Html->link($data['Survey']['creator'], '/users/view/'.$data['Survey']['creator_id'])?></td>
    14     </tr>
    15     <tr>
    16       <td><?php __('Due Date')?>:</td>
    17       <td><?php echo $data['Survey']['due_date']; ?></td>
    18     </tr>
    19     <tr>
    20       <td valign="top"><?php __('Release Date')?>:</td>
    21       <td>
    22       <table width="294" border="0" cellspacing="2" cellpadding="4">
    23       <tr>
    24         <td width="48" valign="top"><?php __('From')?>:</td>
    25         <td width="224"><?php echo $data['Survey']['release_date_begin'] ?></td>
    26       </tr>
    27       <tr>
    28         <td valign="top"><?php __('To')?>:</td>
    29         <td><?php echo $data['Survey']['release_date_end'] ?></td>
    30       </tr>
    31     </table>
    32       </td>
    3310    </tr>
    3411    <tr>
Note: See TracChangeset for help on using the changeset viewer.