forked from m4n3z40/WeLearn
/
segmento.php
executable file
·59 lines (42 loc) · 1.91 KB
/
segmento.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
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Segmento extends WL_Controller {
/**
* Construtor carrega configurações da classes base CI_Controller
* (Resolve bug ao utilizar this->load)
*/
function __construct()
{
parent::__construct();
}
public function recuperar_lista($area = '')
{
if( ! $this->input->is_ajax_request()) {
show_404();
}
set_json_header();
if ($area) {
try {
$segmentoDao = WeLearn_DAO_DAOFactory::create('SegmentoDAO');
$opcoes = array('areaId' => $area);
$listaSegmentos = $segmentoDao->recuperarTodos('', '', $opcoes);
$dropdownSegmentos = array();
foreach ($listaSegmentos as $segmento) {
$dropdownSegmentos[] = $segmento->toCassandra();;
}
$segmentosJSON = Zend_Json::encode($dropdownSegmentos);
echo '{"success":true, "segmentos":' . $segmentosJSON . '}';
} catch(cassandra_NotFoundException $e) {
$error_msg = 'Esta área ainda não possui segmentos,'
.' sinta-se a vontade para adicionar um segmento você mesmo!';
$error = create_json_feedback_error_json($error_msg, 'area');
echo create_json_feedback(false, $error);
} catch(Exception $e) {
log_message('error', 'Erro ao recuperar lista de segmentos: '. create_exception_description($e));
$error = create_json_feedback_error_json('Ops! ocorreu um erro. Tente novamente em breve.');
echo create_json_feedback(false, $error);
}
}
}
}
/* End of file segmento.php */
/* Location: ./application/controllers/segmento.php */