public function update(SubCategory $subCategory)
 {
     $id = $subCategory->getid();
     $description = $this->db > quote($subCategory->getDescription());
     $name = $this->db > quote(${$subCategory}->getName());
     $image = $this->db > quote($subCategory->getImage());
     $query = "UPDATE subcategory SET name=" . $name . " description=" . $description . " image=" . $image . " WHERE id=" . $id;
     $res = $this->db->query($query);
     if ($res) {
         return $this->findById($id);
     } else {
         throw new Exception("internal server error");
     }
 }
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         SubCategory::create([]);
     }
 }
示例#3
0
 /**
  * Display a listing of the resource.
  * GET /subcategories
  *
  * @return Response
  */
 public function index()
 {
     $subCategory = new SubCategory();
     $subCategory->name = Request::get('name');
     $subCategory->description = Request::get('description');
     $subCategory->category_id = Request::get('category_id');
     //$category->user_id = Auth::user()->id;
     // Validation and Filtering is sorely needed!!
     // Seriously, I'm a bad person for leaving that out.
     if (Auth::user()->id == 1) {
         $subCategory->save();
         return Response::json(array('error' => false, 'categories' => $subCategory->toArray()), 200);
     } else {
         return Response::json(array('error' => true, 'reason' => 'Error with user id' . Auth::user()->id), 200);
     }
 }
示例#4
0
 public function actionIndex()
 {
     $criteria = new CDbCriteria();
     $criteria->select = '*';
     $criteria->order = 'category_id ASC, name ASC';
     $this->allRec = SubCategory::model()->findAll($criteria);
     $this->render('index');
 }
 public function create(Category $category, $name, $description, $img)
 {
     $sub_category = new SubCategory($this->db);
     $errors = array();
     try {
         $sub_category->setCategory($category);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $sub_category->setName($name);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $sub_category->setDescription($description);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     try {
         $sub_category->setImg($img);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $idCategory = intval($sub_category->getIdCategory());
         $name = $this->db->quote($sub_category->getName());
         $description = $this->db->quote($sub_category->getDescription());
         $img = $this->db->quote($sub_category->getImg());
         $query = "INSERT INTO sub_category (id_category, name, description, img) VALUES ('" . $idCategory . "', " . $name . ", " . $description . ", " . $img . ")";
         $res = $this->db->exec($query);
         if ($res) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 return $this->findById($id);
             } else {
                 throw new Exception("Internal server error");
             }
         }
     } else {
         return $errors;
     }
 }
示例#6
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     if (Auth::user()->type === 'user') {
         return redirect('admin/patterns');
     }
     $users = User::all();
     // $date = $users->timestamp;
     $patterns = Pattern::all();
     $category = Category::all();
     $subcategory = SubCategory::all();
     $nielsen = RulesNielsen::all();
     $comments = Comment::all();
     return view('admin.dashboard', ['patternsCount' => $patterns->count(), 'patterns' => Pattern::where('active', 1)->orderBy('title', 'desc')->take(8)->get(), 'users' => $users, 'nielsen' => $nielsen, 'category' => $category, 'subcategory' => $subcategory, 'comments' => $comments, 'commentsCount' => $comments->count(), 'usersTime' => Carbon::now()->subDays(1)->diffForHumans(), 'usersCount' => $users->count(), 'usersNormals' => User::where('type', 'user')->orderBy('active', 'desc')->take(8)->get(), 'usersExperts' => User::where('type', 'expert')->orderBy('active', 'desc')->take(8)->get()]);
 }
 public function subcategories($categoryId)
 {
     if (isset($categoryId)) {
         $category = Category::find($categoryId);
         if (isset($category)) {
             $subcategories = SubCategory::where('status', 'active')->where('category_id', $categoryId)->get();
             if (isset($subcategories) && count($subcategories) > 0) {
                 return json_encode(array('message' => 'found', 'subcategories' => $subcategories->toArray()));
             } else {
                 return json_encode(array('message' => 'empty'));
             }
         } else {
             return json_encode(array('message' => 'invalid'));
         }
     } else {
         return json_encode(array('message' => 'invalid'));
     }
 }
示例#8
0
     $mainCategory = new MainCategory();
     $mainCategory->type = $_POST['type'];
     $result = $mainCategory->getIdCategory();
     $cat_id = $result['id'];
     $subCategory = new SubCategory();
     $subCategory->category_id = $cat_id;
     $data = $subCategory->getSubCatByMainCat();
     echo json_encode($data);
     break;
 case 'addProduct':
     # code...
     $mainCategory = new MainCategory();
     $mainCategory->type = $_POST['typeMain'];
     $result = $mainCategory->getIdCategory();
     $cat_id = $result['id'];
     $subCategory = new SubCategory();
     $subCategory->category_id = $cat_id;
     $subCategory->type = $_POST['typeSub'];
     $res = $subCategory->getSubCatId();
     $idSub = $res['id'];
     $product = new Product();
     $product->sub_id = $idSub;
     $product->material = $_POST['material'];
     $product->qty = $_POST['qty'];
     $product->price = $_POST['price'];
     $product->color = $_POST['color'];
     $product->size = $_POST['size'];
     echo $product->insertProduct();
     break;
 default:
     # code...
 public function assignExpertCategory()
 {
     $adminId = Session::get('admin_id');
     if (!isset($adminId)) {
         return json_encode(array('message' => 'not logged'));
     }
     $categoryId = Input::get('category');
     $subcategoryId = Input::get('subcategory');
     $category = Category::find($categoryId);
     $subcategory = SubCategory::find($subcategoryId);
     if (isset($category) && isset($subcategory)) {
         $expertId = Session::get('current_expert_id');
         $tempExpertCategory = ExpertCategory::where('category_id', $categoryId)->where('subcategory_id', $subcategoryId)->where('expert_id', $expertId)->get();
         if (isset($tempExpertCategory) && count($tempExpertCategory) > 0) {
             return json_encode(array('message' => 'duplicate'));
         } else {
             $expertCategory = new ExpertCategory();
             $expertCategory->category_id = $categoryId;
             $expertCategory->subcategory_id = $subcategoryId;
             $expertCategory->expert_id = Session::get('expert_id');
             $expertCategory->status = "active";
             $expertCategory->save();
             return json_encode(array('message' => 'done'));
         }
     } else {
         return json_encode(array('message' => 'invalid'));
     }
 }
