GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 64c0c8...2d0c86 )
by Luis Ramón
05:14
created

index.php ➔ parseArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
rs 9.6666
1
<?php
2
3
/*  ATICA - Web application for supporting Quality Management Systems
4
  Copyright (C) 2009-2015: Luis-Ramón López López
5
6
  This program is free software: you can redistribute it and/or modify
7
  it under the terms of the GNU Affero General Public License as published by
8
  the Free Software Foundation, either version 3 of the License, or
9
  (at your option) any later version.
10
11
  This program is distributed in the hope that it will be useful,
12
  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
  GNU Affero General Public License for more details.
15
16
  You should have received a copy of the GNU Affero General Public License
17
  along with this program.  If not, see [http://www.gnu.org/licenses/]. */
18
19
require '../vendor/autoload.php';
20
require_once '../config/config.php';
21
22
session_set_cookie_params(0, null, null,
23
        isset($preferences['security.securecookies']) ?
24
            $preferences['security.securecookies'] : false,
25
        true);
26
27
session_name('ATICAID');
28
session_cache_limiter(false);
29
session_start();
30
31
// Preparar aplicación
32
$app = new \Slim\Slim(array(
33
    'mode' => 'development',
34
    'templates.path' => '../templates',
35
    'log.level' => \Slim\Log::DEBUG,
36
    'log.enabled' => true,
37
    'log.writer' => new \Slim\Extras\Log\DateTimeFileWriter(array(
38
        'path' => '../logs',
39
        'name_format' => 'y-m-d'
40
            ))
41
        ));
42
43
// Preparar vistas
44
$view = $app->view(new \Slim\Views\Twig());
45
$view->parserOptions = array(
46
    'charset' => 'utf-8',
47
    'debug' => true,
48
    'cache' => realpath('../templates/cache'),
49
    'auto_reload' => true,
50
    'strict_variables' => false,
51
    'autoescape' => true
52
);
53
$view->parserExtensions = array(
54
    new \Slim\Views\TwigExtension(),
55
    new \Atica\Extension\TwigExtension(),
56
    new \Twig_Extension_Debug()
57
);
58
$twig = $view->getInstance();
59
60
// Leer configuración global
61
$config = array(
62
    'appname' => $preferences['appname'],
63
    'base_url' => $app->request()->getUrl() . $app->request()->getRootUri() . '/');
64
65
$app->setName($preferences['appname']);
66
67
$data = ORM::for_table('configuration')->where_not_null('content_type')->
68
        where_null('organization_id')->find_array();
69
70
// Leer datos de la organización
71
$organization = null;
72
if (isset($_SESSION['organization_id'])) {
73
    $organization =
74
            ORM::for_table('organization')->
75
            find_one($_SESSION['organization_id'])->as_array();
76
} else {
77
    if (1 == ORM::for_table('organization')->count()) {
78
        $organization = ORM::for_table('organization')->find_one()->as_array();
79
        $_SESSION['organization_id'] = $organization['id'];
80
    }
81
    else {
82
        // autodetectar organización a partir de la URL
83
        $organizations = ORM::for_table('organization')->order_by_asc('code')->
84
                where_not_null('url_prefix')->find_many();
85
86
        foreach ($organizations as $org) {
87
            if (0 === strpos($config['base_url'], $org['url_prefix'])) {
88
                $_SESSION['organization_id'] = $org['id'];
89
                $organization = $org;
90
                break;
91
            }
92
        }
93
    }
94
}
95
96
// Leer configuración local de la organización
97
if (null != $organization) {
98
    $data = array_merge($data, ORM::for_table('configuration')->
99
            where_equal('organization_id', $_SESSION['organization_id'])->
100
            where_not_null('content_type')->
101
            find_array());
102
}
103
104
if (($data) && (count($data)>0)) {
105
    foreach($data as $item) {
106
        // convertir las filas de configuración en un array
107
        $config[$item['item_id']] = $item['content'];
108
    }
109
}
110
111
// Leer datos del usuario activo
112
$user = null;
113
if (isset($_SESSION['person_id'])) {
114
    $user = ORM::for_table('person')->
115
            find_one($_SESSION['person_id'])->as_array();
116
117
    // comprobar si pertenece a la organización
118
    $membership = ORM::for_table('person_organization')->
119
            where('organization_id', $_SESSION['organization_id'])->
120
            where('person_id', $_SESSION['person_id'])->
121
            where('is_active', 1)->
122
            find_one()->as_array();
123
124
    // si no pertenece, sacar al usuario porque no debería ocurrir
125
    if (!$membership) {
126
        $user = null;
127
        unset($_SESSION['person_id']);
128
    }
129
    else {
130
        // comprobar si es administrador local (siempre lo será si es
131
        // administrador global)
132
        $user['is_admin'] = $user['is_global_administrator'] ||
133
                $membership['is_local_administrator'];
134
        $user['is_active'] = $membership['is_active'];
135
        $user['is_local_administrator'] = $membership['is_local_administrator'];
136
    }
137
}
138
139
// Definir variables globales para las plantillas
140
$twig->addGlobal('config', $config);
141
$twig->addGlobal('organization', $organization);
142
$twig->addGlobal('user', $user);
143
144
// Definir rutas
145
\Slim\Route::setDefaultConditions(array(
146
    'id' => '[0-9]{1,}'
147
));
148
149
require('../routes/session.php');
150
require('../routes/personal.php');
151
require('../routes/frontpage.php');
152
require('../routes/activities.php');
153
require('../routes/event.php');
154
require('../routes/tree.php');
155
require('../routes/upload.php');
156
require('../routes/manage.php');
157
require('../routes/admin.php');
158
159
// Ejecutar aplicación
160
$app->run();
161
162
function parseArray($data, $column='id') {
163
    $return = array();
164
    
165
    foreach($data as $item) {
166
        $return[$item[$column]] = $item;
167
    }
168
    
169
    return $return;
170
}
171
172
function parseArrayMix($data, $column='id') {
173
    $return = array();
174
175
    foreach($data as $item) {
176
        $return[$item[$column]][] = $item;
177
    }
178
179
    return $return;
180
}
181