コード例 #1
0
ファイル: ProductsController.php プロジェクト: racklin/invo
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Phalcon_Model_Query::fromInput("Products", $_POST);
         $this->session->conditions = $query->getConditions();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
         if ($numberPage <= 0) {
             $numberPage = 1;
         }
     }
     $parameters = array();
     if ($this->session->conditions) {
         $parameters["conditions"] = $this->session->conditions;
     }
     $parameters["order"] = "id";
     $products = Products::find($parameters);
     if (count($products) == 0) {
         Flash::notice("The search did not find any products", "alert alert-info");
         return $this->_forward("products/index");
     }
     $paginator = Phalcon_Paginator::factory("Model", array("data" => $products, "limit" => 5, "page" => $numberPage));
     $page = $paginator->getPaginate();
     $this->view->setVar("page", $page);
     $this->view->setVar("products", $products);
 }
コード例 #2
0
ファイル: ProductsController.php プロジェクト: Rho1and0/invo
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Criteria::fromInput($this->di, "Products", $_POST);
         $this->persistent->searchParams = $query->getParams();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
         if ($numberPage <= 0) {
             $numberPage = 1;
         }
     }
     $parameters = array();
     if ($this->persistent->searchParams) {
         $parameters = $this->persistent->searchParams;
     }
     $products = Products::find($parameters);
     if (count($products) == 0) {
         $this->flash->notice("The search did not find any products");
         return $this->forward("products/index");
     }
     $paginator = new Phalcon\Paginator\Adapter\Model(array("data" => $products, "limit" => 5, "page" => $numberPage));
     $page = $paginator->getPaginate();
     $this->view->setVar("page", $page);
 }
コード例 #3
0
 /**
  * Delete a customer record
  */
 public function deleteAction()
 {
     $productsTable = new Products();
     $product = $productsTable->find($this->_getParam('id'))->current();
     !is_null($product) && $product->delete();
     $this->_redirect('/products');
 }
コード例 #4
0
 public static function updateStock($productId)
 {
     $product = Products::find($productId);
     $stockQuantity = Stocks::whereProductId($productId)->sum('quantity');
     $soldQuantity = SalesItems::where('product_id', '=', $productId)->sum('quantity');
     $product->quantity = $stockQuantity - $soldQuantity;
     $product->save();
 }
コード例 #5
0
 public function indexAction()
 {
     $indexProducts = Products::find(array("limit" => 5, "order" => "id asc"));
     $products = Products::find(array("order" => "id asc"));
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $products, "limit" => 8, "page" => $dynamicPageBegin));
     $this->view->page = $paginator->getPaginate();
     $this->view->indexProducts = $indexProducts;
 }
コード例 #6
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     $discountTypes = ['' => 'Select Discount Type', 'percentage' => 'Percentage', 'fixed' => 'Fixed'];
     $statuses = Discounts::$statuses;
     $discount = Discounts::find($id);
     $product = Products::find($discount->product_id);
     return View::make('discounts.edit', compact('discountTypes', 'product', 'statuses', 'discount'));
 }
コード例 #7
0
 public function indexAction()
 {
     $currentPage = 1;
     $currentPage = $this->request->get("page");
     $products = Products::find();
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $products, "limit" => 4, "page" => $currentPage));
     $page = $paginator->getPaginate();
     $this->view->setVar("page", $page);
 }
コード例 #8
0
 /**
  * @param int $customerId
  * @param int $productId
  */
 public function findProductCoalesced($customerId, $productId)
 {
     $productsTable = new Products();
     $p = $productsTable->find($productId)->current();
     $cp = $this->find($productId, $customerId)->current();
     if ($cp) {
         $productCoalesced = array('product_id' => $cp->product_id, 'sku' => $cp->sku ?: $p->sku, 'name' => $cp->name ?: $p->name, 'description' => $cp->description ?: $p->description, 'unit_price' => $cp->unit_price ?: $p->unit_price);
     } else {
         $productCoalesced = array('product_id' => $p->product_id, 'sku' => $p->sku, 'name' => $p->name, 'description' => $p->description, 'unit_price' => $p->unit_price);
     }
     return $productCoalesced;
 }
コード例 #9
0
 public function indexAction()
 {
     $news1 = News::find(array("typeid = 1", "order" => "inputtime desc", "limit" => 5));
     $news2 = News::find(array("typeid = 2", "order" => "inputtime desc", "limit" => 5));
     $news3 = News::find(array("typeid = 3", "order" => "inputtime desc", "limit" => 3));
     $news4 = News::find(array("typeid = 4", "order" => "inputtime desc", "limit" => 5));
     $indexProducts = Products::find(array("limit" => 5, "order" => "id asc"));
     $this->view->indexProducts = $indexProducts;
     $this->view->setVar("news1", $news1);
     $this->view->setVar("news2", $news2);
     $this->view->setVar("news3", $news3);
     $this->view->setVar("news4", $news4);
 }
