/** * Bar constructor. * @param Session $session * @param string[] $barData */ public function __construct($session, $barData) { $this->Session = $session; $this->DB = $session->DB; if (empty(array_diff_key(Bar::ValidArray(), $barData))) { //Loading an existing bar $this->Refresh($barData); $this->Valid = true; } else { if (empty(array_diff_key(Bar::NewArray(), $barData))) { //Creating a new bar $this->Type = $barData['type']; $this->Title = $barData['title']; $this->Description = $barData['description']; $this->CreateStamp = $this->ModifyStamp = (double) microtime(true); $id = (int) $this->DB->Query("\n INSERT INTO tblBars\n (userID, type, title, description, createStamp, modifyStamp)\n VALUES(\n " . (int) $this->Session->ID . "\n , " . $this->DB->Quote($this->Type) . "\n , " . $this->DB->Quote($this->Title) . "\n , " . $this->DB->Quote($this->Description) . "\n , {$this->CreateStamp}\n , {$this->ModifyStamp}\n )\n ", true); if ($id) { $this->ID = $id; $this->Valid = true; } } } }