当前位置: 首页>>代码示例>>PHP>>正文


PHP UserService::withRole方法代码示例

本文整理汇总了PHP中UserService::withRole方法的典型用法代码示例。如果您正苦于以下问题:PHP UserService::withRole方法的具体用法?PHP UserService::withRole怎么用?PHP UserService::withRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserService的用法示例。


在下文中一共展示了UserService::withRole方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: session_start

<?php

session_start();
require_once '../../bootstrap.php';
require '../../services/UserService.php';
require '../../services/ItemService.php';
UserService::withRole(UserService::$CONTRIBUTOR, function () {
    $unit = new unit();
    $unit->setName($_POST["name"]);
    $saved = ItemService::saveWithValidation($unit, 200);
    if ($saved == true) {
        $id = $unit->getId();
        $result = array("id" => $id);
        echo json_encode($result);
    }
});
开发者ID:sandrineBeauche,项目名称:cookbookServer,代码行数:16,代码来源:create.php

示例2: session_start

<?php

session_start();
require_once '../../bootstrap.php';
require '../../services/UserService.php';
UserService::withRole(UserService::$CONTRIBUTOR, function () {
    if (array_key_exists("id", $_GET)) {
        $recipeStepId = $_GET["id"];
        $step = RecipeStepsQuery::create()->findPk($recipeStepId);
    }
    if (isset($step)) {
        $next = $step->getNextStep();
        if (isset($next)) {
            $swap = $step->getorder();
            $step->setorder($next->getorder());
            $next->setorder($swap);
            $step->save();
            $next->save();
        }
        http_response_code(204);
        echo "true";
    } else {
        http_response_code(404);
    }
});
开发者ID:sandrineBeauche,项目名称:cookbookServer,代码行数:25,代码来源:down.php

示例3: function

UserService::withRole(UserService::$CONTRIBUTOR, function () {
    if (array_key_exists("id", $_GET)) {
        $ingredientId = $_GET["id"];
        $ingredient = ingredientTypeQuery::create()->findPk($ingredientId);
    }
    $force = false;
    if (array_key_exists("force", $_GET)) {
        $force = $_GET["force"];
    }
    if (isset($ingredient)) {
        try {
            $databaseName = unitPeer::DATABASE_NAME;
            $constraints = array("ingredient" => "ingredientId");
            if ($force == true) {
                ForeignService::forceForeignConstraints($databaseName, $constraints, $ingredientId, true);
                $ingredient->delete();
                http_response_code(204);
            } else {
                $result = ForeignService::verifyForeignConstraints($databaseName, $constraints, $ingredientId);
                if ($result) {
                    $ingredient->delete();
                    http_response_code(204);
                } else {
                    echo json_encode(array("result" => "Cet ingredient est référencée dans les ingredients de recette."));
                }
            }
        } catch (PropelException $ex) {
            http_response_code(500);
        }
    } else {
        http_response_code(404);
    }
});
开发者ID:sandrineBeauche,项目名称:cookbookServer,代码行数:33,代码来源:delete.php

示例4: session_start

<?php

session_start();
require_once '../../../bootstrap.php';
require '../../../services/UserService.php';
require '../../../services/ItemService.php';
require '../../../utils/Exceptions.php';
UserService::withRole(UserService::$CONTRIBUTOR, function () {
    $ingredient = new ingredient();
    $ingredient->setquantity($_POST["quantity"]);
    if (array_key_exists("unitId", $_POST)) {
        $unitId = $_POST["unitId"];
        if ($unitId != "-1") {
            $ingredient->setunitId($_POST["unitId"]);
        }
    }
    $ingredient->setingredientId($_POST["ingredientId"]);
    $recipeId = $_GET["recipeId"];
    $recipe = RecipeQuery::create()->findPk($recipeId);
    if (isset($recipe)) {
        $recipe->addingredient($ingredient);
        $saved = ItemService::saveWithValidation($ingredient, 200);
        if ($saved == true) {
            $id = $ingredient->getId();
            $result = array("id" => $id);
            echo json_encode($result);
        }
    } else {
        http_response_code(404);
    }
});
开发者ID:sandrineBeauche,项目名称:cookbookServer,代码行数:31,代码来源:create.php

示例5: session_start

<?php

session_start();
require_once '../../bootstrap.php';
require '../../services/UserService.php';
require '../../services/ItemService.php';
require '../../services/RequestService.php';
UserService::withRole(UserService::$CONTRIBUTOR, function () {
    $_PUT = RequestService::processPutParams();
    if (array_key_exists("id", $_GET)) {
        $ingredientId = $_GET["id"];
        $ingredient = ingredientTypeQuery::create()->findPk($ingredientId);
    }
    if (isset($ingredient)) {
        $ingredient->setName($_PUT["name"]);
        ItemService::saveWithValidation($ingredient, 204);
    } else {
        http_response_code(404);
    }
});
开发者ID:sandrineBeauche,项目名称:cookbookServer,代码行数:20,代码来源:update.php

