Пример #1
0
 /**
  * @param string $ps_table Target table
  * @param array $pa_data Test data. Format of a single record is similar to the JSON format used in the
  * Web Service API, only that it's a PHP array, obviously. In fact, we use the same code to insert the data.
  *
  * @see http://docs.collectiveaccess.org/wiki/Web_Service_API#Creating_new_records
  * @see https://gist.githubusercontent.com/skeidel/3871797/raw/item_request.json
  * @return int the primary key of the newly created record
  */
 protected function addTestRecord($ps_table, $pa_data)
 {
     if (!is_array($pa_data)) {
         return false;
     }
     $o_itemservice = new ItemService($this->opo_request, $ps_table);
     $va_return = $o_itemservice->addItem($ps_table, $pa_data);
     if (!$va_return) {
         $this->assertTrue(false, 'Inserting test data failed. API errors are: ' . join(' ', $o_itemservice->getErrors()));
     }
     $this->opa_record_map[$ps_table][] = $vn_return = array_shift($va_return);
     return $vn_return;
 }
Пример #2
0
 public function __call($ps_table, $pa_args)
 {
     $vo_service = new ItemService($this->request, $ps_table);
     $va_content = $vo_service->dispatch();
     if (intval($this->request->getParameter("pretty", pInteger)) > 0) {
         $this->view->setVar("pretty_print", true);
     }
     if ($vo_service->hasErrors()) {
         $this->view->setVar("errors", $vo_service->getErrors());
         $this->render("json_error.php");
     } else {
         $this->view->setVar("content", $va_content);
         $this->render("json.php");
     }
 }
Пример #3
0
 /**
  * Shows a detailed view of the item
  */
 public function view($itemId)
 {
     try {
         $itemService = new ItemService();
         $item = $itemService->fetchDetailed($itemId);
         $supplierService = new SupplierService();
         $suppliers = $supplierService->fetchSuppliersForItem($itemId);
         $itemExpenseService = new ItemExpenseService();
         $buyingPrices = $itemExpenseService->fetchBuyingPricesForItem($itemId);
     } catch (Exception $e) {
         Debug::log($e->getMessage(), 'error');
         redirect('/dashboard');
         exit;
     }
     $this->renderView('view', array('item' => $item, 'suppliers' => $suppliers, 'buyingPrices' => $buyingPrices));
 }
Пример #4
0
 public function processItemExpenseForm($data)
 {
     $this->db->trans_begin();
     try {
         $itemService = new ItemService();
         if ($data['newItem'] == 1) {
             $data['itemId'] = $itemService->saveItem($data);
         }
         if ($data['supplier']) {
             $supplierService = new SupplierService();
             $data['supplierId'] = $supplierService->saveOrUpdate($data);
         }
         $stockService = new StockService();
         $stockService->addItemsToStock($data['itemId'], $data['quantity']);
         $itemExpenseService = new ItemExpenseService();
         $itemExpenseService->saveItemExpense($data);
         $itemService->updateSuggestedSellingPrice($data['itemId'], $data['price']);
     } catch (Exception $e) {
         $this->db->trans_rollback();
         throw new Exception($e->getMessage());
     }
     $this->db->trans_commit();
 }
Пример #5
0
    }
    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);
    }
});
 protected function getSpecificItemInfo()
 {
     return parent::getSpecificItemInfo();
 }
Пример #7
0
 function getList($category_id, $subcategory_id, $location)
 {
     $itemService = new ItemService();
     $items = $itemService->getList($category_id, $subcategory_id, $location);
     return $items;
 }
Пример #8
0
<?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)) {
        $categoryId = $_GET["id"];
        $category = countryQuery::create()->findPk($categoryId);
    }
    if (isset($category)) {
        $category->setName($_PUT["name"]);
        ItemService::saveWithValidation($category, 204);
    } else {
        http_response_code(404);
    }
});
Пример #9
0
<?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)) {
        $countryId = $_GET["id"];
        $country = countryQuery::create()->findPk($countryId);
    }
    if (isset($country)) {
        $country->setName($_PUT["name"]);
        $country->setflag($_PUT["flag"]);
        ItemService::saveWithValidation($country, 204);
    } else {
        http_response_code(404);
    }
});
Пример #10
0
<?php

