<?php

require_once(dirname(__FILE__) . '/dao.php');
$context = array();
$context['theme'] = get_template_directory_uri();
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
if ($current_user_id == 0) {
    $context['message'] = '请先登录';
} else {
    $role = $current_user->roles[0];
    $user_role = '';
    $result = null;
    switch ($role) {
        case 'contributor':
            $result = TospurDao::search_view_house_by_user_id($current_user_id);
            break;
        case 'editor':
            $result = TospurDao::search_view_house_by_consultant_id($current_user_id);
            break;
    }
    if ($result) {
        foreach ($result as $item) {
            $item->time = ($item->time == 0) ? '上午' : (($item->time == 1) ? '中午' : '下午');
            $item->handle = ($item->handle == 0) ? '未接受' : '接受';
        }
        $context['result'] = $result;
    } else {
        $context['message'] = 'not found';
    }
}

Timber::render('list.html', $context);

?>