PHP Method User::getCourseFilterPermission, codiad Code Examples

This page contains top rated real world PHP examples of method User::getCourseFilterPermission from package codiad extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
Show file File: departments_controller.php Project: eecian/Team08-iPeer
0
 /**
  * View a department entry.
  *
  * @param mixed $id - The department id to be viewed
  */
 public function view($id)
 {
     $this->set('title_for_layout', __('View Department', true));
     if (!$id) {
         $this->Session->setFlash(__('Invalid department', true));
         $this->redirect(array('action' => 'index'));
         return;
     }
     $ret = $this->Department->read(null, $id);
     $this->set('department', $ret['Department']['name']);
     $this->set('faculty', $ret['Faculty']['name']);
     $courses = $this->Course->getAllAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'all', array('conditions' => array('Department.id' => $id), 'contain' => 'Department'));
     $this->set('courses', $courses);
 }
Example #2
Show file File: courses_controller.php Project: eecian/Team08-iPeer
0
 /**
  * import
  *
  * @access public
  * @return void
  */
 function import()
 {
     if (!empty($this->data)) {
         // check that file upload worked
         if ($this->FileUpload->success) {
             $uploadFile = $this->FileUpload->uploadDir . DS . $this->FileUpload->finalFile;
         } else {
             $this->Session->setFlash($this->FileUpload->showErrors());
             return;
         }
         $students = Toolkit::parseCSV($uploadFile);
         $identifiers = Set::extract('/' . Course::IDENTIFIER, $students);
         $data = $this->data['Course'];
         $move = $data['action'];
         $field = $data['identifiers'];
         $fieldText = $field == 'student_no' ? __('student number', true) : __('username', true);
         // create a copy of the source survey else grab destSurveys id
         if (isset($data['sourceSurveys'])) {
             if ($data['surveyChoices']) {
                 $event = $this->Event->findById($data['sourceSurveys']);
                 $event['Event']['id'] = null;
                 $event['Event']['course_id'] = $data['destCourses'];
                 if (!$this->Event->save($event['Event'])) {
                     $this->Session->setFlash(__('Error: Event was unable to be created.', true));
                     $this->redirect('import');
                     return;
                 }
                 $destEventId = $this->Event->getLastInsertID();
             } else {
                 $destEventId = $data['destSurveys'];
             }
         }
         $error = array();
         $success = array();
         $users = array();
         if (!empty($identifiers)) {
             $users = $this->User->find('all', array('conditions' => array('User.' . $field => $identifiers, 'Role.id' => $this->User->USER_TYPE_STUDENT), 'contain' => array('Role')));
         }
         $invalid = array_diff($identifiers, Set::extract('/User/' . $field, $users));
         foreach ($invalid as $inv) {
             $error[$inv] = sprintf(__('No student with %s %s exists.', true), $fieldText, $inv);
         }
         $enrolled = $this->UserEnrol->findAllByCourseId($data['sourceCourses']);
         $enrolled = Set::extract('/UserEnrol/user_id', $enrolled);
         $destEnrolled = $this->UserEnrol->findAllByCourseId($data['destCourses']);
         $destEnrolled = Set::extract('/UserEnrol/user_id', $destEnrolled);
         if ($move) {
             $event = $this->Event->findAllByCourseId($data['sourceCourses']);
             $eventIds = Set::extract('/Event/id', $event);
             $sub = $this->EvaluationSubmission->find('all', array('conditions' => array('grp_event_id !=' => null, 'submitter_id' => $enrolled, 'EvaluationSubmission.event_id' => $eventIds)));
             $submission = Set::combine($sub, '{n}.EvaluationSubmission.id', '{n}.EvaluationSubmission', '{n}.EvaluationSubmission.submitter_id');
         }
         // enrol student
         foreach ($users as $user) {
             $identifier = $user['User'][$field];
             // enrol student to destination course if not already enrolled
             if (!in_array($user['User']['id'], $destEnrolled)) {
                 if (!$this->User->addStudent($user['User']['id'], $data['destCourses'])) {
                     $error[$identifier] = __('The student could not be enrolled to the destination course.', true);
                     continue;
                 }
             }
             // move or copy survey submission
             if (isset($data['sourceSurveys'])) {
                 $sub = $this->EvaluationSubmission->getEvalSubmissionByEventIdSubmitter($data['sourceSurveys'], $user['User']['id']);
                 $destSub = $this->EvaluationSubmission->getEvalSubmissionByEventIdSubmitter($data['destSurveys'], $user['User']['id']);
                 if ($sub && empty($destSub)) {
                     $inputs = $this->SurveyInput->getByEventIdUserId($data['sourceSurveys'], $user['User']['id']);
                     // if choose to copy set id to null
                     if (!$move) {
                         $sub['EvaluationSubmission']['id'] = null;
                     }
                     $sub['EvaluationSubmission']['event_id'] = $destEventId;
                     $sInputs = array();
                     foreach ($inputs as $input) {
                         $tmp = $input['SurveyInput'];
                         if (!$move) {
                             $tmp['id'] = null;
                         }
                         $tmp['event_id'] = $destEventId;
                         $sInputs[] = $tmp;
                     }
                     if (!($this->EvaluationSubmission->save($sub) && $this->SurveyInput->saveAll($sInputs))) {
                         $error[$identifier] = __("The student's survey submission could not be transferred, however they are enrolled in the destination course.", true);
                         continue;
                     }
                 }
             }
             if (!isset($error[$identifier])) {
                 $success[$identifier] = __('Success.', true);
             }
             if ($move && in_array($user['User']['id'], $enrolled)) {
                 if (!$this->User->removeStudent($user['User']['id'], $data['sourceCourses'])) {
                     $success[$identifier] .= __(' However they were unsuccessfully unenrolled from the source course.', true);
                 }
             } else {
                 if (!in_array($user['User']['id'], $enrolled)) {
                     $success[$identifier] .= sprintf(__(' However no student with %s %s was enrolled in the source course.', true), $fieldText, $identifier);
                 }
             }
             if ($move && isset($submission[$user['User']['id']])) {
                 $success[$identifier] .= "\n" . __("The student has already submitted a peer evaluation in the source course.", true);
             }
             if (isset($data['sourceSurveys']) && !empty($destSub) && $sub) {
                 $success[$identifier] .= "\n" . __("The student has already submitted to the\n                        destination survey, therefore the survey submission from the source survey was not transferred.", true);
             }
         }
         $this->set('errors', $error);
         $this->set('success', $success);
         $this->set('courseId', $data['destCourses']);
         $this->set('identifier', ucwords($fieldText));
         $this->FileUpload->removeFile($uploadFile);
         $this->render('import_summary');
     }
     $destCourses = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list');
     //$sourceEvents = $this->Event->getActiveSurveyEvents(array_keys($destCourses));
     //$courseIds = array_unique(Set::extract('/Event/course_id', $sourceEvents));
     $courseIds = array_keys($destCourses);
     $sourceCourses = $this->Course->getCourseList($courseIds);
     asort($sourceCourses);
     $this->set('sourceCourses', $sourceCourses);
     $this->set('sourceSurveys', array());
     $this->set('destCourses', $destCourses);
     $this->set('destSurveys', array());
 }
