From 1fa7f23134bb9b9463cc66051993893ca295f49e Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Thu, 21 Sep 2017 16:54:32 -0400 Subject: [PATCH] code for company model --- models/company.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/models/company.php b/models/company.php index 966b990..38ba0af 100644 --- a/models/company.php +++ b/models/company.php @@ -1,43 +1,41 @@ id = $id; $this->name = $name; - $this->age = $age; } } -class People { +class Companies { static function find(){ - $query = file_get_contents(__DIR__ . '/../database/sql/people/find.sql'); + $query = file_get_contents(__DIR__ . '/../database/sql/companies/find.sql'); $result = pg_query($query); - $people = array(); + $companies = array(); while($data = pg_fetch_object($result)){ - $people[] = new Person(intval($data->id), $data->name, intval($data->age)); + $companies[] = new Company(intval($data->id), $data->name); } - return $people; + return $companies; } - static function create($person){ - $query = file_get_contents(__DIR__ . '/../database/sql/people/create.sql'); - $result = pg_query_params($query, array($person->name, $person->age)); + static function create($company){ + $query = file_get_contents(__DIR__ . '/../database/sql/companies/create.sql'); + $result = pg_query_params($query, array($company->name)); return self::find(); } static function delete($id){ - $query = file_get_contents(__DIR__ . '/../database/sql/people/delete.sql'); + $query = file_get_contents(__DIR__ . '/../database/sql/companies/delete.sql'); $result = pg_query_params($query, array($id)); return self::find(); } - static function update($id, $updatedPerson){ - $query = file_get_contents(__DIR__ . '/../database/sql/people/update.sql'); - $result = pg_query_params($query, array($updatedPerson->name, $updatedPerson->age, $id)); + static function update($id, $updatedCompany){ + $query = file_get_contents(__DIR__ . '/../database/sql/companies/update.sql'); + $result = pg_query_params($query, array($updatedCompany->name, $id)); return self::find(); }