Skip to content

Commit 019cb5b

Browse files
authored
Merge pull request #6 from TAMULib/issue-5
Issue 5
2 parents 233afa6 + dba1755 commit 019cb5b

15 files changed

+233
-7
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
namespace App\Classes\Controllers;
3+
use App\Classes\Data as AppClasses;
4+
use Core\Classes as Core;
5+
6+
class DynamicRepoController extends Core\AbstractController {
7+
private $dynamicRepo;
8+
9+
protected function configure() {
10+
$this->dynamicRepo = $this->getSite()->getDataRepository("DynamicRepoExample");
11+
12+
$this->getPage()->setTitle("Manage Dynamic Repo Example Entries");
13+
$this->getPage()->setOptions(array(
14+
array("name"=>"list"),
15+
array("name"=>"add","action"=>"add","modal"=>true)));
16+
$this->getPage()->setIsSearchable(true);
17+
}
18+
19+
protected function remove() {
20+
$data = $this->getSite()->getSanitizedInputData();
21+
if (isset($data['id']) && is_numeric($data['id']) && $this->dynamicRepo->removeById($data['id'])) {
22+
$this->getSite()->addSystemMessage('Repo entry removed');
23+
} else {
24+
$this->getSite()->addSystemError('Error removing repo entry');
25+
}
26+
}
27+
28+
protected function insert() {
29+
$data = $this->getSite()->getSanitizedInputData();
30+
if (isset($data['entry']) && $this->dynamicRepo->add($data['entry'])) {
31+
$this->getSite()->addSystemMessage('Repo entry added');
32+
} else {
33+
$this->getSite()->addSystemError('Error adding repo entry');
34+
}
35+
}
36+
37+
protected function add() {
38+
$this->getPage()->setSubTitle('New Repo Entry');
39+
$this->setViewName('entries.add');
40+
}
41+
42+
protected function update() {
43+
$data = $this->getSite()->getSanitizedInputData();
44+
if (isset($data['entry']) && (isset($data['id']) && is_numeric($data['id'])) && $this->dynamicRepo->update($data['id'],$data['entry'])) {
45+
$this->getSite()->addSystemMessage('Entry updated');
46+
} else {
47+
$this->getSite()->addSystemError('Error updating entry');
48+
}
49+
}
50+
51+
protected function edit() {
52+
$this->getPage()->setSubTitle('Update Entry');
53+
$data = $this->getSite()->getSanitizedInputData();
54+
if (isset($data['id']) && is_numeric($data['id']) && ($entry = $this->dynamicRepo->getById($data['id']))) {
55+
$this->getSite()->getViewRenderer()->registerViewVariable("entry",$entry);
56+
$this->setViewName('entries.edit');
57+
}
58+
}
59+
60+
protected function search() {
61+
$data = $this->getSite()->getSanitizedInputData();
62+
if (isset($data['term'])) {
63+
$this->getSite()->getViewRenderer()->registerViewVariable("entries",$this->dynamicRepo->search($data['term']));
64+
$this->setViewName("entries.list");
65+
} else {
66+
$site->addSystemError('There was an error with the search');
67+
}
68+
}
69+
70+
protected function loadDefault() {
71+
$this->getPage()->setSubTitle('Repo Entries');
72+
$this->getSite()->getViewRenderer()->registerViewVariable("entries", $this->dynamicRepo->get());
73+
$this->setViewName('entries.list');
74+
}
75+
}

App/Classes/Controllers/WidgetsController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ protected function insert() {
4545

4646
protected function add() {
4747
$this->getPage()->setSubTitle('New Widget');
48-
$this->getSite()->getViewRenderer()->setView("widgets.add");
4948
$this->setViewName('widgets.add');
5049
}
5150

@@ -62,7 +61,7 @@ protected function edit() {
6261
$this->getPage()->setSubTitle('Update Widget');
6362
$data = $this->getSite()->getSanitizedInputData();
6463
if (isset($data['id']) && is_numeric($data['id']) && ($widget = $this->widgetsRepo->getById($data['id']))) {
65-
$widget = $this->getSite()->getViewRenderer()->registerViewVariable("widget",$widget);
64+
$this->getSite()->getViewRenderer()->registerViewVariable("widget",$widget);
6665
$this->setViewName('widgets.edit');
6766
}
6867
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace App\Config;
3+
use Core\Classes\Configuration as CoreConfiguration;
4+
5+
define('DYNAMIC_REPOSITORY_KEY', 'dynamicRepositories');
6+
7+
$GLOBALS[DYNAMIC_REPOSITORY_KEY] = array("DynamicRepoExample"=>new CoreConfiguration\DynamicDatabaseRepositoryConfiguration('dynamic_repo_ex','id','name',null,array('name','description')));
8+
?>

App/Config/config.pages.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
$sitePages = array(
2424
"widgets" => new CoreClasses\CoreSitePage("widgets","widgets",SECURITY_USER),
25+
"DynamicRepo" => new CoreClasses\CoreSitePage("dynamic repo","dynamic-repo",SECURITY_USER),
2526
"users" => new CoreClasses\CoreSitePage("users","users",SECURITY_ADMIN));
2627

2728
/* If you'd like to use the app level SitePage, use the following $sitePages array, instead, and uncomment the AppClasses namespace alias at the top of this file.
2829
$sitePages = array(
2930
"widgets" => new AppClasses\SitePage("widgets","widgets",SECURITY_USER),
31+
"DynamicRepo" => new AppClasses\SitePage("dynamic repo","dynamic-repo",SECURITY_USER),
3032
"users" => new AppClasses\SitePage("users","users",SECURITY_ADMIN));
3133
*/
3234
?>

App/Lib/loader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
require PATH_CORE_LIB.'/autoload.php';
2727
}
2828

29+
require_once PATH_CONFIG.'config.dynamic.repositories.php';
2930
require_once PATH_CONFIG.'config.pages.php';
3031

3132
$config = get_defined_constants(true)["user"];
@@ -34,6 +35,11 @@
3435
unset($sitePages);
3536
}
3637