Example #3
Show file File: users_controller.php Project: eecian/Team08-iPeer
0
 /**
  * helper function for users/edit, to not unenrol the user being edited from
  * courses the logged user don't have access to
  *
  * @param int $editor
  * @param int $userId
  *
  * @return array of courses to not unenrol
  */
 private function _notUnenrolCourses($editor, $userId)
 {
     $editor = $this->User->findById($editor);
     $user = $this->User->findById($userId);
     $editorCourses = array();
     $userCourses = array();
     // user's list of courses
     foreach ($user['Course'] as $course) {
         $userCourses[] = $course['id'];
     }
     foreach ($user['Enrolment'] as $course) {
         $userCourses[] = $course['id'];
     }
     foreach ($user['Tutor'] as $course) {
         $userCourses[] = $course['id'];
     }
     // get editor's list of courses
     $editorCourses = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list');
     return array_diff($userCourses, array_keys($editorCourses));
 }
Example #4
Show file File: surveygroups_controller.php Project: eecian/Team08-iPeer
0
 /**
  * export
  *
  * @param mixed $courseId
  *
  * @access public
  * @return void
  */
 function export($courseId)
 {
     $course = $this->Course->getAccessibleCourseById($courseId, User::get('id'), User::getCourseFilterPermission());
     if (!$course) {
         $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
         $this->redirect('index');
         return;
     }
     $surveys = $this->Event->find('all', array('conditions' => array('course_id' => $courseId, 'event_template_type_id' => 3)));
     $surveyGrp = $this->SurveyGroupSet->find('list', array('conditions' => array('survey_id' => Set::extract('/Event/id', $surveys)), 'fields' => array('set_description')));
     $header = array('group_no' => __('Group #', true), 'username' => __('Username', true), 'student_no' => __('Student No', true), 'first_name' => __('First Name', true), 'last_name' => __('Last Name', true));
     if (!User::hasPermission('functions/viewusername')) {
         unset($header['username']);
     }
     $this->set('breadcrumb', $this->breadcrumb->push(array('course' => $course['Course']))->push(__('Export Survey Groups', true)));
     $this->set('survey_group_set', $surveyGrp);
     $this->set('fields', $header);
     if ($this->data) {
         if (!$this->SurveyGroup->save($this->data, array('validate' => 'only'))) {
             // check a filename is provided
             return;
         } else {
             if (!isset($this->data['SurveyGroup']['survey_group_set'])) {
                 // check that a survey group set is selected
                 $this->Session->setFlash(__('Please select a survey group set to export.', true));
                 return;
             } else {
                 if (empty($this->data['SurveyGroup']['fields'])) {
                     // check that a survey group set is selected
                     $this->Session->setFlash(__('Please select at least one export field.', true));
                     return;
                 }
             }
         }
         $this->autoRender = false;
         $fields = array_flip($this->data['SurveyGroup']['fields']);
         $header = array_intersect_key($header, $fields);
         $group_no = false;
         if (in_array('group_no', $this->data['SurveyGroup']['fields'])) {
             unset($fields['group_no']);
             $group_no = true;
         }
         $groups = $this->SurveyGroup->find('all', array('conditions' => array('group_set_id' => $this->data['SurveyGroup']['survey_group_set']), 'contain' => array('Member' => array('fields' => array_keys($fields)))));
         $members = array_merge(array(implode(',', $header)), $this->ExportCsv->buildSurveyGroupSet($groups, $fields, $group_no));
         $members = implode("\n", $members);
         header('Content-Type: application/csv');
         header('Content-Disposition: attachment; filename=' . $this->data['SurveyGroup']['file_name'] . '.csv');
         echo $members;
     }
 }
