Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adampiotrowski committed Mar 21, 2014
1 parent 7e7ca30 commit 6f65a2e
Show file tree
Hide file tree
Showing 66 changed files with 2,228 additions and 275 deletions.
12 changes: 3 additions & 9 deletions application/Gekosale/Core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,14 @@ public function __construct($isDebug)

$this->stopwatch->start('application');

/*
* Create request instance
*/
// Create request instance
$this->request = Request::createFromGlobals();

/*
* Check if service container exists and/or needs to be regenerated
*/
// Check if service container exists and/or needs to be regenerated
$serviceContainerBuilder = new ServiceContainerBuilder($this->getKernelParameters(), $this->isDebug);
$serviceContainerBuilder->check();

/*
* Init Service Container
*/
// Init Service Container
$this->container = new ServiceContainer();
}

Expand Down
6 changes: 4 additions & 2 deletions application/Gekosale/Core/ControllerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function __construct(ContainerInterface $container = null)
*/
public function getController(Request $request)
{


$this->action = $request->attributes->get('_action');
$this->baseController = $request->attributes->get('_controller');
$controllerObject = $this->createController($this->baseController);
Expand All @@ -81,9 +83,9 @@ protected function createController($class)
$controller->setContainer($this->container);
}

return array(
return [
$controller,
$this->action
);
];
}
}
33 changes: 12 additions & 21 deletions application/Gekosale/Core/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,6 @@ public function refresh($datagridId)
return $objResponse;
}

/**
* Redirects user from list to edit form
*
* @param $id
*
* @return mixed
*/
public function editRow($request)
{
return [
'processFunction' => DataGridInterface::REDIRECT,
'data' => $this->generateUrl($this->getEditActionRoute(), ['id' => $request['id']], true)
];
}

/**
* Updates DataGrid row
*
Expand Down Expand Up @@ -134,11 +119,16 @@ public function loadData($request)
$column = $this->columns[$where['column']]['source'];
$operator = $this->getOperator($where['operator']);
$value = $where['value'];
$this->query->where($column, $operator, $value);
if (is_array($value)) {
$this->query->whereIn($column, $value);
} else {
$this->query->where($column, $operator, $value);
}

}

$result = $this->query->get();
$total = count($result);
$total = count($result);

return [
'data_id' => $request['id'],
Expand Down Expand Up @@ -258,13 +248,14 @@ public function setOptions(array $options)
'rows_per_page' => 25
],
'event_handlers' => [
'load' => false,
'load' => $this->getXajaxManager()->registerFunction(['loadData', $this, 'loadData']),
'process' => false,
'delete_row' => false,
'delete_row' => $this->getXajaxManager()->registerFunction(['deleteRow', $this, 'deleteRow']),
'loaded' => false,
'edit_row' => false,
'edit_row' => 'editRow',
'delete_group' => false,
'update_row' => false,
'click_row' => 'editRow',
'update_row' => $this->getXajaxManager()->registerFunction(['updateRow', $this, 'updateRow']),
],
'row_actions' => [
DataGridInterface::ACTION_EDIT,
Expand Down
26 changes: 26 additions & 0 deletions application/Gekosale/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ public function addFieldsetLanguage(array $options)
return new Form\Elements\FieldsetLanguage($options);
}

/**
* Shortcut for adding Image element
*
* @param $options
*
* @return Form\Elements\Image
*/
public function addImage($options)
{
$options['file_types_description'] = $this->trans('Files description');

return new Form\Elements\Image($options, $this->container);
}

/**
* Shortcut for adding Tip element
*
* @param $options
*
* @return Form\Elements\Tip
*/
public function addTip($options)
{
return new Form\Elements\Tip($options);
}

