Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F15172438
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/documentation/database/patches/patch-16.sql b/documentation/database/patches/patch-16.sql
index 9704a74..074ceb3 100644
--- a/documentation/database/patches/patch-16.sql
+++ b/documentation/database/patches/patch-16.sql
@@ -1,3 +1,4 @@
ALTER TABLE `{$prefix}sharable`
- ADD COLUMN `parent_sharable_ID` INT(10) UNSIGNED AFTER `sharable_license`,
- ADD CONSTRAINT `fk_parent_sharable_ID` FOREIGN KEY (`parent_sharable_ID`) REFERENCES `{$prefix}sharable` (`sharable_ID`);
+ ADD COLUMN `sharable_parent` INT(10) UNSIGNED AFTER `sharable_license`,
+ ADD CONSTRAINT `{$prefix}fk_sharable_parent` FOREIGN KEY (`sharable_parent`) REFERENCES `{$prefix}sharable` (`sharable_ID`);
+
diff --git a/includes/class-QuerySharable.php b/includes/class-QuerySharable.php
new file mode 100644
index 0000000..4ccf235
--- /dev/null
+++ b/includes/class-QuerySharable.php
@@ -0,0 +1,124 @@
+<?php
+# Suckless conference
+# Copyright (C) 2020 Valerio Bozzolan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// require dependent traits
+class_exists( QueryEvent::class, true );
+
+/**
+ * Methods related to a QuerySharable class
+ */
+trait QuerySharableTrait {
+
+ /**
+ * Where the Sharable is...
+ *
+ * @param object $event Sharable
+ * @return self
+ */
+ public function whereSharable( $event ) {
+ return $this->whereSharableID( $event->getSharableID() );
+ }
+
+ /**
+ * Where the Sharable ID is...
+ *
+ * @param int $id Sharable ID
+ * @return self
+ */
+ public function whereSharableID( $id ) {
+ return $this->whereInt( $this->SHARABLE_ID, $id );
+ }
+
+ /**
+ * Where the Sharable has a parent
+ *
+ * @param boolean $has Set to false to have not a parent
+ * @return self
+ */
+ public function whereSharableHasParent( $has = true ) {
+
+ // it has the parent if it's not NULL
+ $verb = $has ? 'IS NOT' : 'IS';
+ return $this->compare( Sharable::PARENT, $verb, 'NULL' );
+ }
+
+ /**
+ * Where the Sharable has not a parent
+ *
+ * @param boolean $has Set to false to have not a parent
+ * @return self
+ */
+ public function whereSharableIsRoot() {
+ return $this->whereSharableHasParent( false );
+ }
+
+ /**
+ * Where the Sharable has a parent and it's this one
+ *
+ * @param Sharable $sharable
+ * @return self
+ */
+ public function whereSharableParent( $sharable ) {
+ return $this->whereSharableParentID( $sharable->getSharableParentID() );
+ }
+
+ /**
+ * Where the Sharable has a parent and it's this one
+ *
+ * @param int $id Sharable ID
+ * @return self
+ */
+ public function whereSharableParentID( $id ) {
+ return $this->whereInt( Sharable::PARENT, $id );
+ }
+
+}
+
+/**
+ * Utility used to Query a Sharable.
+ */
+class QuerySharable extends Query {
+
+ use QuerySharableTrait;
+ use QueryEventTrait;
+
+ /**
+ * Univoque Event ID column name
+ *
+ * @var
+ */
+ protected $EVENT_ID = 'sharable.event_ID';
+
+ /**
+ * Constructor
+ *
+ * @param DB $db Database or NULL for the default one
+ * @param string $alias Table alias
+ */
+ public function __construct() {
+
+ // initialize Query
+ parent::__construct();
+
+ // select default table
+ $this->from( Sharable::T );
+
+ // select default result class name
+ $this->defaultClass( Sharable::class );
+ }
+
+}
diff --git a/includes/class-Sharable.php b/includes/class-Sharable.php
index b5cd3ee..87d1bfa 100644
--- a/includes/class-Sharable.php
+++ b/includes/class-Sharable.php
@@ -1,265 +1,268 @@
<?php
# Linux Day 2016 - Construct a database sharable
# Copyright (C) 2016, 2017, 2018, 2019, 2020 Valerio Bozzolan, Linux Day Torino website contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
trait SharableTrait {
/**
* Get the sharable ID
*
* @return int
*/
public function getSharableID() {
return $this->nonnull( Sharable::ID );
}
/**
* Check if this Sharable has a parent
*
* See https://gitpull.it/T557
*
* @return boolean
*/
public function hasParentSharable() {
return $this->has( Sharable::PARENT );
}
/**
* Get the ID of the parent Sharable (if any)
*
* See https://gitpull.it/T557
*
* @return mixed
*/
public function getParentSharableID() {
return $this->get( Sharable::PARENT );
}
/**
* Get the localized sharable title
*
* @param $args array Title arguments like 'prop'
* @return string
*/
public function getSharableTitle( $args = [] ) {
$sharable_title = $this->get( Sharable::TITLE );
if( ! isset( $sharable_title ) ) {
return $this->getDefaultSharableTitle( $args );
}
return __( $sharable_title );
}
/**
* Retrieve something usable as a title
*
* @param $args array Title arguments like 'prop'
* @return string
*/
public function getDefaultSharableTitle( $args = [] ) {
$sharable_type = $this->get( Sharable::TYPE );
if( $sharable_type === 'youtube' ) {
if( isset( $args['prop'] ) && $args['prop'] ) {
return sprintf( __("il %s"), __("video esterno") );
} else {
return __("video esterno");
}
}
$sharable_path = $this->get( Sharable::PATH );
// Get filename from "/asd/asd/asd/(filename)"
$i = 0;
while( strpos( $sharable_path, _, $i ) !== false ) {
$i++;
}
return substr( $sharable_path, $i );
}
/**
* Is it an image?
*
* @return bool
*/
public function isSharableImage() {
return $this->isSharableType( 'image' );
}
/**
* Is it a video?
*
* @return bool
*/
public function isSharableVideo() {
return $this->isSharableType( 'video' );
}
/**
* Is it a document?
*
* @return bool
*/
public function isSharableDocument() {
return $this->isSharableType( 'document' );
}
/**
* Is it an iframe (like a YouTube video?)
*
* @return bool
*/
public function isSharableIframe() {
return $this->isSharableType( 'youtube' );
}
/**
* Is it of a certain type?
*
* @param $type string
* @return bool
*/
private function isSharableType( $type ) {
return $this->get( Sharable::TYPE ) === $type;
}
/**
* It can be downloaded?
*
* @return bool
*/
public function isSharableDownloadable() {
return ! $this->isSharableIframe();
}
+ /**
+ * @TODO: $base = ROOT is wrong and should be $absolute = false
+ */
function getSharablePath( $base = ROOT ) {
$type = $this->get( Sharable::TYPE );
$path = $this->get( Sharable::PATH );
if( 'youtube' === $type ) {
return "https://www.youtube.com/watch?v={$path}";
}
return site_page( $path, $base );
}
/**
* Get the MIME type
*
* @return string|null
*/
public function getSharableMIME() {
return $this->get( Sharable::MIME );
}
/**
* Get the license
*
* @return License
*/
public function getSharableLicense() {
return license( $this->get( Sharable::LICENSE ) );
}
/**
* Normalize a Sharable object
*/
protected function normalizeSharable() {
$this->integers(
Sharable::ID,
Sharable::PARENT,
Event ::ID
);
}
}
/**
* A Sharable is an attachment related to a Talk
*/
class Sharable extends Queried {
use SharableTrait;
/**
* Database table name
*/
const T = 'sharable';
/**
* Sharable ID column
*/
const ID = 'sharable_ID';
/**
* Sharable title column
*/
const TITLE = 'sharable_title';
/**
* Sharable type column
*/
const TYPE = 'sharable_type';
/**
* Sharable path column
*/
const PATH = 'sharable_path';
/**
* Sharable mime type column
*/
const MIME = 'sharable_mimetype';
/**
* Sharable license column
*/
const LICENSE = 'sharable_license';
/**
* Name of the parent sharable_ID column
*
* See https://gitpull.it/T557
*/
- const PARENT = 'parent_sharable_ID';
+ const PARENT = 'sharable_parent';
/**
* Sharable univoque ID
*/
const ID_ = self::T . DOT . self::ID;
/**
* Sharable event ID
*/
const EVENT_ = self::T . DOT . Event::ID;
/**
* Constructor
*/
public function __construct() {
$this->normalizeSharable();
}
/**
* Factory by an event
*
* @param $event_ID int Event ID
* @return Query
*/
public static function factoryByEvent( $event_ID ) {
- return self::factory()
- ->whereInt( Sharable::EVENT_, $event_ID );
+ return ( new QuerySharable )
+ ->whereEventID( $event_ID );
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 19, 01:12 (7 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2263644
Default Alt Text
(9 KB)
Attached To
Mode
R41 suckless-conference
Attached
Detach File
Event Timeline