Example #5
Show file File: home_controller.php Project: eecian/Team08-iPeer
0
 /**
  * index
  *
  *
  * @access public
  * @return void
  */
 function index()
 {
     if (User::hasPermission('functions/coursemanager') || User::isInstructor()) {
         // Admins and profs
         $course_list = $this->Course->getAllAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'all', array('contain' => array('Event', 'Instructor')));
         $this->set('course_list', $this->_formatCourseList($course_list));
         if (!User::isStudentOrTutor()) {
             return;
         }
     }
     // Student and tutor
     $events = $this->Event->getEventsByUserId(User::get('id'));
     // mark events as late if past due date
     foreach ($events as &$type) {
         foreach ($type as &$event) {
             if ($event['Event']['due_in'] > 0) {
                 $event['late'] = false;
                 continue;
             }
             $event['late'] = true;
         }
     }
     // determine the proper penalty to be applied to a late eval
     foreach ($events['Evaluations'] as &$event) {
         if (!$event['late'] || empty($event['Penalty'])) {
             continue;
         }
         // convert seconds to days
         $daysLate = abs($event['Event']['due_in']) / 86400;
         $pctPenalty = 0;
         foreach ($event['Penalty'] as $penalty) {
             $pctPenalty = $penalty['percent_penalty'];
             if ($penalty['days_late'] > $daysLate) {
                 break;
             }
         }
         $event['percent_penalty'] = $pctPenalty;
     }
     // format the 'due in' time interval for display
     foreach ($events as &$types) {
         foreach ($types as &$event) {
             $event['Event']['due_in'] = $this->_formatDueIn(abs($event['Event']['due_in']));
         }
     }
     // remove non-current events and split into upcoming/submitted/expired
     $evals = $this->_splitSubmittedEvents($events['Evaluations']);
     $surveys = $this->_splitSubmittedEvents($events['Surveys']);
     // calculate summary statistics
     $numOverdue = 0;
     $numDue = 0;
     $numDue = sizeof($evals['upcoming']) + sizeof($surveys['upcoming']);
     // only evals can have overdue events right now
     foreach ($evals['upcoming'] as $e) {
         $e['late'] ? $numOverdue++ : '';
     }
     $this->set('evals', $evals);
     $this->set('surveys', $surveys);
     $this->set('numOverdue', $numOverdue);
     $this->set('numDue', $numDue);
     if (!User::isInstructor()) {
         $this->render('studentIndex');
     } else {
         $this->render('combined');
     }
 }
