コード例 #1
0
 public function testGet()
 {
     $broker = new APIBroker(AttributesAPITest::API);
     // Init set
     $set = new AttributeSet("set");
     $attr = new Attribute("attr", 1);
     $attr->id = AttributesService::createAttribute($attr);
     $val1 = new AttributeValue("value1");
     $val2 = new AttributeValue("value2");
     $val1->id = AttributesService::createValue($val1, $attr->id);
     $val2->id = AttributesService::createValue($val2, $attr->id);
     $attr->addValue($val1);
     $attr->addValue($val2);
     $set->addAttribute($attr);
     $set->id = AttributesService::createSet($set);
     // Get it through API
     $result = $broker->run("get", array("id" => $set->id));
     $this->assertEquals(APIResult::STATUS_CALL_OK, $result->status, "Result status check failed");
     $content = $result->content;
     $this->assertNotNull($content, "Content is null");
     $this->assertEquals($set->id, $content->id, "Set id mismatch");
     $this->assertEquals($set->label, $content->label, "Set label mismatch");
     $this->assertTrue(is_array($set->attributes), "Attributes is not an array");
     $this->assertEquals(1, count($set->attributes), "Attribute count mismatch");
     $readAttr = $content->attributes[0];
     $this->assertEquals($attr->id, $readAttr->id, "Attribute id mismatch");
     $this->assertEquals($attr->label, $readAttr->label, "Attribute label mismatch");
     $this->assertEquals($attr->dispOrder, $readAttr->dispOrder, "Attribute display order mismatch");
     $this->assertTrue(is_array($readAttr->values), "Values is not an array");
     $this->assertEquals(2, count($readAttr->values));
     $this->markTestIncomplete("Check values (order issue?)");
 }
コード例 #2
0
 /** Run the service and set result. */
 protected function proceed()
 {
     switch ($this->action) {
         case 'get':
             $this->succeed(AttributesService::get($this->params['id']));
             break;
         case 'getAll':
             $this->succeed(AttributesService::getAll());
             break;
     }
 }
