Skip to content

Commit

Permalink
add required
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Jun 25, 2020
1 parent 1e656b3 commit ac30afd
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 47 deletions.
14 changes: 10 additions & 4 deletions skel/pages/add().php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php echo '<?php' ?>
<?php foreach ($belongsTo as $relation): ?>
$<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?> = DB::selectPairs('select `<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_COLUMN_NAME']; ?>`,`<?php echo $findDisplayField($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']); ?>` from `<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>`');
<?php foreach ($belongsTo as $relation): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; $referencedColumn = $relation['KEY_COLUMN_USAGE']['REFERENCED_COLUMN_NAME']; ?>
$<?php echo $referencedTable; ?> = DB::selectPairs('select `<?php echo $referencedColumn; ?>`,`<?php echo $findDisplayField($referencedTable); ?>` from `<?php echo $referencedTable; ?>`');
<?php endforeach;?>
if ($_SERVER['REQUEST_METHOD']=='POST') {
$data = $_POST;
<?php foreach ($belongsTo as $relation): ?>
if (!isset($<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>[$data['<?php echo $table; ?>']['<?php echo $relation['KEY_COLUMN_USAGE']['COLUMN_NAME']; ?>']])) $errors['<?php echo $table; ?>[<?php echo $relation['KEY_COLUMN_USAGE']['COLUMN_NAME']; ?>]']='<?php echo ucfirst($singularize($humanize($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']))); ?> not found';
<?php foreach ($belongsTo as $relation): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; $column = $relation['KEY_COLUMN_USAGE']['COLUMN_NAME']; ?>
if (!isset($<?php echo $referencedTable; ?>[$data['<?php echo $table; ?>']['<?php echo $column; ?>']])) $errors['<?php echo $table; ?>[<?php echo $column; ?>]']='<?php echo ucfirst($singularize($humanize($referencedTable))); ?> not found';
<?php endforeach;?>
<?php foreach ($fields as $field): if (!$field['COLUMNS']['IS_NULLABLE']): $column = $field['COLUMNS']['COLUMN_NAME']; ?>
if (!$data['<?php echo $table; ?>']['<?php echo $column; ?>']) $errors['<?php echo $table; ?>[<?php echo $column; ?>]']='<?php echo ucfirst($humanize($column)); ?> must be filled';
<?php endif; endforeach;?>
<?php foreach ($fields as $field): if ($field['COLUMNS']['IS_NULLABLE']): $column = $field['COLUMNS']['COLUMN_NAME']; ?>
if (!$data['<?php echo $table; ?>']['<?php echo $column; ?>']) $data['<?php echo $table; ?>']['<?php echo $column; ?>']=null;
<?php endif; endforeach;?>
if (!isset($errors)) {
$id = DB::insert('INSERT INTO `<?php echo $table; ?>` (<?php echo implode(', ', array_map(function ($field) {return '`' . $field['COLUMNS']['COLUMN_NAME'] . '`';}, $fields)); ?>) VALUES (<?php echo implode(', ', array_map(function () {return '?';}, $fields)); ?>)', <?php echo implode(', ', array_map(function ($field) use ($table) {return "\$data['$table']['" . $field['COLUMNS']['COLUMN_NAME'] . "']";}, $fields)); ?>);
if ($id) {
Expand Down
26 changes: 13 additions & 13 deletions skel/pages/add(admin).phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
<h1>New <?php echo $singularize($humanize($table)); ?></h1>
</div>
<form method="post">
<?php foreach ($fields as $field): ?>
<div class="form-group <?php echo '<?php' ?> e(isset($errors['<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]'])?'has-error':''); ?>">
<?php if ($relation = $findBelongsTo($field['COLUMNS']['COLUMN_NAME'])): ?>
<label class="control-label" for="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]"><?php echo ucfirst($singularize($humanize($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']))); ?></label>
<select class="form-control" name="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]" id="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]">
<option value=""<?php echo '<?php' ?> e(''==$data['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME'] ?>']?' selected="selected"':''); ?>>...</option>
<?php echo '<?php' ?> foreach ($<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?> as $key => $value): ?>
<option value="<?php echo '<?php' ?> e($key); ?>"<?php echo '<?php' ?> e($key==$data['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME'] ?>']?' selected="selected"':''); ?>><?php echo '<?php' ?> e($value); ?></option>
<?php echo '<?php' ?> endforeach; ?>
</select>
<?php foreach ($fields as $field): $column = $field['COLUMNS']['COLUMN_NAME']; $optional = $field['COLUMNS']['IS_NULLABLE'];?>
<div class="form-group <?php echo $optional?'optional ':''; ?><?php echo '<?php' ?> e(isset($errors['<?php echo $table; ?>[<?php echo $column; ?>]'])?'has-error':''); ?>">
<?php if ($relation = $findBelongsTo($column)): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME'];?>
<label class="control-label" for="<?php echo $table; ?>[<?php echo $column; ?>]"><?php echo ucfirst($singularize($humanize($referencedTable))); ?></label>
<select class="form-control" name="<?php echo $table; ?>[<?php echo $column; ?>]" id="<?php echo $table; ?>[<?php echo $column; ?>]"<?php echo $optional?'':' required'; ?>>
<option value=""<?php echo '<?php' ?> e(''==$data['<?php echo $table; ?>']['<?php echo $column ?>']?' selected="selected"':''); ?>>...</option>
<?php echo '<?php' ?> foreach ($<?php echo $referencedTable; ?> as $key => $value): ?>
<option value="<?php echo '<?php' ?> e($key); ?>"<?php echo '<?php' ?> e($key==$data['<?php echo $table; ?>']['<?php echo $column ?>']?' selected="selected"':''); ?>><?php echo '<?php' ?> e($value); ?></option>
<?php echo '<?php' ?> endforeach; ?>
</select>
<?php else: ?>
<label class="control-label" for="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]"><?php echo ucfirst($humanize($field['COLUMNS']['COLUMN_NAME'])); ?></label>
<input class="form-control" name="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]" type="text" value="<?php echo '<?php' ?> e($data['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>']); ?>" id="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]" />
<label class="control-label" for="<?php echo $table; ?>[<?php echo $column; ?>]"><?php echo ucfirst($humanize($column)); ?></label>
<input class="form-control" name="<?php echo $table; ?>[<?php echo $column; ?>]" type="text" value="<?php echo '<?php' ?> e($data['<?php echo $table; ?>']['<?php echo $column; ?>']); ?>" id="<?php echo $table; ?>[<?php echo $column; ?>]" />
<?php endif;?>
<span class="help-block"><?php echo '<?php' ?> e(isset($errors['<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]'])?$errors['<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]']:''); ?></span>
<span class="help-block"><?php echo '<?php' ?> e(isset($errors['<?php echo $table; ?>[<?php echo $column; ?>]'])?$errors['<?php echo $table; ?>[<?php echo $column; ?>]']:''); ?></span>
</div>
<?php endforeach;?>

Expand Down
14 changes: 10 additions & 4 deletions skel/pages/edit($id).php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php echo '<?php' ?>
<?php foreach ($belongsTo as $relation): ?>
$<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?> = DB::selectPairs('select `<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_COLUMN_NAME']; ?>`,`<?php echo $findDisplayField($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']); ?>` from `<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>`');
<?php foreach ($belongsTo as $relation): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; $referencedColumn = $relation['KEY_COLUMN_USAGE']['REFERENCED_COLUMN_NAME']; ?>
$<?php echo $referencedTable; ?> = DB::selectPairs('select `<?php echo $referencedColumn; ?>`,`<?php echo $findDisplayField($referencedTable); ?>` from `<?php echo $referencedTable; ?>`');
<?php endforeach;?>
if ($_SERVER['REQUEST_METHOD']=='POST') {
$data = $_POST;
<?php foreach ($belongsTo as $relation): ?>
if (!isset($<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>[$data['<?php echo $table; ?>']['<?php echo $relation['KEY_COLUMN_USAGE']['COLUMN_NAME']; ?>']])) $errors['<?php echo $table; ?>[<?php echo $relation['KEY_COLUMN_USAGE']['COLUMN_NAME']; ?>]']='<?php echo ucfirst($singularize($humanize($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']))); ?> not found';
<?php foreach ($belongsTo as $relation): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; $column = $relation['KEY_COLUMN_USAGE']['COLUMN_NAME']; ?>
if (!isset($<?php echo $referencedTable; ?>[$data['<?php echo $table; ?>']['<?php echo $column; ?>']])) $errors['<?php echo $table; ?>[<?php echo $column; ?>]']='<?php echo ucfirst($singularize($humanize($referencedTable))); ?> not found';
<?php endforeach;?>
<?php foreach ($fields as $field): if (!$field['COLUMNS']['IS_NULLABLE']): $column = $field['COLUMNS']['COLUMN_NAME']; ?>
if (!$data['<?php echo $table; ?>']['<?php echo $column; ?>']) $errors['<?php echo $table; ?>[<?php echo $column; ?>]']='<?php echo ucfirst($humanize($column)); ?> must be filled';
<?php endif; endforeach;?>
<?php foreach ($fields as $field): if ($field['COLUMNS']['IS_NULLABLE']): $column = $field['COLUMNS']['COLUMN_NAME']; ?>
if (!$data['<?php echo $table; ?>']['<?php echo $column; ?>']) $data['<?php echo $table; ?>']['<?php echo $column; ?>']=null;
<?php endif; endforeach;?>
if (!isset($errors)) {
$rowsAffected = DB::update('UPDATE `<?php echo $table; ?>` SET <?php echo implode(', ', array_map(function ($field) {return '`' . $field['COLUMNS']['COLUMN_NAME'] . '`=?';}, $fields)); ?> WHERE `id`=?', <?php echo implode(', ', array_map(function ($field) use ($table) {return "\$data['$table']['" . $field['COLUMNS']['COLUMN_NAME'] . "']";}, $fields)); ?>, $id);
if ($rowsAffected!==false) {
Expand Down
26 changes: 13 additions & 13 deletions skel/pages/edit(admin).phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
<h1>Edit <?php echo $singularize($humanize($table)); ?></h1>
</div>
<form method="post">
<?php foreach ($fields as $field): ?>
<div class="form-group <?php echo '<?php' ?> e(isset($errors['<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]'])?'has-error':''); ?>">
<?php if ($relation = $findBelongsTo($field['COLUMNS']['COLUMN_NAME'])): ?>
<label class="control-label" for="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]"><?php echo ucfirst($singularize($humanize($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']))); ?></label>
<select class="form-control" name="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]" id="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]">
<option value=""<?php echo '<?php' ?> e(''==$data['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME'] ?>']?' selected="selected"':''); ?>>...</option>
<?php echo '<?php' ?> foreach ($<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?> as $key => $value): ?>
<option value="<?php echo '<?php' ?> e($key); ?>"<?php echo '<?php' ?> e($key==$data['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME'] ?>']?' selected="selected"':''); ?>><?php echo '<?php' ?> e($value); ?></option>
<?php echo '<?php' ?> endforeach; ?>
</select>
<?php foreach ($fields as $field): $column = $field['COLUMNS']['COLUMN_NAME']; $optional = $field['COLUMNS']['IS_NULLABLE'];?>
<div class="form-group <?php echo $optional?'optional ':''; ?><?php echo '<?php' ?> e(isset($errors['<?php echo $table; ?>[<?php echo $column; ?>]'])?'has-error':''); ?>">
<?php if ($relation = $findBelongsTo($column)): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME'];?>
<label class="control-label" for="<?php echo $table; ?>[<?php echo $column; ?>]"><?php echo ucfirst($singularize($humanize($referencedTable))); ?></label>
<select class="form-control" name="<?php echo $table; ?>[<?php echo $column; ?>]" id="<?php echo $table; ?>[<?php echo $column; ?>]"<?php echo $optional?'':' required'; ?>>
<option value=""<?php echo '<?php' ?> e(''==$data['<?php echo $table; ?>']['<?php echo $column ?>']?' selected="selected"':''); ?>>...</option>
<?php echo '<?php' ?> foreach ($<?php echo $referencedTable; ?> as $key => $value): ?>
<option value="<?php echo '<?php' ?> e($key); ?>"<?php echo '<?php' ?> e($key==$data['<?php echo $table; ?>']['<?php echo $column ?>']?' selected="selected"':''); ?>><?php echo '<?php' ?> e($value); ?></option>
<?php echo '<?php' ?> endforeach; ?>
</select>
<?php else: ?>
<label class="control-label" for="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]"><?php echo ucfirst($humanize($field['COLUMNS']['COLUMN_NAME'])); ?></label>
<input class="form-control" name="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]" type="text" value="<?php echo '<?php' ?> e($data['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>']); ?>" id="<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]" />
<label class="control-label" for="<?php echo $table; ?>[<?php echo $column; ?>]"><?php echo ucfirst($humanize($column)); ?></label>
<input class="form-control" name="<?php echo $table; ?>[<?php echo $column; ?>]" type="text" value="<?php echo '<?php' ?> e($data['<?php echo $table; ?>']['<?php echo $column; ?>']); ?>" id="<?php echo $table; ?>[<?php echo $column; ?>]" />
<?php endif;?>
<span class="help-block"><?php echo '<?php' ?> e(isset($errors['<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]'])?$errors['<?php echo $table; ?>[<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>]']:''); ?></span>
<span class="help-block"><?php echo '<?php' ?> e(isset($errors['<?php echo $table; ?>[<?php echo $column; ?>]'])?$errors['<?php echo $table; ?>[<?php echo $column; ?>]']:''); ?></span>
</div>
<?php endforeach;?>

Expand Down
8 changes: 4 additions & 4 deletions skel/pages/index(admin).phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<table class="table">
<thead>
<tr>
<?php foreach ($fields as $field):
if ($relation = $findBelongsTo($field['COLUMNS']['COLUMN_NAME'])): ?>
<?php foreach ($fields as $field): $column = $field['COLUMNS']['COLUMN_NAME'];
if ($relation = $findBelongsTo($field['COLUMNS']['COLUMN_NAME'])): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>
<th><?php echo ucfirst($singularize($humanize($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']))); ?></th>
<?php else: ?>
<th><?php echo ucfirst($humanize($field['COLUMNS']['COLUMN_NAME'])); ?></th>
Expand All @@ -14,8 +14,8 @@
<tbody>
<?php echo '<?php' ?> foreach ($data as $row): ?>
<tr>
<?php foreach ($fields as $field):
if ($relation = $findBelongsTo($field['COLUMNS']['COLUMN_NAME'])): ?>
<?php foreach ($fields as $field): $column = $field['COLUMNS']['COLUMN_NAME'];
if ($relation = $findBelongsTo($field['COLUMNS']['COLUMN_NAME'])): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>
<td><?php echo '<?php' ?> e($<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>[$row['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>']]);?></td>
<?php else: ?>
<td><?php echo '<?php' ?> e($row['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>']);?></td>
Expand Down
4 changes: 2 additions & 2 deletions skel/pages/view($id).php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php echo '<?php' ?>
$data = DB::selectOne('select * from `<?php echo $table; ?>` where `id`=?',$id);
<?php foreach ($belongsTo as $relation): ?>
$<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?> = DB::selectPairs('select `<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_COLUMN_NAME']; ?>`,`<?php echo $findDisplayField($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']); ?>` from `<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>`');
<?php foreach ($belongsTo as $relation): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; $referencedColumn = $relation['KEY_COLUMN_USAGE']['REFERENCED_COLUMN_NAME']; ?>
$<?php echo $referencedTable; ?> = DB::selectPairs('select `<?php echo $referencedColumn; ?>`,`<?php echo $findDisplayField($referencedTable); ?>` from `<?php echo $referencedTable; ?>`');
<?php endforeach; ?>
14 changes: 7 additions & 7 deletions skel/pages/view(admin).phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<h1>View <?php echo $singularize($humanize($table)); ?></h1>
</div>
<div>
<?php foreach ($fields as $field): ?>
<?php foreach ($fields as $field): $column = $field['COLUMNS']['COLUMN_NAME']; ?>
<dl>
<?php if ($relation = $findBelongsTo($field['COLUMNS']['COLUMN_NAME'])): ?>
<dt><?php echo ucfirst($singularize($humanize($relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']))); ?></dt>
<?php if ($relation = $findBelongsTo($column)): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>
<dt><?php echo ucfirst($singularize($humanize($referencedTable))); ?></dt>
<?php else: ?>
<dt><?php echo ucfirst($humanize($field['COLUMNS']['COLUMN_NAME'])); ?></dt>
<dt><?php echo ucfirst($humanize($column)); ?></dt>
<?php endif;?>
<?php if ($relation = $findBelongsTo($field['COLUMNS']['COLUMN_NAME'])): ?>
<dd><?php echo '<?php' ?> e($<?php echo $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>[$data['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>']]);?></dd>
<?php if ($relation = $findBelongsTo($column)): $referencedTable = $relation['KEY_COLUMN_USAGE']['REFERENCED_TABLE_NAME']; ?>
<dd><?php echo '<?php' ?> e($<?php echo $referencedTable; ?>[$data['<?php echo $table; ?>']['<?php echo $column; ?>']]);?></dd>
<?php else: ?>
<dd><?php echo '<?php' ?> e($data['<?php echo $table; ?>']['<?php echo $field['COLUMNS']['COLUMN_NAME']; ?>']);?></dd>
<dd><?php echo '<?php' ?> e($data['<?php echo $table; ?>']['<?php echo $column; ?>']);?></dd>
<?php endif;?>
</dl>
<?php endforeach;?>
Expand Down

0 comments on commit ac30afd

Please sign in to comment.