Skip to content

Commit

Permalink
fixed event triggers and updated insertfrompost method
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Aug 7, 2017
1 parent b0b88a1 commit 3daf5d7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions Model.php
Original file line number Diff line number Diff line change
@@ -559,6 +559,7 @@ public function getTableName()

public function insert()
{
$this->triggerEvent('creating');
$insert_query = $this->createInsertQuery();
$prepared_query = $this->db_engine->prepare($insert_query);

@@ -569,10 +570,13 @@ public function insert()
return $prepared_query;
}

public function insertFromPost($post)
public function insertFromPost()
{
$insert_query = $this->createInsertQueryFromPost($post);
$insert_query->execute();
$this->triggerEvent('creating');
$insert_query = $this->createInsertQueryFromPost($_POST);
$insert_query->execute();
$this->triggerEvent('created');
return $this;
}

public function json()
@@ -679,23 +683,26 @@ public function storeCache()
$this->cache = false;
}

private function callEvent($event)
private function callEvent($event, $trigger)
{
$pos = strrpos($event, "\\");

if ($pos !== false) {
$subject = substr_replace($event, "::", $pos, strlen("\\"));
$subject = $event."::".$trigger;
}
$new_instance = new $this;
$new_instance = $this;
unset($new_instance->Events);
return $subject($new_instance);
}

public function triggerEvent($event)
{
if ($this->Events) {
if (array_key_exists($event, $this->Events)) {
$this->callEvent($this->Events[$event]);
foreach($this->Events as $key => $value){
if ($key == $event) {
$this->callEvent($this->Events[$event], $key);
return;
}
}
}
}

0 comments on commit 3daf5d7

Please sign in to comment.