forked from hasith/csespn
/
loader.php
82 lines (65 loc) · 2.11 KB
/
loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
header( 'Content-type: text/html; charset=utf-8' );
require_once './global.inc.php';
require_once 'simple_html_dom.php';
verify_oauth_session_exists();
if (HttpSession::currentUser()->getOrganization()->access_level < 4) {
echo "Access denied";
die();
}
$start_index = 0;
$batch_id;
if(isset($_GET['start_index'])) $start_index = $_GET['start_index'];
if(isset($_GET['batch_id'])) $batch_id = $_GET['batch_id'];
function getSkills($html) {
$skills = array();
if($html) {
foreach($html->find('li.competency') as $element) {
$tech_name = trim($element->find('span', 0)->plaintext);
if (strpos($tech_name, '(') !== 0) {
array_push($skills, $tech_name);
}
}
}
return $skills;
}
function insertSkills($skills, $student_id) {
foreach($skills as $tech){
$techId = Technology::checkTechnologyExists(trim($tech));
if($techId <= 0){
$technology = new Technology();
$technology->name = trim($tech);
$technology->save(TRUE);
}
if(!Endorsement::checkEndorsementExists($techId, $student_id)){
$endorsement = new Endorsement();
$endorsement->student_id = $student_id;
$endorsement->technology_id = $techId;
$endorsement->count = 1;
$endorsement->save(TRUE);
}
}
}
?>
<?php
$studentTools = new StudentTools();
if(isset($batch_id)) {
$students = $studentTools->getStudents($batch_id, 'students.id', null);
} else {
$students = $studentTools->getAllStudents($start_index);
}
echo 'Begining the processing ...<br />';
foreach($students as $student){
try{
$html = file_get_html($student->profile_url);
$skills = getSkills($html);
insertSkills($skills, $student->id);
echo 'Imported data for Student:'.$student->id.'<br />';
flush();
ob_flush();
} catch(Exception $e) {
echo 'Caught exception: '.$e->getMessage().' on Student Id:'.$student->id.'<br />';
}
}
echo 'Processing complete ...<br />';
?>