Exemplo n.º 1
0
$requiredArgs = array('get_userlist' => array('period_id'), 'user_info' => array('user_id', 'period_id'), 'user_love' => array('period_id'), 'mark_favorite' => array('love_id', 'status'), 'favorite_why' => array('love_id', 'why'), 'update_love' => array('love_id', 'love_status', 'period_id'), 'update_wizard' => array('user_review_id', 'wizard_step'), 'peer_review_status' => array('user_review_id', 'user_review_peer_status'), 'get_periods_list' => array('page', 'rows'), 'review_completed' => array('user_review_id'), 'review_started' => array('user_review_id'), 'reset_user_review' => array('user_id'));
if (array_key_exists($_REQUEST['action'], $requiredArgs)) {
    foreach ($requiredArgs[$_REQUEST['action']] as $arg) {
        if (!isset($_REQUEST[$arg])) {
            echo json_encode(array('error' => 'args'));
            return;
        }
    }
}
$periods = new Periods($user->getId());
$review = new Review($user->getId(), $periods);
$review->setUserEmail($user->getUsername());
switch ($_REQUEST['action']) {
    // gets info about requested period with period stats (done/not done)
    case 'get_period':
        $totalCount = $periods->getPeriodCount();
        $position = !empty($_REQUEST['position']) ? intval($_REQUEST['position']) : $periods->getCurrentPeriodCount();
        $period_info = $periods->getPeriodByPosition($position);
        if ($period_info !== null) {
            $period_info = $review->getPeriodById($period_info['id']);
        }
        $period_stats = $review->getPeriodStats($period_info['id']);
        $time_percentage = 0;
        if ($period_info['status'] == 0) {
            $time_percentage = getTimePercentage($period_info['start_date'], $period_info['end_date']);
        }
        echo json_encode(array('info' => $period_info, 'stats' => $period_stats, 'count' => $totalCount, 'position' => $position, 'time_percentage' => $time_percentage));
        break;
        /*        
            case 'add_period':
                $end_date = $_REQUEST['end_date'];