コード例 #10
0
ファイル: ProductsService.php プロジェクト: ynijar/products
 public static function findByName($name)
 {
     $response = new Response();
     if (!$name) {
         $response->status = $response::STATUS_BAD_REQUEST;
         $response->addError('NAME_IS_REQUIRED');
         return $response->toArray();
     }
     try {
         $response->data = Products::find(['conditions' => 'name LIKE :name:', 'bind' => ['name' => '%' . $name . '%'], 'order' => 'name DESC'])->toArray();
     } catch (Exception $e) {
         $response->setException($e);
     } finally {
         return $response->toArray();
     }
 }
コード例 #11
0
ファイル: tags-193.php プロジェクト: aodkrisda/phalcon-code
<?php

// Using data from a resultset
echo $this->tag->select(array("productId", Products::find("type = 'vegetables'"), "using" => array("id", "name")));
// Using data from an array
echo $this->tag->selectStatic(array("status", array("A" => "Active", "I" => "Inactive")));
コード例 #12
0
<?php

//Passing a resultset as data
$paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => Products::find(), "limit" => 10, "page" => $currentPage));
//Passing an array as data
$paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => array(array('id' => 1, 'name' => 'Artichoke'), array('id' => 2, 'name' => 'Carrots'), array('id' => 3, 'name' => 'Beet'), array('id' => 4, 'name' => 'Lettuce'), array('id' => 5, 'name' => '')), "limit" => 2, "page" => $currentPage));
//Passing a querybuilder as data
$builder = $this->modelsManager->createBuilder()->columns('id, name')->from('Robots')->orderBy('name');
$paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 20, "page" => 1));
コード例 #13
0
ファイル: model.php プロジェクト: LWFeng/xnx
{
    // fields
    public $id;
    public $name;
    public function initialize()
    {
        // $this->setSource("the_robots");
    }
}
// Find record with id = 3
$robot = Robots::findFirst(3);
// *** paginator ***
use Phalcon\Paginator\Adapter\Model as ModelPaginator;
use Phalcon\Paginator\Adapter\NativeArray as ArrayPaginator;
use Phalcon\Paginator\Adapter\QueryBuilder as BuildPaginator;
//Passing a resultset as data
$paginator = new ModelPaginator(array("data" => Products::find(), "limit" => 10, "page" => $currentPage));
//Passing an array as data
$paginator = new ArrayPaginator(array("data" => array(array('id' => 1, 'name' => 'Artichoke'), array('id' => 2, 'name' => 'Carrots'), array('id' => 3, 'name' => 'Beet'), array('id' => 4, 'name' => 'Lettuce'), array('id' => 5, 'name' => '')), "limit" => 2, "page" => $currentPage));
$builder = $this->modelsManager->createBuilder()->from("App\\Models\\Article")->where($where)->orderBy("create_time DESC");
$paginator = new BuildPaginator(array("builder" => $builder, "limit" => 5, "page" => $this->request->queryPage()));
$dataset = $paginator->getPaginate();
/*
items       The set of records to be displayed at the current page
current     The current page
before      The previous page to the current one
next        The next page to the current one
last        The last page in the set of records
total_pages The number of pages
total_items The number of items in the source data
//*/
コード例 #14
0
<?php

$products = Products::find($parameters);
if (count($products) == 0) {
    $this->flash->notice("The search did not found any products");
    return $this->forward("products/index");
}
コード例 #15
0
 public function returnitem($id)
 {
     $sales = SalesItems::where('sales_id', '=', $id)->get();
     if ($sales) {
         foreach ($sales as $sale) {
             if ($this->user->outlet_id != 0) {
                 $outletstock = OutletsStocks::where('product_id', '=', $sale->product_id)->where('outlet_id', '=', $this->user->outlet_id)->first();
                 if ($outletstock) {
                     $outletstock->quantity = $outletstock->quantity + $sale->quantity;
                     $outletstock->save();
                     SalesItems::destroy($sale->id);
                 }
             } else {
                 $product = Products::find($sale->product_id);
                 if ($product) {
                     // var_dump($product);exit();
                     $product->quantity = $product->quantity + $sale->quantity;
                     $product->save();
                     SalesItems::destroy($sale->id);
                 }
             }
         }
         Sales::destroy($id);
         return Redirect::route('sales.index')->with('success', 'Item successfully return');
     }
 }
コード例 #16
0
ファイル: micro-326.php プロジェクト: aodkrisda/phalcon-code
<?php

$loader = new \Phalcon\Loader();
$loader->registerDirs(array(__DIR__ . '/models/'))->register();
$app = new \Phalcon\Mvc\Micro();
$app->get('/products/find', function () {
    foreach (Products::find() as $product) {
        echo $product->name, '<br>';
    }
});
$app->handle();
コード例 #17
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($idp)
 {
     //
     Products::find($idp)->delete();
     return Redirect::route('manageproduct.displayInformation')->with('message', 'Deleted Successfully');
 }
コード例 #18
0
<?php