示例#10
0
<?php

include 'sub-cat.php';
$sub = new SubCategory();
include 'product.php';
$pro = new Product();
switch ($_GET['action']) {
    case 'selectsub':
        $id = $_GET['id'];
        $subs = $sub->sub_by_category($id);
        echo json_encode($subs);
        //var_dump($subs);
        break;
    case 'selectProduct':
        $name = $_GET['name'];
        $id = $_GET['id'];
        $proObj = $pro->product($name, $id);
        if ($proObj) {
            $result = array("result" => "false");
        } else {
            $result = array("result" => "true");
        }
        echo json_encode($result);
        //var_dump($proObj);
        break;
    case 'editstatus':
        $id = $_GET['id'];
        $status = $_GET['status'];
        //echo "id = ".$id."status = ".$status;
        $pro->status = $status;
        $product_id = $pro->updateStatus($id);
示例#11
0
 public function setSubCategory(SubCategory $sub_category)
 {
     $this->id_sub_category = $sub_category->getId();
     $this->sub_category = $sub_category;
     return true;
 }
示例#12
0
 function __construct($id = -1)
 {
     if (self::$conn == Null) {
         self::$conn = mysqli_connect('localhost', 'root', 'iti', 'store');
     }
 }
示例#13
0
    $brand = $_GET['brand'];
}
$priceArray = null;
if (isset($_GET['price']) && $_GET['price'] != '') {
    $priceArray = explode(',', $_GET['price']);
    $price = $_GET['price'];
}
?>
<div class="toltip" style="visibility:hidden;position:absolute;cursor:pointer;left:100px;top:50px;border:solid1px#eee;background-color:#ffffdd;padding:10px;z-index:1000;">Le produit a bien été <br> ajouté au panier</div>

  <section  id="columns" class="container_9 clearfix col2-right">
  <div class="breadcrumb"> 
	<a title="return to Home" href="home.php">Acceuil</a> 
	<span class="navigation-pipe">/</span> 
	<?php 
$subCategory = new SubCategory($db, $_GET['idSubCategory']);
$category = $subCategory->getCategory();
?>
	<a class="return_to_category" href="product-grid.php?idSubCategory=<?php 
echo $category['id_categorie'];
?>
">
	<?php 
echo utf8_encode($category['libelle_cat']);
?>
	</a>
	<span class="navigation-pipe">/</span>
	<?php 
echo utf8_encode($subCategory->getSubCategoryName());
?>
  </div>
示例#14
0
<?php

session_start();
include 'sub-cat.php';
$sub_cat = new SubCategory();
if (isset($_GET['method'])) {
    $method = $_GET['method'];
    echo "method = {$method}";
    $id = $_GET['id'];
} else {
    $method = $_POST['method'];
    echo "method = {$method}";
}
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
switch ($method) {
    case 'insert':
        if (isset($_POST['add_sub_cat']) && !empty($_POST['add_sub_cat'])) {
            $sub_cat->name = $_POST['add_sub_cat'];
            $sub_cat->cat_id = $_POST['cat_id'];
            $sub_cat_id = $sub_cat->insert();
            echo "cat_id = " . $_POST['category'];
            echo "sub_cat = " . $_POST['add_sub_cat'];
            echo "<br/>inserted id = " . $sub_cat_id;
            header("location:../controle.php");
        } else {
            $_SESSTION['error'] = "please enter a valid name";
            echo "error";
            header("location:../controle.php");
        }
 /**
  * Get photo sub category list rendering photo sub categories.
  *
  * @return void
  */
 public function getSubCategoryList($categoryCode)
 {
     global $data;
     global $settings;
     $thisCategoryId = $data['categories'][$categoryCode]['id'];
     $thisSubCategories = $data['categories'][$categoryCode]['settings']['sub_categories'];
     $stmt = SubCategory::where('category_id', '=', $thisCategoryId);
     $stmt->whereIn('code', $thisSubCategories);
     $stmt->orderBy(DB::raw("FIELD(code, '" . implode("','", $thisSubCategories) . "')"));
     $result = $stmt->get()->keyBy('code')->toArray();
     return $result;
 }
<?php

$app->get('/public/categorias', function () use($app) {
    //    $c = Category::find(0);
    $c = SubCategory::all();
    $error = false;
    $mensagem = '';
    if (count($c) < 1) {
        $error = true;
        $mensagem = 'Nenhum registro encontrado';
    }
    helpers::send($error, $mensagem, $c);
});