示例6: function

UserService::withRole(UserService::$CONTRIBUTOR, function () {
    $recipe = new Recipe();
    if (array_key_exists("name", $_POST)) {
        $recipe->setName($_POST["name"]);
    }
    if (array_key_exists("description", $_POST)) {
        $recipe->setDescription($_POST["description"]);
    }
    if (array_key_exists("photo", $_POST)) {
        $recipe->setphoto($_POST['photo']);
    }
    if (array_key_exists("cost", $_POST)) {
        $recipe->setcost($_POST['cost']);
    }
    if (array_key_exists("difficulty", $_POST)) {
        $recipe->setdifficulty($_POST['difficulty']);
    }
    if (array_key_exists("time", $_POST)) {
        $recipe->settime($_POST['time']);
    }
    if (array_key_exists("calories", $_POST)) {
        $recipe->setcalories($_POST['calories']);
    }
    if (array_key_exists("countryId", $_POST)) {
        $origin = $_POST["countryId"];
        if ($origin != "-1") {
            $recipe->setorigin($origin);
        }
    }
    if (array_key_exists("categoryId", $_POST)) {
        $category = $_POST["categoryId"];
        if ($category != "-1") {
            $recipe->setcategory($category);
        }
    }
    if (array_key_exists("tags", $_POST)) {
        $tags = TagService::processTags($_POST["tags"]);
        foreach ($tags as $current) {
            $newTag = new tags();
            $newTag->settagNames($current);
            $recipe->addtags($newTag);
        }
    }
    $saved = ItemService::saveWithValidation($recipe, 200);
    if ($saved == true) {
        $id = $recipe->getId();
        $result = array("id" => $id);
        echo json_encode($result);
    }
});
开发者ID:sandrineBeauche,项目名称:cookbookServer,代码行数:50,代码来源:create.php

示例7: session_start

<?php

session_start();
require_once '../../bootstrap.php';
require '../../services/UserService.php';
UserService::withRole(UserService::$CONTRIBUTOR, function () {
    if (array_key_exists("id", $_GET)) {
        $recipeId = $_GET["id"];
        $recipe = RecipeQuery::create()->findPk($recipeId);
    }
    if (isset($recipe)) {
        try {
            tagsQuery::create()->filterByRecipe($recipe)->delete();
            $recipe->delete();
            http_response_code(204);
        } catch (PropelException $ex) {
            http_response_code(500);
        }
    } else {
        http_response_code(404);
    }
});
开发者ID:sandrineBeauche,项目名称:cookbookServer,代码行数:22,代码来源:delete.php

示例8: function

UserService::withRole(UserService::$CONTRIBUTOR, function () {
    $_PUT = RequestService::processPutParams();
    if (array_key_exists("id", $_GET)) {
        $recipeId = $_GET["id"];
        $recipe = RecipeQuery::create()->findPk($recipeId);
    }
    if (isset($recipe)) {
        $recipe->setName($_PUT["name"]);
        $recipe->setDescription($_PUT["description"]);
        if (array_key_exists("photo", $_PUT)) {
            $recipe->setphoto($_PUT['photo']);
        }
        if (array_key_exists("cost", $_PUT)) {
            $recipe->setcost($_PUT['cost']);
        }
        if (array_key_exists("difficulty", $_PUT)) {
            $recipe->setdifficulty($_PUT['difficulty']);
        }
        if (array_key_exists("time", $_PUT)) {
            $recipe->settime($_PUT['time']);
        }
        if (array_key_exists("calories", $_PUT)) {
            $recipe->setcalories($_PUT['calories']);
        }
        if (array_key_exists("countryId", $_PUT) && $_PUT["countryId"] != "-1") {
            $recipe->setorigin($_PUT["countryId"]);
        } else {
            $recipe->setcountry();
        }
        if (array_key_exists("categoryId", $_PUT) && $_PUT["categoryId"] != "-1") {
            $recipe->setcategory($_PUT["categoryId"]);
        } else {
            $recipe->setrecipeType();
        }
        if (array_key_exists("tags", $_PUT)) {
            $tags = TagService::processTags($_PUT["tags"]);
            foreach ($tags as $current) {
                $tagsId[] = $current->getid();
            }
            tagsQuery::create()->filterByRecipe($recipe)->where("tags.tagId NOT IN ?", $tagsId)->delete();
            $existingTags = tagsQuery::create()->filterByRecipe($recipe)->select(array("tagId"))->find()->toArray();
            foreach ($tagsId as $index => $current) {
                if (!in_array($current, $existingTags)) {
                    $newTag = new tags();
                    $newTag->settagNames($tags[$index]);
                    $recipe->addtags($newTag);
                }
            }
        }
        ItemService::saveWithValidation($recipe, 204);
    } else {
        http_response_code(404);
    }
});
开发者ID:sandrineBeauche,项目名称:cookbookServer,代码行数:54,代码来源:update.php


注:本文中的UserService::withRole方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。