123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class TimelistAction extends Action {
- private $start;
- private $duration;
-
- function prepare(array $args = array()) {
- parent::prepare($args);
- $this->start = $this->arg('start');
- $this->duration = $this->boolean('duration', false);
- return true;
- }
-
- function handle()
- {
- parent::handle();
- if (!common_logged_in()) {
-
- $this->clientError(_m('Not logged in.'));
- }
- if (!empty($this->start)) {
- $times = EventTimeList::getTimes($this->start, $this->duration);
- } else {
-
- $this->clientError(_m('Unexpected form submission.'));
- }
- if ($this->boolean('ajax')) {
- header('Content-Type: application/json; charset=utf-8');
- print json_encode($times);
- } else {
-
- $this->clientError(_m('This action is AJAX only.'));
- }
- }
-
- function clientError($msg, $code = 400) {
- if ($this->boolean('ajax')) {
- header('Content-Type: application/json; charset=utf-8');
- print json_encode(
- array(
- 'success' => false,
- 'code' => $code,
- 'message' => $msg
- )
- );
- } else {
- parent::clientError($msg, $code);
- }
- }
- }
|