Example #6
Show file File: evaluations_controller.php Project: eecian/Team08-iPeer
0
 /**
  * viewSurveySummary
  *
  * @param int $eventId
  *
  * @access public
  * @return void
  */
 function viewSurveySummary($eventId)
 {
     // Check that $eventId is valid
     $event = $this->Event->findById($eventId);
     if (null == $event) {
         $this->Session->setFlash(__('Error: Invalid event Id', true));
         $this->redirect('index');
         return;
     }
     if ($event['Course']['student_count'] < 1) {
         $this->Session->setFlash(__('Error: There are no students in the class', true));
         $this->redirect('index');
         return;
     }
     // Check that $surveyId is valid
     $survey = $this->Survey->findById($event['Event']['template_id']);
     if (null == $survey) {
         $this->Session->setFlash(__('Error: Invalid survey Id', true));
         $this->redirect('index');
         return;
     }
     // Check that course is accessible by user
     $course = $this->Course->getAccessibleCourseById($event['Event']['course_id'], User::get('id'), User::getCourseFilterPermission(), array('Enrol'));
     if (!$course) {
         $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
         $this->redirect('index');
         return;
     }
     // Prepare data to pass to view, get current enrolled student Ids first
     // so that we can exclude the dropped students
     $studentIds = Set::extract($course['Enrol'], '/id');
     $formattedResult = $this->Evaluation->formatSurveyEvaluationSummary($survey['Survey']['id'], $eventId, $studentIds);
     $this->set('questions', $formattedResult);
     $this->set('breadcrumb', $this->breadcrumb->push(array('course' => $course['Course']))->push(array('event' => $event['Event']))->push(__('Summary', true)));
     $submissions = $this->SurveyInput->findAllByEventId($eventId);
     // add submission status for each enroled user
     foreach ($course['Enrol'] as $key => $student) {
         $course['Enrol'][$key]['submitted'] = false;
         foreach ($submissions as $submission) {
             if ($student['id'] == $submission['SurveyInput']['user_id']) {
                 $course['Enrol'][$key]['submitted'] = true;
                 break;
             }
         }
     }
     $this->set('students', $course['Enrol']);
     $this->set('eventId', $eventId);
 }
