Skip to content

Commit

Permalink
update layout crud generator
Browse files Browse the repository at this point in the history
  • Loading branch information
gheav committed Sep 9, 2021
1 parent e98f2a9 commit 16864ca
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 60 deletions.
13 changes: 11 additions & 2 deletions app/Controllers/Developers/CRUDGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ function __construct()
}
public function index()
{
$table = $this->request->getGet('table');

$data = array_merge($this->data, [
'title' => 'CRUD Generator',
'Tables' => $this->developerModel->getTableDatabase()
'Tables' => $this->developerModel->getTableDatabase(),
'Columns' => $this->developerModel->getTableDatabase(),
'tableName' => $table,
'create' => $this->request->getGet('create'),
'read' => $this->request->getGet('read'),
'update' => $this->request->getGet('update'),
'delete' => $this->request->getGet('delete'),
'file' => $this->request->getGet('file'),
]);
return view('developers/crudGenerator.php', $data);
return view('developers/crudGenerator', $data);
}
}
2 changes: 1 addition & 1 deletion app/Controllers/Developers/MenuManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public function index()
$data = array_merge($this->data, [
'title' => 'Menu Management'
]);
return view('developers/menuManagement.php', $data);
return view('developers/menuManagement', $data);
}
}
3 changes: 1 addition & 2 deletions app/Controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public function _createController()
$menuTitle = $this->request->getPost('inputMenuTitle');
$controllerName = url_title(ucwords($menuTitle), '', false);
$viewName = url_title($menuTitle, '', true);
$viewPath = $viewName . ".php";
$controllerPath = APPPATH . 'Controllers/' . $controllerName . ".php";
$controllerContent = "<?php
namespace App\Controllers;
Expand All @@ -201,7 +200,7 @@ public function index()
$|data = array_merge($|this->data, [
'title' => '$menuTitle'
]);
return view('$viewPath', $|data);
return view('$viewName', $|data);
}
}
";
Expand Down
256 changes: 201 additions & 55 deletions app/Views/developers/crudGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<?= $this->extend('layouts/main'); ?>
<?= $this->section('content'); ?>
<style>
code {
background-color: #F5F7FB;

border-radius: 0.3rem;
padding: 4px 5px 5px;
white-space: nowrap;
}

pre code {
white-space: inherit;
}

pre {
background-color: #F5F7FB;
padding: 5px;
border-radius: 0.3em;
}
</style>
<h1 class="h3 mb-3"><strong><?= $title; ?></strong> Menu </h1>
<div class="row">
<div class="col-12 col-lg-4 col-xxl-4 d-flex">
Expand All @@ -9,97 +28,224 @@
</div>
<div class="card-body">
<form action="<?= base_url('crudGenerator'); ?> " method="get">
<select class="form-select" aria-label="Default select example">
<option selected>-- Select Table --</option>
<select class="form-select" name="table" required>
<option value="">-- Select Table --</option>
<?php foreach ($Tables as $table) : ?>
<option value="1"><?= $table; ?></option>
<option value="<?= $table; ?>" <?= ($tableName == $table) ? 'selected' : ''; ?>><?= $table; ?></option>
<?php endforeach; ?>
</select>

