private function uploadFile(Bucket $bucket) { print "Uploading hello world file to bucket: " . $bucket->getName() . PHP_EOL; $contents = "Hello world"; $uploadFilename = "hello_world_" . time() . ".txt"; $filepath = __DIR__ . '/upload_file.txt'; file_put_contents($filepath, $contents); $uploadUrlResponse = $this->m_b2->getUploadUrl($bucket->getId()); $b2File = $this->m_b2->uploadFile($uploadFilename, $filepath, $uploadUrlResponse); return $b2File; }
/** * Prepend bucket to the brigade. * * @param \Hoa\Stream\Bucket $bucket Bucket to add. * @return void */ public function prepend(Bucket $bucket) { stream_bucket_prepend($this->getBrigade(), $bucket->getBucket()); return; }
/** * Get buckets this user has access to */ public function getBuckets() { $buckets = Bucket::find(array('$or' => array(array('roles.' . $this->id => array('$exists' => 1)), array('roles.all' => array('$exists' => 1))))); \Utils::model_sort($buckets, 'description'); return $buckets; }
public function contrat(array $data, $disposition = null, $test = false) { $disposition = is_null($disposition) ? 'attachment' : $disposition; $tpl = File::read(APPLICATION_PATH . DS . 'templates/contrat_zechallenge.html'); $bucket = new Bucket(SITE_NAME, 'http://zelift.com/bucket'); $affiliation = isAke($data, 'affiliation', 'resto'); $univers = isAke($data, 'univers', 'resto'); $zechallenge_id = isAke($data, 'compte_zechallenge', 1); $contrat = Model::FacturationContrat()->reset()->where(['platform', '=', 'ZeChallenge'])->where(['affiliation', '=', $affiliation])->where(['univers', '=', $univers])->where(['zechallenge_id', '=', (int) $zechallenge_id])->first(true); if ($contrat && !$test) { $return = true; if ($disposition == 'attachment') { if (!fnmatch('http://*', $contrat->url)) { $contrat->delete(); $return = false; } if ($return) { return ['url' => $contrat->url, 'error' => false]; } } if ($return) { $pdf = dwn($contrat->url); header('Content-Type: application/pdf'); header('Content-Length: ' . strlen($pdf)); header('Content-Disposition: ' . $disposition . '; filename="Contrat-ZeChallenge.pdf"'); header('Cache-Control: private, max-age=0, must-revalidate'); header('Pragma: public'); ini_set('zlib.output_compression', '0'); die($pdf); } } $contract = lib('contrat')->store($univers, 'ZeChallenge', $affiliation, $zechallenge_id); if ($univers == 'resto') { $code_contrat = 'RES'; } elseif ($univers == 'services') { $code_contrat = 'SER'; } $code_contrat .= '-C-' . $contract->id; $data['code_contrat'] = $code_contrat; foreach ($data as $k => $v) { if ($k == 'univers') { $tpl = str_replace("##Univers##", ucfirst($v), $tpl); $tpl = str_replace("##univers##", $v, $tpl); } else { $tpl = str_replace("##{$k}##", $v, $tpl); } } $disposition = is_null($disposition) ? 'attachment' : $disposition; // $keep = lib('keep')->instance(); // $keep['url'] = 'http://zelift.com/'; $pdf = pdfFile($tpl, 'Contrat-ZeChallenge', 'portrait'); $url = $bucket->data($pdf, 'pdf'); $contract->url = $url; if (!fnmatch('http://*', $url)) { return ['url' => false, 'error' => $contract->url]; } if (!$test) { $contract->save(); } if ($disposition == 'attachment') { return ['url' => $url, 'error' => false]; } header('Content-Type: application/pdf'); header('Content-Length: ' . strlen($pdf)); header('Content-Disposition: ' . $disposition . '; filename="Contrat-ZeChallenge.pdf"'); header('Cache-Control: private, max-age=0, must-revalidate'); header('Pragma: public'); ini_set('zlib.output_compression', '0'); die($pdf); }
/** * Fetch a session bucket * @param string $name Name of the bucket to fetch * @return SessionBucket Returns the bucket * @since 1.0-sofia */ public function bucket($name) { $bucket = $this->storage->bucket($name); if (!$bucket) { $bucket = new Bucket($name); $bucket->load($_SESSION[$name]); $this->storage->register($bucket); } return $bucket; }
<?php require_once 'autoload.php'; $bucket = new Bucket(5, 2, 'Test'); echo 'Testing constructor', PHP_EOL; assert($bucket->getMaxVolume() === 5); assert($bucket->getCurrentVolume() === 2); assert($bucket->getName() === 'Test'); echo 'END Testing', PHP_EOL; echo 'Testing Bucket::getRemainingSpace', PHP_EOL; assert($bucket->getRemainingSpace() === 3); echo 'End testing Bucket::getRemainingSpace', PHP_EOL; echo 'Testing Bucket::addLiquid', PHP_EOL; $bucket->addLiquid(2); assert($bucket->getCurrentVolume() === 4); $bucket->addLiquid(2); assert($bucket->getCurrentVolume() <= $bucket->getMaxVolume()); echo 'End testing Bucket::addLiquid', PHP_EOL;
<?php /** * Created by PhpStorm. * User: just * Date: 03.02.16 * Time: 15:10 */ require_once 'autoload.php'; $bucket = new Bucket(5, 2, 'test'); echo 'testing construktor', PHP_EOL; assert($bucket->getMaxVolume() === 5); assert($bucket->getCurrentVolume() === 2); assert($bucket->getName() === 'test');
/** * Send/fire a bucket to a listener. * * @param string $listenerId Listener ID. * @param \Hoa\Event\Bucket $data Data. * @return array * @throws \Hoa\Event\Exception */ public function fire($listenerId, Bucket $data) { if (false === $this->listenerExists($listenerId)) { throw new Exception('Cannot fire on %s because it is not defined.', 1, $listenerId); } $data->setSource($this->_source); $out = []; foreach ($this->_callables[$listenerId] as $callable) { $out[] = $callable($data); } return $out; }
/** * @param Bucket $earliest * @param Bucket $latest * @param Bucket $replace * @return $this */ private function replaceSlice(Bucket $earliest, Bucket $latest, Bucket $replace) { $replace->setNext($earliest->getNext())->setPrev($latest->getPrev()); if ($earliest === $this->getEarliestBucket()) { $this->earliestBucket = $replace; } if ($latest === $this->getLastBucket()) { $this->lastBucket = $replace; } return $this; }
<?php require_once 'autoload.php'; $bucket = new Bucket(5, 2, 'Test'); echo 'Testing constructor', PHP_EOL; assert($bucket->getMaxVolume() === 5); assert($bucket->getCurrentVolume() === 2); assert($bucket->getName() === 'Test'); echo 'END Testing constructor', PHP_EOL; echo 'Testing Bucket::getRemainingSpace', PHP_EOL; assert($bucket->getRemainingSpace() === 3); echo 'END Testing Bucket::getRemainingSpace', PHP_EOL; echo 'Testing Bucket::addLiquid', PHP_EOL; $bucket->addLiquid(2); assert($bucket->getCurrentVolume() === 4); $bucket->addLiquid(2); assert($bucket->getCurrentVolume() <= $bucket->getMaxVolume()); echo 'END Testing Bucket::addLiquid', PHP_EOL; echo 'Testing Bucket::emptyDownDrain', PHP_EOL; $bucket->emptyDownDrain(); assert($bucket->getCurrentVolume() === 0); echo 'END Testing Bucket::emptyDownDrain', PHP_EOL; echo 'Testing Bucket::fill', PHP_EOL; $bucket->fill(); assert($bucket->getCurrentVolume() === $bucket->getMaxVolume()); echo 'END Testing Bucket::fill', PHP_EOL; echo 'Testing Bucket::transfer', PHP_EOL; $bucket->emptyDownDrain(); $smallBucket = new Bucket(2, 2, 'Small'); $bucket->transfer($smallBucket); assert($bucket->getCurrentVolume() === $smallBucket->getMaxVolume());
public function firstMyZelift($reseller_id, $disposition = null) { $bucket = new Bucket(SITE_NAME, 'http://zelift.com/bucket'); $disposition = is_null($disposition) ? 'attachment' : $disposition; $reseller = Model::Reseller()->find((int) $reseller_id); if ($reseller) { $zid = $reseller->zechallenge_id; $myzelift = Model::Myzelift()->where(['zechallenge_id', '=', (int) $zid])->first(true); if ($myzelift) { $contract = Model::FacturationContrat()->where(['zechallenge_id', '=', (int) $zid])->where(['platform', '=', 'MyZeLift'])->first(true); if (!$contract) { exception("facture", 'Aucun contrat zechallenge trouvé.'); } $products = lib('facturation')->abonnementMyzelift(lib('zechallenge')->getContext($reseller->id)); $toBilled = $acomptes = $hasAcomptes = $purchases = []; foreach ($products as $product) { $haveTobeBilled = Model::FacturationAcompte()->where(['status', '=', 'UNBILLED'])->where(['product_id', '=', (int) $product['id']])->where(['zechallenge_id', '=', (int) $zid])->with('product'); foreach ($haveTobeBilled as $hasToBilled) { $purchases[] = $hasToBilled; $acomptes[] = $hasToBilled; $hasAcomptes[$hasToBilled['product_id']] = true; } $haveTobeBilled = Model::FacturationPurchase()->where(['status', '=', 'UNBILLED'])->where(['product_id', '=', (int) $product['id']])->where(['zechallenge_id', '=', (int) $zid])->with('product'); foreach ($haveTobeBilled as $hasToBilled) { if (!isset($hasAcomptes[$hasToBilled['product_id']])) { $purchases[] = $toBilled[] = $hasToBilled; } } } // dd($toBilled); $total = 0; $details = []; foreach ($toBilled as $hastoBilled) { $sum = $hastoBilled['quantity'] * $hastoBilled['product']['amount']; $total += $sum; $details[] = '<tr style="border:1px solid #a4a4a4;border-top:none;"> <td style="width:500px;"> <div style="width:500px; text-indent:30px; height:25px; line-height:25px;"> ' . $hastoBilled['product']['name'] . ' </div> </td> <td style="width:300px; font-size:0; padding:0;"> <div style="width:75px; display:inline-block; font-size:15px; text-align:center;">' . number_format($hastoBilled['product']['amount'], 2) . '€</div> <div style="width:75px; display:inline-block; font-size:15px; text-align:center;">' . $hastoBilled['quantity'] . '</div> <div style="width:75px; display:inline-block; font-size:15px; text-align:center;"></div> <div style="width:75px; display:inline-block; font-size:15px; text-align:center;"> ' . number_format($sum, 2) . '€ </div> </td> </tr>'; } foreach ($acomptes as $hastoBilled) { $sum = $hastoBilled['quantity'] * $hastoBilled['amount']; $total += $sum; $normalPrice = $hastoBilled['product']['amount'] * $hastoBilled['quantity']; $pc = $sum / $normalPrice * 100; $details[] = '<tr style="border:1px solid #a4a4a4;border-top:none;"> <td style="width:500px;"> <div style="width:500px; text-indent:30px; height:25px; line-height:25px;"> ' . $hastoBilled['product']['name'] . ' (Acompte de ' . $pc . ' %) </div> </td> <td style="width:300px; font-size:0; padding:0;"> <div style="width:75px; display:inline-block; font-size:15px; text-align:center;">' . number_format($hastoBilled['amount'], 2) . '€</div> <div style="width:75px; display:inline-block; font-size:15px; text-align:center;">' . $hastoBilled['quantity'] . '</div> <div style="width:75px; display:inline-block; font-size:15px; text-align:center;"></div> <div style="width:75px; display:inline-block; font-size:15px; text-align:center;"> ' . number_format($sum, 2) . '€ </div> </td> </tr>'; } $facture = Model::FacturationFacture()->refresh()->firstOrCreate(['zechallenge_id' => $zid, 'products' => $purchases]); $tva = number_format(round($total * 0.2, 2), 2); $ttc = number_format($total + $tva, 2); $details = implode("\n", $details); $tpl = File::read(APPLICATION_PATH . DS . 'templates/premiere_facture_zechallenge.html'); $ib = Model::Inovibackend()->find((int) $reseller->inovibackend_id); $tpl = str_replace(['##typoColor##', '##typo##', '##no_facture##', '##compte_inovi##', '##no_contrat##', '##univers##', '##affil##', '##nom_client##', '##adresse_client##', '##cp_client##', '##ville_client##', '##lieu_contrat##', '##date_contrat##', '##date_debut##', '##date_fin##', '##date_jour##', '##total##', '##total_tva##', '##total_ttc##', '##details##'], ['#ba68c8', 'MyZeLift', $facture->id, $reseller->inovibackend_id, $zid, lib('zechallenge')->getMarket($reseller->id), lib('segment')->getAffiliation($reseller->id, false), $ib->name, $ib->address, $ib->zip, $ib->city, $ib->city, date('d/m/Y', $contract->contract_date), date('d/m/Y', $contract->contract_date), date('d/m/Y', $contract->end), date('d/m/Y'), number_format($total, 2), $tva, $ttc, $details], $tpl); $pdf = pdfFile($tpl, 'Facture-MyZeLift', 'portrait'); $url = $bucket->data($pdf, 'pdf'); if (!fnmatch('http://*', $url)) { return ['url' => false, 'error' => $url]; } if ($disposition == 'attachment') { return ['url' => $url, 'error' => false]; } header('Content-Type: application/pdf'); header('Content-Length: ' . strlen($pdf)); header('Content-Disposition: ' . $disposition . '; filename="Contrat-MyZeLift.pdf"'); header('Cache-Control: private, max-age=0, must-revalidate'); header('Pragma: public'); ini_set('zlib.output_compression', '0'); die($pdf); } } }
<?php include "../wp-load.php"; $id = isset($_POST['id']) ? $_POST['id'] : null; $name = $_POST['bucket-name']; $description = $_POST['description']; if (!$id) { $bucket = new Bucket($name, $description, $id); $bucketId = $bucket->create(); $frontEndController = new frontEndController(); $frontEndController->addUserToBucket($bucketId); } else { $bucket = new Bucket($name, $description, $id); $id = $bucket->update(); } header("Location: /buckets"); exit;
<?php require_once 'autoload.php'; $fiveBucket = new Bucket(5, 5, "5L"); $threeBucket = new Bucket(3, 0, "3L"); $threeBucket->transfer($fiveBucket); var_dump($fiveBucket, $threeBucket); $threeBucket->emptyDownDrain(); var_dump($fiveBucket, $threeBucket); $threeBucket->transfer($fiveBucket); var_dump($fiveBucket, $threeBucket); $fiveBucket->fill(); var_dump($fiveBucket, $threeBucket); $threeBucket->transfer($fiveBucket); var_dump($fiveBucket, $threeBucket);
/** * Set Prev * * @param Bucket $prev * * @param bool $synchronized * @return Bucket The current instance */ public function setPrev(Bucket $prev = null, $synchronized = true) { $this->prev = $prev; if ($prev && $synchronized) { $prev->setNext($this, false); } return $this; }
/** * Gets a single software bucket * If no key is set, an empty Bucket object will be returned which will act as a repository * * @param string $key optional * * @return Bucket */ public function bucket($key = null) { if (!$this->id) { throw new Exception("The server has no ID, can\\'t get buckets"); } $bucket = new Bucket($this->patrol); $bucket->defaults(['server_id' => $this->id]); if (is_null($key)) { return $bucket; } try { return $bucket->find($key); } catch (Exception $ex) { if ($ex->getMessage() === "Bucket does not exist") { $bucket->key = $key; return $bucket; } } return null; }
$person2->getFName(), $person2->getLName()), PHP_EOL; echo $person->getInfo() . PHP_EOL . $person2->getInfo(); $vehicle = new Vehicle('very nice'); //Clone reference $a = $vehicle; $b = $vehicle; $i = [ $vehicle = new Vehicle('very nice'), $vehicle = new Vehicle('very nice'), $vehicle = new Vehicle('very nice'), $vehicle = new Vehicle('very nice'), $vehicle = new Vehicle('very nice') ]; foreach ($i as $item => $value) { echo $item -> getDescripton; }*/ $bucket3l = new Bucket(3, 0, '3l'); $bucket5l = new Bucket(5, 5, '5l'); $bucket3l->transfer($bucket5l); $bucket3l->emptyDrain(); $bucket3l->transfer($bucket5l); $bucket5l->emptyDrain(); $bucket5l->fill(); $bucket3l->transfer($bucket5l); var_dump($bucket5l, $bucket3l);