Example #7
Show file File: events_controller.php Project: eecian/Team08-iPeer
0
 /**
  * delete
  *
  * @param int $eventId
  *
  * @access public
  * @return void
  */
 function delete($eventId)
 {
     // Check whether the course exists
     if (!($event = $this->Event->getAccessibleEventById($eventId, User::get('id'), User::getCourseFilterPermission(), array('Course', 'Group', 'Penalty')))) {
         $this->Session->setFlash(__('Error: That event does not exist or you dont have access to it', true));
         $this->redirect('/home');
         return;
     }
     // what's this????
     if (isset($this->params['form']['id'])) {
         $eventId = intval(substr($this->params['form']['id'], 5));
     }
     if ($this->Event->delete($eventId)) {
         $this->Session->setFlash(__('The event has been deleted successfully.', true), 'good');
         $this->redirect('index/' . $event['Event']['course_id']);
         return;
     } else {
         $this->Session->setFlash(__('Failed to delete the event', true));
         $this->redirect('index/' . $event['Event']['course_id']);
         return;
     }
 }
Example #8
Show file File: groups_controller.php Project: eecian/Team08-iPeer
0
 /**
  * export
  *
  * @param mixed $courseId
  *
  * @access public
  * @return void
  */
 function export($courseId)
 {
     $course = $this->Course->getAccessibleCourseById($courseId, User::get('id'), User::getCourseFilterPermission());
     if (!$course) {
         $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
         $this->redirect('/courses');
         return;
     }
     $this->set('breadcrumb', $this->breadcrumb->push(array('course' => $course['Course']))->push(__('Export Groups', true)));
     $this->set('courseId', $courseId);
     if (isset($this->params['form']) && !empty($this->params['form'])) {
         // check that filename field is not empty
         if (empty($this->params['form']['file_name'])) {
             $this->Session->setFlash("Please enter a valid filename.");
             $this->redirect('');
             return;
         }
         // check that at least one group has been selected
         if (empty($this->data['Member']['Member'])) {
             $this->Session->setFlash("Please select at least one group to export.");
             $this->redirect('');
             return;
         }
         $this->autoRender = false;
         $fileContent = array();
         $groups = $this->data['Member']['Member'];
         $GroupColumns = array('Group.group_num' => array('form' => 'include_group_numbers', 'title' => __('Group Number', true)), 'Group.group_name' => array('form' => 'include_group_names', 'title' => __('Group Name', true)));
         // took out emails
         $UserColumns = array('Member.username' => array('form' => 'include_usernames', 'title' => __('Username', true)), 'Member.student_no' => array('form' => 'include_student_id', 'title' => __('Student No', true)), 'Member.first_name' => array('form' => 'include_student_name', 'title' => __('First Name', true)), 'Member.last_name' => array('form' => 'include_student_name', 'title' => __('Last Name', true)));
         $titles = array();
         $gFields = array();
         $uFields = array();
         $grp = false;
         foreach ($GroupColumns as $key => $field) {
             if (isset($this->params['form'][$field['form']])) {
                 $grp = true;
                 $titles[] = $field['title'];
                 $gFields[] = $key;
             }
         }
         foreach ($UserColumns as $key => $field) {
             if (isset($this->params['form'][$field['form']])) {
                 $titles[] = $field['title'];
                 $uFields[] = $key;
             }
         }
         $fileContent[] = implode(',', $titles);
         // check that at least one export field has been selected
         $fields = $this->params['form'];
         unset($fields['file_name']);
         $fields = array_filter($fields);
         if (empty($fields)) {
             $this->Session->setFlash("Please select at least one field to export.");
             $this->redirect('');
             return;
         }
         foreach ($groups as $groupId) {
             $group = $this->ExportCsv->buildGroupExportCsvByGroup($gFields, $uFields, $groupId);
             $fileContent = array_merge($fileContent, $group);
         }
         $fileContent = implode("\n", $fileContent);
         header('Content-Type: application/csv');
         header('Content-Disposition: attachment; filename=' . $this->params['form']['file_name'] . '.csv');
         echo $fileContent;
     } else {
         // format data
         $unassignedGroups = $this->Group->find('list', array('conditions' => array('course_id' => $courseId), 'fields' => array('group_name')));
         $this->set('unassignedGroups', $unassignedGroups);
     }
 }
