Skip to content

Commit

Permalink
Resolves #203
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrendel committed May 15, 2024
1 parent f8e9288 commit c507624
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/CustPlantAttrModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ public static function interpretContent($content, $datatype)
public static function addAttribute($plant, $label, $datatype, $content)
{
try {
$user = UserModel::getAuthUser();
if (!$user) {
throw new \Exception('Invalid user');
}

static::raw('INSERT INTO `' . self::tableName() . '` (plant, label, datatype, content) VALUES(?, ?, ?, ?)', [
$plant, $label, $datatype, static::interpretContent($content, $datatype)
]);

LogModel::addLog($user->get('id'), $plant, $label . ' (' . $datatype . ')', $content, url('/plants/details/' . $plant));
} catch (\Exception $e) {
throw $e;
}
Expand All @@ -102,9 +109,16 @@ public static function addAttribute($plant, $label, $datatype, $content)
public static function editAttribute($id, $plant, $label, $datatype, $content)
{
try {
$user = UserModel::getAuthUser();
if (!$user) {
throw new \Exception('Invalid user');
}

static::raw('UPDATE `' . self::tableName() . '` SET label = ?, datatype = ?, content = ? WHERE id = ?', [
$label, $datatype, static::interpretContent($content, $datatype), $id
]);

LogModel::addLog($user->get('id'), $plant, $label . ' (' . $datatype . ')', $content, url('/plants/details/' . $plant));
} catch (\Exception $e) {
throw $e;
}
Expand Down
1 change: 1 addition & 0 deletions app/views/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
<label class="label">{{ __('app.datatype') }}</label>
<div class="control">
<select class="input" name="datatype" id="edit-plant-attribute-datatype" onchange="window.vue.selectDataTypeInputField(this, document.querySelector('#field-custom-edit-attribute-content'));" required>
<option value="" selected disabled>- {{ __('app.select') }} -</option>
@foreach (CustPlantAttrModel::$data_types as $datatype)
<option value="{{ $datatype }}">{{ __('app.custom_attribute_datatype_' . $datatype) }}</option>
@endforeach
Expand Down

0 comments on commit c507624

Please sign in to comment.