Skip to content

Commit

Permalink
Saving and editing hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurko committed Oct 20, 2011
1 parent c0f5d2f commit 6de7d48
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 49 deletions.
2 changes: 1 addition & 1 deletion core/class/Aust.php
Expand Up @@ -640,7 +640,7 @@ public function pegaInformacoesDeEstrutura( $austNode ) {
/**
* Busca na tabela do Aust onde o id é igual à estrutura requisitada.
*/
$result = $this->conexao->query("SELECT * FROM ".Registry::read("austTable")." WHERE id='".$austNode."'" );
$result = $this->conexao->query("SELECT * FROM categorias WHERE id='".$austNode."'" );
return $result;
}

Expand Down
21 changes: 21 additions & 0 deletions core/class/Hook.php
Expand Up @@ -30,6 +30,10 @@ function loadHookEngines(){
return $result;
}

/*
* Each HookEngine has a class. This method return its
* instantiation.
*/
function instantiateHookEngine($engineName = ''){
if( empty($engineName) )
return false;
Expand All @@ -41,6 +45,9 @@ function instantiateHookEngine($engineName = ''){
return $object;
}

/*
* Saves a hook, be it new or update.
*/
function save($post){
$new = false;
if( empty($post['id']) )
Expand Down Expand Up @@ -68,9 +75,23 @@ function save($post){
return false;
}

/*
* Returns all the Hooks created.
*/
function allHooks(){
$sql = 'SELECT * FROM hooks ORDER BY hook_engine';
return Connection::getInstance()->query($sql);
}

function getStructureName($nodeId){
$st = Aust::getInstance()->pegaInformacoesDeEstrutura($nodeId);
$st = reset($st);
return $st["nome"];
}

function find($id){
$sql = "SELECT * FROM hooks WHERE id='{$id}'";
return Connection::getInstance()->query($sql);
}
}
?>
48 changes: 48 additions & 0 deletions core/inc/hooks.inc/_form.inc.php
@@ -0,0 +1,48 @@
<form action="adm_main.php?section=hooks&action=save" method="POST" class="simples">

<?php if( !empty($data["id"]) ){ ?>
<input type="hidden" name="id" value="<?php echo $data["id"] ?>" />
<?php } ?>
<input type="hidden" name="hook_engine" value="<?php echo $_GET["hook_engine"] ?>" />

<div class="field">
<label for="when_action">Quando o usuário: </label>
<select name="when_action" id="when_action">
<option value="delete_record" <?php if(@$data['when_action']=='delete_record') echo "selected='selected'" ?>>excluir um registro</option>
<option value="approve_record" <?php if(@$data['when_action']=='approve_record') echo "selected='selected'" ?>>aprovar um registro</option>
<option value="save_record" <?php if(@$data['when_action']=='save_record') echo "selected='selected'" ?>>salvar um registro</option>
</select>
</div>
<div class="field">
<label for="node_id">Relacionado a uma estrutura:</label>
<?php $structures = Aust::getInstance()->getStructures(); ?>
<select name="node_id">
<?php foreach( $structures as $site){ ?>

<optgroup label="<?php echo $site["Site"]["nome"] ?>">
<?php foreach( $site["Structures"] as $structure ){ ?>
<option value="<?php echo $structure["id"]; ?>" <?php if(@$data['node_id']==$structure["id"]) echo "selected='selected'" ?>>
&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $structure["nome"]; ?>
</option>
<?php } ?>
</optgroup>

<?php } ?>
</select>
</div>
<div class="field">
<label for="description">Descrição</label>
<textarea name="description" id="description" rows="5"><?php echo @$data['description'] ?></textarea>
</div>
<div class="field">
<label for="perform">Realizar seguinte ação</label>
<textarea name="perform" id="perform" rows="12"><?php echo @$data['perform'] ?></textarea>
<span class="explanation">
Campo <em>Perform</em>.
</span>
</div>
<br>
<div class="field">
<input type="submit" value="Enviar" name="submit" />
</div>
</form>
13 changes: 13 additions & 0 deletions core/inc/hooks.inc/edit.inc.php
@@ -0,0 +1,13 @@
<div class="title_column">
<h2>
Editar Hook
</h2>
</div>

<?php
$hook = new Hook();
$data = $hook->find($_GET["id"]);
$data = reset($data);

include(INC_DIR."hooks.inc/_form.inc.php");
?>
13 changes: 11 additions & 2 deletions core/inc/hooks.inc/index.inc.php
Expand Up @@ -51,10 +51,19 @@

<div class="item">
<label class="configuration_variable_label" for="<?php echo $key ?>_input">
<?php echo $attributes["hook_engine"] ?>
<?php
echo "<strong>".$attributes["hook_engine"]."</strong>";
if( !empty($attributes["node_id"]) ){
echo ', '.$hooksClass->getStructureName( $attributes["node_id"] );
}
if( !empty($attributes["when_action"]) ){
echo ', when '.$attributes["when_action"];
}

?>
</label>
<div class="input">

<a href="adm_main.php?section=hooks&action=edit&hook_engine=<?php echo $hook ?>&id=<?php echo $attributes["id"] ?>">Editar</a>
</div>
</div>

Expand Down
45 changes: 1 addition & 44 deletions core/inc/hooks.inc/new.inc.php
Expand Up @@ -8,48 +8,5 @@
$hooksObject = new Hook();
$hook = $hooksObject->instantiateHookEngine($_GET["hook_engine"]);

include(INC_DIR."hooks.inc/_form.inc.php")
?>
<form action="adm_main.php?section=hooks&action=save" method="POST" class="simples">
<input type="hidden" name="hook_engine" value="<?php echo $_GET["hook_engine"] ?>" />

<div class="field">
<label for="when_action">Quando o usuário: </label>
<select name="when_action" id="when_action">
<option value="delete_record" <?php if(@$data['when_action']=='delete_record') echo "selected='selected'" ?>>excluir um registro</option>
<option value="approve_record" <?php if(@$data['when_action']=='approve_record') echo "selected='selected'" ?>>aprovar um registro</option>
<option value="save_record" <?php if(@$data['when_action']=='save_record') echo "selected='selected'" ?>>salvar um registro</option>
</select>
</div>
<div class="field">
<label for="node_id">Relacionado a uma estrutura:</label>
<?php $structures = Aust::getInstance()->getStructures(); ?>
<select name="node_id">
<?php foreach( $structures as $site){ ?>

<optgroup label="<?php echo $site["Site"]["nome"] ?>">
<?php foreach( $site["Structures"] as $structure ){ ?>
<option value="<?php echo $structure["id"]; ?>" <?php if(@$data['node_id']==$structure["id"]) echo "selected='selected'" ?>>
&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $structure["nome"]; ?>
</option>
<?php } ?>
</optgroup>

<?php } ?>
</select>
</div>
<div class="field">
<label for="description">Descrição</label>
<textarea name="description" id="description" rows="5"><?php echo @$data['description'] ?></textarea>
</div>
<div class="field">
<label for="perform">Realizar seguinte ação</label>
<textarea name="perform" id="perform" rows="12"><?php echo @$data['perform'] ?></textarea>
<span class="explanation">
Campo <em>Perform</em>.
</span>
</div>
<br>
<div class="field">
<input type="submit" value="Enviar" name="submit" />
</div>
</form>
2 changes: 1 addition & 1 deletion tests/config/database.php
Expand Up @@ -9,7 +9,7 @@ class DATABASE_CONFIG
{
static $dbConn = array(
'server' => '127.0.0.1',
'database' => 'aust',
'database' => 'aust_test_v0_2',
'username' => 'root',
'password' => '',
'encoding' => 'utf8',
Expand Down
6 changes: 5 additions & 1 deletion tests/core/class/HookTest.php
Expand Up @@ -9,9 +9,13 @@ public function setUp(){
}

function testLoadHookEngineDirectories(){

$this->assertArrayHasKey( 'email_sender', $this->obj->loadHookEngines() );
}

function testGetStructureName(){
Connection::getInstance()->exec("INSERT INTO categorias (nome) VALUES ('Test777')");
$stId = Connection::getInstance()->lastInsertId();
$this->assertEquals( 'Test777', $this->obj->getStructureName($stId) );
}
}
?>

0 comments on commit 6de7d48

Please sign in to comment.