Skip to content

Commit 452cf17

Browse files
author
Ivan Kutuzov
committed
fix update sql type storage
1 parent 529f891 commit 452cf17

File tree

21 files changed

+131
-63
lines changed

21 files changed

+131
-63
lines changed

exampl/zf1/app/code/Mms/Model/Order/Storage.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class Mms_Model_Order_Storage extends Mms_Storage_Table
4141
'title' => array(
4242
'en' => 'State',
4343
),
44-
'type' => 'int'
44+
'type' => 'int',
45+
'tpl' => 'list_of_array',
46+
'isChangeable' => true,
4547
),
4648
),
4749
self::MD_PATH => array(
@@ -53,7 +55,13 @@ class Mms_Model_Order_Storage extends Mms_Storage_Table
5355
),
5456
self::MD_OPERATION => array('default' => array(
5557
Mms_Storage_Abstract::OPERATION_CREATE => array(),
56-
Mms_Storage_Abstract::OPERATION_UPDATE => array(),
58+
Mms_Storage_Abstract::OPERATION_UPDATE => array('processData' => array(
59+
'field' => array('id',
60+
'userId',
61+
'amount',
62+
'created',
63+
'state',
64+
))),
5765
Mms_Storage_Abstract::OPERATION_DELETE => array(),
5866
Mms_Storage_Abstract::OPERATION_EXPORT => array('link' => '/export/model/%s'),
5967
Mms_Storage_Abstract::OPERATION_FILTER => array(),
@@ -73,7 +81,6 @@ class Mms_Model_Order_Storage extends Mms_Storage_Table
7381
'operations' => array(
7482
'each' => array(
7583
'update',
76-
'delete',
7784
),
7885
'all' => array('export'),
7986
),
@@ -97,9 +104,44 @@ class Mms_Model_Order_Storage extends Mms_Storage_Table
97104
'state',
98105
),
99106
),
107+
'update' => array(
108+
'alias' => array(
109+
'userId',
110+
'amount',
111+
'created',
112+
'state',
113+
),
114+
),
115+
)),
116+
self::MD_HELPERS => array('default' => array(
117+
'state' => array('state'))
118+
),
119+
self::MD_FIELD_SET => array('default' => array(
120+
'state' => 'state',
100121
)),
101122
);
102123

124+
protected static function _getStateSet()
125+
{
126+
return array(
127+
0 => array('label' => 'wait', 'title' => 'новый'),
128+
4 => array('label' => 'warning', 'title' => 'в процессе'),
129+
5 => array('label' => 'success', 'title' => 'выполненный'),
130+
9 => array('label' => 'important', 'title' => 'неудачный'),
131+
);
132+
}
133+
134+
public static function helperState(& $data, $alias, $params)
135+
{
136+
$stateSet = self::getMetadata(self::MD_FIELD_SET);
137+
$stateSet = $stateSet['state'];
138+
139+
foreach (array_keys($data) as $rowKey) {
140+
$stateKey = $data[$rowKey][$alias];
141+
$data[$rowKey][$alias] = ' <span class="label label-'. $stateSet[$stateKey]['label'] . '" >'. $stateSet[$stateKey]['title'].' </span>';
142+
}
143+
}
144+
103145
/******************************************************************************
104146
* END
105147
******************************************************************************/

exampl/zf1/lib/Mms/Control/Abstract.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ public function unsetParam($name)
241241
******************************************************************************/
242242