Example #9
Show file File: emailer_controller.php Project: eecian/Team08-iPeer
0
 /**
  * Write an email to either a class, group, or user.
  *
  * There are 3 possible character values for type:
  * 'C' - for class
  * 'G' - for group
  * ' ' - no clue what this is used for, but it returns an empty list
  *
  * All others characters indicate single user.
  *
  * @param string $type - a class, group, or user
  * @param int $id - the id of the class, group, or user we're writing to
  *
  * @access public
  * @return void
  */
 public function write($type = null, $id = null)
 {
     // class, group, user
     if ('C' == $type || 'G' == $type || null != $id) {
         if ('C' == $type) {
             $group = $this->Course->findById($id);
             $this->breadcrumb->push(array('course' => $group['Course']));
             $courseId = $id;
         } else {
             if ('G' == $type) {
                 $group = $this->Group->findById($id);
                 $courseId = $group['Group']['course_id'];
                 $groupId = $id;
             } else {
                 if (null != $id) {
                     $group = $this->User->findById($id);
                 }
             }
         }
         // check for valid id
         if (empty($group)) {
             $this->Session->setFlash(__('Invalid Id', true));
             $this->redirect('index');
         }
     }
     $courseList = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list');
     //for checking if the user can email to class with $id
     if ('C' == $type && !User::hasPermission('functions/email/allcourses')) {
         if (!in_array($id, array_keys($courseList))) {
             $this->Session->setFlash(__('Error: You do not have permission to write emails to this course', true));
             $this->redirect('index');
         }
         // for checking if the user can email to group with $id
     } else {
         if ('G' == $type && !User::hasPermission('functions/email/allgroups')) {
             // check if they have access to group with $id
             $group = $this->Group->findById($id);
             if (!in_array($group['Course']['id'], array_keys($courseList))) {
                 $this->Session->setFlash(__('Error: You do not have permission to write emails to this group', true));
                 $this->redirect('index');
             }
         }
     }
     $this->set('breadcrumb', $this->breadcrumb->push(__('Write Email', true)));
     if (!isset($this->data)) {
         //Get recipients' email address
         $courseId = isset($courseId) ? $courseId : null;
         $grpId = isset($groupId) ? $groupId : null;
         $recipients = $this->getRecipient($type, $id);
         $this->set('recipients', $recipients['Display']);
         //Write current recipients into session
         $this->Session->write('email_recipients', $recipients['Users']);
         // Write the course id (and group id)
         $this->Session->write('grp_id', $grpId);
         $this->Session->write('course_id', $courseId);
         //Users who are not in recipients of the email
         $this->set('recipients_rest', $this->User->find('list', array('conditions' => array('NOT' => array('User.id' => Set::extract('/User/id', $recipients['Users']))))));
         $this->set('templatesList', $this->EmailTemplate->getPermittedEmailTemplate($this->Auth->user('id'), 'list'));
         $this->set('mergeList', $this->EmailMerge->getMergeList());
     } else {
         $recipients = $this->Session->read('email_recipients');
         $data = $this->data;
         $data = $data['Email'];
         $data['from'] = $this->Auth->user('id');
         $to = Set::extract('/User/id', $recipients);
         $to = implode(';', $to);
         $data['to'] = $to;
         $data['course_id'] = $this->Session->read('course_id');
         $data['grp_id'] = $this->Session->read('grp_id');
         $date = $data['date'];
         //Set current date if no schedule
         if ("" == $data['date']) {
             $data['date'] = date("Y-m-d H:i:s");
         } else {
             $tmp_data = array();
             for ($i = 1; $i <= $data['times']; $i++) {
                 $tmp_data[$i] = $data;
                 $tmp_data[$i]['date'] = date("Y-m-d H:i:s", strtotime($date) + ($i - 1) * $data['interval_type'] * $data['interval_num']);
             }
             $data = $tmp_data;
         }
         //Push an email into email_schedules table
         $data = $this->_multiMap($data);
         $this->EmailSchedule->saveAll($data);
         $this->Session->setFlash(__('The Email was saved successfully', true), 'good');
         $this->redirect('index/');
     }
 }