Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions class/Command/ValidateActivityImport.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of Internship Inventory.
*
Expand Down Expand Up @@ -35,20 +36,21 @@



class ValidateActivityImport {
class ValidateActivityImport
{

public function execute()
{
// Check permissions
if(!\Current_User::allow('intern', 'internship_import')){
if (!\Current_User::allow('intern', 'internship_import')) {
\NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'You do not have permission to import student data.');
\NQ::close();
\PHPWS_Core::home();
return;
}

// Check that an import id was supplied
if(!isset($_REQUEST['import_id'])){
if (!isset($_REQUEST['import_id'])) {
\NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'The import id was missing. Try selecting an import from the import list below.');
\NQ::close();
\PHPWS_Core::reroute('index.php?module=intern&action=ShowImportActivitiesStart');
Expand Down Expand Up @@ -85,7 +87,7 @@ public function execute()


// Check each row in this import
foreach($importRows as $row){
foreach ($importRows as $row) {
//var_dump($row);

$validationIssues = array();
Expand All @@ -94,43 +96,42 @@ public function execute()
$student = null;
try {
$student = StudentFactory::getStudent($row['student_id'], $row['term']);
}catch(StudentNotFoundException $e){
} catch (StudentNotFoundException $e) {
$validationIssues[] = "Unknown student ID: {$row['student_id']}";
}

// Check term code
if(!in_array($row['term'], $terms)){
if (!in_array($row['term'], $terms)) {
$validationIssues[] = "Unknown/invalid term code: {$row['term']}";
}

// Check level
if(!in_array(strtolower($row['level']), Student::LEVELS)){
if (!in_array(strtolower($row['level']), Student::LEVELS)) {
$validationIssues[] = "Unknown/invalid level: {$row['level']}";
}

// Check experience type
if(!in_array(strtolower($row['experience_type']), $expTypes)){
if (!in_array(strtolower($row['experience_type']), $expTypes)) {
$validationIssues[] = "Unknown/invalid experience type: {$row['experience_type']}";

}

// Check host name (not empty)
if($row['host_name'] === ''){
if ($row['host_name'] === '') {
$validationIssues[] = 'Missing host name';
}

// Check host state (is valid state abbreviation)
if(!in_array($row['host_state'], $states)){
if (!in_array($row['host_state'], $states)) {
$validationIssues[] = 'Invalid host state. State is not enabled in State Authorization settings, or the abbreviation is incorrect (should be two upper-case letters, ex. "NC").';
}

// Department Name (Is a valid department name)
if(!in_array($row['department_name'], $departmentNames)){
if (!in_array($row['department_name'], $departmentNames)) {
$validationIssues[] = 'Unknown department name: ' . $row['department_name'];
}

// Set the row as validated or list the issues
if(sizeof($validationIssues) == 0){
if (sizeof($validationIssues) == 0) {
// Row is valid
// Will clear any previous validation errors, if any
$validRowStmt = $db->prepare('UPDATE intern_import_activity SET validated_on = :now, validation_errors = \'\' WHERE id = :id AND import_id = :import_id');
Expand Down
8 changes: 5 additions & 3 deletions class/DataProvider/Major/TestMajorsProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of Internship Inventory.
*
Expand All @@ -23,7 +24,8 @@
use Intern\AcademicMajorList;
use Intern\AcademicMajor;

class TestMajorsProvider extends BannerMajorsProvider {
class TestMajorsProvider extends BannerMajorsProvider
{

public function __construct($currentUserName)
{
Expand All @@ -44,7 +46,8 @@ public function getMajors($term): AcademicMajorList

$majors = array();

foreach ($objs as $obj){
foreach ($objs as $obj) {
// TODO: This will need to be updated for the new AcademicMajor constructor
$majors[] = new AcademicMajor($obj->major_code, $obj->major_desc, $obj->levl);
}

Expand Down Expand Up @@ -73,5 +76,4 @@ private function createMajor($majorCode, $majorDesc, $level)

return $major;
}

}
29 changes: 17 additions & 12 deletions class/DataProvider/Student/LocalDbStudentDataProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of Internship Inventory.
*
Expand Down Expand Up @@ -27,8 +28,10 @@

use Intern\Exception\StudentNotFoundException;

class LocalDbStudentDataProvider extends StudentDataProvider {
public function getStudent($studentId){
class LocalDbStudentDataProvider extends StudentDataProvider
{
public function getStudent($studentId)
{
$db = PdoFactory::getPdoInstance();

$query = 'SELECT * FROM intern_local_student_data WHERE student_id = :studentId';
Expand All @@ -38,7 +41,7 @@ public function getStudent($studentId){

$result = $stmt->fetch(\PDO::FETCH_ASSOC);

if($result === false){
if ($result === false) {
throw new StudentNotFoundException('Could not find student in local data with id: ' . $studentId);
}

Expand All @@ -48,7 +51,7 @@ public function getStudent($studentId){
return $student;
}

protected function plugValues(&$student, Array $data)
protected function plugValues(&$student, array $data)
{
/**********************
* Basic Demographics *
Expand All @@ -62,7 +65,7 @@ protected function plugValues(&$student, Array $data)
$student->setPreferredName($data['preferred_name']);
$student->setGender($data['gender']);

if($data['confidential'] === 'Y'){
if ($data['confidential'] === 'Y') {
$student->setConfidentialFlag(true);
} else {
$student->setConfidentialFlag(false);
Expand All @@ -77,9 +80,9 @@ protected function plugValues(&$student, Array $data)
* Academic Info *
*****************/
// Campus
if($data['campus'] === 'main_campus'){
if ($data['campus'] === 'main_campus') {
$student->setCampus(Student::MAIN_CAMPUS);
} else if ($data['campus'] != ''){
} else if ($data['campus'] != '') {
$student->setCampus($data['campus']);
}

Expand All @@ -91,15 +94,17 @@ protected function plugValues(&$student, Array $data)

// Majors - Only one allowed here (this differs from WebServiceDataProvider)
// code and description fields must both be not null and not empty string to add a major
if($data['major_code'] !== null && $data['major_code'] !== ''
&& $data['major_description'] !== null && $data['major_description'] !== '') {
$student->addMajor(new AcademicMajor($data['major_code'], $data['major_description'], $data['level']));
if (
$data['major_code'] !== null && $data['major_code'] !== ''
&& $data['major_description'] !== null && $data['major_description'] !== ''
) {
$student->addMajor(new AcademicMajor($data['major_code'], $data['major_description'], $data['level'], null, null, 0));
}

$student->setGpa(round($data['gpa'], 4));

// Grad date, if available
if($data['grad_date'] !== null && $data['grad_date'] != '') {
if ($data['grad_date'] !== null && $data['grad_date'] != '') {
$student->setGradDateFromString($data['grad_date']);
}

Expand All @@ -125,7 +130,7 @@ public function getCreditHours(string $studentId, string $term)

$result = $stmt->fetch(\PDO::FETCH_ASSOC);

if($result === false){
if ($result === false) {
throw new StudentNotFoundException('Could not find student in local data with id: ' . $studentId);
}

Expand Down
13 changes: 7 additions & 6 deletions class/DataProvider/Student/StudentDataProviderFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of Internship Inventory.
*
Expand Down Expand Up @@ -28,7 +29,8 @@
* @author Jeremy Booker
* @package Intern
*/
class StudentDataProviderFactory {
class StudentDataProviderFactory
{

/**
* Returns a concrete instance of a StudenDataProvider object,
Expand All @@ -39,13 +41,13 @@ class StudentDataProviderFactory {
public static function getProvider(): StudentDataProvider
{
// First, check if the test flag override is on
if(STUDENT_DATA_TEST){
return new TestWebServiceDataProvider(\Current_User::getUsername());
}
// if (STUDENT_DATA_TEST) {
// return new TestWebServiceDataProvider(\Current_User::getUsername());
// }

$providerName = InternSettings::getInstance()->getStudentDataSource();

switch($providerName){
switch ($providerName) {
case 'localDataProvider':
return new LocalDbStudentDataProvider();
case 'webServiceDataProvider':
Expand All @@ -54,7 +56,6 @@ public static function getProvider(): StudentDataProvider
return new TestWebServiceDataProvider(\Current_User::getUsername());
default:
throw new \UnexpectedValueException('No configuration for student data provider.');

}
}
}
4 changes: 3 additions & 1 deletion class/StudentFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of Internship Inventory.
*
Expand All @@ -22,7 +23,8 @@

use \Intern\DataProvider\Student\StudentDataProviderFactory;

class StudentFactory {
class StudentFactory
{

public static function getStudent($studentId, $term)
{
Expand Down