Nimbin[12]?Web & Tools / dienstplancreator / api/objects/roster_editable_cell_right_class.php

dienstplancreator git · main

Dienstplan (roster) creator, PHP/JS web app

php javascript roster web · first commit 2023-07-13 · last commit 2023-09-14 (3 years ago) · synced 3 days ago · upstream: github.com/nimbin2/dienstplancreator

JavaScript 50% PHP 40.5% CSS 8.5%
git clone https://git.christianimmanuel.de/web-tools/dienstplancreator.gitwget https://git.christianimmanuel.de/web-tools/dienstplancreator/archive/dienstplancreator.tar.gz
api/objects/roster_editable_cell_right_class.php 4.7 KB · 132 lines raw
<?php

class Roster_editable_cell_right
{
	private $data_id;
	private $id;
	private $yearweek;
	private $text;
	/* Constructor */
	public function __construct() {
		$this->data_id = NULL;
		$this->id = NULL;
		$this->yearweek = NULL;
		$this->text = NULL;
	}
	
	/* Destructor */
	public function __destruct() { }

	public function add(int $data_id, string $id, string $yearweek, string $text): int {
		global $pdo;
		$data_id	= trim($data_id);
		$id     	= trim($id);
		$yearweek	= trim($yearweek);
		$text	    = trim($text);

		$query = 'INSERT INTO datadienstplandb.roster_editable_cell_right (data_id, id, yearweek, text) VALUES (:data_id, :id, :yearweek, :text)';

        $values = array(':data_id' => $data_id, ':id' => $id, ':yearweek' => $yearweek, ':text' => $text);

		try
		{
			$res = $pdo->prepare($query);
			$res->execute($values);
		}
		catch (PDOException $e)
		{
		   throw new Exception('Database query error roster_editable_cell_right_class.php');
		}

		return $pdo->lastInsertId();
	}
    public function get(int $data_id, string $yearweek) {
        global $pdo;
		$data_id    = trim($data_id);
		$yearweek	= trim($yearweek);
        $query          = 'SELECT * FROM datadienstplandb.roster_editable_cell_right WHERE data_id = :data_id AND yearweek = :yearweek';
        $values         = array(':data_id' => $data_id, ':yearweek' => $yearweek);

        try {
            $res = $pdo->prepare($query);
            $res->execute($values);
        }
        catch (PDOException $e) {
            throw new Exception('Database query error roster_editable_cell_right_class.php');
        }

        $roster_editable_cell_right=array();
        $roster_editable_cell_right["roster_editable_cell_right"]=array();
        while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
            extract($row);
			$roster_editable_cell_right_item=array(
				"id"        => $id,
				"yearweek"  => $yearweek,
				"text"      => $text
			);
			array_push($roster_editable_cell_right["roster_editable_cell_right"], $roster_editable_cell_right_item);
        }
        return $roster_editable_cell_right;
    }
    public function getWhereId(int $data_id, $yearweek, $id) {
        global $pdo;
		$data_id    = trim($data_id);
		$yearweek	= trim($yearweek);
        $query          = 'SELECT * FROM datadienstplandb.roster_editable_cell_right WHERE data_id = :data_id AND yearweek = :yearweek AND id = :id';
        $values         = array(':data_id' => $data_id, ':yearweek' => $yearweek, ':id' => $id);

        try {
            $res = $pdo->prepare($query);
            $res->execute($values);
        }
        catch (PDOException $e) {
            throw new Exception('Database query error roster_editable_cell_right_class.php');
        }
        return $res->fetch(PDO::FETCH_ASSOC);
    }
    public function update(int $data_id, string $yearweek, string $id, string $text) {
        global $pdo;
        $data_id    = trim($data_id);
        $yearweek   = trim($yearweek);
        $id         = trim($id);
        $text	    = trim($text);
        $query = 'INSERT INTO datadienstplandb.roster_editable_cell_right (data_id, yearweek, id, text) VALUES (:data_id, :yearweek, :id, :text) ON DUPLICATE KEY UPDATE text = :text';

        $values = array(':data_id' => $data_id, ':yearweek' => $yearweek, ':id' => $id, ':text' => $text);

        try {
            $res = $pdo->prepare($query);
            $res->execute($values);
        } catch (PDOException $e) {
            throw new Exception('Database query error roster_editable_cell_right_class.php');
        }
    }   
	public function remove(int $data_id, string $yearweek) {
        global $pdo;

        $data_id  = trim($data_id);
        $yearweek = trim($yearweek);
        $query   = "DELETE FROM datadienstplandb.roster_editable_cell_right WHERE data_id = :data_id AND yearweek = :yearweek";
        $values  = array(':data_id' => $data_id, ':yearweek' => $yearweek);

        try {
            $res = $pdo->prepare($query);
            $res->execute($values);
        } catch (PDOException $e) {
            throw new Exception('Database query error roster_editable_cell_right_class.php');
        }
    }
    public function removeWhereDataId(int $data_id) {
        global $pdo;
        $data_id = trim($data_id);
        $query   = "DELETE FROM datadienstplandb.roster_editable_cell_right WHERE data_id = :data_id";
        $values  = array(':data_id' => $data_id);

        try {
            $res = $pdo->prepare($query);
            $res->execute($values);
        } catch (PDOException $e) {
            throw new Exception('Database query error roster_editable_cell_right_class.php');
        }
    } 
}