Commit a8f371b9 authored by Nicola Tomassoni's avatar Nicola Tomassoni

Digisin release

parent efa5f6bf
......@@ -11,3 +11,4 @@ vendor/
# ignore temporary files
*~
/nbproject/private/
\ No newline at end of file
{
"name": "cornernote/yii2-softdelete",
"name": "digisin/yii2-softdelete",
"description": "Soft delete behavior for Yii2.",
"keywords": ["yii2", "soft delete"],
"type": "yii2-behavior",
......@@ -8,6 +8,10 @@
{
"name": "Brett O'Donnell",
"email": "cornernote@gmail.com"
},
{
"name": "Nicola Tomassoni",
"email": "nicola@digisin.it"
}
],
"require": {
......@@ -20,7 +24,7 @@
},
"autoload": {
"psr-4": {
"cornernote\\softdelete\\": "src"
"digisin\\softdelete\\": "src"
}
}
}
include.path=${php.global.include.path}
php.version=PHP_56
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=false
web.root=.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>yii2-softdelete</name>
</data>
</configuration>
</project>
<?php
/**
* @author Brett O'Donnell <cornernote@gmail.com>
* @copyright 2015 Mr PHP
......@@ -6,7 +7,7 @@
* @license BSD-3-Clause https://raw.github.com/cornernote/yii2-softdelete/master/LICENSE.md
*/
namespace cornernote\softdelete;
namespace digisin\softdelete;
use yii\base\Behavior;
use yii\base\Event;
......@@ -31,8 +32,8 @@ use yii\db\Expression;
*
* @property BaseActiveRecord $owner
*/
class SoftDeleteBehavior extends Behavior
{
class SoftDeleteBehavior extends Behavior {
/**
* @var string SoftDelete attribute
*/
......@@ -49,8 +50,7 @@ class SoftDeleteBehavior extends Behavior
/**
* @inheritdoc
*/
public function events()
{
public function events() {
return [BaseActiveRecord::EVENT_BEFORE_DELETE => 'softDeleteEvent'];
}
......@@ -59,8 +59,7 @@ class SoftDeleteBehavior extends Behavior
*
* @param Event $event
*/
public function softDeleteEvent($event)
{
public function softDeleteEvent($event) {
// remove and mark as invalid to prevent real deletion
$this->softDelete();
$event->isValid = false;
......@@ -69,8 +68,7 @@ class SoftDeleteBehavior extends Behavior
/**
* Soft delete record
*/
public function softDelete()
{
public function softDelete() {
// set attribute with evaluated timestamp
$attribute = $this->attribute;
$this->owner->$attribute = $this->getValue(null);
......@@ -81,8 +79,7 @@ class SoftDeleteBehavior extends Behavior
/**
* Restore record
*/
public function unDelete()
{
public function unDelete() {
// set attribute as null
$attribute = $this->attribute;
$this->owner->$attribute = null;
......@@ -93,8 +90,7 @@ class SoftDeleteBehavior extends Behavior
/**
* Delete record from database regardless of the $safeMode attribute
*/
public function hardDelete()
{
public function hardDelete() {
// store model so that we can detach the behavior
$model = $this->owner;
$this->detach();
......@@ -108,8 +104,7 @@ class SoftDeleteBehavior extends Behavior
* @param Event|null $event the event that triggers the current attribute updating.
* @return mixed the attribute value
*/
protected function getValue($event)
{
protected function getValue($event) {
if ($this->value instanceof Expression) {
return $this->value;
} else {
......
<?php
namespace cornernote\softdelete;
namespace digisin\softdelete;
use yii\base\Behavior;
use yii\db\ActiveQuery;
......@@ -25,8 +25,8 @@ use yii\db\ActiveRecord;
*
* @author cornernote <cornernote@gmail.com>
*/
class SoftDeleteQueryBehavior extends Behavior
{
class SoftDeleteQueryBehavior extends Behavior {
/**
* @var string SoftDelete attribute
*/
......@@ -35,24 +35,21 @@ class SoftDeleteQueryBehavior extends Behavior
/**
* @return static
*/
public function deleted()
{
public function deleted() {
return $this->owner->andWhere($this->tableName() . '.' . $this->attribute . ' IS NOT NULL');
}
/**
* @return static
*/
public function notDeleted()
{
public function notDeleted() {
return $this->owner->andWhere($this->tableName() . '.' . $this->attribute . ' IS NULL');
}
/**
* @return string
*/
protected function tableName()
{
protected function tableName() {
/** @var ActiveRecord $modelClass */
$modelClass = $this->owner->modelClass;
return $modelClass::tableName();
......
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