1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 02:09:22 +02:00
Oinktube/plugin/Bookmark/Objects/BookmarkTable.php
2022-08-22 15:45:42 -03:00

117 lines
3.5 KiB
PHP

<?php
require_once dirname(__FILE__) . '/../../../videos/configuration.php';
require_once dirname(__FILE__) . '/../../../objects/bootGrid.php';
require_once dirname(__FILE__) . '/../../../objects/user.php';
class BookmarkTable extends ObjectYPT {
protected $id, $timeInSeconds, $name, $videos_id;
static function getSearchFieldsNames() {
return array('name','title');
}
static function getTableName() {
return 'bookmarks';
}
function getTimeInSeconds() {
return $this->timeInSeconds;
}
function getName() {
return $this->name;
}
function getVideos_id() {
return $this->videos_id;
}
function setTimeInSeconds($timeInSeconds) {
$this->timeInSeconds = $timeInSeconds;
}
function setName($name) {
$this->name = $name;
}
function setVideos_id($videos_id) {
$this->videos_id = $videos_id;
}
static function deleteAllFromVideo($videos_id) {
global $global;
if (!empty($videos_id)) {
$sql = "DELETE FROM " . static::getTableName() . " ";
$sql .= " WHERE videos_id = ?";
$global['lastQuery'] = $sql;
//_error_log("Delete Query: ".$sql);
return sqlDAL::writeSql($sql,"i",array($videos_id));
}
return false;
}
static function getAllFromVideo($videos_id) {
global $global;
$sql = "SELECT * FROM " . static::getTableName() . " WHERE videos_id = ? ";
//$sql .= self::getSqlFromPost();
$res = sqlDAL::readSql($sql,"i",array($videos_id));
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res!=false) {
foreach ($fullData as $row) {
$rows[] = $row;
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $rows;
}
static function getAll() {
global $global;
$sql = "SELECT b.*, title, filename FROM " . static::getTableName() . " b LEFT JOIN videos v on v.id = videos_id WHERE 1=1 ";
$sql .= self::getSqlFromPost();
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res!=false) {
foreach ($fullData as $row) {
$rows[] = $row;
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $rows;
}
public function save() {
// make sure that will be only one bookmark for each time
$row = self::getFromTime($this->getVideos_id(), $this->getTimeInSeconds());
if(!empty($row)){
$this->id = $row['id'];
}
parent::save();
}
static protected function getFromTime($videos_id, $timeInSeconds) {
global $global;
$sql = "SELECT * FROM " . static::getTableName() . " WHERE videos_id = ? AND timeInSeconds = ? LIMIT 1";
// I had to add this because the about from customize plugin was not loading on the about page http://127.0.0.1/AVideo/about
$res = sqlDAL::readSql($sql,"ii",array($videos_id, $timeInSeconds));
$data = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
if ($res) {
$row = $data;
} else {
$row = false;
}
return $row;
}
}