2017-04-16 23:11:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class GrocyPhpHelper
|
|
|
|
{
|
|
|
|
public static function FindObjectInArrayByPropertyValue($array, $propertyName, $propertyValue)
|
|
|
|
{
|
|
|
|
foreach($array as $object)
|
|
|
|
{
|
|
|
|
if($object->{$propertyName} == $propertyValue)
|
|
|
|
{
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2017-04-20 17:10:21 +02:00
|
|
|
|
|
|
|
public static function FindAllObjectsInArrayByPropertyValue($array, $propertyName, $propertyValue, $operator = '==')
|
|
|
|
{
|
|
|
|
$returnArray = array();
|
|
|
|
|
|
|
|
foreach($array as $object)
|
|
|
|
{
|
|
|
|
switch($operator)
|
|
|
|
{
|
|
|
|
case '==':
|
|
|
|
if($object->{$propertyName} == $propertyValue)
|
|
|
|
{
|
|
|
|
$returnArray[] = $object;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
if($object->{$propertyName} > $propertyValue)
|
|
|
|
{
|
|
|
|
$returnArray[] = $object;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
if($object->{$propertyName} < $propertyValue)
|
|
|
|
{
|
|
|
|
$returnArray[] = $object;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $returnArray;
|
|
|
|
}
|
2017-04-21 12:50:53 +02:00
|
|
|
|
|
|
|
public static function SumArrayValue($array, $propertyName)
|
|
|
|
{
|
|
|
|
$sum = 0;
|
|
|
|
foreach($array as $object)
|
|
|
|
{
|
|
|
|
$sum += $object->{$propertyName};
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sum;
|
|
|
|
}
|
2017-07-25 20:03:31 +02:00
|
|
|
|
|
|
|
public static function GetClassConstants($className)
|
|
|
|
{
|
|
|
|
$r = new ReflectionClass($className);
|
|
|
|
return $r->getConstants();
|
|
|
|
}
|
2017-04-16 23:11:03 +02:00
|
|
|
}
|