Skip to content

Instantly share code, notes, and snippets.

@aasumitro
Last active July 29, 2018 06:27
Show Gist options
  • Save aasumitro/8608a19fc06a0ebaefaa3aeaec874fa3 to your computer and use it in GitHub Desktop.
Save aasumitro/8608a19fc06a0ebaefaa3aeaec874fa3 to your computer and use it in GitHub Desktop.
<?php
class Collection
{
public $pembayaran = array();
public $cashier_summary = array();
public function addItem( $obj, $key = null, $data = null)
{
if ($data === 1) {
if ($key == null) {
$this->pembayaran[] = $obj;
}
else {
if (isset($this->pembayaran[$key])) {
echo "Key $key already in use.";
}
else {
$this->pembayaran[$key] = $obj;
}
}
} else if ($data === 2) {
if ($key == null) {
$this->cashier_summary[] = $obj;
}
else {
if (isset($this->cashier_summary[$key])) {
echo "Key $key already in use.";
}
else {
$this->cashier_summary[$key] = $obj;
}
}
} else {
return false;
}
}
public function deleteItem($data = null, $key)
{
if ($data === 1) {
if (isset($this->pembayaran[$key])) {
unset($this->pembayaran[$key]);
}
else {
echo "Invalid key $key.";
}
} else if ($data === 2) {
if (isset($this->cashier_summary[$key])) {
unset($this->cashier_summary[$key]);
}
else {
echo "Invalid key $key.";
}
} else {
return false;
}
}
public function getItem($data = null, $key)
{
if ($data === 1) {
if (isset($this->pembayaran[$key])) {
return $this->pembayaran[$key];
}
else {
echo "Invalid key $key.";
}
} else if ($data === 2) {
if (isset($this->cashier_summary[$key])) {
return $this->cashier_summary[$key];
}
else {
echo "Invalid key $key.";
}
} else {
return false;
}
}
public function keysAvail($data = null) {
if ($data === 1) {
return array_keys($this->pembayaran);
} else if ($data === 2) {
return array_keys($this->cashier_summary);
} else {
return false;
}
}
}
<?php
class CollectionModel
{
private $tipe;
private $mata_uang;
private $total_origin;
private $total_idr;
public function __construct($tipe, $mata_uang, $total_origin, $total_idr)
{
$this->tipe = $tipe;
$this->mata_uang = $mata_uang;
$this->total_origin = $total_origin;
$this->total_idr = $total_idr;
}
}
<?php
// use this collection
class main
{
public function logicMain()
{
$c = new Collection();
$c->addItem(new ShiftCashierCollection("Bayar", "IDR", 0, 12000), "BAYAR", 1);
$c->addItem(new ShiftCashierCollection("Bayar", "IDR", 0, 12000), "KEMBALIAN", 1);
$c->deleteItem(1, "payment");
$c->keysAvail(1);
$c->keysAvail(2);
dd($c->getItem(1, "cashback"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment