Newer
Older
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
<?php
/**
* PublicViewController
*
* @author
* @version
*/
class Courses_PublicViewController extends App_Controller_Action {
/**
* The default action - show the home page
*/
public function allCoursesAction()
{
$layout = Zend_Layout::getMvcInstance();
$layout->disableLayout();
$this->getFrontController()->setParam('noViewRenderer', true);
}
/**
* This action syncronizes the qreqCourses.currentGeneration field with data from creqCourseGenerations
*
*/
public function testAction()
{
$layout = Zend_Layout::getMvcInstance();
$layout->disableLayout();
$this->getFrontController()->setParam('noViewRenderer', true);
header('Content-type: text/plain');
$db = Zend_Registry::get('db');
$sql = 'SELECT * FROM creqCourseGenerations';
$data = $db->query($sql)->fetchAll();
$courses = array();
foreach ($data as $row) {
$courseId = $row['course'];
$generationId = $row['courseGenerationId'];
$courses[$courseId][$generationId] = $row;
}
$courseLatest = array();
foreach ($courses as $courseId => $course) {
$parent = null;
$parentIds = array();
foreach ($course as $generation) {
if ($generation['parent']) {
$parentIds[] = $generation['parent'];
}
}
foreach ($course as $generation) {
if (!in_array($generation['courseGenerationIds'], $parentIds)) {
$latest = $generation;
}
}
while ($latest['parent'] && $latest['type'] != 'official') {
$latest = $course[$latest['parent']];
}
if ($latest['type'] != 'official') {
$latestId = null;
} else {
$latestId = $latest['courseGenerationId'];
}
$courseLatest[$courseId] = $latestId;
}
foreach ($courseLatest as $courseId => $latestId) {
$data = array('currentGeneration' => $latestId);
$where = 'courseId = ' . $courseId;
$db->update('creqCourses', $data, $where);
}
}
}