getById($value, $useConnection); } public function getById($value, $useConnection = 'read') { if (is_null($value)) { throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } $query = 'SELECT * FROM `build_meta` WHERE `id` = :id LIMIT 1'; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':id', $value); if ($stmt->execute()) { if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) { return new BuildMeta($data); } } return null; } public function getByProjectId($value, $limit = null, $useConnection = 'read') { if (is_null($value)) { throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } $add = ''; if ($limit) { $add .= ' LIMIT ' . $limit; } $query = 'SELECT * FROM `build_meta` WHERE `project_id` = :project_id' . $add; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':project_id', $value); if ($stmt->execute()) { $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $map = function ($item) { return new BuildMeta($item); }; $rtn = array_map($map, $res); $count = count($rtn); return array('items' => $rtn, 'count' => $count); } else { return array('items' => array(), 'count' => 0); } } public function getByBuildId($value, $limit = null, $useConnection = 'read') { if (is_null($value)) { throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.'); } $add = ''; if ($limit) { $add .= ' LIMIT ' . $limit; } $query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id' . $add; $stmt = Database::getConnection($useConnection)->prepare($query); $stmt->bindValue(':build_id', $value); if ($stmt->execute()) { $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $map = function ($item) { return new BuildMeta($item); }; $rtn = array_map($map, $res); $count = count($rtn); return array('items' => $rtn, 'count' => $count); } else { return array('items' => array(), 'count' => 0); } } }