mirror of
https://github.com/danielbrendel/hortusfox-web.git
synced 2026-01-06 04:40:13 -06:00
#276 Add inventory items
This commit is contained in:
@@ -172,6 +172,7 @@ return [
|
||||
array('/api/plants/log/edit', 'ANY', 'api@edit_plant_log_entry'),
|
||||
array('/api/plants/log/remove', 'ANY', 'api@remove_plant_log_entry'),
|
||||
array('/api/plants/log/fetch', 'ANY', 'api@fetch_plant_log_entries'),
|
||||
array('/api/inventory/add', 'ANY', 'api@add_inventory_item'),
|
||||
array('/api/chat/message/add', 'ANY', 'api@add_chat_message'),
|
||||
|
||||
/** Backup Controller */
|
||||
|
||||
@@ -455,6 +455,35 @@ class ApiController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles URL: /api/inventory/add
|
||||
*
|
||||
* @param Asatru\Controller\ControllerArg $request
|
||||
* @return Asatru\View\JsonHandler
|
||||
*/
|
||||
public static function add_inventory_item($request)
|
||||
{
|
||||
try {
|
||||
$name = $request->params()->query('name', null);
|
||||
$description = $request->params()->query('description', null);
|
||||
$location = $request->params()->query('location', null);
|
||||
$group = $request->params()->query('group', null);
|
||||
$photo = $request->params()->query('photo', null);
|
||||
|
||||
$itemid = InventoryModel::addItem($name, $description, $location, $group, $photo, true);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'item' => $itemid
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles URL: /api/chat/message/add
|
||||
*
|
||||
|
||||
@@ -14,14 +14,15 @@ class InventoryModel extends \Asatru\Database\Model {
|
||||
* @param $location
|
||||
* @param $group
|
||||
* @param $photo
|
||||
* @param $api
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function addItem($name, $description, $location, $group, $photo)
|
||||
public static function addItem($name, $description, $location, $group, $photo, $api = false)
|
||||
{
|
||||
try {
|
||||
$user = UserModel::getAuthUser();
|
||||
if (!$user) {
|
||||
if ((!$user) && (!$api)) {
|
||||
throw new \Exception('Invalid user');
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ class InventoryModel extends \Asatru\Database\Model {
|
||||
}
|
||||
|
||||
static::raw('INSERT INTO `' . self::tableName() . '` (name, group_ident, description, location, last_edited_user, last_edited_date) VALUES(?, ?, ?, ?, ?, CURRENT_TIMESTAMP)', [
|
||||
$name, $group, $description, $location, $user->get('id')
|
||||
$name, $group, $description, $location, (($user) ? $user->get('id') : 0)
|
||||
]);
|
||||
|
||||
$row = static::raw('SELECT * FROM `' . self::tableName() . '` ORDER BY id DESC LIMIT 1')->first();
|
||||
@@ -61,9 +62,11 @@ class InventoryModel extends \Asatru\Database\Model {
|
||||
}
|
||||
}
|
||||
|
||||
LogModel::addLog($user->get('id'), 'inventory', 'add_inventory_item', $name, url('/inventory?expand=' . $row->get('id') . '#anchor-item-' . $row->get('id')));
|
||||
TextBlockModule::createdInventoryItem($name, url('/inventory?expand=' . $row->get('id') . '#anchor-item-' . $row->get('id')));
|
||||
|
||||
if (!$api) {
|
||||
LogModel::addLog($user->get('id'), 'inventory', 'add_inventory_item', $name, url('/inventory?expand=' . $row->get('id') . '#anchor-item-' . $row->get('id')));
|
||||
TextBlockModule::createdInventoryItem($name, url('/inventory?expand=' . $row->get('id') . '#anchor-item-' . $row->get('id')));
|
||||
}
|
||||
|
||||
return $row->get('id');
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
</div>
|
||||
|
||||
<div class="inventory-item-author">
|
||||
{{ __('app.last_edited_by', ['name' => UserModel::getNameById($inventory->get($i)->get('last_edited_user')), 'when' => (new Carbon($inventory->get($i)->get('last_edited_date')))->diffForHumans()]) }}
|
||||
{{ __('app.last_edited_by', ['name' => (($inventory->get($i)->get('last_edited_user')) ? UserModel::getNameById($inventory->get($i)->get('last_edited_user')) : 'System'), 'when' => (new Carbon($inventory->get($i)->get('last_edited_date')))->diffForHumans()]) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user