243243
const P_DATA = 'data';
244+
const P_PROC_DATA = 'procData';
244245
const P_TITLE = 'title';
245246
const P_PARAMS = 'params';
246247
const P_METADATA = 'metadata';
@@ -250,6 +251,7 @@ public function unsetParam($name)
250251
//in specific control define keys only with true, that really need
251252
protected $_requireData = array(
252253
self::P_DATA => false,
254+
self::P_PROC_DATA => false,
253255
self::P_TITLE => false,
254256
self::P_PARAMS => false,
255257
self::P_METADATA => false,

exampl/zf1/lib/Mms/Control/Datagrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Mms_Control_Datagrid extends Mms_Control_Abstract
66
******************************************************************************/
77

88
protected $_requireData = array(
9-
self::P_DATA => true,
9+
self::P_PROC_DATA => true,
1010
self::P_TITLE => true,
1111
self::P_PARAMS => true,
1212
self::P_METADATA => true,

exampl/zf1/lib/Mms/Control/view/datagrid.phtml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if ($this->params['countData'] > 0) :
2727
<tbody id="checkboxes">
2828
<?php
2929
$i = 0;
30-
foreach ($this->data as $rowKey => $row) :
30+
foreach ($this->procData as $rowKey => $row) :
3131
$i++;
3232
?>
3333
<tr class="toggleRow" data-line-number="<?= $i ?>">
@@ -39,23 +39,7 @@ foreach ($this->aliasSet as $alias) {
3939
echo '<td></td>';
4040
continue;
4141
}
42-
echo '<td>';
43-
if (empty($this->metadata[Mms_Storage_Abstract::MD_FIELD][$alias]['tpl']) || $this->metadata[Mms_Storage_Abstract::MD_FIELD][$alias]['tpl'] == 'text') {
44-
echo $data;
45-
} else {
46-
try {
47-
echo $this->partial(
48-
'datagrid/' . $this->metadata[Mms_Storage_Abstract::MD_FIELD][$alias]['tpl'] . '.phtml',
49-
array(
50-
'alias' => $alias,
51-
'data' => $row,
52-
'metaData' => $this->metadata[Mms_Storage_Abstract::MD_FIELD][$alias],
53-
));
54-
}catch(Exception $ex) {
55-
echo $ex->getMessage();
56-
}
57-
}
58-
echo '</td>' . PHP_EOL;
42+
echo '<td>' . $data . '</td>' . PHP_EOL;
5943
}
6044
if ($operationBlock != '') {
6145
echo '<td>' . vsprintf($operationBlock, array($row['id'])) . '</td>' . PHP_EOL;

exampl/zf1/lib/Mms/Control/view/field/list.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<select id="<?= $this->id ?>" class="medium" name="<?= $this->name ?>">
2-
<?php foreach ($this->listSet as $key => $instance) {
2+
<?php foreach ($this->valueSet as $key => $instance) {
33
echo '<option value="' . $key . '"'
44
. (($this->field == $instance)?' selected="selected"':'')
55
. '>' . $instance . '</option>';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<select id="<?= $this->id ?>" class="medium" name="<?= $this->name ?>">
2+
<?php foreach ($this->valueSet as $key => $param) {
3+
echo '<option value="' . $key . '"'
4+
. (($this->field == $key)?' selected="selected"':'')
5+
. '>' . $param['title'] . '</option>';
6+
}
7+
?>
8+
</select>

exampl/zf1/lib/Mms/Control/view/form/update.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $data = current($this->data);
1919
? $this->fieldMetadata[$alias]['default']
2020
: '',
2121
'field' => isset($data[$alias]) ? $data[$alias] : '',
22-
'valueSet' => $this->valueSet,
22+
'valueSet' => (isset($this->valueSet[$alias]) ? $this->valueSet[$alias] : array()),
2323
'alias' => $alias,
2424
)
2525
);

exampl/zf1/lib/Mms/Entity/Row.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function _loadData()
1212
$fieldsData = $storageClass::getMetadata(Mms_Storage_Abstract::MD_FIELD);
1313
$data = array();
1414
$entityData = $this->_specificEntity->toArray();
15-
foreach ($fieldsData as $alias) {
15+
foreach (array_keys($fieldsData) as $alias) {
1616
if (isset($entityData[$pathSet[$alias]])) {
1717
$data[$alias] = $entityData[$pathSet[$alias]];
1818
}
@@ -23,7 +23,7 @@ public function _loadData()
2323
public function _saveData()
2424
{
2525
$storageClass = $this->getStorageClass();
26-
$pathSet = $storageClass::getPath();
26+
$pathSet = $storageClass::getPathSet();
2727
$fieldSet = $storageClass::getMetadata(Mms_Storage_Abstract::MD_FIELD);
2828
foreach ($this->_data as $alias => $value) {
2929
if ($fieldSet[$alias]['isChangeable'] === true) {

exampl/zf1/lib/Mms/Manager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ protected function _setControlParamData()
220220
return $storage->getDataSet();
221221
}
222222

223+
protected function _setControlParamProcData()
224+
{
225+
$storage = $this->getStorage();
226+
return $storage->getProcDataSet();
227+
}
228+
223229
protected function _setControlParamExportData()
224230
{
225231
$storage = $this->getStorage();

exampl/zf1/lib/Mms/Storage/Abstract.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ protected function _initFieldsSet()
4343
if (empty($fieldSet)) {
4444
return;
4545
}
46-
$profile = $this->getProfile();
46+
$mdField = self::getMetadata(self::MD_FIELD);
47+
$virtualSet = self::getMetadata(self::MD_VIRTUAL);
4748
foreach ($fieldSet as $fieldAlias) {
48-
if (!isset(static::$_metadata[self::MD_FIELD][$fieldAlias])
49-
&& !isset(static::$_metadata[self::MD_VIRTUAL][$fieldAlias])
49+
if (!isset($mdField[$fieldAlias])
50+
&& !isset($virtualSet[$fieldAlias])
5051
) {
5152
continue;
5253
}
5354
$getMethodName = '_get' . ucfirst($fieldAlias) . 'Set';
5455
if (method_exists($this, $getMethodName)) {
55-
static::$_metadata[self::MD_FIELD_SET][$profile][$fieldAlias] = $this->{$getMethodName}();
56+
static::$_metadata[self::MD_FIELD_SET][$fieldAlias] = $this->{$getMethodName}();
5657
}
5758
}
5859
}
@@ -522,7 +523,7 @@ public static function exportFilterMoney(& $dataSet, $path = null)
522523
protected $_dataSet;
523524
public $isExport = false;
524525

525-
public function getDataSet($withLimits = true, $withFields = false)
526+
public function getProcDataSet($withLimits = true, $withFields = false)
526527
{
527528
$dataSet = array();
528529
$pathSet = $this->_selectData($dataSet, $withLimits, $withFields);
@@ -541,13 +542,25 @@ public function getDataSet($withLimits = true, $withFields = false)
541542
$params = null;
542543
}
543544
$helperMethodName = 'helper' . ucfirst($helperAlias);
544-
self::$helperMethodName($dataSet, $alias, $params);
545+
static::$helperMethodName($dataSet, $alias, $params);
545546
}
546547
}
547548
}
548549
return $dataSet;
549550
}
550551

552+
public function getDataSet($withLimits = true, $withFields = false)
553+
{
554+
$dataSet = array();
555+
$pathSet = $this->_selectData($dataSet, $withLimits, $withFields);
556+
foreach ($pathSet as $alias => $path) {
557+
foreach (array_keys($dataSet) as $rowKey) {
558+
$dataSet[$rowKey][$alias] = $dataSet[$rowKey][$path];
559+
}
560+
}
561+
return $dataSet;
562+
}
563+
551564
abstract protected function _selectData(& $dataSet, $withLimits = true, $withFields = false);
552565

553566

0 commit comments

Comments
 (0)