1<?php
2/*
3 * vim:set softtabstop=4 shiftwidth=4 expandtab:
4 *
5 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
6 * Copyright 2001 - 2020 Ampache.org
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22
23declare(strict_types=0);
24
25namespace Ampache\Repository\Model;
26
27use Ampache\Module\System\Dba;
28
29class Personal_Video extends Video
30{
31    protected const DB_TABLENAME = 'personal_video';
32
33    public $location;
34    public $summary;
35    public $video;
36
37    public $f_location;
38
39    /**
40     * Constructor
41     * This pulls the personal video information from the database and returns
42     * a constructed object
43     * @param integer $object_id
44     */
45    public function __construct($object_id)
46    {
47        parent::__construct($object_id);
48
49        $info = $this->get_info($object_id);
50        foreach ($info as $key => $value) {
51            $this->$key = $value;
52        }
53
54        return true;
55    } // Constructor
56
57    public function getId(): int
58    {
59        return (int) $this->id;
60    }
61
62    /**
63     * garbage_collection
64     *
65     * This cleans out unused personal videos
66     */
67    public static function garbage_collection()
68    {
69        $sql = "DELETE FROM `personal_video` USING `personal_video` LEFT JOIN `video` ON `video`.`id` = `personal_video`.`id` WHERE `video`.`id` IS NULL";
70        Dba::write($sql);
71    }
72
73    /**
74     * create
75     * This takes a key'd array of data as input and inserts a new personal video entry, it returns the record id
76     * @param array $data
77     * @param array $gtypes
78     * @param array $options
79     * @return mixed
80     */
81    public static function insert(array $data, $gtypes = array(), $options = array())
82    {
83        $sql = "INSERT INTO `personal_video` (`id`, `location`, `summary`) VALUES (?, ?, ?)";
84        Dba::write($sql, array($data['id'], $data['location'], $data['summary']));
85
86        return $data['id'];
87    } // create
88
89    /**
90     * update
91     * This takes a key'd array of data as input and updates a personal video entry
92     * @param array $data
93     * @return integer
94     */
95    public function update(array $data)
96    {
97        parent::update($data);
98
99        $sql = "UPDATE `personal_video` SET `location` = ?, `summary` = ? WHERE `id` = ?";
100        Dba::write($sql, array($data['location'], $data['summary'], $this->id));
101
102        return $this->id;
103    } // update
104
105    /**
106     * format
107     * this function takes the object and formats some values
108     * @param boolean $details
109     * @return boolean
110     */
111
112    public function format($details = true)
113    {
114        parent::format($details);
115
116        $this->f_location = $this->location;
117
118        return true;
119    } // format
120
121    /**
122     * Remove the video from disk.
123     */
124    public function remove()
125    {
126        $deleted = parent::remove();
127        if ($deleted) {
128            $sql     = "DELETE FROM `personal_video` WHERE `id` = ?";
129            $deleted = Dba::write($sql, array($this->id));
130        }
131
132        return $deleted;
133    }
134}
135