From 1f2fe9a29ec15ed627cb0b60e1fe5ae13109ef80 Mon Sep 17 00:00:00 2001 From: homyak Date: Sat, 24 Feb 2024 00:29:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20'h?= =?UTF-8?q?tdocs/includes/repositories/modelrepository.class.php'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/modelrepository.class.php | 102 ------------------ 1 file changed, 102 deletions(-) delete mode 100644 htdocs/includes/repositories/modelrepository.class.php diff --git a/htdocs/includes/repositories/modelrepository.class.php b/htdocs/includes/repositories/modelrepository.class.php deleted file mode 100644 index 92d8d0d..0000000 --- a/htdocs/includes/repositories/modelrepository.class.php +++ /dev/null @@ -1,102 +0,0 @@ -_class = $class; - } - - /** - * Returnes an initiated ModelRepository - * - * @return ModelRepository - */ - public static function getInstance() - { - if (self::$_singletonInstance === null) { - self::$_singletonInstance = new ModelRepository(); - } - - return self::$_singletonInstance; - } - - /** - * Returns an object based on the provided sql - * - * @param string $sql - * @param array $arg - * @return StandardItem - */ - public function getObjectFromSql($sql, $arg) - { - $pdo = PDOConnection::getInstance(); - - $stmt = $pdo->prepareAndExec($sql, $arg); - if ($record = $stmt->fetch(PDO::FETCH_ASSOC)) { - return $this->_getObjectFromRecord($record); - } - - // No object found, return empty object - return new $this->_class(null); - } - - /** - * Returns an array of object based on the provided sql - * - * @param string $sql - * @param array $arg - * @return array - */ - public function getObjectListFromSql($sql, $arg) - { - $pdo = PDOConnection::getInstance(); - - $stmt = $pdo->prepareAndExec($sql, $arg); - $records = $stmt->fetchAll(PDO::FETCH_ASSOC); - if (is_array($records) && !empty($records)) { - return $this->_getObjectListFromRecords($records); - } - - // No object found, return empty array - return []; - } - - /** - * Returns an object based on the provided record - * - * @param array $record - * @return StandardItem - */ - protected function _getObjectFromRecord($record) - { - if (isset($record['id'])) { - $object = new $this->_class($record['id']); - } else { - $object = new $this->_class(0); - } - $object->updateObjectFromArray($record); - return $object; - } - - /** - * Returns a list of objects filled with values from the provided records - * - * @param array $records - * @return Array of StandardItem - */ - protected function _getObjectListFromRecords($records) - { - $list = Array(); - - foreach ($records as $record) { - $list[] = $this->_getObjectFromRecord($record); - } - - return $list; - } -} \ No newline at end of file