Exemple #1
0
 public static function delete_action()
 {
     // 拦截
     self::method('delete');
     self::role('member');
     self::csrf('member');
     // 校验
     // 执行
     self::send_json(category_service::delete(g_int('id')));
 }
function category_service(&$sm, $action, $command)
{
    require_once dirname(__FILE__) . '/Categories.service.php';
    $category_service = new category_service($sm);
    $um = $sm->get_url_manager();
    $dm = $sm->get_dump_manager();
    $lang = $sm->get_lang();
    $category_id = $um->get_param('CATEGORY_id');
    if ($command == 'add') {
        $in_category = $um->get_param_regexp('/^CATEGORY_/');
        $response = $category_service->add_category($in_category);
        if ($response) {
            $dm->add_dump('info', 0, $lang->get_value($um->get_param('CATEGORY_redirect') ? 'LNG_INFO_LINK_ADD_SUCCESS' : 'LNG_INFO_CATEGORY_ADD_SUCCESS'));
            vivvo_cache::get_instance()->delete('categories');
            vivvo_hooks_manager::call('category_add_postaction');
            header('X-Vivvo-Action-Status: 1');
            return true;
        } else {
            header('X-Vivvo-Action-Status: 0');
            header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info()));
            return false;
        }
    } elseif ($command == 'delete') {
        $response = $category_service->delete_category($category_id);
        if ($response) {
            $dm->add_dump('info', 0, $lang->get_value($um->get_param('CATEGORY_redirect') ? 'LNG_INFO_LINK_DELETE_SUCCESS' : 'LNG_INFO_CATEGORY_DELETE_SUCCESS'));
            vivvo_cache::get_instance()->delete('categories');
            vivvo_hooks_manager::call('category_delete_postaction');
            header('X-Vivvo-Action-Status: 1');
            return true;
        } else {
            header('X-Vivvo-Action-Status: 0');
            header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info()));
            return false;
        }
    } elseif ($command == 'edit') {
        $category_id = $um->get_param('CATEGORY_id');
        $in_category = $um->get_param_regexp('/^CATEGORY_/');
        $response = $category_service->edit_category($category_id, $in_category);
        if ($response) {
            $dm->add_dump('info', 0, $lang->get_value($um->get_param('CATEGORY_redirect') ? 'LNG_INFO_LINK_EDIT_SUCCESS' : 'LNG_INFO_CATEGORY_EDIT_SUCCESS'));
            vivvo_cache::get_instance()->delete('categories');
            vivvo_hooks_manager::call('category_edit_postaction');
            header('X-Vivvo-Action-Status: 1');
            return true;
        } else {
            header('X-Vivvo-Action-Status: 0');
            header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info()));
            return false;
        }
    } elseif ($command == 'reorder') {
        $in_category = $um->get_param('category_list');
        $in_category = json_decode($in_category, true);
        $response = $category_service->reorder_category(0, $in_category);
        if ($response !== false) {
            $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_CATEGORY_REORDER_SUCCESS'));
            vivvo_cache::get_instance()->delete('categories');
            vivvo_hooks_manager::call('category_reorder_postaction');
            header('X-Vivvo-Action-Status: 1');
            return true;
        } else {
            header('X-Vivvo-Action-Status: 0');
            header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info()));
            return false;
        }
    } elseif ($command == 'deleteImage') {
        $category_id = $um->get_param('CATEGORY_id');
        $response = $category_service->delete_image($category_id);
        if ($response) {
            $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_CATEGORY_DELETE_IMAGE_SUCCESS'));
            vivvo_cache::get_instance()->delete('categories');
            vivvo_hooks_manager::call('category_deleteImage_postaction');
            header('X-Vivvo-Action-Status: 1');
            return true;
        } else {
            header('X-Vivvo-Action-Status: 0');
            header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info()));
            return false;
        }
    }
    return true;
}