sync with sch inventory on first login if no labs or assets for school

parent c0671634
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace SchInventory;
class Equipment
{
protected $id;
protected $category;
protected $description;
protected $location;
protected $manufacturer;
protected $propertyNumber;
public function __construct($id, $category, $description, $location, $manufacturer, $propertyNumber)
{
$this->id = $id;
$this->category = $category;
$this->description = $description;
$this->location = $location;
$this->manufacturer = $manufacturer;
$this->propertyNumber = $propertyNumber;
}
public function __get($name)
{
if (property_exists($this, $name)) {
return $this->{$name};
}
return;
}
public function toArray()
{
return [
'id' => $this->id,
'category' => $this->category,
'description' => $this->description,
'location' => $this->location,
'manufacturer' => $this->manufacturer,
'propertyNumber' => $this->propertyNumber,
];
}
}
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace SchInventory;
use CallbackFilterIterator;
use InvalidArgumentException;
use Traversable;
class EquipmentCollection extends ImmutableArrayObject
{
/**
* Collection constructor
*
* @param array|Traversable
*/
public function __construct($equipmentObjects)
{
if ($equipmentObjects instanceof Traversable) {
$equipmentObjects = iterator_to_array($equipmentObjects);
}
$previousHandler = set_error_handler(['self', 'handleErrors']);
parent::__construct(array_map(function (Equipment $equipment) {
return $equipment;
}, $equipmentObjects));
set_error_handler($previousHandler);
}
/**
* Returns a new Equipment collection with equimpment matching the given location
*
* @param string $location
* @retun EquipmentCollection
*/
public function withLocation($location)
{
return new self(new CallbackFilterIterator($this->getIterator(), function (Equipment $equipment) use ($location) {
return $equipment->location === $location;
}));
}
/**
* Returns a new Equipment collection with equimpment matching the given category
*
* @param string $category
* @retun EquipmentCollection
*/
public function withCategory($category)
{
return new self(new CallbackFilterIterator($this->getIterator(), function (Equipment $equipment) use ($category) {
return $equipment->category === $category;
}));
}
private static function handleErrors($severity, $message, $file, $line)
{
throw new InvalidArgumentException($message);
}
}
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace SchInventory;
use ArrayObject;
use LogicException;
class ImmutableArrayObject extends ArrayObject
{
public function append($value)
{
throw new LogicException('Attempting to write to an immutable array');
}
public function exchangeArray($input)
{
throw new LogicException('Attempting to write to an immutable array');
}
public function offsetSet($index, $newval)
{
throw new LogicException('Attempting to write to an immutable array');
}
public function offsetUnset($index)
{
throw new LogicException('Attempting to write to an immutable array');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment