Skip to content

Commit

Permalink
Changes in category management
Browse files Browse the repository at this point in the history
  • Loading branch information
adampiotrowski committed Mar 25, 2014
1 parent 6b107d0 commit c18d1d0
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 242 deletions.
7 changes: 0 additions & 7 deletions application/Gekosale/Core/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ public function editAction($id)
*/
abstract protected function getRepository();

/**
* Returns DataGrid service for controller
*
* @return \Gekosale\Core\DataGrid|object
*/
abstract protected function getDataGrid();

/**
* Returns Form service for controller
*
Expand Down
31 changes: 13 additions & 18 deletions application/Gekosale/Core/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@
*/
class Helper extends Component
{
/**
* Returns current translation from translation Collection
*
* @param Collection $collection
*/
public function getCurrentTranslation(Collection $collection)
{
$language = $this->getCurrentLanguage();

$data = $collection->each(function ($item) use ($collection, $language) {
if ($item->language_id == $language) {
return $item;
}
});

return $data;
}

/**
* Replaces commas with dots
*
Expand All @@ -50,4 +32,17 @@ public static function changeCommaToDot($value)
{
return str_replace(',', '.', $value);
}

/**
* @param $name
*/
public static function makeSlug($name, $delimiter = '-')
{
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $name);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);

return $clean;
}
}
32 changes: 31 additions & 1 deletion application/Gekosale/Core/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@
* @package Gekosale\Core\Model
* @author Adam Piotrowski <adam@gekosale.com>
*/
class Category extends Model
class Category extends Model implements TranslatableModelInterface
{
protected $table = 'category';
public $timestamps = true;
protected $softDelete = false;
protected $fillable = array('id');

public function translation()
{
return $this->hasMany('Gekosale\Core\Model\CategoryTranslation');
}

public function photo()
{
return $this->belongsToOne('Gekosale\Core\Model\File');
}

public function scopeParents($query)
{
return $query->whereNull('parent_id');
Expand Down Expand Up @@ -57,4 +67,24 @@ public function getEnabledAttribute($value)
{
return (int)$value;
}

/**
* Mutator for parent_id attribute
*
* @param $value
*/
public function setParentIdAttribute($value)
{
$this->attributes['parent_id'] = ((int)$value == 0) ? null : $value;
}

/**
* Mutator for hierarchy attribute
*
* @param $value
*/
public function setHierarchyAttribute($value)
{
$this->attributes['hierarchy'] = (int)$value;
}
}
73 changes: 73 additions & 0 deletions application/Gekosale/Core/Model/CategoryTranslation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/*
* Gekosale Open-Source E-Commerce Platform
*
* This file is part of the Gekosale package.
*
* (c) Adam Piotrowski <adam@gekosale.com>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/
namespace Gekosale\Core\Model;

use Gekosale\Core\Model;

/**
* Class CategoryTranslation
*
* @package Gekosale\Core\Model
* @author Adam Piotrowski <adam@gekosale.com>
*/
class CategoryTranslation extends Model
{

/**
* @var string
*/
protected $table = 'category_translation';

/**
* @var bool
*/
public $timestamps = true;

/**
* @var bool
*/
protected $softDelete = false;

/**
* @var array
*/
protected $fillable = ['category_id', 'language_id'];

/**
* @var array
*/
protected $translatable
= [
'name',
'slug',
'short_description',
'description',
'meta_title',
'meta_keywords',
'meta_description'
];

public function category()
{
return $this->belongsTo('Gekosale\Core\Model\Category');
}

/**
* Relation with language table
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function language()
{
return $this->belongsTo('Gekosale\Core\Model\Language');
}
}
14 changes: 14 additions & 0 deletions application/Gekosale/Core/Model/CustomCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
*/
class CustomCollection extends Collection
{
/**
* Returns current translation from translation Collection
*
* @param Collection $collection
*/
public function getCurrentTranslation($language)
{
foreach ($this as $item) {
if ($item->language_id == $language) {
return $item;
}
}
}

/**
* Flatten Collection to key-value pairs used in forms
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@ public function indexAction()
);
}

public function addAction()
{
$form = $this->getForm()->init();

$this->registerFunctions();

if ($form->isValid()) {

$this->getRepository()->save($form->getSubmitValues());

return $this->redirect($this->generateUrl($this->getDefaultRoute()));
}

return Array(
'form' => $form
);
}

public function editAction($id)
{
$this->registerFunctions();
Expand All @@ -71,14 +53,6 @@ public function editAction($id)
);
}

/**
* Get DataGrid
*/
protected function getDataGrid()
{
return $this->get('category.datagrid');
}

/**
* Get Repository
*/
Expand Down Expand Up @@ -130,10 +104,25 @@ protected function registerFunctions()
'doAJAXRefreshSeoCategory'
]);

$this->getXajaxManager()->registerFunction([
'AddCategory',
$this->getRepository(),
'quickAddCategory'
]);

$this->getXajaxManager()->registerFunction([
'DeleteCategory',
$this->getRepository(),
'delete'
]);

$this->getXajaxManager()->registerFunction([
'ChangeCategoryOrder',
$this->getRepository(),
'changeCategoryOrder'
]);

$this->getXajaxManager()->registerFunctions([
'DeleteCategory' => [$this->getRepository(), 'deleteCategory'],
'AddCategory' => [$this->getRepository(), 'addEmptyCategory'],
'ChangeCategoryOrder' => [$this->getRepository(), 'changeCategoryOrder'],
'doAJAXCreateSeoCategory' => [$this->getRepository(), 'doAJAXCreateSeoCategory'],
]);
}
Expand Down
Loading

0 comments on commit c18d1d0

Please sign in to comment.