/**
* Shortcut for adding TextField element
*
Expand Down
104 changes: 20 additions & 84 deletions application/Gekosale/Core/Form/Elements/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Gekosale\Core\Form\Elements;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class File
*
Expand All @@ -24,119 +26,53 @@ class File extends Field implements ElementInterface
public $datagrid;

protected static $_filesLoadHandlerSet = false;
protected $_jsFunction;
protected $jsFunction;

public function __construct($attributes)
public function __construct($attributes, ContainerInterface $container)
{
parent::__construct($attributes);

$this->container = $container;
$this->datagrid = $container->get('file.datagrid');
$this->_attributes['session_name'] = session_name();
$this->_attributes['session_id'] = session_id();
$this->_jsFunction = 'LoadFiles_' . $this->_id;
$this->_attributes['load_handler'] = 'xajax_' . $this->_jsFunction;
App::getRegistry()->xajax->registerFunction(array(
$this->_jsFunction,
$this->jsFunction = 'LoadFiles_' . $this->_id;
$this->_attributes['load_handler'] = 'xajax_' . $this->jsFunction;

$this->container->get('xajax_manager')->registerFunction([
$this->jsFunction,
$this,
'doLoadFilesForDatagrid_' . $this->_id
));
]);

$this->datagrid->init();
}

public function __call($function, $arguments)
{
if (substr($function, 0, strlen('doLoadFilesForDatagrid_')) == 'doLoadFilesForDatagrid_') {
return call_user_func_array(Array(
return call_user_func_array([
$this,
'doLoadFilesForDatagrid'
), $arguments);
], $arguments);
}
throw new CoreException('Tried to call a method that doesn\'t exist: ' . $function);
}

public function doLoadFilesForDatagrid($request, $processFunction)
public function doLoadFilesForDatagrid($request)
{
if (isset($this->_attributes['file_types']) && is_array($this->_attributes['file_types']) && count($this->_attributes['file_types'])) {
if (!isset($request['where']) || !is_array($request['where'])) {
$request['where'] = Array();
$request['where'] = [];
}
$request['where'][] = Array(
'operator' => 'IN',
'column' => 'fileextension',
'column' => 'extension',
'value' => $this->_attributes['file_types']
);
$request['limit'] = !empty($this->_attributes['limit']) ? $this->_attributes['limit'] : 10;
}

return $this->getDatagrid()->getData($request, $processFunction);
}

public function getDatagrid()
{
if ($this->datagrid == null) {
$this->datagrid = App::getModel(get_class($this) . '/datagrid');
$this->initDatagrid($this->datagrid);
}

return $this->datagrid;
}

public function getThumbForId($id)
{
try {
$image = App::getModel('gallery')->getSmallImageById($id);
} catch (Exception $e) {
$image = Array(
'path' => ''
);
}

return $image['path'];
}

protected function initDatagrid($datagrid)
{
$datagrid->setTableData('file', Array(
'idfile' => Array(
'source' => 'F.idfile'
),
'filename' => Array(
'source' => 'F.name',
'prepareForAutosuggest' => true
),
'fileextension' => Array(
'source' => 'FE.name',
'prepareForSelect' => true
),
'filetype' => Array(
'source' => 'FT.name',
'prepareForSelect' => true
),
'adddate' => Array(
'source' => 'F.adddate'
),
'thumb' => Array(
'source' => 'F.idfile',
'processFunction' => Array(
$this,
'getThumbForId'
)
)
));
$datagrid->setFrom('
`file` F
INNER JOIN `filetype` FT ON FT.idfiletype = F.filetypeid
INNER JOIN `fileextension` FE ON FE.idfileextension = F.fileextensionid
');

$datagrid->setGroupBy('
F.idfile
');

if (isset($this->_attributes['ids']) && count($this->_attributes['ids'] > 0)) {
$datagrid->setAdditionalWhere('F.idfile IN (' . implode(',', $this->_attributes['ids']) . ')');
} else {
$datagrid->setAdditionalWhere("F.idfile IS NOT NULL");
}

return $this->datagrid->loadData($request);
}

public function prepareAttributesJs()
Expand Down
21 changes: 8 additions & 13 deletions application/Gekosale/Core/Form/Elements/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Gekosale\Core\Form\Elements;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class Image
*
Expand All @@ -21,22 +23,15 @@
class Image extends File implements ElementInterface
{

public function __construct($attributes)
public function __construct($attributes, ContainerInterface $container)
{
parent::__construct($attributes);
$this->_attributes['file_types'] = Array(
parent::__construct($attributes, $container);

$this->_attributes['file_types'] = [
'jpg',
'jpeg',
'png',
'gif',
'swf'
);
$this->_attributes['file_types_description'] = Translation::get('TXT_FILE_TYPES_IMAGE');
}

protected function prepareAttributesJs()
{
parent::prepareAttributesJs();
'gif'
];
}

}
2 changes: 1 addition & 1 deletion application/Gekosale/Core/Form/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function extractRepetitions($array, $targetLevel, $level = 0)
protected function formatAttributesJs($attributes)
{
$attributes = array_merge($attributes, $this->prepareAutoAttributesJs());
$attributesString = "\n";
$attributesString = PHP_EOL;
foreach ($attributes as $attribute) {
if (!empty($attribute)) {
$attributesString .= $this->_tabs . $attribute . ",\n";
Expand Down
54 changes: 51 additions & 3 deletions application/Gekosale/Core/Migration/Migration1394382543.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,63 @@ public function up()
$this->getDb()->schema()->create('shipping_method_cost', function ($table) {
$table->increments('id');
$table->integer('shipping_method_id')->unsigned();
$table->decimal('from',15,4)->default(0);
$table->decimal('to', 15,4)->default(0);
$table->decimal('cost', 15,4)->default(0);
$table->decimal('from', 15, 4)->default(0);
$table->decimal('to', 15, 4)->default(0);
$table->decimal('cost', 15, 4)->default(0);
$table->integer('tax_id')->unsigned()->default(null)->nullable();
$table->timestamps();
$table->foreign('shipping_method_id')->references('id')->on('shipping_method')->onDelete('CASCADE')->onUpdate('NO ACTION');
$table->foreign('tax_id')->references('id')->on('tax')->onDelete('CASCADE')->onUpdate('NO ACTION');
});
}

if (!$this->getDb()->schema()->hasTable('payment_method')) {
$this->getDb()->schema()->create('payment_method', function ($table) {
$table->increments('id');
$table->integer('hierarchy')->unsigned()->default(0);
$table->integer('enabled')->default(1);
$table->string('service', 255);
$table->integer('file_id')->unsigned()->nullable();
$table->timestamps();
$table->foreign('file_id')->references('id')->on('file')->onDelete('SET NULL')->onUpdate('NO ACTION');
});
}

if (!$this->getDb()->schema()->hasTable('payment_method_translation')) {
$this->getDb()->schema()->create('payment_method_translation', function ($table) {
$table->increments('id');
$table->string('name', 255);
$table->integer('payment_method_id')->unsigned();
$table->integer('language_id')->unsigned();
$table->timestamps();
$table->foreign('payment_method_id')->references('id')->on('payment_method')->onDelete('cascade')->onUpdate('NO ACTION');
$table->foreign('language_id')->references('id')->on('language')->onDelete('CASCADE')->onUpdate('NO ACTION');
$table->unique(Array('name', 'language_id'));
});
}

if (!$this->getDb()->schema()->hasTable('payment_method_shop')) {
$this->getDb()->schema()->create('payment_method_shop', function ($table) {
$table->increments('id');
$table->integer('payment_method_id')->unsigned();
$table->integer('shop_id')->unsigned();
$table->timestamps();
$table->foreign('payment_method_id')->references('id')->on('payment_method')->onDelete('cascade')->onUpdate('NO ACTION');
$table->foreign('shop_id')->references('id')->on('shop')->onDelete('CASCADE')->onUpdate('NO ACTION');
$table->unique(Array('payment_method_id', 'shop_id'));
});
}

if (!$this->getDb()->schema()->hasTable('shipping_method_payment_method')) {
$this->getDb()->schema()->create('shipping_method_payment_method', function ($table) {
$table->increments('id');
$table->integer('payment_method_id')->unsigned();
$table->integer('shipping_method_id')->unsigned();
$table->timestamps();
$table->foreign('payment_method_id')->references('id')->on('payment_method')->onDelete('cascade')->onUpdate('no action');
$table->foreign('shipping_method_id')->references('id')->on('shipping_method')->onDelete('cascade')->onUpdate('no action');
});
}
}

public function down()
Expand Down
Loading

0 comments on commit 6f65a2e

Please sign in to comment.