コード例 #3
0
 protected function setUp()
 {
     // Attribute set
     $set = new AttributeSet("set");
     $attr = new Attribute("attr", 1);
     $val = new AttributeValue("value");
     $attr->id = AttributesService::createAttribute($attr);
     $val->id = AttributesService::createValue($val, $attr->id);
     $attr->addValue($val);
     $set->addAttribute($attr);
     $set->id = AttributesService::createSet($set);
     // Product, tax and category
     $taxCat = new TaxCat("Tax");
     $tax = new Tax(null, "Tax", stdtimefstr("2001-01-01 00:00:00"), 0.1);
     $taxCat->addTax($tax);
     $taxCat->id = TaxesService::createCat($taxCat);
     $taxCat2 = new TaxCat("Tax2");
     $tax2 = new Tax(null, "Tax2", stdtimefstr("2001-01-01 00:00:00"), 0.2);
     $taxCat2->addTax($tax2);
     $taxCat2->id = TaxesService::createCat($taxCat2);
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("INSERT INTO CATEGORIES (ID, NAME) " . "VALUES (:id, :name)");
     $stmt->execute(array(":id" => "-1", ":name" => "Refill"));
     $cat = new Category(null, "Category", false, 1);
     $cat->id = CategoriesService::createCat($cat);
     $prd = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, false, 0.5, $set->id);
     $prd->id = ProductsService::create($prd);
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 1, $taxCat2->id, true, false, 0.5, null);
     $prd2->id = ProductsService::create($prd2);
     $prdRefill = new Product("REFILL", "Refill", 1.0, "-1", null, 1, $taxCat->id, true, false);
     $prdRefill->id = ProductsService::create($prdRefill);
     // Tariff area
     $srvArea = new TariffAreasService();
     $area = new TariffArea("area", 1);
     $area->addPrice($prd->id, 0.8);
     $area->id = $srvArea->create($area);
     $this->areaId = $area->id;
     // Customer
     $srvCust = new CustomersService();
     $cust = new Customer(1, "Cust", "It's me", "card", null, null, 50.0, 10.0, 5.0, stdtimefstr("2012-01-01 00:00:00"), "It's", "me", "*****@*****.**", "012345", "23456", "11111", "Address1", "Address2", "59000", "City", "Region", "France", "Note", true);
     $cust->id = $srvCust->create($cust);
     $this->custId = $cust->id;
     // Location
     $locSrv = new LocationsService();
     $loc = new Location("Location");
     $loc->id = $locSrv->create($loc);
     $this->locationId = $loc->id;
     // Cash register
     $srvCashReg = new CashRegistersService();
     $cashReg = new CashRegister("Cash", $loc->id, 1);
     $cashReg->id = $srvCashReg->create($cashReg);
     // Cash
     $srvCash = new CashesService();
     $cash = $srvCash->add($cashReg->id);
     $cash->openDate = stdtimefstr("2000-02-02 02:02:02");
     $srvCash->update($cash);
     $this->cashId = $cash->id;
     // User
     $srvUsers = new UsersService();
     $user = new User("User", null, null, "0", true, false);
     $user->id = $srvUsers->create($user);
     // Currency
     $curr = new Currency("Eur", "€", ",", ".", "#,##0.00\$", 1, true, false);
     $srvCurr = new CurrenciesService();
     $curr->id = $srvCurr->create($curr);
     // Discount profile
     $profSrv = new DiscountProfilesService();
     $prof = new DiscountProfile("Profile", 0.1);
     $prof->id = $profSrv->create($prof);
     $this->discountProfilId = $prof->id;
     // Ticket
     $tkt1 = array("date" => stdtimefstr("2012-01-01 00:00:00"), "userId" => $user->id, "customerId" => null, "type" => Ticket::TYPE_SELL, "custCount" => 3, "tariffAreaId" => null, "discountRate" => 0.0, "discountProfileId" => null, "payments" => array(array("type" => "cash", "amount" => 10, "currencyId" => $curr->id, "currencyAmount" => 12)), "lines" => array(array("dispOrder" => 1, "productId" => $prd->id, "taxId" => $tax->id, "attributes" => null, "quantity" => 1.0, "price" => 10.0, "discountRate" => 0.0)));
     $jsAttr = array("attributeSetId" => $set->id, "values" => array(array("id" => $attr->id, "value" => "value")));
     $tkt2 = array("date" => stdtimefstr("2012-01-01 00:00:00"), "userId" => $user->id, "customerId" => null, "type" => Ticket::TYPE_SELL, "custCount" => 3, "tariffAreaId" => null, "discountRate" => 0.25, "discountProfileId" => $prof->id, "payments" => array(array("type" => "cash", "amount" => 10, "currencyId" => $curr->id, "currencyAmount" => 12)), "lines" => array(array("dispOrder" => 1, "productId" => $prd->id, "taxId" => $tax->id, "attributes" => $jsAttr, "quantity" => 1.0, "price" => 10.0, "discountRate" => 0.25)));
     $this->jsTicket1 = json_encode($tkt1);
     $this->jsTicket2 = json_encode($tkt2);
 }
