You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.7 KiB
83 lines
1.7 KiB
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: garrett
|
|
* Date: 4/17/16
|
|
* Time: 11:59 AM
|
|
*/
|
|
|
|
namespace Glmdev\Meta;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Glmdev\Foundation\FoundationModel;
|
|
|
|
class Meta extends Model implements FoundationModel
|
|
{
|
|
|
|
protected $fillable = ['meta', 'uuid'];
|
|
|
|
function read( $key ){
|
|
$meta = unserialize( $this->meta );
|
|
if ( array_key_exists( $key, $meta ) ){
|
|
return $meta[ $key ];
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function write( $key, $value ){
|
|
$meta = unserialize( $this->meta );
|
|
$meta[ $key ] = $value;
|
|
$meta = serialize( $meta );
|
|
$this->meta = $meta;
|
|
$this->save();
|
|
}
|
|
|
|
function readRaw(){
|
|
return $this->meta;
|
|
}
|
|
|
|
function writeRaw( $serialized ){
|
|
$this->meta = $serialized;
|
|
$this->save();
|
|
}
|
|
|
|
public function getUUID(){
|
|
return $this->uuid;
|
|
}
|
|
|
|
public function setUuid(){
|
|
// check if UUID is set
|
|
if( !isset($this->uuid) || is_null($this->uuid) || $this->uuid === "" ){
|
|
$this->uuid = Uuid::uuid4();
|
|
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function rawUuid( Uuid $uuid ){
|
|
$this->uuid = $uuid;
|
|
$this->save();
|
|
}
|
|
|
|
public static function formTable( Blueprint $table ){
|
|
$table->uuid('uuid');
|
|
$table->text('meta');
|
|
}
|
|
|
|
public static function route(){}
|
|
|
|
public static function create( array $args ){
|
|
$args['meta'] = serialize([]);
|
|
$args['uuid'] = '';
|
|
|
|
return parent::create($args);
|
|
}
|
|
|
|
} |