public function run() { Eloquent::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('categories')->delete(); Categorie::create(array('user_id' => 2, 'nom' => 'Men Cat 1', 'nomcourt' => 'M1', 'sexe_id' => 1, 'hcpmin' => -5, 'hcpmax' => 18.4, 'agemin' => 30, 'agemax' => 99, 'agelimityear' => 0, 'tee_id' => 3)); Categorie::create(array('user_id' => 2, 'nom' => 'Men Cat 2', 'nomcourt' => 'M2', 'sexe_id' => 1, 'hcpmin' => 18.5, 'hcpmax' => 36, 'agemin' => 30, 'agemax' => 99, 'agelimityear' => 0, 'tee_id' => 4)); Categorie::create(array('user_id' => 2, 'nom' => 'Ladies Cat 1', 'nomcourt' => 'L1', 'sexe_id' => 2, 'hcpmin' => -5, 'hcpmax' => 20.4, 'agemin' => 30, 'agemax' => 99, 'agelimityear' => 0, 'tee_id' => 6)); Categorie::create(array('user_id' => 2, 'nom' => 'Ladies Cat 2', 'nomcourt' => 'L2', 'sexe_id' => 2, 'hcpmin' => 20.5, 'hcpmax' => 36, 'agemin' => 30, 'agemax' => 99, 'agelimityear' => 0, 'tee_id' => 7)); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); }
/** * Create category object * * @param array $request_data Request data * @return int ID of category * * @url POST category/ */ function post($request_data = NULL) { if (!DolibarrApiAccess::$user->rights->categorie->creer) { throw new RestException(401); } // Check mandatory fields $result = $this->_validate($request_data); foreach ($request_data as $field => $value) { $this->category->{$field} = $value; } if ($this->category->create(DolibarrApiAccess::$user) < 0) { throw new RestException(503, 'Error when create category : ' . $this->category->error); } return $this->category->id; }
/** */ public function testCategorieCreate() { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Categorie($this->savdb); $localobject->initAsSpecimen(); $result=$localobject->create($user); $this->assertLessThan($result, 0); print __METHOD__." result=".$result."\n"; return $result; }
$object->socid = ($_POST["socid"] ? $_POST["socid"] : 'null'); $object->visible = $_POST["visible"]; $object->type = $type; if($_POST['catMere'] != "-1") $object->id_mere = $_POST['catMere']; if (! $object->label) { $object->error = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")); $_GET["action"] = 'create'; } // Create category in database if (! $object->error) { $result = $object->create(); if ($result > 0) { $action = 'confirmed'; $_POST["addcat"] = ''; } } } // Confirm action if (($action == 'add' || $action == 'confirmed') && $user->rights->categorie->creer) { // Action confirmation de creation categorie if ($action == 'confirmed') { if ($urlfrom)
/** * testCategorieProduct * * @param int $id Id of category * @return int * * @depends testCategorieCreate * The depends says test is run only if previous is ok */ public function testCategorieProduct($id) { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; $localobjecttmp = new Categorie($this->savdb); $localobjecttmp->initAsSpecimen(); $localobjecttmp->label = 'Specimen Category for product'; $localobjecttmp->type = 0; // product category $catid = $localobjecttmp->create($user); print __METHOD__ . " catid=" . $catid . "\n"; $this->assertGreaterThan(0, $catid); // Try to create product linked to category $localobject2 = new Product($this->savdb); $localobject2->initAsSpecimen(); $localobject2->ref .= '-CATEG'; $localobject2->tva_npr = 1; $result = $localobject2->create($user); $cat = new Categorie($this->savdb); $cat->id = $catid; $result = $cat->add_type($localobject2, "product"); print __METHOD__ . " result=" . $result . "\n"; $this->assertGreaterThan(0, $result); // Get list of categories for product $localcateg = new Categorie($this->savdb); $listofcateg = $localcateg->containing($localobject2->id, 'product', 'label'); $this->assertTrue(in_array('Specimen Category for product', $listofcateg), 'Categ not found linked to product when it should'); return $id; }
llxHeader("","",$langs->trans("Categories")); print_titre($langs->trans("CatCreated")); print '<table border="0" width="100%">'; print '<tr><td valign="top" width="30%">'; $categorie = new Categorie($db); $categorie->label = $_REQUEST["nom"]; $categorie->description = $_REQUEST["description"]; $cats_meres = isset($_REQUEST['cats_meres']) ? $_REQUEST['cats_meres'] : array(); $res = $categorie->create(); if ($res < 0) { print "<p>Impossible d'ajouter la cat�gorie ".$categorie->label.".</p>"; } else { print "<p>La cat�gorie ".$categorie->label." a �t� ajout�e avec succ�s.</p>"; foreach ($cats_meres as $id) { $mere = new Categorie($db, $id); $res = $mere->add_fille($categorie); if ($res < 0)
/** * testCategorieProduct * * @param int $id Id of category * @return int * * @depends testCategorieCreate * The depends says test is run only if previous is ok */ public function testCategorieProduct($id) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobjecttmp=new Categorie($this->savdb); $localobjecttmp->initAsSpecimen(); $localobjecttmp->label='Specimen Category for product'; $localobjecttmp->type=0; // product category $catid=$localobjecttmp->create($user); print __METHOD__." catid=".$catid."\n"; $this->assertGreaterThan(0, $catid); // Category $localobject2=new Product($this->savdb); $localobject2->initAsSpecimen(); $localobject2->ref.='-CATEG'; $localobject2->tva_npr=1; $localobject2->catid=$catid; $result=$localobject2->create($user); print __METHOD__." result=".$result."\n"; $this->assertGreaterThan(0, $result); return $id; }