session_start();
require_once '../../bootstrap.php';
require '../../services/UserService.php';
require '../../services/ItemService.php';
UserService::withRole(UserService::$CONTRIBUTOR, function () {
    $country = new country();
    $country->setName($_POST["name"]);
    $country->setflag($_POST["flag"]);
    $saved = ItemService::saveWithValidation($country, 200);
    if ($saved == true) {
        $id = $country->getId();
        $result = array("id" => $id);
        echo json_encode($result);
    }
});
Пример #11
0
<?php

session_start();
require_once '../../bootstrap.php';
require '../../services/UserService.php';
require '../../services/ItemService.php';
UserService::withRole(UserService::$CONTRIBUTOR, function () {
    $category = new recipeType();
    $category->setName($_POST["name"]);
    $saved = ItemService::saveWithValidation($category, 200);
    if ($saved == true) {
        $id = $category->getId();
        $result = array("id" => $id);
        echo json_encode($result);
    }
});
Пример #12
0
<?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)) {
        $recipeStepId = $_GET["id"];
        $step = RecipeStepsQuery::create()->findPk($recipeStepId);
    }
    if (isset($step)) {
        $step->setdescription($_PUT["description"]);
        ItemService::saveWithValidation($step, 204);
    } else {
        http_response_code(404);
    }
});
Пример #13
0
    /**
     * This part of the service is basically a wrapper around BaseModel::get so we don't
     * need to test that extensively here. We "just" have to make sure the integration works.
     */
    public function testGetSpecificItemInfo()
    {
        global $_SERVER;
        // emulate client request
        $_SERVER["REQUEST_METHOD"] = "GET";
        $_SERVER["SCRIPT_NAME"] = "/service.php";
        $vo_response = new ResponseHTTP();
        $vo_request = new RequestHTTP($vo_response);
        $vs_request_body = <<<JSON
{
\t"bundles" : {
\t\t"ca_objects.access" : {
\t\t\t"convertCodesToDisplayText" : true
\t\t},
\t\t"ca_objects.preferred_labels.name" : {
\t\t\t"delimiter" : "; "
\t\t},
\t\t"ca_entities.entity_id" : {
\t\t\t"returnAsArray" : true
\t\t}
\t}
}
JSON;
        $vo_request->setParameter("id", 27, "GET");
        $vo_request->setRawPostData($vs_request_body);
        $vo_service = new ItemService($vo_request, "ca_objects");
        $va_return = $vo_service->dispatch();
        $this->assertFalse($vo_service->hasErrors());
        $this->assertEquals("Public", $va_return["ca_objects.access"]);
        $this->assertEquals("Astroland arcade, Surf Avenue", $va_return["ca_objects.preferred_labels.name"]);
        $this->assertEquals(array("4"), $va_return["ca_entities.entity_id"]);
    }
Пример #14
0
<?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)) {
        $unitId = $_GET["id"];
        $unit = unitQuery::create()->findPk($unitId);
    }
    if (isset($unit)) {
        $unit->setName($_PUT["name"]);
        ItemService::saveWithValidation($unit, 204);
    } else {
        http_response_code(404);
    }
});
Пример #15
0
        }
        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);
    }
});
Пример #16
0
<?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);
    }
});
Пример #17
0
<?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);
    }
});
Пример #18
0
    $pitems = new Plinq($itemsrev);
    $items1 = $pitems->Where(function ($key, $value) {
        return $key % 2 != 0;
    })->ToArray();
    $items2 = $pitems->Where(function ($key, $value) {
        return $key % 2 == 0;
    })->ToArray();
    foreach ($items1 as $item) {
        $html1 .= $app->view()->fetch("item.php", ["model" => $item]);
    }
    foreach ($items2 as $item) {
        $html2 .= $app->view()->fetch("item.php", ["model" => $item]);
    }
    $app->render('template.php', array('view' => "home.php", 'state' => $state, 'items1' => $html1, 'items2' => $html2));
});
$app->post('/add/', function () use($app) {
    $response = new JsonResponse();
    $itemService = new ItemService();
    $model = $itemService->insert($_POST, $_FILES["images"]);
    $modelWithImages = $itemService->getWithImages($model->id);
    $html = $app->view()->fetch("item.php", ["model" => $modelWithImages]);
    $response->successful("Successfully added a new post", $modelWithImages, $html);
});
$app->post("/delete/", function () use($app) {
    $response = new JsonResponse();
    $itemService = new ItemService();
    $id = $_POST["id"];
    $result = $itemService->delete($id);
    $response->successful("Successfully deleted the post", $result);
});
$app->run();