@@ -4,36 +4,36 @@ discard block |
||
| 4 | 4 | $optionsHtml = ''; |
| 5 | 5 | |
| 6 | 6 | foreach ($options['values'] as $key => $value) { |
| 7 | - $selected = ''; |
|
| 7 | + $selected = ''; |
|
| 8 | 8 | |
| 9 | - $primaryValue = isset($options['value']) ? $options['value'] : null; |
|
| 10 | - $primaryValue = is_array($primaryValue) && isset($primaryValue['primary']) ? $primaryValue['primary'] : $primaryValue; |
|
| 11 | - if (is_numeric($key) && !is_array($primaryValue) && $primaryValue !== '') { |
|
| 9 | + $primaryValue = isset($options['value']) ? $options['value'] : null; |
|
| 10 | + $primaryValue = is_array($primaryValue) && isset($primaryValue['primary']) ? $primaryValue['primary'] : $primaryValue; |
|
| 11 | + if (is_numeric($key) && !is_array($primaryValue) && $primaryValue !== '') { |
|
| 12 | 12 | $primaryValue = (int) $primaryValue; |
| 13 | - } |
|
| 14 | - if ( |
|
| 15 | - (!is_array($primaryValue) && ($key === $primaryValue || (isset($form->userDataTree[$name]) && $form->userDataTree[$name] === $key))) || |
|
| 13 | + } |
|
| 14 | + if ( |
|
| 15 | + (!is_array($primaryValue) && ($key === $primaryValue || (isset($form->userDataTree[$name]) && $form->userDataTree[$name] === $key))) || |
|
| 16 | 16 | (is_array($primaryValue) && (in_array($key, $primaryValue) || (isset($form->userDataTree[$name]) && in_array($key, $form->userDataTree[$name])))) |
| 17 | - ) { |
|
| 17 | + ) { |
|
| 18 | 18 | $selected = ' selected="selected"'; |
| 19 | - } |
|
| 20 | - if (is_array($value)) { |
|
| 19 | + } |
|
| 20 | + if (is_array($value)) { |
|
| 21 | 21 | $aditionalInputs[] = $value['input']; |
| 22 | 22 | if ($selected) { |
| 23 | - $showedInput = count($aditionalInputs) - 1; |
|
| 24 | - $aditionValue = !empty($options['aditionalValue']) ? $options['aditionalValue'] : ''; |
|
| 23 | + $showedInput = count($aditionalInputs) - 1; |
|
| 24 | + $aditionValue = !empty($options['aditionalValue']) ? $options['aditionalValue'] : ''; |
|
| 25 | 25 | } |
| 26 | 26 | $optionsHtml .= "<option data-aditionalInput='" . ( count($aditionalInputs) - 1) . "' value ='{$key}'{$selected}>{$value['text']}</option>"; |
| 27 | - } else { |
|
| 27 | + } else { |
|
| 28 | 28 | $optionsHtml .= "<option value ='{$key}'{$selected}>{$value}</option>"; |
| 29 | - } |
|
| 29 | + } |
|
| 30 | 30 | } |
| 31 | 31 | ?> |
| 32 | 32 | <?= empty($options['noContainer']) ? '<div class="form-group">' : ''; ?> |
| 33 | 33 | <?= $label !== false ? "<label>{$label}" : ''; ?> |
| 34 | 34 | <?php |
| 35 | 35 | if ($label !== false && !empty($options['createBtn'])) { |
| 36 | - echo ' (<a href="" onclick="' . $options['createBtn']['onclick'] . ';this.disabled=true;return false;">' . $options['createBtn']['text'] . '</a>)'; |
|
| 36 | + echo ' (<a href="" onclick="' . $options['createBtn']['onclick'] . ';this.disabled=true;return false;">' . $options['createBtn']['text'] . '</a>)'; |
|
| 37 | 37 | } |
| 38 | 38 | ?> |
| 39 | 39 | <?= $label !== false ? "</label>" : ''; ?> |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | </select> |
| 43 | 43 | <?php |
| 44 | 44 | foreach ($aditionalInputs as $key => $input) { |
| 45 | - $input['options']['noContainer'] = true; |
|
| 45 | + $input['options']['noContainer'] = true; |
|
| 46 | 46 | |
| 47 | - if ($key !== $showedInput) { |
|
| 47 | + if ($key !== $showedInput) { |
|
| 48 | 48 | $input['options']['disabled'] = true; |
| 49 | 49 | $input['options']['class'] = !empty($input['options']['class']) ? $input['options']['class'] . ' hidden' : 'hidden'; |
| 50 | - } else { |
|
| 50 | + } else { |
|
| 51 | 51 | $input['options']['value'] = empty($input['options']['value']) ? $aditionValue : $input['options']['value']; |
| 52 | - } |
|
| 53 | - if ($input['type'] == 'select') { |
|
| 52 | + } |
|
| 53 | + if ($input['type'] == 'select') { |
|
| 54 | 54 | $input['options']['values'] = \Ui\ActiveForm::getOptionsList($input); |
| 55 | - } |
|
| 56 | - $form->input($input['type'], empty($input['name']) ? $name . '[aditional]' : $input['name'], false, $input['options']); |
|
| 55 | + } |
|
| 56 | + $form->input($input['type'], empty($input['name']) ? $name . '[aditional]' : $input['name'], false, $input['options']); |
|
| 57 | 57 | } |
| 58 | 58 | ?> |
| 59 | 59 | <?= empty($options['noContainer']) ? '</div>' : ''; ?> |
| 60 | 60 | \ No newline at end of file |
@@ -6,10 +6,10 @@ discard block |
||
| 6 | 6 | <?= $label; ?> |
| 7 | 7 | </h3> |
| 8 | 8 | <?php |
| 9 | - if ($options['source'] == 'relation' && empty($options['modelPk'])) { |
|
| 9 | + if ($options['source'] == 'relation' && empty($options['modelPk'])) { |
|
| 10 | 10 | echo '<h4 class=" text-muted">Чтобы добавить связи, сначала создайте объект</h4>'; |
| 11 | 11 | echo '<p class=" text-muted">Просто заполните доступные поля и нажмите кнопку внизу формы. После этого дополнительные поля разблокируются</p>'; |
| 12 | - } else { |
|
| 12 | + } else { |
|
| 13 | 13 | ?> |
| 14 | 14 | <div class="table-responsive"> |
| 15 | 15 | <table class ='table table-striped'> |
@@ -17,15 +17,15 @@ discard block |
||
| 17 | 17 | <tr> |
| 18 | 18 | <?php |
| 19 | 19 | foreach ($options['cols'] as $colName => $col) { |
| 20 | - echo "<th>"; |
|
| 21 | - echo $col['col']['label']; |
|
| 22 | - if (!empty($col['col']['model'])) { |
|
| 20 | + echo "<th>"; |
|
| 21 | + echo $col['col']['label']; |
|
| 22 | + if (!empty($col['col']['model'])) { |
|
| 23 | 23 | $modelName = $col['col']['model']; |
| 24 | 24 | $onclick = 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
| 25 | 25 | . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this));return false;'; |
| 26 | 26 | echo ' (<a href="" onclick="' . $onclick . ';this.disabled=true;return false;">Создать</a>)'; |
| 27 | - } |
|
| 28 | - echo "</th>"; |
|
| 27 | + } |
|
| 28 | + echo "</th>"; |
|
| 29 | 29 | } |
| 30 | 30 | ?> |
| 31 | 31 | <td> </td> |
@@ -33,29 +33,29 @@ discard block |
||
| 33 | 33 | </thead> |
| 34 | 34 | <tbody class="listBody"> |
| 35 | 35 | <?php |
| 36 | - $i = 0; |
|
| 37 | - if (!empty($options['values'])) { |
|
| 36 | + $i = 0; |
|
| 37 | + if (!empty($options['values'])) { |
|
| 38 | 38 | foreach ($options['values'] as $row) { |
| 39 | - $i++; |
|
| 40 | - echo '<tr>'; |
|
| 41 | - foreach ($options['cols'] as $colName => $col) { |
|
| 39 | + $i++; |
|
| 40 | + echo '<tr>'; |
|
| 41 | + foreach ($options['cols'] as $colName => $col) { |
|
| 42 | 42 | echo '<td>'; |
| 43 | 43 | $col['options']['noContainer'] = true; |
| 44 | 44 | $col['options']['value'] = $row[$colName]; |
| 45 | 45 | $form->input($col['type'], $name . '[' . ($i) . '][' . $colName . ']', false, $col['options']); |
| 46 | 46 | echo '</td>'; |
| 47 | - } |
|
| 48 | - echo '<td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td>'; |
|
| 49 | - echo '</tr>'; |
|
| 47 | + } |
|
| 48 | + echo '<td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td>'; |
|
| 49 | + echo '</tr>'; |
|
| 50 | 50 | } |
| 51 | - } |
|
| 52 | - ?> |
|
| 51 | + } |
|
| 52 | + ?> |
|
| 53 | 53 | </tbody> |
| 54 | 54 | <tfoot> |
| 55 | 55 | <tr> |
| 56 | 56 | <?php |
| 57 | 57 | foreach ($options['cols'] as $colName => $col) { |
| 58 | - echo "<th>{$col['col']['label']}</th>"; |
|
| 58 | + echo "<th>{$col['col']['label']}</th>"; |
|
| 59 | 59 | } |
| 60 | 60 | ?> |
| 61 | 61 | <td> </td> |
@@ -68,21 +68,21 @@ discard block |
||
| 68 | 68 | <script>/* |
| 69 | 69 | <tr> |
| 70 | 70 | <?php |
| 71 | - foreach ($options['cols'] as $colName => $col) { |
|
| 71 | + foreach ($options['cols'] as $colName => $col) { |
|
| 72 | 72 | echo '<td>'; |
| 73 | 73 | $col['input']->options['noContainer'] = true; |
| 74 | 74 | $col['input']->colParams['label'] = false; |
| 75 | 75 | $col['input']->draw(); |
| 76 | 76 | echo '</td>'; |
| 77 | - } |
|
| 78 | - ?> |
|
| 77 | + } |
|
| 78 | + ?> |
|
| 79 | 79 | <td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td> |
| 80 | 80 | </tr> |
| 81 | 81 | */</script> |
| 82 | 82 | </div> |
| 83 | 83 | <?php |
| 84 | - } |
|
| 85 | - ?> |
|
| 84 | + } |
|
| 85 | + ?> |
|
| 86 | 86 | </div> |
| 87 | 87 | <?php |
| 88 | 88 | //exit(); |
@@ -12,61 +12,61 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | class DataManager extends \Object { |
| 14 | 14 | |
| 15 | - public $modelName = ''; |
|
| 16 | - public $managerOptions = []; |
|
| 17 | - public $managerName = 'customManager'; |
|
| 18 | - public $name = 'Менеджер данных'; |
|
| 19 | - public $limit = 30; |
|
| 20 | - public $page = 1; |
|
| 21 | - public $table = null; |
|
| 22 | - public $joins = []; |
|
| 23 | - public $predraw = false; |
|
| 24 | - public $cols = []; |
|
| 25 | - public $managerId = ''; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Construct new data manager |
|
| 29 | - * |
|
| 30 | - * @param string|array $modelNameOrOptions |
|
| 31 | - * @param string $managerName |
|
| 32 | - * @throws Exception |
|
| 33 | - */ |
|
| 34 | - public function __construct($modelNameOrOptions, $managerName = 'manager') { |
|
| 15 | + public $modelName = ''; |
|
| 16 | + public $managerOptions = []; |
|
| 17 | + public $managerName = 'customManager'; |
|
| 18 | + public $name = 'Менеджер данных'; |
|
| 19 | + public $limit = 30; |
|
| 20 | + public $page = 1; |
|
| 21 | + public $table = null; |
|
| 22 | + public $joins = []; |
|
| 23 | + public $predraw = false; |
|
| 24 | + public $cols = []; |
|
| 25 | + public $managerId = ''; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Construct new data manager |
|
| 29 | + * |
|
| 30 | + * @param string|array $modelNameOrOptions |
|
| 31 | + * @param string $managerName |
|
| 32 | + * @throws Exception |
|
| 33 | + */ |
|
| 34 | + public function __construct($modelNameOrOptions, $managerName = 'manager') { |
|
| 35 | 35 | $this->managerName = $managerName; |
| 36 | 36 | |
| 37 | 37 | if (!is_array($modelNameOrOptions)) { |
| 38 | - if (!class_exists($modelNameOrOptions)) { |
|
| 38 | + if (!class_exists($modelNameOrOptions)) { |
|
| 39 | 39 | throw new \Exception("model {$modelNameOrOptions} not exists"); |
| 40 | - } |
|
| 41 | - $this->modelName = $modelNameOrOptions; |
|
| 42 | - $this->managerOptions = !empty($modelNameOrOptions::$dataManagers[$managerName]) ? $modelNameOrOptions::$dataManagers[$managerName] : []; |
|
| 43 | - if (isset($modelNameOrOptions::$objectName)) { |
|
| 40 | + } |
|
| 41 | + $this->modelName = $modelNameOrOptions; |
|
| 42 | + $this->managerOptions = !empty($modelNameOrOptions::$dataManagers[$managerName]) ? $modelNameOrOptions::$dataManagers[$managerName] : []; |
|
| 43 | + if (isset($modelNameOrOptions::$objectName)) { |
|
| 44 | 44 | $this->name = $modelNameOrOptions::$objectName; |
| 45 | - } else { |
|
| 45 | + } else { |
|
| 46 | 46 | $this->name = $modelNameOrOptions; |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | } else { |
| 49 | - $this->managerOptions = $modelNameOrOptions; |
|
| 49 | + $this->managerOptions = $modelNameOrOptions; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | if (!$this->managerOptions || !is_array($this->managerOptions)) { |
| 53 | - throw new \Exception('empty DataManager'); |
|
| 53 | + throw new \Exception('empty DataManager'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | if (!empty($this->managerOptions['name'])) { |
| 57 | - $this->name = $this->managerOptions['name']; |
|
| 57 | + $this->name = $this->managerOptions['name']; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $this->managerId = str_replace('\\', '_', 'dataManager_' . $this->modelName . '_' . $this->managerName . '_' . \Tools::randomString()); |
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Get buttons for manager |
|
| 65 | - * |
|
| 66 | - * @param string $params |
|
| 67 | - * @param object $model |
|
| 68 | - */ |
|
| 69 | - public function getButtons($params = [], $model = null) { |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Get buttons for manager |
|
| 65 | + * |
|
| 66 | + * @param string $params |
|
| 67 | + * @param object $model |
|
| 68 | + */ |
|
| 69 | + public function getButtons($params = [], $model = null) { |
|
| 70 | 70 | $modelName = $this->modelName; |
| 71 | 71 | |
| 72 | 72 | |
@@ -76,48 +76,48 @@ discard block |
||
| 76 | 76 | 'formName' => !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager' |
| 77 | 77 | ]; |
| 78 | 78 | if ($model) { |
| 79 | - $formModelName = get_class($model); |
|
| 80 | - $relations = $formModelName::relations(); |
|
| 81 | - $type = !empty($relations[$params['relation']]['type']) ? $relations[$params['relation']]['type'] : 'to'; |
|
| 82 | - switch ($type) { |
|
| 79 | + $formModelName = get_class($model); |
|
| 80 | + $relations = $formModelName::relations(); |
|
| 81 | + $type = !empty($relations[$params['relation']]['type']) ? $relations[$params['relation']]['type'] : 'to'; |
|
| 82 | + switch ($type) { |
|
| 83 | 83 | case 'relModel': |
| 84 | 84 | $formParams['preset'] = [ |
| 85 | - $formModelName::index() => $model->pk() |
|
| 86 | - ]; |
|
| 87 | - break; |
|
| 85 | + $formModelName::index() => $model->pk() |
|
| 86 | + ]; |
|
| 87 | + break; |
|
| 88 | 88 | default: |
| 89 | 89 | $formParams['preset'] = [ |
| 90 | - $relations[$params['relation']]['col'] => $model->pk() |
|
| 91 | - ]; |
|
| 92 | - } |
|
| 90 | + $relations[$params['relation']]['col'] => $model->pk() |
|
| 91 | + ]; |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $buttons = []; |
| 96 | 96 | if (!empty($this->managerOptions['sortMode'])) { |
| 97 | - $buttons[] = [ |
|
| 98 | - 'class' => 'modeBtn', |
|
| 99 | - 'data-mode' => 'sort', |
|
| 100 | - 'text' => 'Сортировать', |
|
| 101 | - ]; |
|
| 97 | + $buttons[] = [ |
|
| 98 | + 'class' => 'modeBtn', |
|
| 99 | + 'data-mode' => 'sort', |
|
| 100 | + 'text' => 'Сортировать', |
|
| 101 | + ]; |
|
| 102 | 102 | } |
| 103 | 103 | if (!empty($this->managerOptions['filters'])) { |
| 104 | - $buttons[] = [ |
|
| 105 | - 'text' => 'Фильтры', |
|
| 106 | - 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
| 104 | + $buttons[] = [ |
|
| 105 | + 'text' => 'Фильтры', |
|
| 106 | + 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
| 107 | 107 | modal.modal("show");', |
| 108 | - ]; |
|
| 108 | + ]; |
|
| 109 | 109 | } |
| 110 | 110 | if (!empty($modelName::$forms['simpleItem'])) { |
| 111 | - $formParams['formName'] = 'simpleItem'; |
|
| 112 | - $buttons[] = [ |
|
| 113 | - 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
|
| 114 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
| 115 | - ]; |
|
| 111 | + $formParams['formName'] = 'simpleItem'; |
|
| 112 | + $buttons[] = [ |
|
| 113 | + 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
|
| 114 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
| 115 | + ]; |
|
| 116 | 116 | } |
| 117 | 117 | $formParams['formName'] = !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager'; |
| 118 | 118 | $name = 'Элемент'; |
| 119 | 119 | if ($modelName::$objectName) { |
| 120 | - $name = $modelName::$objectName; |
|
| 120 | + $name = $modelName::$objectName; |
|
| 121 | 121 | } |
| 122 | 122 | $buttons[] = [ |
| 123 | 123 | 'text' => 'Создать ' . $name, |
@@ -125,45 +125,45 @@ discard block |
||
| 125 | 125 | ]; |
| 126 | 126 | |
| 127 | 127 | return $buttons; |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - function getActions($onlyGroupActions = false) { |
|
| 130 | + function getActions($onlyGroupActions = false) { |
|
| 131 | 131 | $actions = [ |
| 132 | 132 | 'Open' => ['className' => 'Open'], 'Edit' => ['className' => 'Edit'], 'Delete' => ['className' => 'Delete'] |
| 133 | 133 | ]; |
| 134 | 134 | if (isset($this->managerOptions['actions'])) { |
| 135 | - $actions = array_merge($actions, $this->managerOptions['actions']); |
|
| 135 | + $actions = array_merge($actions, $this->managerOptions['actions']); |
|
| 136 | 136 | } |
| 137 | 137 | $return = []; |
| 138 | 138 | foreach ($actions as $key => $action) { |
| 139 | - if ($action === false) { |
|
| 139 | + if ($action === false) { |
|
| 140 | 140 | continue; |
| 141 | - } |
|
| 142 | - if (is_array($action)) { |
|
| 141 | + } |
|
| 142 | + if (is_array($action)) { |
|
| 143 | 143 | if (!empty($action['access']['groups']) && !in_array(\Users\User::$cur->group_id, $action['access']['groups'])) { |
| 144 | - continue; |
|
| 144 | + continue; |
|
| 145 | 145 | } |
| 146 | 146 | $return[$key] = $action; |
| 147 | - } else { |
|
| 147 | + } else { |
|
| 148 | 148 | $key = $action; |
| 149 | 149 | $return[$key] = [ |
| 150 | 150 | 'className' => $action |
| 151 | 151 | ]; |
| 152 | - } |
|
| 153 | - $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
| 154 | - if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
| 152 | + } |
|
| 153 | + $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
| 154 | + if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
| 155 | 155 | unset($return[$key]); |
| 156 | - } |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | return $return; |
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Get cols for manager |
|
| 163 | - * |
|
| 164 | - * @return string |
|
| 165 | - */ |
|
| 166 | - public function getCols() { |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Get cols for manager |
|
| 163 | + * |
|
| 164 | + * @return string |
|
| 165 | + */ |
|
| 166 | + public function getCols() { |
|
| 167 | 167 | $actions = $this->getActions(); |
| 168 | 168 | ob_start(); |
| 169 | 169 | ?> |
@@ -179,12 +179,12 @@ discard block |
||
| 179 | 179 | <li><a href ='' onclick='inji.Ui.dataManagers.get(this).rowSelection("inverse");return false;'>Инвертировать</a></li> |
| 180 | 180 | <li role="separator" class="divider"></li> |
| 181 | 181 | <?php |
| 182 | - foreach ($actions as $action => $actionParams) { |
|
| 182 | + foreach ($actions as $action => $actionParams) { |
|
| 183 | 183 | if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
| 184 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
| 184 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
| 185 | + } |
|
| 185 | 186 | } |
| 186 | - } |
|
| 187 | - ?> |
|
| 187 | + ?> |
|
| 188 | 188 | </ul> |
| 189 | 189 | </div> |
| 190 | 190 | <?php |
@@ -197,299 +197,299 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | $modelName = $this->modelName; |
| 199 | 199 | foreach ($this->managerOptions['cols'] as $key => $col) { |
| 200 | - if (is_array($col)) { |
|
| 200 | + if (is_array($col)) { |
|
| 201 | 201 | $colName = $key; |
| 202 | 202 | $colOptions = $col; |
| 203 | - } else { |
|
| 203 | + } else { |
|
| 204 | 204 | $colName = $col; |
| 205 | 205 | $colOptions = []; |
| 206 | - } |
|
| 207 | - $colInfo = []; |
|
| 208 | - if ($modelName) { |
|
| 206 | + } |
|
| 207 | + $colInfo = []; |
|
| 208 | + if ($modelName) { |
|
| 209 | 209 | $colInfo = $modelName::getColInfo($colName); |
| 210 | - } |
|
| 211 | - if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
| 210 | + } |
|
| 211 | + if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
| 212 | 212 | $colOptions['label'] = $colInfo['label']; |
| 213 | - } elseif (empty($colOptions['label'])) { |
|
| 213 | + } elseif (empty($colOptions['label'])) { |
|
| 214 | 214 | $colOptions['label'] = $colName; |
| 215 | - } |
|
| 216 | - $cols[$colName] = $colOptions; |
|
| 215 | + } |
|
| 216 | + $cols[$colName] = $colOptions; |
|
| 217 | 217 | } |
| 218 | 218 | return $cols; |
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Get rows for manager |
|
| 223 | - * |
|
| 224 | - * @param array $params |
|
| 225 | - * @param object $model |
|
| 226 | - * @return type |
|
| 227 | - */ |
|
| 228 | - public function getRows($params = [], $model = null) { |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Get rows for manager |
|
| 223 | + * |
|
| 224 | + * @param array $params |
|
| 225 | + * @param object $model |
|
| 226 | + * @return type |
|
| 227 | + */ |
|
| 228 | + public function getRows($params = [], $model = null) { |
|
| 229 | 229 | $modelName = $this->modelName; |
| 230 | 230 | if (!class_exists($modelName)) { |
| 231 | - return []; |
|
| 231 | + return []; |
|
| 232 | 232 | } |
| 233 | 233 | if (!$this->checkAccess()) { |
| 234 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 235 | - return []; |
|
| 234 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 235 | + return []; |
|
| 236 | 236 | } |
| 237 | 237 | $modelName = $this->modelName; |
| 238 | 238 | $queryParams = []; |
| 239 | 239 | if (empty($params['all'])) { |
| 240 | - if (!empty($params['limit'])) { |
|
| 240 | + if (!empty($params['limit'])) { |
|
| 241 | 241 | $this->limit = (int) $params['limit']; |
| 242 | - } |
|
| 243 | - if (!empty($params['page'])) { |
|
| 242 | + } |
|
| 243 | + if (!empty($params['page'])) { |
|
| 244 | 244 | $this->page = (int) $params['page']; |
| 245 | - } |
|
| 246 | - $queryParams['limit'] = $this->limit; |
|
| 247 | - $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
| 245 | + } |
|
| 246 | + $queryParams['limit'] = $this->limit; |
|
| 247 | + $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
| 248 | 248 | } |
| 249 | 249 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
| 250 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 250 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 251 | 251 | } |
| 252 | 252 | if (!empty($params['appType'])) { |
| 253 | - $queryParams['appType'] = $params['appType']; |
|
| 253 | + $queryParams['appType'] = $params['appType']; |
|
| 254 | 254 | } |
| 255 | 255 | if ($this->joins) { |
| 256 | - $queryParams['joins'] = $this->joins; |
|
| 256 | + $queryParams['joins'] = $this->joins; |
|
| 257 | 257 | } |
| 258 | 258 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
| 259 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
| 259 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
| 260 | 260 | if (!empty($colOptions['userCol'])) { |
| 261 | - if (strpos($colOptions['userCol'], ':')) { |
|
| 261 | + if (strpos($colOptions['userCol'], ':')) { |
|
| 262 | 262 | $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
| 263 | 263 | $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
| 264 | 264 | $queryParams['where'][] = [$colName, \Users\User::$cur->$rel->$param]; |
| 265 | - } |
|
| 265 | + } |
|
| 266 | 266 | } elseif (isset($colOptions['value'])) { |
| 267 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
| 267 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
| 268 | + } |
|
| 268 | 269 | } |
| 269 | - } |
|
| 270 | 270 | } |
| 271 | 271 | if (!empty($this->managerOptions['filters'])) { |
| 272 | - foreach ($this->managerOptions['filters'] as $col) { |
|
| 272 | + foreach ($this->managerOptions['filters'] as $col) { |
|
| 273 | 273 | $colInfo = $modelName::getColInfo($col); |
| 274 | 274 | switch ($colInfo['colParams']['type']) { |
| 275 | - case 'select': |
|
| 275 | + case 'select': |
|
| 276 | 276 | if (empty($params['filters'][$col]['value'])) { |
| 277 | - continue; |
|
| 277 | + continue; |
|
| 278 | 278 | } |
| 279 | 279 | if (is_array($params['filters'][$col]['value'])) { |
| 280 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
| 280 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
| 281 | 281 | if ($value === '') { |
| 282 | - unset($params['filters'][$col]['value'][$key]); |
|
| 282 | + unset($params['filters'][$col]['value'][$key]); |
|
| 283 | + } |
|
| 283 | 284 | } |
| 284 | - } |
|
| 285 | 285 | } |
| 286 | 286 | if (!$params['filters'][$col]['value']) { |
| 287 | - continue; |
|
| 287 | + continue; |
|
| 288 | 288 | } |
| 289 | 289 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
| 290 | 290 | break; |
| 291 | - case 'bool': |
|
| 291 | + case 'bool': |
|
| 292 | 292 | |
| 293 | 293 | if (!isset($params['filters'][$col]['value']) || $params['filters'][$col]['value'] === '') { |
| 294 | - continue; |
|
| 294 | + continue; |
|
| 295 | 295 | } |
| 296 | 296 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
| 297 | 297 | break; |
| 298 | - case 'dateTime': |
|
| 298 | + case 'dateTime': |
|
| 299 | 299 | case 'date': |
| 300 | 300 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
| 301 | - continue; |
|
| 301 | + continue; |
|
| 302 | 302 | } |
| 303 | 303 | if (!empty($params['filters'][$col]['min'])) { |
| 304 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 304 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 305 | 305 | } |
| 306 | 306 | if (!empty($params['filters'][$col]['max'])) { |
| 307 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
| 307 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
| 308 | 308 | |
| 309 | 309 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
| 310 | - } else { |
|
| 310 | + } else { |
|
| 311 | 311 | $date = $params['filters'][$col]['max']; |
| 312 | - } |
|
| 313 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
| 312 | + } |
|
| 313 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
| 314 | 314 | } |
| 315 | 315 | break; |
| 316 | - case 'number': |
|
| 316 | + case 'number': |
|
| 317 | 317 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
| 318 | - continue; |
|
| 318 | + continue; |
|
| 319 | 319 | } |
| 320 | 320 | if (!empty($params['filters'][$col]['min'])) { |
| 321 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 321 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 322 | 322 | } |
| 323 | 323 | if (!empty($params['filters'][$col]['max'])) { |
| 324 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
| 324 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
| 325 | 325 | } |
| 326 | 326 | break; |
| 327 | - case 'email': |
|
| 327 | + case 'email': |
|
| 328 | 328 | case 'text': |
| 329 | 329 | case 'textarea': |
| 330 | 330 | case 'html': |
| 331 | 331 | if (empty($params['filters'][$col]['value'])) { |
| 332 | - continue; |
|
| 332 | + continue; |
|
| 333 | 333 | } |
| 334 | 334 | switch ($params['filters'][$col]['compareType']) { |
| 335 | - case 'contains': |
|
| 335 | + case 'contains': |
|
| 336 | 336 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
| 337 | 337 | break; |
| 338 | - case 'equals': |
|
| 338 | + case 'equals': |
|
| 339 | 339 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
| 340 | 340 | break; |
| 341 | - case 'starts_with': |
|
| 341 | + case 'starts_with': |
|
| 342 | 342 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
| 343 | 343 | break; |
| 344 | - case 'ends_with': |
|
| 344 | + case 'ends_with': |
|
| 345 | 345 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
| 346 | 346 | break; |
| 347 | 347 | } |
| 348 | 348 | break; |
| 349 | 349 | } |
| 350 | - } |
|
| 350 | + } |
|
| 351 | 351 | } |
| 352 | 352 | if (!empty($params['mode']) && $params['mode'] == 'sort') { |
| 353 | - $queryParams['order'] = ['weight', 'asc']; |
|
| 353 | + $queryParams['order'] = ['weight', 'asc']; |
|
| 354 | 354 | } elseif (!empty($params['sortered']) && !empty($this->managerOptions['sortable'])) { |
| 355 | - foreach ($params['sortered'] as $key => $sortType) { |
|
| 355 | + foreach ($params['sortered'] as $key => $sortType) { |
|
| 356 | 356 | $keys = array_keys($this->managerOptions['cols']); |
| 357 | 357 | $colName = ''; |
| 358 | 358 | if (isset($keys[$key])) { |
| 359 | - if (is_array($this->managerOptions['cols'][$keys[$key]])) { |
|
| 359 | + if (is_array($this->managerOptions['cols'][$keys[$key]])) { |
|
| 360 | 360 | $colName = $keys[$key]; |
| 361 | - } else { |
|
| 361 | + } else { |
|
| 362 | 362 | $colName = $this->managerOptions['cols'][$keys[$key]]; |
| 363 | - } |
|
| 363 | + } |
|
| 364 | 364 | } |
| 365 | 365 | if ($colName && in_array($colName, $this->managerOptions['sortable'])) { |
| 366 | - $sortType = in_array($sortType, ['desc', 'asc']) ? $sortType : 'desc'; |
|
| 367 | - $queryParams['order'][] = [$colName, $sortType]; |
|
| 366 | + $sortType = in_array($sortType, ['desc', 'asc']) ? $sortType : 'desc'; |
|
| 367 | + $queryParams['order'][] = [$colName, $sortType]; |
|
| 368 | + } |
|
| 368 | 369 | } |
| 369 | - } |
|
| 370 | 370 | } |
| 371 | 371 | if ($model && !empty($params['relation'])) { |
| 372 | - $relation = $model::getRelation($params['relation']); |
|
| 373 | - $items = $model->$params['relation']($queryParams); |
|
| 372 | + $relation = $model::getRelation($params['relation']); |
|
| 373 | + $items = $model->$params['relation']($queryParams); |
|
| 374 | 374 | } else { |
| 375 | - $relation = false; |
|
| 376 | - $items = $modelName::getList($queryParams); |
|
| 375 | + $relation = false; |
|
| 376 | + $items = $modelName::getList($queryParams); |
|
| 377 | 377 | } |
| 378 | 378 | $rows = []; |
| 379 | 379 | foreach ($items as $item) { |
| 380 | - if ($relation && !empty($relation['relModel'])) { |
|
| 380 | + if ($relation && !empty($relation['relModel'])) { |
|
| 381 | 381 | $item = $relation['relModel']::get([[$item->index(), $item->id], [$model->index(), $model->id]]); |
| 382 | - } |
|
| 383 | - $row = []; |
|
| 384 | - $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
| 385 | - $row[] = $item->pk(); |
|
| 386 | - foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
| 382 | + } |
|
| 383 | + $row = []; |
|
| 384 | + $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
| 385 | + $row[] = $item->pk(); |
|
| 386 | + foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
| 387 | 387 | if (!empty($params['download'])) { |
| 388 | - $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
| 388 | + $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
| 389 | 389 | } else { |
| 390 | - $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
| 390 | + $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
| 391 | + } |
|
| 391 | 392 | } |
| 392 | - } |
|
| 393 | - $row[] = $this->rowButtons($item, $params); |
|
| 394 | - $rows[] = $row; |
|
| 393 | + $row[] = $this->rowButtons($item, $params); |
|
| 394 | + $rows[] = $row; |
|
| 395 | 395 | } |
| 396 | 396 | return $rows; |
| 397 | - } |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
| 399 | + public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
| 400 | 400 | $modelName = get_class($item); |
| 401 | 401 | if (!class_exists($modelName)) { |
| 402 | - return false; |
|
| 402 | + return false; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | if (!$originalCol) { |
| 406 | - $originalCol = $colName; |
|
| 406 | + $originalCol = $colName; |
|
| 407 | 407 | } |
| 408 | 408 | if (!$originalItem) { |
| 409 | - $originalItem = $item; |
|
| 409 | + $originalItem = $item; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | $relations = $modelName::relations(); |
| 413 | 413 | if (strpos($colName, ':') !== false && !empty($relations[substr($colName, 0, strpos($colName, ':'))])) { |
| 414 | - $rel = substr($colName, 0, strpos($colName, ':')); |
|
| 415 | - $col = substr($colName, strpos($colName, ':') + 1); |
|
| 416 | - if ($item->$rel) { |
|
| 414 | + $rel = substr($colName, 0, strpos($colName, ':')); |
|
| 415 | + $col = substr($colName, strpos($colName, ':') + 1); |
|
| 416 | + if ($item->$rel) { |
|
| 417 | 417 | return DataManager::drawCol($item->$rel, $col, $params, $dataManager, $originalCol, $originalItem); |
| 418 | - } else { |
|
| 418 | + } else { |
|
| 419 | 419 | return 'Не указано'; |
| 420 | - } |
|
| 420 | + } |
|
| 421 | 421 | } |
| 422 | 422 | if (!empty($modelName::$cols[$colName]['relation'])) { |
| 423 | - $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
| 424 | - switch ($type) { |
|
| 423 | + $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
| 424 | + switch ($type) { |
|
| 425 | 425 | case 'relModel': |
| 426 | 426 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 427 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
| 428 | - $count = $count ? $count : 'Нет'; |
|
| 429 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 427 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
| 428 | + $count = $count ? $count : 'Нет'; |
|
| 429 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 430 | 430 | case 'many': |
| 431 | 431 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 432 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
| 433 | - $count = $count ? $count : 'Нет'; |
|
| 434 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 432 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
| 433 | + $count = $count ? $count : 'Нет'; |
|
| 434 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 435 | 435 | default : |
| 436 | 436 | if ($item->{$modelName::$cols[$colName]['relation']}) { |
| 437 | 437 | if (\App::$cur->name == 'admin') { |
| 438 | - $href = "<a href ='/admin/" . str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model']) . "/" . $item->{$modelName::$cols[$colName]['relation']}->pk() . "'>"; |
|
| 439 | - if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
| 438 | + $href = "<a href ='/admin/" . str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model']) . "/" . $item->{$modelName::$cols[$colName]['relation']}->pk() . "'>"; |
|
| 439 | + if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
| 440 | 440 | $href .= $item->{$modelName::$cols[$colName]['relation']}->{$modelName::$cols[$colName]['showCol']}; |
| 441 | - } else { |
|
| 441 | + } else { |
|
| 442 | 442 | |
| 443 | 443 | $href .= $item->{$modelName::$cols[$colName]['relation']}->name(); |
| 444 | - } |
|
| 445 | - $href .= '</a>'; |
|
| 446 | - return $href; |
|
| 444 | + } |
|
| 445 | + $href .= '</a>'; |
|
| 446 | + return $href; |
|
| 447 | 447 | } else { |
| 448 | - return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
| 448 | + return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
| 449 | 449 | } |
| 450 | - } else { |
|
| 450 | + } else { |
|
| 451 | 451 | return $item->$colName; |
| 452 | - } |
|
| 453 | - } |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | 454 | } else { |
| 455 | - if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
| 455 | + if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
| 456 | 456 | switch ($modelName::$cols[$colName]['view']['type']) { |
| 457 | - case 'widget': |
|
| 457 | + case 'widget': |
|
| 458 | 458 | ob_start(); |
| 459 | 459 | \App::$cur->view->widget($modelName::$cols[$colName]['view']['widget'], ['item' => $item, 'colName' => $colName, 'colParams' => $modelName::$cols[$colName]]); |
| 460 | 460 | $content = ob_get_contents(); |
| 461 | 461 | ob_end_clean(); |
| 462 | 462 | return $content; |
| 463 | - case 'moduleMethod': |
|
| 463 | + case 'moduleMethod': |
|
| 464 | 464 | return \App::$cur->{$modelName::$cols[$colName]['view']['module']}->{$modelName::$cols[$colName]['view']['method']}($item, $colName, $modelName::$cols[$colName]); |
| 465 | - case 'many': |
|
| 465 | + case 'many': |
|
| 466 | 466 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 467 | 467 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
| 468 | 468 | return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count} " . \Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов']) . "</a>"; |
| 469 | - default: |
|
| 469 | + default: |
|
| 470 | 470 | return $item->$colName; |
| 471 | 471 | } |
| 472 | - } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
| 472 | + } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
| 473 | 473 | if (\App::$cur->name == 'admin' && $originalCol == 'name' || ( $dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
| 474 | - $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
| 475 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 476 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($originalItem)) . "/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 474 | + $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
| 475 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 476 | + return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($originalItem)) . "/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 477 | 477 | } elseif (\App::$cur->name == 'admin' && $colName == 'name') { |
| 478 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 479 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 478 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 479 | + return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 480 | 480 | } else { |
| 481 | - return \Model::resloveTypeValue($item, $colName); |
|
| 481 | + return \Model::resloveTypeValue($item, $colName); |
|
| 482 | 482 | } |
| 483 | - } else { |
|
| 483 | + } else { |
|
| 484 | 484 | return $item->$colName; |
| 485 | - } |
|
| 485 | + } |
|
| 486 | + } |
|
| 486 | 487 | } |
| 487 | - } |
|
| 488 | 488 | |
| 489 | - public function rowButtons($item, $params) { |
|
| 489 | + public function rowButtons($item, $params) { |
|
| 490 | 490 | $modelName = $this->modelName; |
| 491 | 491 | if (!class_exists($modelName)) { |
| 492 | - return false; |
|
| 492 | + return false; |
|
| 493 | 493 | } |
| 494 | 494 | ob_start(); |
| 495 | 495 | $widgetName = !empty($this->managerOptions['rowButtonsWidget']) ? $this->managerOptions['rowButtonsWidget'] : 'Ui\DataManager/rowButtons'; |
@@ -501,129 +501,129 @@ discard block |
||
| 501 | 501 | $buttons = ob_get_contents(); |
| 502 | 502 | ob_end_clean(); |
| 503 | 503 | return $buttons; |
| 504 | - } |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - public function getPages($params = [], $model = null) { |
|
| 506 | + public function getPages($params = [], $model = null) { |
|
| 507 | 507 | $modelName = $this->modelName; |
| 508 | 508 | if (!class_exists($modelName)) { |
| 509 | - return []; |
|
| 509 | + return []; |
|
| 510 | 510 | } |
| 511 | 511 | if (!$this->checkAccess()) { |
| 512 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 513 | - return []; |
|
| 512 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 513 | + return []; |
|
| 514 | 514 | } |
| 515 | 515 | if (!empty($params['limit'])) { |
| 516 | - $this->limit = (int) $params['limit']; |
|
| 516 | + $this->limit = (int) $params['limit']; |
|
| 517 | 517 | } |
| 518 | 518 | if (!empty($params['page'])) { |
| 519 | - $this->page = (int) $params['page']; |
|
| 519 | + $this->page = (int) $params['page']; |
|
| 520 | 520 | } |
| 521 | 521 | $queryParams = [ |
| 522 | 522 | 'count' => true |
| 523 | 523 | ]; |
| 524 | 524 | $modelName = $this->modelName; |
| 525 | 525 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
| 526 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 526 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 527 | 527 | } |
| 528 | 528 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
| 529 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
| 529 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
| 530 | 530 | if (!empty($colOptions['userCol'])) { |
| 531 | - if (strpos($colOptions['userCol'], ':')) { |
|
| 531 | + if (strpos($colOptions['userCol'], ':')) { |
|
| 532 | 532 | $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
| 533 | 533 | $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
| 534 | 534 | $queryParams['where'][] = [$colName, \Users\User::$cur->$rel->$param]; |
| 535 | - } |
|
| 535 | + } |
|
| 536 | 536 | } elseif (isset($colOptions['value'])) { |
| 537 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
| 537 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
| 538 | + } |
|
| 538 | 539 | } |
| 539 | - } |
|
| 540 | 540 | } |
| 541 | 541 | $modelName = $this->modelName; |
| 542 | 542 | if (!empty($this->managerOptions['filters'])) { |
| 543 | - foreach ($this->managerOptions['filters'] as $col) { |
|
| 543 | + foreach ($this->managerOptions['filters'] as $col) { |
|
| 544 | 544 | $colInfo = $modelName::getColInfo($col); |
| 545 | 545 | switch ($colInfo['colParams']['type']) { |
| 546 | - case 'select': |
|
| 546 | + case 'select': |
|
| 547 | 547 | if (empty($params['filters'][$col]['value'])) { |
| 548 | - continue; |
|
| 548 | + continue; |
|
| 549 | 549 | } |
| 550 | 550 | if (is_array($params['filters'][$col]['value'])) { |
| 551 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
| 551 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
| 552 | 552 | if ($value === '') { |
| 553 | - unset($params['filters'][$col]['value'][$key]); |
|
| 553 | + unset($params['filters'][$col]['value'][$key]); |
|
| 554 | + } |
|
| 554 | 555 | } |
| 555 | - } |
|
| 556 | 556 | } |
| 557 | 557 | if (!$params['filters'][$col]['value']) { |
| 558 | - continue; |
|
| 558 | + continue; |
|
| 559 | 559 | } |
| 560 | 560 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
| 561 | 561 | break; |
| 562 | - case 'bool': |
|
| 562 | + case 'bool': |
|
| 563 | 563 | |
| 564 | 564 | if (empty($params['filters'][$col]['value'])) { |
| 565 | - continue; |
|
| 565 | + continue; |
|
| 566 | 566 | } |
| 567 | 567 | $queryParams['where'][] = [$col, '1']; |
| 568 | 568 | break; |
| 569 | - case 'dateTime': |
|
| 569 | + case 'dateTime': |
|
| 570 | 570 | case 'date': |
| 571 | 571 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
| 572 | - continue; |
|
| 572 | + continue; |
|
| 573 | 573 | } |
| 574 | 574 | if (!empty($params['filters'][$col]['min'])) { |
| 575 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 575 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 576 | 576 | } |
| 577 | 577 | if (!empty($params['filters'][$col]['max'])) { |
| 578 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
| 578 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
| 579 | 579 | |
| 580 | 580 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
| 581 | - } else { |
|
| 581 | + } else { |
|
| 582 | 582 | $date = $params['filters'][$col]['max']; |
| 583 | - } |
|
| 584 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
| 583 | + } |
|
| 584 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
| 585 | 585 | } |
| 586 | 586 | break; |
| 587 | - case 'number': |
|
| 587 | + case 'number': |
|
| 588 | 588 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
| 589 | - continue; |
|
| 589 | + continue; |
|
| 590 | 590 | } |
| 591 | 591 | if (!empty($params['filters'][$col]['min'])) { |
| 592 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 592 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 593 | 593 | } |
| 594 | 594 | if (!empty($params['filters'][$col]['max'])) { |
| 595 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
| 595 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
| 596 | 596 | } |
| 597 | 597 | break; |
| 598 | - case 'email': |
|
| 598 | + case 'email': |
|
| 599 | 599 | case 'text': |
| 600 | 600 | case 'textarea': |
| 601 | 601 | case 'html': |
| 602 | 602 | if (empty($params['filters'][$col]['value'])) { |
| 603 | - continue; |
|
| 603 | + continue; |
|
| 604 | 604 | } |
| 605 | 605 | switch ($params['filters'][$col]['compareType']) { |
| 606 | - case 'contains': |
|
| 606 | + case 'contains': |
|
| 607 | 607 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
| 608 | 608 | break; |
| 609 | - case 'equals': |
|
| 609 | + case 'equals': |
|
| 610 | 610 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
| 611 | 611 | break; |
| 612 | - case 'starts_with': |
|
| 612 | + case 'starts_with': |
|
| 613 | 613 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
| 614 | 614 | break; |
| 615 | - case 'ends_with': |
|
| 615 | + case 'ends_with': |
|
| 616 | 616 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
| 617 | 617 | break; |
| 618 | 618 | } |
| 619 | 619 | break; |
| 620 | 620 | } |
| 621 | - } |
|
| 621 | + } |
|
| 622 | 622 | } |
| 623 | 623 | if ($model && !empty($params['relation'])) { |
| 624 | - $count = $model->$params['relation']($queryParams); |
|
| 624 | + $count = $model->$params['relation']($queryParams); |
|
| 625 | 625 | } else { |
| 626 | - $count = $modelName::getCount($queryParams); |
|
| 626 | + $count = $modelName::getCount($queryParams); |
|
| 627 | 627 | } |
| 628 | 628 | $pages = new Pages([ |
| 629 | 629 | 'limit' => $this->limit, |
@@ -633,9 +633,9 @@ discard block |
||
| 633 | 633 | 'dataManager' => $this |
| 634 | 634 | ]); |
| 635 | 635 | return $pages; |
| 636 | - } |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | - public function preDraw($params = [], $model = null) { |
|
| 638 | + public function preDraw($params = [], $model = null) { |
|
| 639 | 639 | $this->predraw = true; |
| 640 | 640 | |
| 641 | 641 | $cols = $this->getCols(); |
@@ -643,16 +643,16 @@ discard block |
||
| 643 | 643 | $this->table = new Table(); |
| 644 | 644 | $tableCols = []; |
| 645 | 645 | foreach ($cols as $colName => $colOptions) { |
| 646 | - $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
|
| 646 | + $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
|
| 647 | 647 | } |
| 648 | 648 | $tableCols[] = ''; |
| 649 | 649 | $this->table->class .=' datamanagertable'; |
| 650 | 650 | $this->table->setCols($tableCols); |
| 651 | - } |
|
| 651 | + } |
|
| 652 | 652 | |
| 653 | - public function draw($params = [], $model = null) { |
|
| 653 | + public function draw($params = [], $model = null) { |
|
| 654 | 654 | if (!$this->predraw) { |
| 655 | - $this->preDraw($params, $model); |
|
| 655 | + $this->preDraw($params, $model); |
|
| 656 | 656 | } |
| 657 | 657 | \App::$cur->view->widget('Ui\DataManager/DataManager', [ |
| 658 | 658 | 'dataManager' => $this, |
@@ -660,58 +660,58 @@ discard block |
||
| 660 | 660 | 'table' => $this->table, |
| 661 | 661 | 'params' => $params |
| 662 | 662 | ]); |
| 663 | - } |
|
| 663 | + } |
|
| 664 | 664 | |
| 665 | - public function drawCategorys() { |
|
| 665 | + public function drawCategorys() { |
|
| 666 | 666 | if (!class_exists($this->modelName)) { |
| 667 | - return false; |
|
| 667 | + return false; |
|
| 668 | 668 | } |
| 669 | 669 | if (!$this->checkAccess()) { |
| 670 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 671 | - return []; |
|
| 670 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 671 | + return []; |
|
| 672 | 672 | } |
| 673 | 673 | $tree = new Tree(); |
| 674 | 674 | $tree->ul($this->managerOptions['categorys']['model'], 0, function($category) { |
| 675 | - $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
| 676 | - $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
| 677 | - return "<a href='#' onclick='inji.Ui.dataManagers.get(this).switchCategory(this);return false;' data-index='{$category->index()}' data-path ='{$path}' data-id='{$category->pk()}' data-model='{$this->managerOptions['categorys']['model']}'> {$category->name}</a> |
|
| 675 | + $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
| 676 | + $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
| 677 | + return "<a href='#' onclick='inji.Ui.dataManagers.get(this).switchCategory(this);return false;' data-index='{$category->index()}' data-path ='{$path}' data-id='{$category->pk()}' data-model='{$this->managerOptions['categorys']['model']}'> {$category->name}</a> |
|
| 678 | 678 | |
| 679 | 679 | <a href = '#' class ='glyphicon glyphicon-edit' onclick = 'inji.Ui.forms.popUp(\"{$cleanClassName}:{$category->pk()}\")'></a> |
| 680 | 680 | <a href = '#' class ='glyphicon glyphicon-remove' onclick = 'inji.Ui.dataManagers.get(this).delCategory({$category->pk()});return false;'></a>"; |
| 681 | 681 | }); |
| 682 | 682 | ?> |
| 683 | 683 | <?php |
| 684 | - } |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * Draw error message |
|
| 688 | - * |
|
| 689 | - * @param string $errorText |
|
| 690 | - */ |
|
| 691 | - public function drawError($errorText) { |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * Draw error message |
|
| 688 | + * |
|
| 689 | + * @param string $errorText |
|
| 690 | + */ |
|
| 691 | + public function drawError($errorText) { |
|
| 692 | 692 | echo $errorText; |
| 693 | - } |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Check access cur user to manager with name in param |
|
| 697 | - * |
|
| 698 | - * @return boolean |
|
| 699 | - */ |
|
| 700 | - public function checkAccess() { |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Check access cur user to manager with name in param |
|
| 697 | + * |
|
| 698 | + * @return boolean |
|
| 699 | + */ |
|
| 700 | + public function checkAccess() { |
|
| 701 | 701 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
| 702 | - return false; |
|
| 702 | + return false; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | if (!empty($this->managerOptions['options']['access']['apps']) && !in_array(\App::$cur->name, $this->managerOptions['options']['access']['apps'])) { |
| 706 | - return false; |
|
| 706 | + return false; |
|
| 707 | 707 | } |
| 708 | 708 | if (!empty($this->managerOptions['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->managerOptions['options']['access']['groups'])) { |
| 709 | - return true; |
|
| 709 | + return true; |
|
| 710 | 710 | } |
| 711 | 711 | if ($this->managerName == 'manager' && !\Users\User::$cur->isAdmin()) { |
| 712 | - return false; |
|
| 712 | + return false; |
|
| 713 | 713 | } |
| 714 | 714 | return true; |
| 715 | - } |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | 717 | } |
@@ -13,118 +13,118 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class ActiveForm extends \Object { |
| 15 | 15 | |
| 16 | - public $model = null; |
|
| 17 | - public $modelName = ''; |
|
| 18 | - public $header = ""; |
|
| 19 | - public $action = ""; |
|
| 20 | - public $form = []; |
|
| 21 | - public $inputs = []; |
|
| 22 | - public $formName = 'noNameForm'; |
|
| 23 | - public $requestFormName = ''; |
|
| 24 | - public $requestFullFormName = ''; |
|
| 25 | - public $parent = null; |
|
| 16 | + public $model = null; |
|
| 17 | + public $modelName = ''; |
|
| 18 | + public $header = ""; |
|
| 19 | + public $action = ""; |
|
| 20 | + public $form = []; |
|
| 21 | + public $inputs = []; |
|
| 22 | + public $formName = 'noNameForm'; |
|
| 23 | + public $requestFormName = ''; |
|
| 24 | + public $requestFullFormName = ''; |
|
| 25 | + public $parent = null; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - * @param array|\Model $model |
|
| 30 | - * @param array|string $form |
|
| 31 | - */ |
|
| 32 | - public function __construct($model, $form = '') { |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + * @param array|\Model $model |
|
| 30 | + * @param array|string $form |
|
| 31 | + */ |
|
| 32 | + public function __construct($model, $form = '') { |
|
| 33 | 33 | if (is_array($model)) { |
| 34 | - $this->form = $model; |
|
| 35 | - if (is_string($form)) { |
|
| 34 | + $this->form = $model; |
|
| 35 | + if (is_string($form)) { |
|
| 36 | 36 | $this->formName = $form; |
| 37 | - } |
|
| 37 | + } |
|
| 38 | 38 | } else { |
| 39 | - $this->model = $model; |
|
| 40 | - $this->modelName = get_class($model); |
|
| 41 | - if (is_array($form)) { |
|
| 39 | + $this->model = $model; |
|
| 40 | + $this->modelName = get_class($model); |
|
| 41 | + if (is_array($form)) { |
|
| 42 | 42 | if (empty($form)) { |
| 43 | - throw new \Exception('empty form'); |
|
| 43 | + throw new \Exception('empty form'); |
|
| 44 | 44 | } |
| 45 | 45 | $this->form = $form; |
| 46 | - } else { |
|
| 46 | + } else { |
|
| 47 | 47 | $this->formName = $form; |
| 48 | 48 | $this->form = \App::$cur->ui->getModelForm($this->modelName, $form); |
| 49 | 49 | if (empty($this->form)) { |
| 50 | - throw new \Exception('empty form ' . $form); |
|
| 50 | + throw new \Exception('empty form ' . $form); |
|
| 51 | 51 | } |
| 52 | 52 | $this->inputs = $this->getInputs(); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | } |
| 55 | 55 | $this->requestFormName = "ActiveForm_{$this->formName}"; |
| 56 | 56 | $modeName = $this->modelName; |
| 57 | 57 | |
| 58 | 58 | if (!empty($this->form['name'])) { |
| 59 | - $this->header = $this->form['name']; |
|
| 59 | + $this->header = $this->form['name']; |
|
| 60 | 60 | } elseif (!empty($modeName::$objectName)) { |
| 61 | - $this->header = $modeName::$objectName; |
|
| 61 | + $this->header = $modeName::$objectName; |
|
| 62 | 62 | } else { |
| 63 | - $this->header = $this->modelName; |
|
| 63 | + $this->header = $this->modelName; |
|
| 64 | + } |
|
| 64 | 65 | } |
| 65 | - } |
|
| 66 | 66 | |
| 67 | - public function getInputs() { |
|
| 67 | + public function getInputs() { |
|
| 68 | 68 | $inputs = !empty($this->form['inputs']) ? $this->form['inputs'] : []; |
| 69 | 69 | $modelName = $this->modelName; |
| 70 | 70 | foreach ($this->form['map'] as $row) { |
| 71 | - foreach ($row as $col) { |
|
| 71 | + foreach ($row as $col) { |
|
| 72 | 72 | if (!$col || !empty($inputs[$col])) { |
| 73 | - continue; |
|
| 73 | + continue; |
|
| 74 | 74 | } |
| 75 | 75 | if (strpos($col, 'form:') === 0) { |
| 76 | - $colPath = explode(':', $col); |
|
| 77 | - if ($this->model->{$colPath[1]}) { |
|
| 76 | + $colPath = explode(':', $col); |
|
| 77 | + if ($this->model->{$colPath[1]}) { |
|
| 78 | 78 | $inputs[$col] = new ActiveForm($this->model->{$colPath[1]}, $colPath[2]); |
| 79 | - } else { |
|
| 79 | + } else { |
|
| 80 | 80 | $relOptions = $modelName::getRelation($colPath[1]); |
| 81 | 81 | if (!isset($this->model->_params[$modelName::index()])) { |
| 82 | - $this->model->_params[$modelName::index()] = 0; |
|
| 82 | + $this->model->_params[$modelName::index()] = 0; |
|
| 83 | 83 | } |
| 84 | 84 | $relOptions['model']::fixPrefix($relOptions['col']); |
| 85 | 85 | $inputs[$col] = new ActiveForm(new $relOptions['model']([ $relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]); |
| 86 | - } |
|
| 87 | - $inputs[$col]->parent = $this; |
|
| 86 | + } |
|
| 87 | + $inputs[$col]->parent = $this; |
|
| 88 | 88 | } elseif (!empty($modelName::$cols[$col])) { |
| 89 | - $inputs[$col] = $modelName::$cols[$col]; |
|
| 89 | + $inputs[$col] = $modelName::$cols[$col]; |
|
| 90 | + } |
|
| 90 | 91 | } |
| 91 | - } |
|
| 92 | 92 | } |
| 93 | 93 | return $inputs; |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function checkRequest($params = [], $ajax = false) { |
|
| 96 | + public function checkRequest($params = [], $ajax = false) { |
|
| 97 | 97 | if (!$this->checkAccess()) { |
| 98 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
| 99 | - return []; |
|
| 98 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
| 99 | + return []; |
|
| 100 | 100 | } |
| 101 | 101 | $successId = 0; |
| 102 | 102 | if (!empty($_POST[$this->requestFormName][$this->modelName])) { |
| 103 | - $request = $_POST[$this->requestFormName][$this->modelName]; |
|
| 104 | - if ($this->model) { |
|
| 103 | + $request = $_POST[$this->requestFormName][$this->modelName]; |
|
| 104 | + if ($this->model) { |
|
| 105 | 105 | if ($this->form['handler']) { |
| 106 | - $modelName = $this->model; |
|
| 107 | - $modelName::{$this->form['handler']}($request); |
|
| 108 | - $text = 'Новый элемент был успешно добавлен'; |
|
| 109 | - \Msg::add($text, 'success'); |
|
| 110 | - \Msg::show(); |
|
| 106 | + $modelName = $this->model; |
|
| 107 | + $modelName::{$this->form['handler']}($request); |
|
| 108 | + $text = 'Новый элемент был успешно добавлен'; |
|
| 109 | + \Msg::add($text, 'success'); |
|
| 110 | + \Msg::show(); |
|
| 111 | 111 | } else { |
| 112 | - $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
|
| 113 | - if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
|
| 112 | + $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
|
| 113 | + if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
|
| 114 | 114 | $presets = array_merge($presets, $this->form['userGroupPreset'][\Users\User::$cur->group_id]); |
| 115 | - } |
|
| 116 | - $afterSave = []; |
|
| 117 | - $error = false; |
|
| 118 | - foreach ($this->inputs as $col => $param) { |
|
| 115 | + } |
|
| 116 | + $afterSave = []; |
|
| 117 | + $error = false; |
|
| 118 | + foreach ($this->inputs as $col => $param) { |
|
| 119 | 119 | if (!empty($presets[$col])) { |
| 120 | - continue; |
|
| 120 | + continue; |
|
| 121 | 121 | } |
| 122 | 122 | if (is_object($param)) { |
| 123 | - $afterSave[] = $param; |
|
| 124 | - continue; |
|
| 123 | + $afterSave[] = $param; |
|
| 124 | + continue; |
|
| 125 | 125 | } |
| 126 | 126 | if (!empty($this->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($col, $this->form['userGroupReadonly'][\Users\User::$cur->group_id])) { |
| 127 | - continue; |
|
| 127 | + continue; |
|
| 128 | 128 | } |
| 129 | 129 | $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($param['type']); |
| 130 | 130 | $input = new $inputClassName(); |
@@ -134,186 +134,186 @@ discard block |
||
| 134 | 134 | $input->colName = $col; |
| 135 | 135 | $input->colParams = $param; |
| 136 | 136 | try { |
| 137 | - $input->validate($request); |
|
| 138 | - $input->parseRequest($request); |
|
| 137 | + $input->validate($request); |
|
| 138 | + $input->parseRequest($request); |
|
| 139 | 139 | } catch (\Exception $exc) { |
| 140 | - \Msg::add($exc->getMessage(), 'danger'); |
|
| 141 | - $error = true; |
|
| 140 | + \Msg::add($exc->getMessage(), 'danger'); |
|
| 141 | + $error = true; |
|
| 142 | + } |
|
| 142 | 143 | } |
| 143 | - } |
|
| 144 | - if (!$error && empty($_GET['notSave'])) { |
|
| 144 | + if (!$error && empty($_GET['notSave'])) { |
|
| 145 | 145 | foreach ($presets as $col => $preset) { |
| 146 | - if (!empty($preset['value'])) { |
|
| 146 | + if (!empty($preset['value'])) { |
|
| 147 | 147 | $this->model->$col = $preset['value']; |
| 148 | - } elseif (!empty($preset['userCol'])) { |
|
| 148 | + } elseif (!empty($preset['userCol'])) { |
|
| 149 | 149 | if (strpos($preset['userCol'], ':')) { |
| 150 | - $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
| 151 | - $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
| 152 | - $this->model->$col = \Users\User::$cur->$rel->$param; |
|
| 150 | + $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
| 151 | + $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
| 152 | + $this->model->$col = \Users\User::$cur->$rel->$param; |
|
| 153 | 153 | } else { |
| 154 | - $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
| 154 | + $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
| 155 | + } |
|
| 155 | 156 | } |
| 156 | - } |
|
| 157 | 157 | } |
| 158 | 158 | if (!$this->parent) { |
| 159 | - if (!empty($this->form['successText'])) { |
|
| 159 | + if (!empty($this->form['successText'])) { |
|
| 160 | 160 | $text = $this->form['successText']; |
| 161 | - } else { |
|
| 161 | + } else { |
|
| 162 | 162 | $text = $this->model->pk() ? 'Изменения были успешно сохранены' : 'Новый элемент был успешно добавлен'; |
| 163 | - } |
|
| 164 | - \Msg::add($text, 'success'); |
|
| 163 | + } |
|
| 164 | + \Msg::add($text, 'success'); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $this->model->save(!empty($params['dataManagerParams']) ? $params['dataManagerParams'] : []); |
| 168 | 168 | foreach ($afterSave as $form) { |
| 169 | - $form->checkRequest(); |
|
| 169 | + $form->checkRequest(); |
|
| 170 | 170 | } |
| 171 | 171 | if ($ajax) { |
| 172 | - \Msg::show(); |
|
| 172 | + \Msg::show(); |
|
| 173 | 173 | } elseif (!empty($_GET['redirectUrl'])) { |
| 174 | - \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
| 174 | + \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
| 175 | 175 | } |
| 176 | 176 | $successId = $this->model->pk(); |
| 177 | - } |
|
| 177 | + } |
|
| 178 | + } |
|
| 178 | 179 | } |
| 179 | - } |
|
| 180 | - if (!is_array($params) && is_callable($params)) { |
|
| 180 | + if (!is_array($params) && is_callable($params)) { |
|
| 181 | 181 | $params($request); |
| 182 | - } |
|
| 182 | + } |
|
| 183 | 183 | } |
| 184 | 184 | return $successId; |
| 185 | - } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - public function draw($params = [], $ajax = false) { |
|
| 187 | + public function draw($params = [], $ajax = false) { |
|
| 188 | 188 | if (!$this->checkAccess()) { |
| 189 | - $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
| 190 | - return []; |
|
| 189 | + $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
| 190 | + return []; |
|
| 191 | 191 | } |
| 192 | 192 | $form = new Form(!empty($this->form['formOptions']) ? $this->form['formOptions'] : []); |
| 193 | 193 | \App::$cur->view->widget('Ui\ActiveForm', ['form' => $form, 'activeForm' => $this, 'ajax' => $ajax, 'params' => $params]); |
| 194 | - } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - public function drawCol($colName, $options, $form, $params = []) { |
|
| 196 | + public function drawCol($colName, $options, $form, $params = []) { |
|
| 197 | 197 | if (is_object($options)) { |
| 198 | - $options->draw(); |
|
| 198 | + $options->draw(); |
|
| 199 | 199 | } else { |
| 200 | - $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
| 201 | - $input = new $inputClassName(); |
|
| 202 | - $input->form = $form; |
|
| 203 | - $input->activeForm = $this; |
|
| 204 | - $input->activeFormParams = $params; |
|
| 205 | - $input->modelName = $this->modelName; |
|
| 206 | - $input->colName = $colName; |
|
| 207 | - $input->colParams = $options; |
|
| 208 | - $input->options = !empty($options['options']) ? $options['options'] : []; |
|
| 209 | - $input->draw(); |
|
| 200 | + $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
| 201 | + $input = new $inputClassName(); |
|
| 202 | + $input->form = $form; |
|
| 203 | + $input->activeForm = $this; |
|
| 204 | + $input->activeFormParams = $params; |
|
| 205 | + $input->modelName = $this->modelName; |
|
| 206 | + $input->colName = $colName; |
|
| 207 | + $input->colParams = $options; |
|
| 208 | + $input->options = !empty($options['options']) ? $options['options'] : []; |
|
| 209 | + $input->draw(); |
|
| 210 | 210 | } |
| 211 | 211 | return true; |
| 212 | - } |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) { |
|
| 214 | + public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) { |
|
| 215 | 215 | $values = []; |
| 216 | 216 | switch ($inputParams['source']) { |
| 217 | - case 'model': |
|
| 217 | + case 'model': |
|
| 218 | 218 | $values = $inputParams['model']::getList(['forSelect' => true]); |
| 219 | 219 | break; |
| 220 | - case 'array': |
|
| 220 | + case 'array': |
|
| 221 | 221 | $values = $inputParams['sourceArray']; |
| 222 | 222 | break; |
| 223 | - case 'method': |
|
| 223 | + case 'method': |
|
| 224 | 224 | if (!empty($inputParams['params'])) { |
| 225 | - $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']); |
|
| 225 | + $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']); |
|
| 226 | 226 | } else { |
| 227 | - $values = \App::$cur->$inputParams['module']->$inputParams['method'](); |
|
| 227 | + $values = \App::$cur->$inputParams['module']->$inputParams['method'](); |
|
| 228 | 228 | } |
| 229 | 229 | break; |
| 230 | - case 'relation': |
|
| 230 | + case 'relation': |
|
| 231 | 231 | if (!$modelName) { |
| 232 | - return []; |
|
| 232 | + return []; |
|
| 233 | 233 | } |
| 234 | 234 | $relation = $modelName::getRelation($inputParams['relation']); |
| 235 | 235 | if (!empty($params['dataManagerParams']['appType'])) { |
| 236 | - $options['appType'] = $params['dataManagerParams']['appType']; |
|
| 236 | + $options['appType'] = $params['dataManagerParams']['appType']; |
|
| 237 | 237 | } |
| 238 | 238 | $items = []; |
| 239 | 239 | if (class_exists($relation['model'])) { |
| 240 | - $filters = $relation['model']::managerFilters(); |
|
| 241 | - if (!empty($filters['getRows']['where'])) { |
|
| 240 | + $filters = $relation['model']::managerFilters(); |
|
| 241 | + if (!empty($filters['getRows']['where'])) { |
|
| 242 | 242 | $options['where'][] = $filters['getRows']['where']; |
| 243 | - } |
|
| 244 | - if (!empty($relation['order'])) { |
|
| 243 | + } |
|
| 244 | + if (!empty($relation['order'])) { |
|
| 245 | 245 | $options['order'] = $relation['order']; |
| 246 | - } |
|
| 247 | - if (!empty($inputParams['itemName'])) { |
|
| 246 | + } |
|
| 247 | + if (!empty($inputParams['itemName'])) { |
|
| 248 | 248 | $options['itemName'] = $inputParams['itemName']; |
| 249 | - } |
|
| 250 | - $items = $relation['model']::getList($options); |
|
| 249 | + } |
|
| 250 | + $items = $relation['model']::getList($options); |
|
| 251 | 251 | } |
| 252 | 252 | if (!empty($params['noEmptyValue'])) { |
| 253 | - $values = []; |
|
| 253 | + $values = []; |
|
| 254 | 254 | } else { |
| 255 | - $values = [0 => 'Не задано']; |
|
| 255 | + $values = [0 => 'Не задано']; |
|
| 256 | 256 | } |
| 257 | 257 | foreach ($items as $key => $item) { |
| 258 | - if (!empty($inputParams['showCol'])) { |
|
| 258 | + if (!empty($inputParams['showCol'])) { |
|
| 259 | 259 | if (is_array($inputParams['showCol'])) { |
| 260 | - switch ($inputParams['showCol']['type']) { |
|
| 260 | + switch ($inputParams['showCol']['type']) { |
|
| 261 | 261 | case 'staticMethod': |
| 262 | 262 | $values[$key] = $inputParams['showCol']['class']::{$inputParams['showCol']['method']}($item); |
| 263 | - break; |
|
| 264 | - } |
|
| 263 | + break; |
|
| 264 | + } |
|
| 265 | 265 | } else { |
| 266 | - $values[$key] = $item->$inputParams['showCol']; |
|
| 266 | + $values[$key] = $item->$inputParams['showCol']; |
|
| 267 | 267 | } |
| 268 | - } else { |
|
| 268 | + } else { |
|
| 269 | 269 | $values[$key] = $item->name(); |
| 270 | - } |
|
| 270 | + } |
|
| 271 | 271 | } |
| 272 | 272 | break; |
| 273 | 273 | } |
| 274 | 274 | foreach ($values as $key => $value) { |
| 275 | - if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
| 275 | + if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
| 276 | 276 | $values[$key]['input']['name'] = $aditionalInputNamePrefix . "[{$value['input']['name']}]"; |
| 277 | - } |
|
| 277 | + } |
|
| 278 | 278 | } |
| 279 | 279 | return $values; |
| 280 | - } |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Draw error message |
|
| 284 | - * |
|
| 285 | - * @param string $errorText |
|
| 286 | - */ |
|
| 287 | - public function drawError($errorText) { |
|
| 282 | + /** |
|
| 283 | + * Draw error message |
|
| 284 | + * |
|
| 285 | + * @param string $errorText |
|
| 286 | + */ |
|
| 287 | + public function drawError($errorText) { |
|
| 288 | 288 | echo $errorText; |
| 289 | - } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Check access cur user to form with name in param and $model |
|
| 293 | - * |
|
| 294 | - * @return boolean |
|
| 295 | - */ |
|
| 296 | - public function checkAccess() { |
|
| 291 | + /** |
|
| 292 | + * Check access cur user to form with name in param and $model |
|
| 293 | + * |
|
| 294 | + * @return boolean |
|
| 295 | + */ |
|
| 296 | + public function checkAccess() { |
|
| 297 | 297 | if (empty($this->form)) { |
| 298 | - $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
| 299 | - return false; |
|
| 298 | + $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
| 299 | + return false; |
|
| 300 | 300 | } |
| 301 | 301 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
| 302 | - return false; |
|
| 302 | + return false; |
|
| 303 | 303 | } |
| 304 | 304 | if (!empty($this->form['options']['access']['apps']) && !in_array(\App::$cur->name, $this->form['options']['access']['apps'])) { |
| 305 | - return false; |
|
| 305 | + return false; |
|
| 306 | 306 | } |
| 307 | 307 | if (!empty($this->form['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->form['options']['access']['groups'])) { |
| 308 | - return true; |
|
| 308 | + return true; |
|
| 309 | 309 | } |
| 310 | 310 | if ($this->model && !empty($this->form['options']['access']['self']) && \Users\User::$cur->id == $this->model->user_id) { |
| 311 | - return true; |
|
| 311 | + return true; |
|
| 312 | 312 | } |
| 313 | 313 | if ($this->formName == 'manager' && !\Users\User::$cur->isAdmin()) { |
| 314 | - return false; |
|
| 314 | + return false; |
|
| 315 | 315 | } |
| 316 | 316 | return true; |
| 317 | - } |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | 319 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Select extends \Ui\ActiveForm\Input { |
| 15 | 15 | |
| 16 | - public function draw() { |
|
| 16 | + public function draw() { |
|
| 17 | 17 | $inputName = $this->colName(); |
| 18 | 18 | $inputLabel = $this->colLabel(); |
| 19 | 19 | $inputParams = $this->colParams; |
@@ -25,41 +25,41 @@ discard block |
||
| 25 | 25 | ]; |
| 26 | 26 | $modelName = ''; |
| 27 | 27 | switch ($inputParams['source']) { |
| 28 | - case 'model': |
|
| 28 | + case 'model': |
|
| 29 | 29 | $modelName = $inputParams['model']; |
| 30 | 30 | break; |
| 31 | - case 'relation': |
|
| 31 | + case 'relation': |
|
| 32 | 32 | if ($this->activeForm->modelName) { |
| 33 | - $itemModelName = $this->activeForm->modelName; |
|
| 34 | - $relation = $itemModelName::getRelation($inputParams['relation']); |
|
| 35 | - if ($relation['model'] && class_exists($relation['model'])) { |
|
| 33 | + $itemModelName = $this->activeForm->modelName; |
|
| 34 | + $relation = $itemModelName::getRelation($inputParams['relation']); |
|
| 35 | + if ($relation['model'] && class_exists($relation['model'])) { |
|
| 36 | 36 | $modelName = $relation['model']; |
| 37 | - } |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | if (!empty($modelName)) { |
| 41 | - $inputOptions['createBtn'] = [ |
|
| 42 | - 'text' => 'Создать', |
|
| 43 | - 'onclick' => 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
|
| 44 | - . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this));return false;' |
|
| 45 | - ]; |
|
| 41 | + $inputOptions['createBtn'] = [ |
|
| 42 | + 'text' => 'Создать', |
|
| 43 | + 'onclick' => 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
|
| 44 | + . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this));return false;' |
|
| 45 | + ]; |
|
| 46 | 46 | } |
| 47 | 47 | if (!empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]) && |
| 48 | 48 | is_array($inputOptions['values'][$this->activeForm->model->{$this->colName}]) && |
| 49 | 49 | !empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]['input'])) { |
| 50 | - $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name']; |
|
| 51 | - $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol; |
|
| 50 | + $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name']; |
|
| 51 | + $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $preset = $this->preset(); |
| 55 | 55 | |
| 56 | 56 | if ($preset !== null) { |
| 57 | - $inputOptions['disabled'] = true; |
|
| 58 | - $this->form->input('hidden', $inputName, '', $inputOptions); |
|
| 59 | - return true; |
|
| 57 | + $inputOptions['disabled'] = true; |
|
| 58 | + $this->form->input('hidden', $inputName, '', $inputOptions); |
|
| 59 | + return true; |
|
| 60 | 60 | } |
| 61 | 61 | $this->form->input('select', $inputName, $inputLabel, $inputOptions); |
| 62 | 62 | return true; |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class DynamicList extends \Ui\ActiveForm\Input { |
| 15 | 15 | |
| 16 | - public function draw() { |
|
| 16 | + public function draw() { |
|
| 17 | 17 | $inputName = $this->colName(); |
| 18 | 18 | $inputLabel = $this->colLabel(); |
| 19 | 19 | $inputOptions = [ |
@@ -25,84 +25,84 @@ discard block |
||
| 25 | 25 | ]; |
| 26 | 26 | $this->form->input('dynamicList', $inputName, $inputLabel, $inputOptions); |
| 27 | 27 | return true; |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function parseRequest($request) { |
|
| 30 | + public function parseRequest($request) { |
|
| 31 | 31 | $modelName = $this->modelName; |
| 32 | 32 | switch ($this->colParams['source']) { |
| 33 | - case'options': |
|
| 33 | + case'options': |
|
| 34 | 34 | |
| 35 | 35 | break; |
| 36 | - default: |
|
| 36 | + default: |
|
| 37 | 37 | $rels = []; |
| 38 | 38 | $relation = $modelName::getRelation($this->colParams['relation']); |
| 39 | 39 | if (!empty($request[$this->colName]) && $this->activeForm->model->pk()) { |
| 40 | - switch ($relation['type']) { |
|
| 40 | + switch ($relation['type']) { |
|
| 41 | 41 | case 'relModel': |
| 42 | 42 | foreach ($request[$this->colName] as $row) { |
| 43 | 43 | $rels[$row['relItem']] = true; |
| 44 | - } |
|
| 45 | - $relModels = $relation['relModel']::getList(['where' => [$modelName::index(), $this->activeForm->model->pk()], 'key' => $relation['model']::index()]); |
|
| 46 | - foreach ($relModels as $model) { |
|
| 44 | + } |
|
| 45 | + $relModels = $relation['relModel']::getList(['where' => [$modelName::index(), $this->activeForm->model->pk()], 'key' => $relation['model']::index()]); |
|
| 46 | + foreach ($relModels as $model) { |
|
| 47 | 47 | if (empty($rels[$model->{$relation['model']::index()}])) { |
| 48 | - $model->delete(); |
|
| 48 | + $model->delete(); |
|
| 49 | 49 | } else { |
| 50 | - unset($rels[$model->{$relation['model']::index()}]); |
|
| 50 | + unset($rels[$model->{$relation['model']::index()}]); |
|
| 51 | 51 | } |
| 52 | - } |
|
| 53 | - foreach ($rels as $relId => $trash) { |
|
| 52 | + } |
|
| 53 | + foreach ($rels as $relId => $trash) { |
|
| 54 | 54 | $model = new $relation['relModel']([ |
| 55 | 55 | $modelName::index() => $this->activeForm->model->pk(), |
| 56 | 56 | $relation['model']::index() => $relId |
| 57 | 57 | ]); |
| 58 | 58 | $model->save(); |
| 59 | - } |
|
| 60 | - break; |
|
| 61 | - } |
|
| 59 | + } |
|
| 60 | + break; |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | - } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function value() { |
|
| 66 | + public function value() { |
|
| 67 | 67 | $values = []; |
| 68 | 68 | switch ($this->colParams['source']) { |
| 69 | - case'options': |
|
| 69 | + case'options': |
|
| 70 | 70 | |
| 71 | 71 | break; |
| 72 | - default: |
|
| 72 | + default: |
|
| 73 | 73 | if ($this->activeForm->model) { |
| 74 | - $items = $this->activeForm->model->{$this->colParams['relation']}(['array' => true]); |
|
| 75 | - foreach ($items as $key => $item) { |
|
| 74 | + $items = $this->activeForm->model->{$this->colParams['relation']}(['array' => true]); |
|
| 75 | + foreach ($items as $key => $item) { |
|
| 76 | 76 | $values[] = ['relItem' => $key]; |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | return $values; |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function getCols() { |
|
| 84 | + public function getCols() { |
|
| 85 | 85 | $modelName = $this->modelName; |
| 86 | 86 | switch ($this->colParams['source']) { |
| 87 | - case'options': |
|
| 87 | + case'options': |
|
| 88 | 88 | foreach ($this->colParams['options']['inputs'] as $colName => $col) { |
| 89 | - $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($col['type']); |
|
| 90 | - $input = new $inputClassName(); |
|
| 91 | - $input->form = $this->form; |
|
| 92 | - $input->activeForm = $this->activeForm; |
|
| 93 | - $input->activeFormParams = $this->activeFormParams; |
|
| 94 | - $input->modelName = $this->modelName; |
|
| 95 | - $input->colName = "[{$this->colName}][{$colName}][]"; |
|
| 96 | - $input->colParams = $col; |
|
| 97 | - $input->options = !empty($col['options']) ? $col['options'] : []; |
|
| 98 | - $cols[] = ['input' => $input, 'col' => $col]; |
|
| 89 | + $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($col['type']); |
|
| 90 | + $input = new $inputClassName(); |
|
| 91 | + $input->form = $this->form; |
|
| 92 | + $input->activeForm = $this->activeForm; |
|
| 93 | + $input->activeFormParams = $this->activeFormParams; |
|
| 94 | + $input->modelName = $this->modelName; |
|
| 95 | + $input->colName = "[{$this->colName}][{$colName}][]"; |
|
| 96 | + $input->colParams = $col; |
|
| 97 | + $input->options = !empty($col['options']) ? $col['options'] : []; |
|
| 98 | + $cols[] = ['input' => $input, 'col' => $col]; |
|
| 99 | 99 | } |
| 100 | 100 | break; |
| 101 | - default: |
|
| 101 | + default: |
|
| 102 | 102 | $relation = $modelName::getRelation($this->colParams['relation']); |
| 103 | 103 | $cols = []; |
| 104 | 104 | switch ($relation['type']) { |
| 105 | - case 'relModel': |
|
| 105 | + case 'relModel': |
|
| 106 | 106 | $cols['relItem'] = [ |
| 107 | 107 | 'col' => [ |
| 108 | 108 | 'label' => $relation['model']::objectName(), |
@@ -116,6 +116,6 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | return $cols; |
| 119 | - } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | } |
@@ -13,15 +13,15 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Input extends \Object { |
| 15 | 15 | |
| 16 | - public $form = null; |
|
| 17 | - public $activeForm = null; |
|
| 18 | - public $activeFormParams = []; |
|
| 19 | - public $modelName = ''; |
|
| 20 | - public $colName = ''; |
|
| 21 | - public $colParams = []; |
|
| 22 | - public $options = []; |
|
| 16 | + public $form = null; |
|
| 17 | + public $activeForm = null; |
|
| 18 | + public $activeFormParams = []; |
|
| 19 | + public $modelName = ''; |
|
| 20 | + public $colName = ''; |
|
| 21 | + public $colParams = []; |
|
| 22 | + public $options = []; |
|
| 23 | 23 | |
| 24 | - public function draw() { |
|
| 24 | + public function draw() { |
|
| 25 | 25 | $inputName = $this->colName(); |
| 26 | 26 | $inputLabel = $this->colLabel(); |
| 27 | 27 | |
@@ -31,78 +31,78 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | $preset = $this->preset(); |
| 33 | 33 | if ($preset !== null) { |
| 34 | - $inputOptions['disabled'] = true; |
|
| 35 | - $this->form->input('hidden', $inputName, '', $inputOptions); |
|
| 36 | - return true; |
|
| 34 | + $inputOptions['disabled'] = true; |
|
| 35 | + $this->form->input('hidden', $inputName, '', $inputOptions); |
|
| 36 | + return true; |
|
| 37 | 37 | } |
| 38 | 38 | $classPath = explode('\\', get_called_class()); |
| 39 | 39 | $inputType = lcfirst(array_pop($classPath)); |
| 40 | 40 | $this->form->input($inputType, $inputName, $inputLabel, $inputOptions); |
| 41 | 41 | return true; |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function parseRequest($request) { |
|
| 44 | + public function parseRequest($request) { |
|
| 45 | 45 | $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col']; |
| 46 | 46 | if (isset($request[$this->colName])) { |
| 47 | - $this->activeForm->model->{$colName} = $request[$this->colName]; |
|
| 47 | + $this->activeForm->model->{$colName} = $request[$this->colName]; |
|
| 48 | 48 | } else { |
| 49 | - $this->activeForm->model->{$colName} = 0; |
|
| 50 | - $this->activeForm->model->{$colName} = ''; |
|
| 49 | + $this->activeForm->model->{$colName} = 0; |
|
| 50 | + $this->activeForm->model->{$colName} = ''; |
|
| 51 | + } |
|
| 51 | 52 | } |
| 52 | - } |
|
| 53 | 53 | |
| 54 | - public function value() { |
|
| 54 | + public function value() { |
|
| 55 | 55 | $value = isset($this->colParams['default']) ? $this->colParams['default'] : ''; |
| 56 | 56 | if ($this->activeForm) { |
| 57 | - $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col']; |
|
| 58 | - $value = ($this->activeForm && $this->activeForm->model && isset($this->activeForm->model->{$colName})) ? $this->activeForm->model->{$colName} : $value; |
|
| 57 | + $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col']; |
|
| 58 | + $value = ($this->activeForm && $this->activeForm->model && isset($this->activeForm->model->{$colName})) ? $this->activeForm->model->{$colName} : $value; |
|
| 59 | 59 | } |
| 60 | 60 | return $value; |
| 61 | - } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function preset() { |
|
| 63 | + public function preset() { |
|
| 64 | 64 | $preset = !empty($this->activeForm->form['preset'][$this->colName]) ? $this->activeForm->form['preset'][$this->colName] : []; |
| 65 | 65 | if (!empty($this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName])) { |
| 66 | - $preset = array_merge($preset, $this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName]); |
|
| 66 | + $preset = array_merge($preset, $this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName]); |
|
| 67 | 67 | } |
| 68 | 68 | if ($preset) { |
| 69 | - $value = ''; |
|
| 70 | - if (!empty($preset['value'])) { |
|
| 69 | + $value = ''; |
|
| 70 | + if (!empty($preset['value'])) { |
|
| 71 | 71 | $value = $preset['value']; |
| 72 | - } elseif (!empty($preset['userCol'])) { |
|
| 72 | + } elseif (!empty($preset['userCol'])) { |
|
| 73 | 73 | if (strpos($preset['userCol'], ':')) { |
| 74 | - $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
| 75 | - $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
| 76 | - $value = \Users\User::$cur->$rel->$param; |
|
| 74 | + $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
| 75 | + $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
| 76 | + $value = \Users\User::$cur->$rel->$param; |
|
| 77 | 77 | } |
| 78 | - } |
|
| 79 | - return $value; |
|
| 78 | + } |
|
| 79 | + return $value; |
|
| 80 | 80 | } |
| 81 | 81 | return null; |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function colName() { |
|
| 84 | + public function colName() { |
|
| 85 | 85 | return "{$this->activeForm->requestFormName}[{$this->activeForm->modelName}]".(stristr($this->colName, '[')?$this->colName:"[{$this->colName}]"); |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public function colLabel() { |
|
| 88 | + public function colLabel() { |
|
| 89 | 89 | $modelName = $this->modelName; |
| 90 | 90 | return isset($this->colParams['label']) ? $this->colParams['label'] : (($this->activeForm->model && !empty($modelName::$labels[$this->colName])) ? $modelName::$labels[$this->colName] : $this->colName); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function readOnly() { |
|
| 93 | + public function readOnly() { |
|
| 94 | 94 | return !empty($this->activeForm->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($this->colName, $this->activeForm->form['userGroupReadonly'][\Users\User::$cur->group_id]); |
| 95 | - } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - public function validate(&$request) { |
|
| 97 | + public function validate(&$request) { |
|
| 98 | 98 | if (empty($request[$this->colName]) && !empty($this->colParams['required'])) { |
| 99 | - throw new \Exception('Вы не заполнили: ' . $this->colLabel()); |
|
| 99 | + throw new \Exception('Вы не заполнили: ' . $this->colLabel()); |
|
| 100 | 100 | } |
| 101 | 101 | if (!empty($this->colParams['validator'])) { |
| 102 | - $modelName = $this->modelName; |
|
| 103 | - $validator = $modelName::validator($this->colParams['validator']); |
|
| 104 | - $validator($this->activeForm, $request); |
|
| 102 | + $modelName = $this->modelName; |
|
| 103 | + $validator = $modelName::validator($this->colParams['validator']); |
|
| 104 | + $validator($this->activeForm, $request); |
|
| 105 | + } |
|
| 105 | 106 | } |
| 106 | - } |
|
| 107 | 107 | |
| 108 | 108 | } |
@@ -13,57 +13,57 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Item extends \Model { |
| 15 | 15 | |
| 16 | - public static $categoryModel = 'Ecommerce\Category'; |
|
| 17 | - public static $objectName = 'Товар'; |
|
| 18 | - public static $labels = [ |
|
| 19 | - 'name' => 'Название', |
|
| 20 | - 'alias' => 'Алиас', |
|
| 21 | - 'category_id' => 'Раздел', |
|
| 22 | - 'description' => 'Описание', |
|
| 23 | - 'item_type_id' => 'Тип товара', |
|
| 24 | - 'image_file_id' => 'Изображение', |
|
| 25 | - 'best' => 'Лучшее предложение', |
|
| 26 | - 'options' => 'Параметры', |
|
| 27 | - 'offers' => 'Торговые предложения', |
|
| 28 | - 'widget' => 'Виджет для отображения в каталоге', |
|
| 29 | - 'view' => 'Шаблон для отображения полной информации', |
|
| 30 | - 'deleted' => 'Удален', |
|
| 31 | - 'imgs' => 'Фото' |
|
| 32 | - ]; |
|
| 33 | - public static $cols = [ |
|
| 34 | - //Основные параметры |
|
| 35 | - 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
| 36 | - 'image_file_id' => ['type' => 'image'], |
|
| 37 | - 'name' => ['type' => 'text'], |
|
| 38 | - 'alias' => ['type' => 'text'], |
|
| 39 | - 'description' => ['type' => 'html'], |
|
| 40 | - 'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
| 41 | - 'best' => ['type' => 'bool'], |
|
| 42 | - 'deleted' => ['type' => 'bool'], |
|
| 43 | - //Системные |
|
| 44 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 45 | - 'weight' => ['type' => 'number'], |
|
| 46 | - 'sales' => ['type' => 'number'], |
|
| 47 | - 'imported' => ['type' => 'text'], |
|
| 48 | - 'tree_path' => ['type' => 'text'], |
|
| 49 | - 'search_index' => ['type' => 'text'], |
|
| 50 | - 'date_create' => ['type' => 'dateTime'], |
|
| 51 | - 'widget' => ['type' => 'text'], |
|
| 52 | - 'view' => ['type' => 'text'], |
|
| 53 | - //Менеджеры |
|
| 54 | - 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
| 55 | - 'offers' => ['type' => 'dataManager', 'relation' => 'offers'], |
|
| 56 | - 'imgs' => ['type' => 'dataManager', 'relation' => 'images'], |
|
| 57 | - ]; |
|
| 16 | + public static $categoryModel = 'Ecommerce\Category'; |
|
| 17 | + public static $objectName = 'Товар'; |
|
| 18 | + public static $labels = [ |
|
| 19 | + 'name' => 'Название', |
|
| 20 | + 'alias' => 'Алиас', |
|
| 21 | + 'category_id' => 'Раздел', |
|
| 22 | + 'description' => 'Описание', |
|
| 23 | + 'item_type_id' => 'Тип товара', |
|
| 24 | + 'image_file_id' => 'Изображение', |
|
| 25 | + 'best' => 'Лучшее предложение', |
|
| 26 | + 'options' => 'Параметры', |
|
| 27 | + 'offers' => 'Торговые предложения', |
|
| 28 | + 'widget' => 'Виджет для отображения в каталоге', |
|
| 29 | + 'view' => 'Шаблон для отображения полной информации', |
|
| 30 | + 'deleted' => 'Удален', |
|
| 31 | + 'imgs' => 'Фото' |
|
| 32 | + ]; |
|
| 33 | + public static $cols = [ |
|
| 34 | + //Основные параметры |
|
| 35 | + 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
| 36 | + 'image_file_id' => ['type' => 'image'], |
|
| 37 | + 'name' => ['type' => 'text'], |
|
| 38 | + 'alias' => ['type' => 'text'], |
|
| 39 | + 'description' => ['type' => 'html'], |
|
| 40 | + 'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
| 41 | + 'best' => ['type' => 'bool'], |
|
| 42 | + 'deleted' => ['type' => 'bool'], |
|
| 43 | + //Системные |
|
| 44 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 45 | + 'weight' => ['type' => 'number'], |
|
| 46 | + 'sales' => ['type' => 'number'], |
|
| 47 | + 'imported' => ['type' => 'text'], |
|
| 48 | + 'tree_path' => ['type' => 'text'], |
|
| 49 | + 'search_index' => ['type' => 'text'], |
|
| 50 | + 'date_create' => ['type' => 'dateTime'], |
|
| 51 | + 'widget' => ['type' => 'text'], |
|
| 52 | + 'view' => ['type' => 'text'], |
|
| 53 | + //Менеджеры |
|
| 54 | + 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
| 55 | + 'offers' => ['type' => 'dataManager', 'relation' => 'offers'], |
|
| 56 | + 'imgs' => ['type' => 'dataManager', 'relation' => 'images'], |
|
| 57 | + ]; |
|
| 58 | 58 | |
| 59 | - public static function simpleItemHandler($request) { |
|
| 59 | + public static function simpleItemHandler($request) { |
|
| 60 | 60 | if ($request) { |
| 61 | - $item = new Item(); |
|
| 62 | - $item->name = $request['name']; |
|
| 63 | - $item->description = $request['description']; |
|
| 64 | - $item->category_id = $request['category']; |
|
| 65 | - $item->save(); |
|
| 66 | - if (!empty($_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'])) { |
|
| 61 | + $item = new Item(); |
|
| 62 | + $item->name = $request['name']; |
|
| 63 | + $item->description = $request['description']; |
|
| 64 | + $item->category_id = $request['category']; |
|
| 65 | + $item->save(); |
|
| 66 | + if (!empty($_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'])) { |
|
| 67 | 67 | $file_id = \App::$primary->files->upload([ |
| 68 | 68 | 'tmp_name' => $_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'], |
| 69 | 69 | 'name' => $_FILES['ActiveForm_simpleItem']['name']['Ecommerce\Item']['image'], |
@@ -75,131 +75,131 @@ discard block |
||
| 75 | 75 | 'accept_group' => 'image' |
| 76 | 76 | ]); |
| 77 | 77 | if ($file_id) { |
| 78 | - $item->image_file_id = $file_id; |
|
| 79 | - $item->save(); |
|
| 78 | + $item->image_file_id = $file_id; |
|
| 79 | + $item->save(); |
|
| 80 | + } |
|
| 80 | 81 | } |
| 81 | - } |
|
| 82 | - if (!empty($request['options']['option'])) { |
|
| 82 | + if (!empty($request['options']['option'])) { |
|
| 83 | 83 | foreach ($request['options']['option'] as $key => $option_id) { |
| 84 | - $param = new Item\Param(); |
|
| 85 | - $param->item_id = $item->id; |
|
| 86 | - $param->value = $request['options']['value'][$key]; |
|
| 87 | - $param->item_option_id = $option_id; |
|
| 88 | - $param->save(); |
|
| 84 | + $param = new Item\Param(); |
|
| 85 | + $param->item_id = $item->id; |
|
| 86 | + $param->value = $request['options']['value'][$key]; |
|
| 87 | + $param->item_option_id = $option_id; |
|
| 88 | + $param->save(); |
|
| 89 | 89 | } |
| 90 | - } |
|
| 91 | - $offer = new Item\Offer(); |
|
| 92 | - $offer->item_id = $item->id; |
|
| 93 | - $offer->save(); |
|
| 94 | - if (!empty($request['offerOptions']['option'])) { |
|
| 90 | + } |
|
| 91 | + $offer = new Item\Offer(); |
|
| 92 | + $offer->item_id = $item->id; |
|
| 93 | + $offer->save(); |
|
| 94 | + if (!empty($request['offerOptions']['option'])) { |
|
| 95 | 95 | foreach ($request['offerOptions']['option'] as $key => $option_id) { |
| 96 | - $param = new Item\Offer\Param(); |
|
| 97 | - $param->item_offer_id = $offer->id; |
|
| 98 | - $param->value = $request['offerOptions']['value'][$key]; |
|
| 99 | - $param->item_offer_option_id = $option_id; |
|
| 100 | - $param->save(); |
|
| 96 | + $param = new Item\Offer\Param(); |
|
| 97 | + $param->item_offer_id = $offer->id; |
|
| 98 | + $param->value = $request['offerOptions']['value'][$key]; |
|
| 99 | + $param->item_offer_option_id = $option_id; |
|
| 100 | + $param->save(); |
|
| 101 | + } |
|
| 101 | 102 | } |
| 102 | - } |
|
| 103 | - $price = new Item\Offer\Price(); |
|
| 104 | - $price->price = $request['price']; |
|
| 105 | - $price->item_offer_id = $offer->id; |
|
| 106 | - $price->currency_id = $request['currency']; |
|
| 107 | - $price->save(); |
|
| 103 | + $price = new Item\Offer\Price(); |
|
| 104 | + $price->price = $request['price']; |
|
| 105 | + $price->item_offer_id = $offer->id; |
|
| 106 | + $price->currency_id = $request['currency']; |
|
| 107 | + $price->save(); |
|
| 108 | + } |
|
| 108 | 109 | } |
| 109 | - } |
|
| 110 | 110 | |
| 111 | - public static $dataManagers = [ |
|
| 112 | - 'manager' => [ |
|
| 113 | - 'name' => 'Товары', |
|
| 114 | - 'cols' => [ |
|
| 115 | - 'name', |
|
| 116 | - 'imgs', |
|
| 117 | - 'category_id', |
|
| 118 | - 'item_type_id', |
|
| 119 | - 'best', |
|
| 120 | - 'deleted', |
|
| 121 | - 'options', |
|
| 122 | - 'offers', |
|
| 123 | - ], |
|
| 124 | - 'categorys' => [ |
|
| 125 | - 'model' => 'Ecommerce\Category', |
|
| 126 | - ], |
|
| 127 | - 'sortMode' => true |
|
| 128 | - ] |
|
| 129 | - ]; |
|
| 130 | - public static $forms = [ |
|
| 131 | - 'manager' => [ |
|
| 132 | - 'map' => [ |
|
| 133 | - ['name', 'alias'], |
|
| 134 | - ['category_id', 'item_type_id', 'deleted'], |
|
| 135 | - ['widget', 'view'], |
|
| 136 | - ['best', 'image_file_id'], |
|
| 137 | - ['description'], |
|
| 138 | - ['imgs'], |
|
| 139 | - ['options'], |
|
| 140 | - ['offers'], |
|
| 141 | - ] |
|
| 142 | - ], |
|
| 143 | - 'simpleItem' => [ |
|
| 144 | - 'options' => [ |
|
| 145 | - 'access' => [ |
|
| 146 | - 'groups' => [ |
|
| 147 | - 3 |
|
| 148 | - ] |
|
| 149 | - ], |
|
| 150 | - ], |
|
| 151 | - 'name' => 'Простой товар с ценой', |
|
| 152 | - 'inputs' => [ |
|
| 153 | - 'name' => ['type' => 'text'], |
|
| 154 | - 'description' => ['type' => 'html'], |
|
| 155 | - 'category' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Category', 'label' => 'Категория'], |
|
| 156 | - 'image' => ['type' => 'image', 'label' => 'Изображение'], |
|
| 157 | - 'price' => ['type' => 'text', 'label' => 'Цена'], |
|
| 158 | - 'currency' => ['type' => 'select', 'source' => 'model', 'model' => 'Money\Currency', 'label' => 'Валюта'], |
|
| 159 | - 'options' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [ |
|
| 160 | - 'inputs' => [ |
|
| 161 | - 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Option', 'label' => 'Свойство'], |
|
| 162 | - 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
|
| 163 | - ] |
|
| 164 | - ] |
|
| 165 | - ], |
|
| 166 | - 'offerOptions' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [ |
|
| 167 | - 'inputs' => [ |
|
| 168 | - 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Offer\Option', 'label' => 'Свойство предложения'], |
|
| 169 | - 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
|
| 170 | - ] |
|
| 171 | - ],'label'=>'Параметры предлоежния' |
|
| 172 | - ] |
|
| 173 | - ], |
|
| 174 | - 'map' => [ |
|
| 175 | - ['name', 'category'], |
|
| 176 | - ['description'], |
|
| 177 | - ['image'], |
|
| 178 | - ['price', 'currency'], |
|
| 179 | - ['options'], |
|
| 180 | - ['offerOptions'], |
|
| 181 | - ], |
|
| 182 | - 'handler' => 'simpleItemHandler' |
|
| 183 | - ] |
|
| 184 | - ]; |
|
| 111 | + public static $dataManagers = [ |
|
| 112 | + 'manager' => [ |
|
| 113 | + 'name' => 'Товары', |
|
| 114 | + 'cols' => [ |
|
| 115 | + 'name', |
|
| 116 | + 'imgs', |
|
| 117 | + 'category_id', |
|
| 118 | + 'item_type_id', |
|
| 119 | + 'best', |
|
| 120 | + 'deleted', |
|
| 121 | + 'options', |
|
| 122 | + 'offers', |
|
| 123 | + ], |
|
| 124 | + 'categorys' => [ |
|
| 125 | + 'model' => 'Ecommerce\Category', |
|
| 126 | + ], |
|
| 127 | + 'sortMode' => true |
|
| 128 | + ] |
|
| 129 | + ]; |
|
| 130 | + public static $forms = [ |
|
| 131 | + 'manager' => [ |
|
| 132 | + 'map' => [ |
|
| 133 | + ['name', 'alias'], |
|
| 134 | + ['category_id', 'item_type_id', 'deleted'], |
|
| 135 | + ['widget', 'view'], |
|
| 136 | + ['best', 'image_file_id'], |
|
| 137 | + ['description'], |
|
| 138 | + ['imgs'], |
|
| 139 | + ['options'], |
|
| 140 | + ['offers'], |
|
| 141 | + ] |
|
| 142 | + ], |
|
| 143 | + 'simpleItem' => [ |
|
| 144 | + 'options' => [ |
|
| 145 | + 'access' => [ |
|
| 146 | + 'groups' => [ |
|
| 147 | + 3 |
|
| 148 | + ] |
|
| 149 | + ], |
|
| 150 | + ], |
|
| 151 | + 'name' => 'Простой товар с ценой', |
|
| 152 | + 'inputs' => [ |
|
| 153 | + 'name' => ['type' => 'text'], |
|
| 154 | + 'description' => ['type' => 'html'], |
|
| 155 | + 'category' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Category', 'label' => 'Категория'], |
|
| 156 | + 'image' => ['type' => 'image', 'label' => 'Изображение'], |
|
| 157 | + 'price' => ['type' => 'text', 'label' => 'Цена'], |
|
| 158 | + 'currency' => ['type' => 'select', 'source' => 'model', 'model' => 'Money\Currency', 'label' => 'Валюта'], |
|
| 159 | + 'options' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [ |
|
| 160 | + 'inputs' => [ |
|
| 161 | + 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Option', 'label' => 'Свойство'], |
|
| 162 | + 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
|
| 163 | + ] |
|
| 164 | + ] |
|
| 165 | + ], |
|
| 166 | + 'offerOptions' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [ |
|
| 167 | + 'inputs' => [ |
|
| 168 | + 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Offer\Option', 'label' => 'Свойство предложения'], |
|
| 169 | + 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
|
| 170 | + ] |
|
| 171 | + ],'label'=>'Параметры предлоежния' |
|
| 172 | + ] |
|
| 173 | + ], |
|
| 174 | + 'map' => [ |
|
| 175 | + ['name', 'category'], |
|
| 176 | + ['description'], |
|
| 177 | + ['image'], |
|
| 178 | + ['price', 'currency'], |
|
| 179 | + ['options'], |
|
| 180 | + ['offerOptions'], |
|
| 181 | + ], |
|
| 182 | + 'handler' => 'simpleItemHandler' |
|
| 183 | + ] |
|
| 184 | + ]; |
|
| 185 | 185 | |
| 186 | - public function realType() { |
|
| 186 | + public function realType() { |
|
| 187 | 187 | if ($this->option && $this->option->type) { |
| 188 | - $type = $this->option->type; |
|
| 188 | + $type = $this->option->type; |
|
| 189 | 189 | |
| 190 | - if ($type == 'select') { |
|
| 190 | + if ($type == 'select') { |
|
| 191 | 191 | return [ |
| 192 | 192 | 'type' => 'select', |
| 193 | 193 | 'source' => 'relation', |
| 194 | 194 | 'relation' => 'option:items', |
| 195 | 195 | ]; |
| 196 | - } |
|
| 197 | - return $type; |
|
| 196 | + } |
|
| 197 | + return $type; |
|
| 198 | 198 | } |
| 199 | 199 | return 'text'; |
| 200 | - } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - public static function indexes() { |
|
| 202 | + public static function indexes() { |
|
| 203 | 203 | return [ |
| 204 | 204 | 'ecommerce_item_item_category_id' => [ |
| 205 | 205 | 'type' => 'INDEX', |
@@ -220,45 +220,45 @@ discard block |
||
| 220 | 220 | ] |
| 221 | 221 | ], |
| 222 | 222 | ]; |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - public function beforeSave() { |
|
| 225 | + public function beforeSave() { |
|
| 226 | 226 | |
| 227 | 227 | if ($this->id) { |
| 228 | - $this->search_index = $this->name . ' '; |
|
| 229 | - if ($this->category) { |
|
| 228 | + $this->search_index = $this->name . ' '; |
|
| 229 | + if ($this->category) { |
|
| 230 | 230 | $this->search_index .= $this->category->name . ' '; |
| 231 | - } |
|
| 232 | - if ($this->options) { |
|
| 231 | + } |
|
| 232 | + if ($this->options) { |
|
| 233 | 233 | foreach ($this->options as $option) { |
| 234 | - if ($option->item_option_searchable && $option->value) { |
|
| 234 | + if ($option->item_option_searchable && $option->value) { |
|
| 235 | 235 | if ($option->item_option_type != 'select') { |
| 236 | - $this->search_index .= $option->value . ' '; |
|
| 236 | + $this->search_index .= $option->value . ' '; |
|
| 237 | 237 | } elseif (!empty($option->option->items[$option->value])) { |
| 238 | - $option->option->items[$option->value]->value . ' '; |
|
| 238 | + $option->option->items[$option->value]->value . ' '; |
|
| 239 | 239 | } |
| 240 | - } |
|
| 240 | + } |
|
| 241 | + } |
|
| 241 | 242 | } |
| 242 | - } |
|
| 243 | - if ($this->offers) { |
|
| 243 | + if ($this->offers) { |
|
| 244 | 244 | foreach ($this->offers as $offer) { |
| 245 | - if ($offer->options) { |
|
| 245 | + if ($offer->options) { |
|
| 246 | 246 | foreach ($offer->options as $option) { |
| 247 | - if ($option->item_offer_option_searchable && $option->value) { |
|
| 247 | + if ($option->item_offer_option_searchable && $option->value) { |
|
| 248 | 248 | if ($option->item_offer_option_type != 'select') { |
| 249 | - $this->search_index .= $option->value . ' '; |
|
| 249 | + $this->search_index .= $option->value . ' '; |
|
| 250 | 250 | } elseif (!empty($option->option->items[$option->value])) { |
| 251 | - $option->option->items[$option->value]->value . ' '; |
|
| 251 | + $option->option->items[$option->value]->value . ' '; |
|
| 252 | 252 | } |
| 253 | - } |
|
| 253 | + } |
|
| 254 | + } |
|
| 254 | 255 | } |
| 255 | - } |
|
| 256 | 256 | } |
| 257 | - } |
|
| 257 | + } |
|
| 258 | + } |
|
| 258 | 259 | } |
| 259 | - } |
|
| 260 | 260 | |
| 261 | - public static function relations() { |
|
| 261 | + public static function relations() { |
|
| 262 | 262 | |
| 263 | 263 | return [ |
| 264 | 264 | 'category' => [ |
@@ -296,55 +296,55 @@ discard block |
||
| 296 | 296 | 'col' => 'user_id' |
| 297 | 297 | ] |
| 298 | 298 | ]; |
| 299 | - } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - public function getPrice() { |
|
| 301 | + public function getPrice() { |
|
| 302 | 302 | $offers = $this->offers(['key' => false]); |
| 303 | 303 | $curPrice = null; |
| 304 | 304 | |
| 305 | 305 | foreach ($offers[0]->prices as $price) { |
| 306 | - if (!$price->type) { |
|
| 306 | + if (!$price->type) { |
|
| 307 | 307 | $curPrice = $price; |
| 308 | - } elseif ( |
|
| 309 | - (!$price->type->roles && !$curPrice) || |
|
| 308 | + } elseif ( |
|
| 309 | + (!$price->type->roles && !$curPrice) || |
|
| 310 | 310 | ($price->type->roles && !$curPrice && strpos($price->type->roles, "|" . \Users\User::$cur->role_id . "|") !== false) |
| 311 | - ) { |
|
| 311 | + ) { |
|
| 312 | 312 | $curPrice = $price; |
| 313 | - } |
|
| 313 | + } |
|
| 314 | 314 | } |
| 315 | 315 | return $curPrice; |
| 316 | - } |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - public function name() { |
|
| 318 | + public function name() { |
|
| 319 | 319 | if (!empty(\App::$primary->ecommerce->config['item_option_as_name'])) { |
| 320 | - $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]); |
|
| 321 | - if ($param && $param->value) { |
|
| 320 | + $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]); |
|
| 321 | + if ($param && $param->value) { |
|
| 322 | 322 | return $param->value; |
| 323 | - } |
|
| 323 | + } |
|
| 324 | 324 | } |
| 325 | 325 | return $this->name; |
| 326 | - } |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - public function beforeDelete() { |
|
| 328 | + public function beforeDelete() { |
|
| 329 | 329 | if ($this->id) { |
| 330 | - if ($this->options) { |
|
| 330 | + if ($this->options) { |
|
| 331 | 331 | foreach ($this->options as $option) { |
| 332 | - $option->delete(); |
|
| 332 | + $option->delete(); |
|
| 333 | + } |
|
| 333 | 334 | } |
| 334 | - } |
|
| 335 | - if ($this->offers) { |
|
| 335 | + if ($this->offers) { |
|
| 336 | 336 | foreach ($this->offers as $offer) { |
| 337 | - $offer->delete(); |
|
| 337 | + $offer->delete(); |
|
| 338 | 338 | } |
| 339 | - } |
|
| 340 | - if ($this->image) { |
|
| 339 | + } |
|
| 340 | + if ($this->image) { |
|
| 341 | 341 | $this->image->delete(); |
| 342 | - } |
|
| 342 | + } |
|
| 343 | + } |
|
| 343 | 344 | } |
| 344 | - } |
|
| 345 | 345 | |
| 346 | - public function getHref() { |
|
| 346 | + public function getHref() { |
|
| 347 | 347 | return "/ecommerce/view/{$this->pk()}"; |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | 350 | } |
@@ -10,28 +10,28 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class EcommerceController extends adminController { |
| 12 | 12 | |
| 13 | - public function dashboardAction() { |
|
| 13 | + public function dashboardAction() { |
|
| 14 | 14 | $this->view->setTitle('Онлайн магазин'); |
| 15 | 15 | $forms = \Ecommerce\Item::$magicForms; |
| 16 | 16 | \Ecommerce\Item::$forms['simpleItem']['handler'](); |
| 17 | 17 | $this->view->page(); |
| 18 | - } |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function configureAction() { |
|
| 20 | + public function configureAction() { |
|
| 21 | 21 | if (!empty($_POST['config'])) { |
| 22 | - $config = App::$cur->ecommerce->config; |
|
| 23 | - $config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true; |
|
| 24 | - $config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true; |
|
| 25 | - $config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true; |
|
| 26 | - $config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true; |
|
| 27 | - $config['notify_mail'] = $_POST['config']['notify_mail']; |
|
| 28 | - $config['defaultCategoryView'] = $_POST['config']['defaultCategoryView']; |
|
| 29 | - $config['defaultCurrency'] = $_POST['config']['defaultCurrency']; |
|
| 30 | - $config['orderPrefix'] = $_POST['config']['orderPrefix']; |
|
| 31 | - $config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true; |
|
| 32 | - $config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true; |
|
| 33 | - Config::save('module', $config, 'Ecommerce'); |
|
| 34 | - Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success'); |
|
| 22 | + $config = App::$cur->ecommerce->config; |
|
| 23 | + $config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true; |
|
| 24 | + $config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true; |
|
| 25 | + $config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true; |
|
| 26 | + $config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true; |
|
| 27 | + $config['notify_mail'] = $_POST['config']['notify_mail']; |
|
| 28 | + $config['defaultCategoryView'] = $_POST['config']['defaultCategoryView']; |
|
| 29 | + $config['defaultCurrency'] = $_POST['config']['defaultCurrency']; |
|
| 30 | + $config['orderPrefix'] = $_POST['config']['orderPrefix']; |
|
| 31 | + $config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true; |
|
| 32 | + $config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true; |
|
| 33 | + Config::save('module', $config, 'Ecommerce'); |
|
| 34 | + Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success'); |
|
| 35 | 35 | } |
| 36 | 36 | $managers = [ |
| 37 | 37 | 'Ecommerce\Delivery', |
@@ -51,51 +51,51 @@ discard block |
||
| 51 | 51 | ]; |
| 52 | 52 | $this->view->setTitle('Настройки магазина'); |
| 53 | 53 | $this->view->page(['data' => compact('managers')]); |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function reBlockIndexAction() { |
|
| 56 | + public function reBlockIndexAction() { |
|
| 57 | 57 | set_time_limit(0); |
| 58 | 58 | $carts = Cart::getList(); |
| 59 | 59 | foreach ($carts as $cart) { |
| 60 | - $cart->save(); |
|
| 60 | + $cart->save(); |
|
| 61 | 61 | } |
| 62 | 62 | Tools::redirect('/admin/ecommerce/configure', 'Данные о блокировках обновлены'); |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function reSearchIndexAction($i = 0) { |
|
| 65 | + public function reSearchIndexAction($i = 0) { |
|
| 66 | 66 | set_time_limit(0); |
| 67 | 67 | $count = 100; |
| 68 | 68 | $items = Ecommerce\Item::getList(['start' => $i * $count, 'limit' => $count]); |
| 69 | 69 | if (!$items) { |
| 70 | - Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен'); |
|
| 70 | + Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен'); |
|
| 71 | 71 | } else { |
| 72 | - $i++; |
|
| 73 | - foreach ($items as $key => $item) { |
|
| 72 | + $i++; |
|
| 73 | + foreach ($items as $key => $item) { |
|
| 74 | 74 | $item->save(); |
| 75 | 75 | unset($items[$key]); |
| 76 | 76 | unset($item); |
| 77 | - } |
|
| 78 | - echo 'Происходит процесс индексации: проиндексировано ' . $i * $count; |
|
| 79 | - Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i); |
|
| 77 | + } |
|
| 78 | + echo 'Происходит процесс индексации: проиндексировано ' . $i * $count; |
|
| 79 | + Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i); |
|
| 80 | + } |
|
| 80 | 81 | } |
| 81 | - } |
|
| 82 | 82 | |
| 83 | - public function newOrdersSubscribeAction() { |
|
| 83 | + public function newOrdersSubscribeAction() { |
|
| 84 | 84 | $this->Notifications->subscribe('Ecommerce-orders'); |
| 85 | - } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function closeCartAction($cartId = 0) { |
|
| 87 | + public function closeCartAction($cartId = 0) { |
|
| 88 | 88 | $cart = Ecommerce\Cart::get((int) $cartId); |
| 89 | 89 | $result = new Server\Result(); |
| 90 | 90 | if ($cart && $cart->cart_status_id != 5) { |
| 91 | - $cart->cart_status_id = 5; |
|
| 92 | - $cart->save(); |
|
| 93 | - $result->successMsg = 'Заказ был завершен'; |
|
| 94 | - $result->send(); |
|
| 91 | + $cart->cart_status_id = 5; |
|
| 92 | + $cart->save(); |
|
| 93 | + $result->successMsg = 'Заказ был завершен'; |
|
| 94 | + $result->send(); |
|
| 95 | 95 | } |
| 96 | 96 | $result->success = false; |
| 97 | 97 | $result->content = 'Такая корзина не найдена'; |
| 98 | 98 | $result->send(); |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | } |