PHP Classes

File: examples/testreduce.php

Recommend this page to a friend!
  Classes of Jorge Castro   PHP Document Store One   examples/testreduce.php   Download  
File: examples/testreduce.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Document Store One
Store and retrieve key-value pairs in flat files
Author: By
Last change:
Date: 4 years ago
Size: 824 bytes
 

Contents

Class file image Download
<?

use eftec\DocumentStoreOne\DocumentStoreOne;

include
"../lib/DocumentStoreOne.php";
include
"modelinvoices/Models.php";

try {
   
$ds = new DocumentStoreOne('base', 'purchases');
} catch (
Exception $e) {
    die(
$e->getMessage());
}

$products=$ds->collection('products')->get('listproducts'); // if the list of products is limited then, we could store the whole list in a single document.
$purchases=$ds->collection('purchases')->select(); // they are keys such as 14,15...

$customerXPurchase=[];

foreach(
$purchases as $k) {
   
$purchase=unserialize( $ds->get($k));
    @
$customerXPurchase[$purchase->customer]+=($purchase->amount * @$products[$purchase->productpurchase]); // we add the amount
}

$ds->collection('total')->insertOrUpdate(serialize($customerXPurchase),'customerXPurchase'); // we store the result.