szurubooru/src/Models/Model_Property.php
2013-11-23 17:29:01 +01:00

38 lines
840 B
PHP

<?php
class Model_Property extends RedBean_SimpleModel
{
const FeaturedPostId = 0;
const FeaturedPostUserName = 1;
const FeaturedPostDate = 2;
const DbVersion = 'db-version';
static $allProperties = null;
public static function get($propertyId)
{
if (self::$allProperties === null)
{
self::$allProperties = [];
foreach (R::find('property') as $prop)
{
self::$allProperties[$prop->prop_id] = $prop->value;
}
}
return isset(self::$allProperties[$propertyId])
? self::$allProperties[$propertyId]
: null;
}
public static function set($propertyId, $value)
{
$row = R::findOne('property', 'prop_id = ?', [$propertyId]);
if (!$row)
{
$row = R::dispense('property');
$row->prop_id = $propertyId;
}
$row->value = $value;
self::$allProperties[$propertyId] = $value;
R::store($row);
}
}