Created
March 25, 2017 15:20
-
-
Save Deviad/0a8b4b7b82acecd4453c6f818cfb90c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Entity; | |
use Db\DbObj; | |
class FormField | |
{ | |
public $the_table; | |
public $id; | |
public $event_id; | |
public $type; | |
public $language; | |
public $title; | |
public $slug; | |
public $values; | |
private $db; | |
public function __construct() { | |
$this->the_table = "`fields`"; | |
$this->db = new DbObj(); | |
} | |
public function getFormFields($event_id, $language) | |
{ | |
// $the_attrs = 'event_id, language'; | |
$projection = '`id`, `event_id`, `type`, `language`, `title`, `slug`, `values`'; | |
$condition = " WHERE `event_id` = '{$event_id}' AND `language` = '{$language}'"; | |
$fetched_array = $this->db->getObj($projection, $this->the_table, $condition); | |
return $fetched_array; | |
} | |
public function insertFormFields() { | |
$the_attrs = ['id','event_id', 'type', 'language', 'title', 'slug', 'values']; | |
$filled_attrs_values = array(); | |
foreach($the_attrs as $attr) { | |
if ($this->$attr) { | |
$filled_attrs_values['attrs'][] = "`{$attr}`"; | |
$this_attr_string = (string)$this->$attr; | |
$filled_attrs_values['values'][] = "'$this_attr_string'"; | |
} | |
} | |
//converting array to string | |
$the_filled_attrs = implode(", ", $filled_attrs_values['attrs']); | |
$the_filled_values = implode(", ", $filled_attrs_values['values']); | |
$this->db->addObj($this->the_table, $the_filled_attrs, $the_filled_values); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment