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.
PlexShare/fuel/app/classes/model/overwrite.php

36 lines
1.0 KiB

<?php
use Fuel\Core\DB;
use Fuel\Core\Model_Crud;
use Fuel\Core\Str;
abstract class Model_Overwrite extends Model_Crud
{
protected static function disable()
{
return isset(static::$_disable) ? 'disabled' : null;
}
public function delete()
{
static::disable() ? $query = DB::update(static::$_table_name)
->value('disable', 1)
->where(static::primary_key(), '=', $this->{static::primary_key()}) : null;
$this->pre_delete($query);
$result = $query ? $query->execute(static::get_connection(true)) : null;
return $this->post_delete($result);
}
protected function pre_save(&$query)
{
if($this->is_new()) {
if(!isset($this->{static::primary_key()}) || !$this->{static::primary_key()} || $this->{static::primary_key()} === null) {
$this->{static::primary_key()} = Str::random('uuid');
$query->set([static::primary_key() => $this->{static::primary_key()}]);
}
}
}
}