// Cache the resultset for only for 5 minutes
$products = Products::find(array("cache" => array("key" => "my-cache", "lifetime" => 300)));
コード例 #19
0
 public function allowProductEditDelete()
 {
     $product_id = Input::json('id');
     $requested_ch_right = "AllowProductEditDelete";
     $usergroup = User::find(Auth::id())->usergroup()->first();
     $channel_id = Products::find($product_id)->Channel_Id;
     //select form usergroup channel rights where the channel_id and usergroup_id and ch_right
     $Right_list = DB::select(DB::raw("SELECT ugchr.* FROM usergroupchannelrights ugchr, channelsrights chr\n\t\t\t\tWHERE ugchr.Channel_Id = " . $channel_id . " and ugchr.UserGroup_Id = " . $usergroup->UserGroup_Id . "\n\t\t\t\t\tand ugchr.Channel_Right_Id =  chr.ChannelRight_Id\n\t\t\t\t\tand chr.Channel_Right_Name = '" . $requested_ch_right . "'"));
     return Response::json(count($Right_list) > 0);
 }
コード例 #20
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), Stocks::$rules);
     if ($validator->passes()) {
         $stock = new Stocks();
         $stock->supplier_id = Input::get('supplier_id');
         $stock->product_id = Input::get('product_id');
         $stock->quantity = Input::get('quantity');
         $stock->save();
         $product = Products::find(Input::get('product_id'));
         $product->quantity = $product->quantity + Input::get('quantity');
         $product->save();
         //Products::updateStock($stock->product_id);
         return Redirect::route('stocks.index')->with('success', 'Stock created successfully');
     } else {
         return Redirect::route('stocks.create')->withErrors($validator)->withInput(Input::all());
     }
 }
コード例 #21
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function deletemodel($id)
 {
     //
     if ($this->isAdminRequest()) {
         $product_category_id = Input::get('product_category_id');
         $product = Products::find($id);
         $product->delete();
         Session::flash('message', 'Successfully deleted model.');
         return Redirect::to('admin/products/' . $product_category_id . '/models');
     }
 }
コード例 #22
0
 public function deleteCategoryAction()
 {
     if (ApiController::access()) {
         $category = new Category();
         $product = new Products();
         if (isset($_POST['id'])) {
             $category = $category->findFirst($this->request->getPost('id'));
             $products = $product->find(array("category = :category:", 'bind' => array('category' => $this->request->getPost('id'))));
         } else {
             die('не передан обязательный параметр id');
         }
         $success = $category->delete($this->request->getPost('id'));
         foreach ($products as $product) {
             $product->category = null;
             $product->save();
         }
         if ($success != false) {
             echo json_encode(array('error_code' => 200, 'error_desc' => 'Delete category: ' . $this->request->getPost('id')));
         } else {
             die('Что-то пошло не так...');
         }
         $this->view->disable();
     }
 }
コード例 #23
0
<?php

// Get products without caching
$products = Products::find();
// Just cache the resultset. The cache will expire in 1 hour (3600 seconds)
$products = Products::find(array("cache" => array("key" => "my-cache")));
// Cache the resultset for only for 5 minutes
$products = Products::find(array("cache" => array("key" => "my-cache", "lifetime" => 300)));
// Using a custom cache
$products = Products::find(array("cache" => $myCache));
コード例 #24
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     if (!$id) {
         return Redirect::route('products.index')->with('error', 'Please provide product id');
     }
     $product = Products::find($id);
     if (empty($product)) {
         return Redirect::route('products.index')->with('error', 'Product not found');
     }
     Products::destroy($id);
     return Redirect::route('products.index')->with('success', 'Product deleted successfully');
 }
コード例 #25
0
 /**
  * Search the record for the Select2 JQuery Object by ajax
  * @return json
  */
 public function searchAction()
 {
     if ($this->getRequest()->isXmlHttpRequest()) {
         $term = $this->getParam('term');
         $id = $this->getParam('id');
         if (!empty($term)) {
             $term = "%{$term}%";
             $records = Products::findbyName($term, "product_id, pd.name as name", true);
             die(json_encode($records));
         }
         if (!empty($id)) {
             $records = Products::find($id);
             die(json_encode($records));
         }
         $records = Products::getAll('product_id, pd.name as name');
         die(json_encode($records));
     } else {
         die;
     }
 }
コード例 #26
0
ファイル: tags-245.php プロジェクト: aodkrisda/phalcon-code
<?php

// Creating a Select Tag with an empty option
echo Phalcon\Tag::select(array("productId", Products::find("type = 'vegetables'"), "using" => array("id", "name"), "useEmpty" => true));
コード例 #27
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     if (!$id) {
         return Redirect::route('distributions.index')->with('error', 'Please provide distribution id');
     }
     $distribution = Distributions::find($id);
     if (empty($distribution)) {
         return Redirect::route('distributions.index')->with('error', 'Distribution not found');
     }
     $outletStock = OutletsStocks::whereProductId($distribution->product_id)->first();
     if ($distribution->quantity <= $outletStock->quantity) {
         $product = Products::find($distribution->product_id);
         $product->quantity += $distribution->quantity;
         $product->save();
         $outletStock->quantity -= $distribution->quantity;
         $outletStock->save();
         Distributions::destroy($id);
         return Redirect::route('distributions.index')->with('success', 'Distribution deleted successfully');
     } else {
         return Redirect::route('distributions.index')->with('error', 'Distribution cannot be deleted as the items from this distribution are already sold.');
     }
 }