38+
if (!empty($GLOBALS[DYNAMIC_REPOSITORY_KEY])) {
39+
$config[DYNAMIC_REPOSITORY_KEY] = $GLOBALS[DYNAMIC_REPOSITORY_KEY];
40+
unset($GLOBALS[DYNAMIC_REPOSITORY_KEY]);
41+
}
42+
3743
if (!empty($forceRedirectUrl)) {
3844
$config['forceRedirectUrl'] = $forceRedirectUrl;
3945
unset($forceRedirectUrl);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<form class="do-submit" name="addentry" method="POST" action="<?php echo $app_http;?>">
2+
<input type="hidden" name="action" value="insert" />
3+
<div class="form-group">
4+
<label for="entry[name]">Name</label>
5+
<input class="form-control" type="text" name="entry[name]" />
6+
</div>
7+
<div class="form-group">
8+
<label for="entry[description]">Description</label>
9+
<textarea class="form-control" name="entry[description]"></textarea>
10+
</div>
11+
<input class="btn btn-default" type="submit" name="submitentry" value="Add Entry" />
12+
</form>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
$entry = $parameters['entry'];
3+
?>
4+
<form class="do-submit" name="editentry" method="POST" action="<?php echo $app_http;?>">
5+
<input type="hidden" name="action" value="update" />
6+
<input type="hidden" name="id" value="<?php echo $entry['id'];?>" />
7+
<div class="form-group">
8+
<label for="entry[name]">Name</label>
9+
<input class="form-control" type="text" name="entry[name]" value="<?php echo $entry['name'];?>" />
10+
</div>
11+
<div class="form-group">
12+
<label for="entry[description]">Description</label>
13+
<textarea class="form-control" name="entry[description]"><?php echo $entry['description'];?></textarea>
14+
</div>
15+
<input class="btn btn-default" type="submit" name="submitentry" value="Update Entry" />
16+
</form>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<div class="do-results">
2+
<?php
3+
if ($parameters['entries']) {
4+
?>
5+
<table class="table">
6+
<tr>
7+
<th>Name</th>
8+
<th>Actions</th>
9+
</tr>
10+
<?php
11+
foreach ($parameters['entries'] as $entry) {
12+
echo "<tr>
13+
<td>{$entry['name']}</td>
14+
<td class=\"capitalize\">";
15+
echo ' <a class="btn btn-default do-loadmodal" href="'.$app_http.'?action=edit&id='.$entry['id'].'">Edit</a>
16+
<form class="inline-block do-submit-confirm" name="removeentry" method="POST" action="'.$app_http.'">
17+
<input type="hidden" name="action" value="remove" />
18+
<input type="hidden" name="id" value="'.$entry['id'].'" />
19+
<input class="btn btn-default" type="submit" name="submitremove" value="Remove" />
20+
</form>';
21+
echo "
22+
</td>
23+
</tr>";
24+
}
25+
?>
26+
</table>
27+
<?php
28+
} else {
29+
echo 'No entries yet!';
30+
}
31+
?>
32+
</div>

App/Views/bootstrap/widgets.add.view.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
echo '<form class="do-submit" name="addbuilding" method="POST" action="'.$app_http.'">
2+
echo '<form class="do-submit" name="addwidget" method="POST" action="'.$app_http.'">
33
<input type="hidden" name="action" value="insert" />
44
<div class="form-group">
55
<label for="widget[name]">Name</label>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
echo '<form class="do-submit" name="addbuilding" method="POST" action="'.$app_http.'">
3+
<input type="hidden" name="action" value="insert" />
4+
<div class="column column-half">
5+
<label for="entry[name]">Name</label>
6+
<input type="text" name="entry[name]" />
7+
<label for="entry[description]">Description</label>
8+
<textarea name="entry[description]"></textarea>
9+
</div>
10+
<input type="submit" name="submitentry" value="Add Entry" />
11+
</form>';
12+
?>

0 commit comments

Comments
 (0)