Example #1
0
    public function create($name, $description)
    {
        $category = new Category($this->db);
        try {
            $category->setName($name);
            $category->setDescription($description);
        } catch (Exception $e) {
            $err = $e->getMessage();
        }
        if (!isset($err)) {
            $name = $this->db->quote($category->getName());
            $description = $this->db->quote($category->getDescription());
            $query = '	INSERT INTO category (name, description)
								VALUES (' . $name . ', ' . $description . ')';
            $res = $this->db->exec($query);
            if ($res) {
                $id = $this->db->lastInsertId();
                if ($id) {
                    return $this->readById($id);
                } else {
                    throw new Exception('Database error');
                }
            } else {
                throw new Exception("Database error");
            }
        } else {
            throw new Exception($err);
        }
    }
 private function parseForm(HTTPRequest $request, Category $category)
 {
     $name = htmlspecialchars($request->postData('name'));
     $description = htmlspecialchars($request->postData('description'));
     $isRoot = !$request->postExists('parent-category');
     $category->setName($name);
     $category->setIsRoot($isRoot);
     $category->setDescription($description);
     if (!$isRoot) {
         $parentCategoryId = $request->postData('parent-category');
         $category->setParentCategoryId($parentCategoryId);
     }
 }
 public function create($name, $description, $img)
 {
     $category = new Category($this->db);
     $errors = array();
     try {
         $category->setName($name);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $category->setDescription($description);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $category->setImg($img);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $name = $this->db->quote($category->getName());
         $description = $this->db->quote($category->getDescription());
         $img = $this->db->quote($category->getImg());
         $query = "INSERT INTO category (name, description, img) VALUES(" . $name . "," . $description . "," . $img . ")";
         $res = $this->db->exec($query);
         if ($res) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 return $this->findById($id);
             } else {
                 $errors[] = "Category not found";
                 return $errors;
             }
         } else {
             $errors[] = "Internal server error";
             return $errors;
         }
     } else {
         return $errors;
     }
 }
Example #4
0
 public function importCategories(Import $entity, $output)
 {
     $em = $this->container->get('doctrine')->getManager();
     $sql = ' SELECT s.id, s.nombre, s.slug FROM  `servicio` AS s ' . ' ORDER BY s.id ';
     //               . ' LIMIT '.$entity->getLimitStart().', '.$entity->getLimitEnd();
     $link = mysqli_connect($entity->getServer(), $entity->getUsername(), $entity->getPassword(), $entity->getDbname()) or die('No se pudo conectar: ' . mysqli_error($link));
     $resultado = $link->query($sql);
     if (mysqli_num_rows($resultado) > 0) {
         while ($fila = mysqli_fetch_assoc($resultado)) {
             //Create Categories
             $category = new Category();
             $category->setName(utf8_encode($fila['nombre']));
             $category->setDescription(utf8_encode($fila['nombre']));
             $category->setMetaTitle(utf8_encode($fila['nombre']));
             $category->setMetaDescription(utf8_encode($fila['nombre']));
             $category->setSlug(utf8_encode($fila['slug']));
             $em->persist($category);
         }
         $em->flush();
     }
 }
 public function create(User $currentUser, $name, $description)
 {
     $category = new Category($this->database);
     if ($currentUser) {
         if ($currentUser->getRights() == 2) {
             $set = $category->setName($name);
             if ($set === true) {
                 $set = $category->setDescription($description);
                 if ($set === true) {
                     $name = $this->database->quote($category->getName());
                     $description = $this->database->quote($category->getDescription());
                     $query = "INSERT INTO category (name, description)\n\t\t\t\t\t\t\tVALUES (" . $name . ", " . $description . ")";
                     $result = $this->database->exec($query);
                     if ($result) {
                         $id = $this->database->lastInsertId();
                         if ($id) {
                             try {
                                 return $this->findById($id);
                             } catch (Exception $e) {
                                 $errors[] = $e->getMessage();
                             }
                         } else {
                             throw new Exception("Catastrophe serveur.");
                         }
                     } else {
                         throw new Exception("Catastrophe base de données.");
                     }
                 } else {
                     throw new Exception($set);
                 }
             } else {
                 throw new Exception($set);
             }
         } else {
             throw new Exception("Erreur : Droits d'administration requis.");
         }
     } else {
         throw new Exception("Erreur : Connexion requise.");
     }
 }
    if (!empty($row['phone']['number'])) {
        $person->setPhoneNumber($row['phone']['number']);
    }
    if (!empty($row['phone']['device_id'])) {
        $person->setPhoneDeviceId($row['phone']['device_id']);
    }
    $person->save();
    $zend_db->insert('people_crosswalk', array('person_id' => $person->getId(), 'mongo_id' => (string) $row['_id']));
    echo "Person: {$person->getFullname()}\n";
}
// Load the Categories
$result = $mongo->categories->find();
foreach ($result as $r) {
    $c = new Category();
    $c->setName($r['name']);
    $c->setDescription($r['description']);
    $c->setDisplayPermissionLevel($r['displayPermissionLevel']);
    $c->setPostingPermissionLevel($r['postingPermissionLevel']);
    $g = new CategoryGroup($r['group']['name']);
    $c->setCategoryGroup($g);
    $d = new Department($r['department']['name']);
    $c->setDepartment($d);
    if (!empty($r['customFields'])) {
        $c->setCustomFields(json_encode($r['customFields']));
    }
    $c->save();
    echo "Category: {$c->getName()}\n";
}
// Now that we've got People and Categories in the database,
// Link the Departments with their Categories and Default Person
$result = $mongo->departments->find();
Example #7
0
<?php

require '../class/class_category.php';
if (isset($_POST) && !empty($_POST)) {
    $category = new Category();
    $category->setName($_POST['name']);
    $category->setDescription($_POST["description"]);
    $category->setPicture("");
    $category->create();
    var_dump($category);
    exit;
}