<hr>
<div class="form-group">
<div class="form-group mb-3">
<label for="" class="fw-bold">Generate Function</label>
<div class="input-group mt-2 ">
<div class="form-check form-check-inline ms-3">
<input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
<input class="form-check-input" type="checkbox" id="inlineCheckbox1" name="create" value="1" <?= ($create == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="inlineCheckbox1">Create</label>
</div>
<div class="form-check form-check-inline ms-3">
<input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2">
<input class="form-check-input" type="checkbox" id="inlineCheckbox2" name="read" value="1" <?= ($read == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="inlineCheckbox2">Read</label>
</div>
<div class="form-check form-check-inline ms-3">
<input class="form-check-input" type="checkbox" id="inlineCheckbox3" value="option3">
<input class="form-check-input" type="checkbox" id="inlineCheckbox3" name="update" value="1" <?= ($update == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="inlineCheckbox3">Update</label>
</div>
<div class="form-check form-check-inline ms-3">
<input class="form-check-input" type="checkbox" id="inlineCheckbox3" value="option3">
<input class="form-check-input" type="checkbox" id="inlineCheckbox3" name="delete" value="1" <?= ($delete == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="inlineCheckbox3">Delete</label>
</div>
</div>
</div>
<div class="form-group mb-3">
<label for="" class="fw-bold">File</label>
<div class="input-group mt-2 ">
<select class="form-select" name="file" required>
<option value="">-- Select File --</option>
<option value="controller" <?= ($file == 'controller') ? 'selected' : ''; ?>>Controller</option>
<option value="model" <?= ($file == 'model') ? 'selected' : ''; ?>>Model</option>
<option value="view" <?= ($file == 'view') ? 'selected' : ''; ?>>View</option>
</select>
</div>
</div>
<hr>

<div class="d-grid gap-2 mt-3">
<button class="btn btn-primary" type="button">Generate Code</button>
<button class="btn btn-primary" type="submit">Generate Code</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-12 col-lg-8 col-xxl-8 d-flex">
<div class="card flex-fill">
<div class="card-header">
<h5 class="card-title mb-0"><i class="align-middle" data-feather="code"></i> Source Code </h5>
<div class="card border flex-fill">
<div class="card-header mb-0">
<h5 class="card-title "> Source Code </h5>
</div>
<div class="card-body ">
<div class="row">
<div class="col-sm-4 ">
<h3 class="fw-bold">Controller</h3>

</div>
<div class="col-sm-4 ">
<h3 class="fw-bold">Model</h3>

</div>
<div class="col-sm-4 ">
<h3 class="fw-bold">View</h3>
<div class="card-body">
<?php if ($file == 'controller') : ?>
<h5 class="fw-bold"> Read</h5>
<hr>
<pre>
<code class="text-primary">
public function index()
{
$this->Model->getData();
}
</code>
</pre>
<hr>
<h5 class="fw-bold"> Insert</h5>
<hr>
<pre>
<code class="text-primary">
public function createUser()
{
if (!$this->validate(['inputUsername' => ['rules' => 'is_unique[users.username]']])) {
session()->setFlashdata('notif_error', '<b>Failed to add new user</b> The user already exists! ');
return redirect()->to(base_url('users'));
}
$createUser = $this->userModel->createUser($this->request->getPost(null, FILTER_SANITIZE_STRING));
if ($createUser) {
session()->setFlashdata('notif_success', '<b>Successfully added new user</b> ');
return redirect()->to(base_url('users'));
} else {
session()->setFlashdata('notif_error', '<b>Failed to add new user</b> ');
return redirect()->to(base_url('users'));
}
}
</code>
</pre>
<hr>
<h5 class="fw-bold"> Update</h5>
<hr>
<pre>
<code class="text-primary">
public function updateUser()
{
$updateUser = $this->userModel->updateUser($this->request->getPost(null, FILTER_SANITIZE_STRING));
if ($updateUser) {
session()->setFlashdata('notif_success', '<b>Successfully update user data</b> ');
return redirect()->to(base_url('users'));
} else {
session()->setFlashdata('notif_error', '<b>Failed to update user data</b> ');
return redirect()->to(base_url('users'));
}
}
</code>
</pre>
<h5 class="fw-bold"> Delete</h5>
<hr>
<pre>
<code class="text-primary">

</div>
</div>
<div class="row">
<div class="col-sm-4 border">
<h5 class="fw-bold"> Read</h5>
<br>
<h5 class="fw-bold"> Insert</h5>
<br>
<h5 class="fw-bold"> Update</h5>
<br>
<h5 class="fw-bold"> Delete</h5>
public function deleteUser($userID)
{
if (!$userID) {
return redirect()->to(base_url('users'));
}
$deleteUser = $this->userModel->deleteUser($userID);
if ($deleteUser) {
session()->setFlashdata('notif_success', '<b>Successfully delete user</b> ');
return redirect()->to(base_url('users'));
} else {
session()->setFlashdata('notif_error', '<b>Failed to delete user</b> ');
return redirect()->to(base_url('users'));
}
}
</code>
</pre>
<?php elseif ($file == 'model') : ?>
<h5 class="fw-bold"> Read</h5>
<hr>
<pre>
<code class="text-primary">
public function getUser($username = false, $userID = false)
{
if ($username) {
return $this->db->table('users')
->select('*,users.id AS userID,user_role.id AS role_id')
->join('user_role', 'users.role = user_role.id')
->where(['username' => $username])
->get()->getRowArray();
} elseif ($userID) {
return $this->db->table('users')
->select('*,users.id AS userID,user_role.id AS role_id')
->join('user_role', 'users.role = user_role.id')
->where(['users.id' => $userID])
->get()->getRowArray();
} else {
return $this->db->table('users')
->select('*,users.id AS userID,user_role.id AS role_id')
->join('user_role', 'users.role = user_role.id')
->get()->getResultArray();
}
}
</code>
</pre>
<hr>
<h5 class="fw-bold"> Insert</h5>
<hr>
<pre>
<code class="text-primary">
public function createMenu($dataMenu)
{
return $this->db->table('user_menu')->insert([
'menu_category' => $dataMenu['inputMenuCategory'],
'title' => $dataMenu['inputMenuTitle'],
'url' => $dataMenu['inputMenuURL'],
'icon' => $dataMenu['inputMenuIcon'],
'parent' => 0
]);
}
</code>
</pre>
<hr>
<h5 class="fw-bold"> Update</h5>
<hr>
<pre>
<code class="text-primary">
return $this->db->table('users')->update([
'fullname' => $dataUser['inputFullname'],
'username' => $dataUser['inputUsername'],
'password' => $password,
'role' => $dataUser['inputRole'],
], ['id' => $dataUser['userID']]);
</code>
</pre>
<h5 class="fw-bold"> Delete</h5>
<hr>
<pre>
<code class="text-primary">

</div>
<div class="col-sm-4 border">
<h5 class="fw-bold"> Read</h5>
<br>
<h5 class="fw-bold"> Insert</h5>
<br>
<h5 class="fw-bold"> Update</h5>
<br>
<h5 class="fw-bold"> Delete</h5>
public function deleteUser($userID)
{
return $this->db->table('users')->delete(['id' => $userID]);
}

</div>
<div class="col-sm-4 border">
<h5 class="fw-bold"> Read</h5>
<br>
<h5 class="fw-bold"> Insert</h5>
<br>
<h5 class="fw-bold"> Update</h5>
<br>
<h5 class="fw-bold"> Delete</h5>
</code>
</pre>
<?php elseif ($file == 'view') : ?>
<pre>
<code class="text-primary">
&lt;table class=&quot;table&quot;&gt;
&lt;thead&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</code>
</pre>

</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>


<?= $this->endSection(); ?>

0 comments on commit 16864ca

Please sign in to comment.