Skip to content

Commit

Permalink
Added revisionable fields for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Jan 15, 2015
1 parent dc83513 commit 446828f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 9 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ Inventory is bare-bones inventory solution. It provides the basics of inventory

All movements, stocks and inventory items are automatically given the current logged in user's ID.

## Customization

Want to use your own models and add custom relationships? No problem, just extend your model to the existing inventory model like so:



## Requirements

- Laravel 4.* | 5.* - Not Tested
Expand Down Expand Up @@ -44,6 +38,11 @@ Run the migration

You're good to go!

## Customization

Want to use your own models and add custom relationships? No problem, just extend your model to the existing inventory model like so:


## Usage

Using inventory is exactly like using ordinary Laravel models, and that's because they all extend the Laravel model class.
Expand Down Expand Up @@ -275,4 +274,4 @@ Occurs when a location cannot be found, or the specified location is not a subcl
Integration with Sentry, Sentinel and Laravel's auth driver is built in, so inventory items, stocks and movements are automatically
tagged to the current logged in user. However, you turn this off if you'd like in the config file under:

'allow_no_user' => false
'allow_no_user' => false //Set to true
4 changes: 4 additions & 0 deletions src/Stevebauman/Inventory/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Category extends Node {
'belongs_to',
);

protected $revisionFormattedFieldNames = array(
'name' => 'Name',
);

/**
* Returns a single lined string with arrows indicating depth of the current category
*
Expand Down
11 changes: 11 additions & 0 deletions src/Stevebauman/Inventory/Models/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ class Inventory extends BaseModel
'description'
);

/**
* Revisionable field names
*
* @var array
*/
protected $revisionFormattedFieldNames = array(
'category_id' => 'Category',
'metric_id' => 'Metric',
'name' => 'Name',
);

/**
* The hasOne category relationship
*
Expand Down
5 changes: 5 additions & 0 deletions src/Stevebauman/Inventory/Models/InventoryStock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class InventoryStock extends BaseModel
'quantity'
);

protected $revisionFormattedFieldNames = array(
'location_id' => 'Location',
'quantity' => 'Quantity',
);

/**
* The belongsTo item relationship
*
Expand Down
4 changes: 4 additions & 0 deletions src/Stevebauman/Inventory/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Location extends Node
'name',
);

protected $revisionFormattedFieldNames = array(
'name' => 'Name',
);

/**
* Returns a single lined string with arrows indicating depth of the current category
*
Expand Down
37 changes: 35 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,43 @@
* @param string $default
* @return mixed (array or string)
*/
if(!function_exists('config'))
{
if (!function_exists('config')) {
function config($key, $default = NULL)
{
return Config::get($key, $default);
}
}

/**
* Returns a single lined path for a baum node
*
* @param $node
* @return string
*/
if (!function_exists('renderNode')) {

function renderNode($node)
{
$html = '';

if (is_object($node)) {
$ancestors = $node->getAncestorsAndSelf();

foreach ($ancestors as $ancestor) {
if ($node->equals($ancestor) && $node->isRoot()) {
$html .= sprintf('<b>%s</b>', $ancestor->name);
} elseif ($node->equals($ancestor)) {
$html .= sprintf(' > <b>%s</b>', $ancestor->name);
} elseif ($ancestor->isRoot()) {
$html .= sprintf('%s', $ancestor->name);
} else {
$html .= sprintf(' > %s', $ancestor->name);
}
}

return $html;
}
return $node;
}

}

0 comments on commit 446828f

Please sign in to comment.