Skip to content

Commit

Permalink
Merge pull request #118 from franzose/3.x
Browse files Browse the repository at this point in the history
 fixed #117
  • Loading branch information
franzose committed May 18, 2014
2 parents 10cd0b8 + 0d41710 commit 4d8b1f1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 43 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ $page->deleteSubtree(false, true); //without subtree ancestor and force delete
```

## Customization
You can customize the default things in your classes created by the ClosureTable `artisan` command:<br>
1. **Entity table name** by changing `protected $table` of your own `Entity` (e.g. `Page`)<br>
2. **Closure table name** by changing `protected $table` of your own `ClosureTable` (e.g. `PageClosure`)<br>
3. **`parent_id`, `position`, and `real depth` column names** by changing `const PARENT_ID`, `const POSITION`, and `const REAL_DEPTH` of your own `EntityInterface` (e.g. `PageInterface`) respectively<br>
4. **`ancestor`, `descendant`, and `depth` columns names** by changing `const ANCESTOR`, `const DESCENDANT`, and `const DEPTH` of your own `ClosureTableInterface` (e.g. `PageClosureInterface`) respectively.
You can customize default things in your own classes created by the ClosureTable `artisan` command:<br>
1. **Entity table name**: change `protected $table` property<br>
2. **Closure table name**: do the same in your `ClosureTable` (e.g. `PageClosure`)<br>
3. **Entity's `parent_id`, `position`, and `real depth` column names**: change return values of `getParentIdColumn()`, `getPositionColumn()`, and `getRealDepthColumn()` respectively<br>
4. **Closure table's `ancestor`, `descendant`, and `depth` columns names**: change return values of `getAncestorColumn()`, `getDescendantColumn()`, and `getDepthColumn()` respectively.
8 changes: 4 additions & 4 deletions docs/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Customization

You can customize the default things in your classes created by the ClosureTable ``artisan`` command:

1. **Entity table name** by changing ``protected $table`` of your own ``Entity`` (e.g. ``Page``)
2. **Closure table name** by changing ``protected $table`` of your own ``ClosureTable`` (e.g. ``PageClosure``)
3. ``parent_id``, ``position``, and ``real depth`` column names by changing ``const PARENT_ID``, ``const POSITION``, and ``const REAL_DEPTH`` of your own ``EntityInterface`` (e.g. ``PageInterface``) respectively
4. ``ancestor``, ``descendant``, and ``depth`` columns names by changing ``const ANCESTOR``, ``const DESCENDANT``, and ``const DEPTH`` of your own ``ClosureTableInterface`` (e.g. ``PageClosureInterface``) respectively.
1. **Entity table name**: change ``protected $table`` property
2. **Closure table name**: do the same in your ``ClosureTable`` (e.g. ``PageClosure``)
3. **Entity's ``parent_id``, ``position``, and ``real depth`` column names**: change return values of ``getParentIdColumn()``, ``getPositionColumn()``, and ``getRealDepthColumn()`` respectively
4. **Closure table's ``ancestor``, ``descendant``, and ``depth`` columns names**: change return values of ``getAncestorColumn()``, ``getDescendantColumn()``, and ``getDepthColumn()`` respectively.
19 changes: 10 additions & 9 deletions src/Franzose/ClosureTable/Contracts/ClosureTableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
* @package Franzose\ClosureTable
*/
interface ClosureTableInterface {

/**
* The ancestor column name.
* Get the short name of the "ancestor" column.
*
* @var string
* @return string
*/
const ANCESTOR = 'ancestor';
public function getAncestorColumn();

/**
* The descendant column name.
* Get the short name of the "descendant" column.
*
* @var string
* @return string
*/
const DESCENDANT = 'descendant';
public function getDescendantColumn();

/**
* The depth column name.
* Get the short name of the "depth" column.
*
* @var string
* @return string
*/
const DEPTH = 'depth';
public function getDepthColumn();

/**
* Inserts new node into closure table.
Expand Down
24 changes: 12 additions & 12 deletions src/Franzose/ClosureTable/Contracts/EntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
interface EntityInterface {

/**
* The parent id column name.
* Gets the short name of the "parent id" column.
*
* @var string
* @return string
*/
const PARENT_ID = 'parent_id';
public function getParentIdColumn();

/**
* The position column name.
* Gets the short name of the "position" column.
*
* @var string
* @return string
*/
const POSITION = 'position';
public function getPositionColumn();

/**
* The "real depth" column name.
* Gets the short name of the "real depth" column.
*
* @var string
* @return string
*/
const REAL_DEPTH = 'real_depth';
public function getRealDepthColumn();

/**
* Relations array key that stores children collection.
* Gets the "children" relation index.
*
* @var string
* @return string
*/
const CHILDREN = 'children';
public function getChildrenRelationIndex();

/**
* "Query all models" flag.
Expand Down
12 changes: 6 additions & 6 deletions src/Franzose/ClosureTable/Models/ClosureTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function setAncestorAttribute($value)
*/
public function getQualifiedAncestorColumn()
{
return $this->getTable() . '.' . static::ANCESTOR;
return $this->getTable() . '.' . $this->getAncestorColumn();
}

/**
Expand All @@ -197,7 +197,7 @@ public function getQualifiedAncestorColumn()
*/
public function getAncestorColumn()
{
return static::ANCESTOR;
return 'ancestor';
}

/**
Expand Down Expand Up @@ -227,7 +227,7 @@ public function setDescendantAttribute($value)
*/
public function getQualifiedDescendantColumn()
{
return $this->getTable() . '.' . static::DESCENDANT;
return $this->getTable() . '.' . $this->getDescendantColumn();
}

/**
Expand All @@ -237,7 +237,7 @@ public function getQualifiedDescendantColumn()
*/
public function getDescendantColumn()
{
return static::DESCENDANT;
return 'descendant';
}

/**
Expand Down Expand Up @@ -267,7 +267,7 @@ public function setDepthAttribute($value)
*/
public function getQualifiedDepthColumn()
{
return $this->getTable() . '.' . static::DEPTH;
return $this->getTable() . '.' . $this->getDepthColumn();
}

/**
Expand All @@ -277,6 +277,6 @@ public function getQualifiedDepthColumn()
*/
public function getDepthColumn()
{
return static::DEPTH;
return 'depth';
}
}
14 changes: 7 additions & 7 deletions src/Franzose/ClosureTable/Models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function setParentIdAttribute($value)
*/
public function getQualifiedParentIdColumn()
{
return $this->getTable() . '.' . static::PARENT_ID;
return $this->getTable() . '.' . $this->getParentIdColumn();
}

/**
Expand All @@ -152,7 +152,7 @@ public function getQualifiedParentIdColumn()
*/
public function getParentIdColumn()
{
return static::PARENT_ID;
return 'parent_id';
}

/**
Expand Down Expand Up @@ -186,7 +186,7 @@ public function setPositionAttribute($value)
*/
public function getQualifiedPositionColumn()
{
return $this->getTable() . '.' . static::POSITION;
return $this->getTable() . '.' . $this->getPositionColumn();
}

/**
Expand All @@ -196,7 +196,7 @@ public function getQualifiedPositionColumn()
*/
public function getPositionColumn()
{
return static::POSITION;
return 'position';
}

/**
Expand Down Expand Up @@ -230,7 +230,7 @@ protected function setRealDepthAttribute($value)
*/
public function getQualifiedRealDepthColumn()
{
return $this->getTable() . '.' . static::REAL_DEPTH;
return $this->getTable() . '.' . $this->getRealDepthColumn();
}

/**
Expand All @@ -240,7 +240,7 @@ public function getQualifiedRealDepthColumn()
*/
public function getRealDepthColumn()
{
return static::REAL_DEPTH;
return 'real_depth';
}

/**
Expand All @@ -250,7 +250,7 @@ public function getRealDepthColumn()
*/
public function getChildrenRelationIndex()
{
return static::CHILDREN;
return 'children';
}

/**
Expand Down

0 comments on commit 4d8b1f1

Please sign in to comment.