コード例 #4
0
ファイル: forms.php プロジェクト: booko/pasteque-server
function form_input($form_id, $class, $object, $field, $type, $args = array())
{
    if (!isset($args['nolabel']) || $args['nolabel'] === false) {
        echo "<div class=\"row\">\n";
    }
    if (isset($args['nameid']) && $args['nameid'] == true) {
        $name = $field . "-" . $form_id;
    } else {
        $name = $field;
    }
    if (isset($args['array']) && $args['array'] == true) {
        $name = $name . "[]";
    }
    if ($type != "pick_multiple") {
        if (!isset($args['nolabel']) || $args['nolabel'] === false) {
            echo '<label for="' . esc_attr($form_id . '-' . $field) . '">';
            $fieldLabel = $field;
            if (substr($field, -2) == "Id") {
                $fieldLabel = substr($field, 0, -2);
            }
            echo esc_html(\i18n($class . "." . $fieldLabel));
            echo "</label>\n";
        }
    }
    $required = "";
    if (isset($args['required']) && $args['required']) {
        $required = ' required="true"';
    }
    switch ($type) {
        case 'string':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="text" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'text':
            echo '<textarea id="' . esc_attr($form_id . '-' . $field) . '" name="' . esc_attr($name) . '">';
            if ($object != NULL) {
                echo esc_html($object->{$field});
            }
            echo '</textarea>';
            break;
        case 'numeric':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="numeric" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'boolean':
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="checkbox" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                if ($object->{$field}) {
                    echo ' checked="checked"';
                }
            } else {
                if (!isset($args['default']) || $args['default'] == TRUE) {
                    echo ' checked="checked"';
                }
            }
            echo " />\n";
            break;
        case 'float':
            if (!isset($args['step'])) {
                $step = 0.01;
            } else {
                $step = $args['step'];
            }
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="number" step="' . esc_attr($step) . '" min="0.00" name="' . esc_attr($name) . '"';
            if ($object != NULL) {
                echo ' value="' . esc_attr($object->{$field}) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'date':
            // Class dateinput will be catched to show js date picker
            echo '<input id="' . esc_attr($form_id . '-' . $field) . '" type="text" class="dateinput" name="' . esc_attr($name) . '"';
            if ($object !== null) {
                if (isset($args['dataformat'])) {
                    if ($args['dataformat'] == 'standard') {
                        $timestamp = stdtimefstr($object->{$field});
                    } else {
                        $timestamp = timefstr($args['dataformat'], $object->{$field});
                    }
                } else {
                    $timestamp = $object->{$field};
                }
                echo ' value="' . esc_attr(\i18nDate($timestamp)) . '"';
            }
            echo "{$required} />\n";
            break;
        case 'pick':
            $model = $args['model'];
            $data = $args['data'];
            if ($model !== null) {
                switch ($model) {
                    case 'Category':
                        $data = CategoriesService::getAll(false);
                        break;
                    case 'Provider':
                        $data = ProvidersService::getAll();
                        break;
                    case 'TaxCategory':
                        $data = TaxesService::getAll();
                        break;
                    case 'Tax':
                        $cats = TaxesService::getAll();
                        $data = array();
                        foreach ($cats as $cat) {
                            $data[] = $cat->getCurrentTax();
                        }
                        break;
                    case 'CustTaxCat':
                        $data = CustTaxCatsService::getAll();
                        break;
                    case 'Role':
                        $data = RolesService::getAll();
                        break;
                    case 'Attribute':
                        $data = AttributesService::getAllAttrs();
                        break;
                    case 'AttributeSet':
                        $data = AttributesService::getAll();
                        break;
                    case 'Location':
                        $locSrv = new LocationsService();
                        $data = $locSrv->getAll();
                        break;
                    case 'DiscountProfile':
                        $profSrv = new DiscountProfilesService();
                        $data = $profSrv->getAll();
                        break;
                    case 'TariffArea':
                        $areaSrv = new TariffAreasService();
                        $data = $areaSrv->getAll();
                        break;
                }
            }
            echo '<select id="' . esc_attr($form_id . '-' . $field) . '" name="' . esc_attr($name) . '">';
            if (isset($args['nullable']) && $args['nullable']) {
                echo '<option value=""></option>';
            }
            foreach ($data as $r) {
                $selected = "";
                $r_id = $r->id;
                $r_label = $r->label;
                if ($model == null) {
                    $r_id = $r['id'];
                    $r_label = $r['label'];
                }
                if ($object != NULL && ($object->{$field} == $r_id || is_object($object->{$field}) && $object->{$field}->id == $r_id)) {
                    $selected = ' selected="true"';
                }
                echo '<option value="' . esc_attr($r_id) . '"' . $selected . '>' . esc_html($r_label) . '</option>';
            }
            echo "</select>\n";
            break;
        case 'pick_multiple':
            $model = $args['model'];
            switch ($model) {
                case 'Category':
                    $data = CategoriesService::getAll();
                    break;
            }
            foreach ($data as $r) {
                $selected = "";
                if ($object != NULL && array_search($r->id, $object->{$field}) !== FALSE) {
                    $selected = ' checked="true"';
                }
                $id = $form_id . "-" . $field . "-" . $r->id;
                echo '<label for="' . esc_attr($id) . '">' . esc_html($r->label) . '</label>';
                echo '<input id="' . esc_attr($id) . '" type="checkbox" name="' . esc_attr($name) . '[]" value="' . esc_attr($r->id) . '"' . $selected . "/>\n";
            }
            break;
    }
    if (!isset($args['nolabel']) || $args['nolabel'] === false) {
        echo "</div>";
    }
}
コード例 #5
0
 protected function setUp()
 {
     // Attribute set
     $set = new AttributeSet("set");
     $attr = new Attribute("attr", 1);
     $val = new AttributeValue("value");
     $attr->id = AttributesService::createAttribute($attr);
     $val->id = AttributesService::createValue($val, $attr->id);
     $attr->addValue($val);
     $this->attr = $attr;
     $set->addAttribute($attr);
     $set->id = AttributesService::createSet($set);
     $this->attrSet = $set;
     // Product, tax and category
     $taxCat = new TaxCat("Tax");
     $tax = new Tax(null, "Tax", stdtimefstr("2001-01-01 00:00:00"), 0.1);
     $taxCat->addTax($tax);
     $taxCat->id = TaxesService::createCat($taxCat);
     $taxCat2 = new TaxCat("Tax2");
     $tax2 = new Tax(null, "Tax2", stdtimefstr("2001-01-01 00:00:00"), 0.2);
     $taxCat2->addTax($tax2);
     $taxCat2->id = TaxesService::createCat($taxCat2);
     $this->tax = $taxCat->taxes[0];
     $this->tax2 = $taxCat2->taxes[0];
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("INSERT INTO CATEGORIES (ID, NAME) " . "VALUES (:id, :name)");
     $stmt->execute(array(":id" => "-1", ":name" => "Refill"));
     $cat = new Category(null, "Category", false, 1);
     $cat->id = CategoriesService::createCat($cat);
     $prd = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, false, 0.5, $set->id);
     $prd->id = ProductsService::create($prd);
     $this->prd = $prd;
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 1, $taxCat2->id, true, false, 0.5, null);
     $prd2->id = ProductsService::create($prd2);
     $prdRefill = new Product("REFILL", "Refill", 1.0, "-1", null, 1, $taxCat->id, true, false);
     $prdRefill->id = ProductsService::create($prdRefill);
     $this->prd = $prd;
     $this->prd2 = $prd2;
     $this->prdRefill = $prdRefill;
     // Tariff area
     $srvArea = new TariffAreasService();
     $area = new TariffArea("area", 1);
     $area->addPrice($this->prd->id, 0.8);
     $area->id = $srvArea->create($area);
     $this->area = $area;
     // Discount profile
     $srvProfile = new DiscountProfilesService();
     $profile = new DiscountProfile("Discount profile", 1.0);
     $profile->id = $srvProfile->create($profile);
     $this->discountProfile = $profile;
     // Customer
     $srvCust = new CustomersService();
     $cust = new Customer(1, "Cust", "It's me", "card", null, null, 50.0, 10.0, 5.0, stdtimefstr("2012-01-01 00:00:00"), "It's", "me", "*****@*****.**", "012345", "23456", "11111", "Address1", "Address2", "59000", "City", "Region", "France", "Note", true);
     $cust->id = $srvCust->create($cust);
     $this->customer = $cust;
     // Location
     $locSrv = new LocationsService();
     $loc = new Location("Location");
     $loc->id = $locSrv->create($loc);
     $this->location = $loc;
     // Cash
     $srvCashReg = new CashRegistersService();
     $cashReg = new CashRegister("CashReg", $loc->id, 1);
     $cashReg->id = $srvCashReg->create($cashReg);
     $srvCash = new CashesService();
     $cash = $srvCash->add($cashReg->id);
     $cash->openDate = stdtimefstr("2000-02-02 02:02:02");
     $srvCash->update($cash);
     $this->cash = $cash;
     // User
     $srvUsers = new UsersService();
     $user = new User("User", null, null, "0", true, false);
     $user->id = $srvUsers->create($user);
     $this->user = $user;
     // Currency
     $curr = new Currency("Eur", "€", ",", ".", "#,##0.00\$", 1, true, false);
     $srvCurr = new CurrenciesService();
     $curr->id = $srvCurr->create($curr);
     $this->currency = $curr;
 }
コード例 #6
0
 static function getAttribute($id)
 {
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("SELECT * FROM ATTRIBUTE WHERE ID = :id");
     if ($stmt->execute(array(':id' => $id)) !== false) {
         if ($row = $stmt->fetch()) {
             return AttributesService::buildDBAttr($row, $pdo);
         }
     }
     return null;
 }
コード例 #7
0
 /** @depends testCreateSet
  */
 public function testDeleteSet()
 {
     $set = new AttributeSet("set");
     $attr = new Attribute("attr", 1);
     $attrId = AttributesService::createAttribute($attr);
     $attr->id = $attrId;
     $set->addAttribute($attr);
     $id = AttributesService::createSet($set);
     $this->assertTrue(AttributesService::deleteSet($id), "Delete failed");
     $pdo = PDOBuilder::getPDO();
     $sql = "SELECT * FROM ATTRIBUTEUSE";
     $stmt = $pdo->prepare($sql);
     $stmt->execute();
     $row = $stmt->fetch();
     $this->assertFalse($row, "Something was found in ATTRIBUTEUSE after delete");
     $sql = "SELECT * FROM ATTRIBUTESET";
     $stmt = $pdo->prepare($sql);
     $stmt->execute();
     $row = $stmt->fetch();
     $this->assertFalse($row, "Something was found in ATTRIBUTESET after delete");
 }