diff --git a/2016/event-edit.php b/2016/event-edit.php
index 6d306f6..3dae757 100644
--- a/2016/event-edit.php
+++ b/2016/event-edit.php
@@ -1,631 +1,635 @@
.
/*
* Event edit
*
* From this page you can create/edit an User and assign some skills/interests etc.
*/
// load configurations and framework
require 'load.php';
// inherit the Conference or specify one
$conference_uid = CURRENT_CONFERENCE_UID;
if( isset( $_REQUEST['conference'] ) ) {
$conference_uid = $_REQUEST['conference'];
}
// check if the Conference exists
$conference = FullConference::factoryFromUID( $conference_uid )
->queryRow();
if( !$conference ) {
die_with_404();
}
// retrieve the Event (if existing)
$event = null;
if( isset( $_GET['uid'] ) ) {
$event = ( new QueryEvent() )
->whereConference( $conference )
->joinConference()
->joinChapter()
->whereEventUID( $_GET['uid'] )
->queryRow();
if( !$event ) {
die_with_404();
}
if( !$event->isEventEditable() ) {
error_die("Can't edit event");
}
} else {
// check if there are permissions to add event
if( !has_permission( 'add-event' ) ) {
die( 'missing permissions' );
}
}
// known columns internationalized in multiple languages
$i18n_columns = [
Event::ABSTRACT => __( "Abstract" ),
Event::DESCRIPTION => __( "Descrizione" ),
Event::NOTE => __( "Note" ),
];
$warning = null;
if( $_POST ) {
if( is_action( 'save-event' ) ) {
$conference_ID = $conference->getConferenceID();
$data = [];
$data[] = new DBCol( Event::TITLE, $_POST['title'], 's' );
$data[] = new DBCol( Event::UID, $_POST['uid'], 's' );
$data[] = new DBCol( Event::LANGUAGE, $_POST['language'], 's' );
$data[] = new DBCol( Event::SUBTITLE, $_POST['subtitle'], 's' );
$data[] = new DBCol( Event::START, $_POST['start'], 's' );
$data[] = new DBCol( Event::END, $_POST['end'], 's' );
$data[] = new DBCol( Event::IMAGE, $_POST['image'], 'snull' );
$data[] = new DBCol( Chapter::ID, $_POST['chapter'], 'd' );
$data[] = new DBCol( Room::ID, $_POST['room'], 'd' );
$data[] = new DBCol( Track::ID, $_POST['track'], 'd' );
$data[] = new DBCol( Conference::ID, $conference_ID, 'd' );
// for each language save the fields
foreach( all_languages() as $lang ) {
foreach( $i18n_columns as $i18n_column => $label ) {
// generic column name in this language
$field = $i18n_column . '_' . $lang->getISO();
// sent column value
$value = $_POST[ $field ] ?? null;
// prepare to be saved
$data[] = new DBCol( $field, $value, 'snull' );
}
}
// convert empty strings to NULL, if possible
foreach( $data as $row ) {
$row->promoteNULL();
}
if( $event ) {
// update the existing Event
( new QueryEvent() )
->whereEvent( $event )
->update( $data );
} else {
// insert a new Event
Event::factory()
->insertRow( $data );
}
$id = $event ? $event->getEventID() : last_inserted_ID();
// get the updated Event
$event = FullEvent::factory()
->whereInt( Event::ID, $id )
->queryRow();
// POST-redirect-GET
http_redirect( $event->getFullEventEditURL(), 303 );
}
/**
* Change the Image
*/
if( $event && is_action( 'change-image' ) ) {
// prepare the image uploader
$image = new FileUploader( 'image', [
'category' => 'image',
'override-filename' => "event-" . $event->getEventUID(),
] );
// prepare the image pathnames
$img_url = $event->getConferenceUID() . _ . 'images';
$img_path = ABSPATH . __ . $event->getConferenceUID() . __ . 'images';
// really upload that shitty image somewhere
if( $image->fileChoosed() ) {
$ok = $image->uploadTo( $img_path, $status, $filename, $ext );
if( $ok ) {
// now update
( new QueryEvent() )
->whereEvent( $event )
->update( [
'event_img' => $img_url . "/$filename.$ext",
] );
// POST-redirect-GET
http_redirect( $event->getFullEventEditURL(), 303 );
} else {
$warning = $image->getErrorMessage();
}
}
}
/*
* Add the user
*/
if( $event && is_action( 'add-user' ) && isset( $_POST['user'] ) ) {
// Add user
$user = User::factoryFromUID( $_POST['user'] )
->select( User::ID )
->queryRow();
if( $user ) {
- EventUser::delete( $event->getEventID(), $user->getUserID() );
+ ( new QueryEventUser() )
+ ->whereEvent( $event )
+ ->whereUser( $user )
+ ->delete();
- insert_row('event_user', [
+ ( new QueryEventUser() )->insertRow( [
new DBCol( Event::ID, $event->getEventID(), 'd' ),
- new DBCol( User::ID, $user->getUserID(), 'd' ),
+ new DBCol( User ::ID, $user->getUserID(), 'd' ),
+ new DBCol( EventUser::ORDER, 0, 'd' ),
] );
}
}
/**
* Update an user order
*/
if( $event && is_action( 'update-user' ) && isset( $_POST['user'] ) ) {
$user = User::factoryFromUID( $_POST['user'] )
->select( User::ID )
->queryRow();
if( $user ) {
if ( !empty( $_POST['delete'] ) ) {
// Delete user
EventUser::delete( $event->getEventID(), $user->getUserID() );
} elseif( isset( $_POST['order'] ) ) {
// change order
EventUser::factory()
->whereInt( Event::ID, $event->getEventID() )
->whereInt( User ::ID, $user->getUserID() )
->update( [
new DBCol( EventUser::ORDER, $_POST['order'], 'd')
] );
}
}
}
// post -> redirect -> get (no: it hide errors)
// http_redirect( $_SERVER[ 'REQUEST_URI' ], 303 );
}
if( $event ) {
Header::spawn( null, [
'title' => sprintf(
__("Modifica %s: %s"),
$event->getChapterName(),
$event->getEventTitle()
),
] );
} else {
Header::spawn( null, [
'title' => sprintf(
__( "Aggiungi %s" ),
__( "Evento" )
),
] );
}
?>
= esc_html( $warning ) ?>
= HTML::a(
$conference->getConferenceURL(),
esc_html( $conference->getConferenceTitle() ) . icon( 'home', 'left' )
) ?>
= HTML::a(
// href
$event->getEventURL(),
// text
__( "Vedi" ) . icon( 'account_box', 'left' )
) ?>
= HTML::a(
ROOT . '/2016/user-edit.php',
sprintf(
__( "Aggiungi %s" ),
sprintf(
__( "Nuovo %s" ),
__( "Utente" )
)
)
) ?>
factoryUserByEvent()
->select( [
User::UID,
EventUser::ORDER,
] )
->defaultClass( EventUser::class )
->orderBy( EventUser::ORDER )
->queryGenerator();
?>
valid() ): ?>
.
trait EventUserTrait {
/**
* Get the event user order
*
* @return int
*/
public function getEventUserOrder() {
return $this->get( EventUser::ORDER );
}
/**
* Delete this Event-User from the database
*
* Can be called statically
*/
function deleteEventUser( $event_ID = null, $user_ID = null ) {
if( $event_ID === null ) {
$event_ID = $this->getEventID();
}
if( $user_ID === null ) {
$user_ID = $this->getUserID();
}
EventUser::delete( $event_ID, $user_ID );
}
/**
* Normalize an EventUser object
*/
protected function normalizeEventUser() {
$this->integers( EventUser::ORDER );
$this->normalizeEvent();
$this->normalizeUser();
}
}
class_exists( 'Event' );
class_exists( 'User' );
/**
* Relation between an event and users
*/
class EventUser extends Queried {
use EventUserTrait;
use EventTrait;
use UserTrait;
/**
* Database table name
*/
const T = 'event_user';
/**
* Complete user column name
*/
const USER_ = self::T . DOT . User::ID;
/**
* Complete event column name
*/
const EVENT_ = self::T . DOT . Event::ID;
/**
* User order column name
*/
const ORDER = 'event_user_order';
/**
* Constructor
*/
public function __construct() {
$this->normalizeEventUser();
}
-
- /**
- * Delete the connection of an Event to an User
- *
- * @param int $event_ID Event ID
- * @param int $user_ID User ID
- */
- public static function delete( $event_ID, $user_ID ) {
- EventUser::factory()
- ->whereInt( 'event_ID', $event_ID )
- ->whereInt( 'user_ID', $user_ID )
- ->delete();
- }
}
diff --git a/includes/class-QueryEvent.php b/includes/class-QueryEvent.php
index 3c6521f..0ed1f47 100644
--- a/includes/class-QueryEvent.php
+++ b/includes/class-QueryEvent.php
@@ -1,182 +1,193 @@
.
// load dependent traits
class_exists( QueryConference::class, true );
+/**
+ * Methods for a QueryEvent class
+ */
+trait QueryEventTrait {
+
+ use QueryConferenceTrait;
+
+ /**
+ * Where the Event is...
+ *
+ * @param object $event Event
+ * @return self
+ */
+ public function whereEvent( $event ) {
+ return $this->whereEventID( $event->getEventID() );
+ }
+
+ /**
+ * Where the Event ID is...
+ *
+ * @param int $id Event ID
+ * @return self
+ */
+ public function whereEventID( $id ) {
+ return $this->whereInt( $this->EVENT_ID, $id );
+ }
+
+ /**
+ * Where the Event UID is this one
+ *
+ * @param string $uid Event UID
+ * @return self
+ */
+ public function whereEventUID( $uid ) {
+ return $this->whereStr( Event::UID, $uid );
+ }
+
+}
+
/**
* Class able to query a FullEvent.
*/
class QueryEvent extends Query {
- use QueryConferenceTrait;
+ use QueryEventTrait;
/**
* Univoque Event ID column name
*
* @var
*/
protected $EVENT_ID = 'event.event_ID';
/**
* Univoque Chapter ID column name
*
* @var
*/
protected $CHAPTER_ID = 'event.chapter_ID';
/*
* Univoque Conference ID column name
*
* Used from ConferenceTrait#joinConference()
*
* @var
*/
protected $CONFERENCE_ID = 'event.conference_ID';
/**
* Univoque Track ID column name
*
* @var
*/
protected $TRACK_ID = 'event.track_ID';
/**
* Univoque Room ID column name
*
* @var
*/
protected $ROOM_ID = 'event.room_ID';
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->from( Event::T );
$this->defaultClass( FullEvent::class );
}
- /**
- * Where the Event is...
- *
- * @param object $event Event
- * @return self
- */
- public function whereEvent( $event ) {
- return $this->whereEventID( $event->getEventID() );
- }
-
- /**
- * Where the Event ID is...
- *
- * @param int $id Event ID
- * @return self
- */
- public function whereEventID( $id ) {
- return $this->whereInt( $this->EVENT_ID, $id );
- }
-
/**
* Limit to a certain User
*
+ * @deprecated
+ *
* @param $user User
* @return self
*/
public function whereUser( $user ) {
return $this->joinEventUser()
->whereInt( EventUser::USER_, $user->getUserID() );
}
- /**
- * Where the Event UID is this one
- *
- * @param string $uid Event UID
- * @return self
- */
- public function whereEventUID( $uid ) {
- return $this->whereStr( Event::UID, $uid );
- }
-
/**
* Join a table with the Chapter table
*
* @return self
*/
public function joinChapter() {
return $this->joinOn( 'INNER', 'chapter', 'chapter.chapter_ID' , $this->CHAPTER_ID );
}
/**
* Join a table with the Track table
*
* @return self
*/
public function joinTrack() {
return $this->joinOn( 'INNER', Track::T, Track::ID_, $this->TRACK_ID );
}
/**
* Join a table with the Room table
*
* @return self
*/
public function joinRoom() {
return $this->joinOn( 'INNER', Room::T, Room::ID_, $this->ROOM_ID );
}
/**
* Join Events to User IDs
*
* You can call it multiple time safely.
*
* @return self
*/
public function joinEventUser() {
if( empty( $this->joinedEventUser ) ) {
$this->from( EventUser::T );
$this->equals( EventUser::EVENT_, Event::ID_ );
$this->joinedEventUser = true;
}
return $this;
}
/**
* Join Events and their Track, Chapter and Room (can be NULL).
*
* You can call it multiple time safely.
*
* @return self
*/
public function joinTrackChapterRoom() {
if( empty( $this->joinedTrackChapterRoom ) ) {
$this->from( Room::T )
->equals( Room::ID_, Event::ROOM_ );
$this->from( Track::T )
->equals( Track::ID_, Event::TRACK_ );
$this->from( Chapter::T )
->equals( Chapter::ID_, Event::CHAPTER_ );
$this->joinedTrackChapterRoom = true;
}
return $this;
}
}
diff --git a/includes/class-QueryEventUser.php b/includes/class-QueryEventUser.php
new file mode 100644
index 0000000..d7578be
--- /dev/null
+++ b/includes/class-QueryEventUser.php
@@ -0,0 +1,80 @@
+.
+
+// load dependent traits
+class_exists( 'QueryEvent', true );
+class_exists( 'QueryUser', true );
+
+/**
+ * Class able to query a QueryEventUser
+ */
+trait QueryEventUserTrait {
+
+ use QueryEventTrait;
+ use QueryUserTrait;
+
+ /*
+ * Univoque User ID column name
+ *
+ * Used from EventUserTrait.
+ *
+ * @var
+ */
+ protected $USER_ID = 'event_user.user_ID';
+
+ /*
+ * Univoque Event ID column name
+ *
+ * Used from EventUserTrait.
+ *
+ * @var
+ */
+ protected $EVENT_ID = 'event_user.event_ID';
+
+ /**
+ * Limit to a specific EventUser
+ *
+ * @param $event_user EventUser
+ * @return self
+ */
+ public function whereEventUser( $event_user ) {
+ return $this->whereEvent( $event_user )
+ ->whereUser( $event_user );
+ }
+
+}
+
+/**
+ * Query an EventUser
+ */
+class QueryEventUser extends Query {
+
+ use QueryEventUserTrait;
+
+ /**
+ * Constructor
+ */
+ public function __construct( $db = null ) {
+
+ // set database connection and default result class
+ parent::__construct( $db, EventUser::class );
+
+ // set the default table
+ $this->from( EventUser::T );
+ }
+
+}
diff --git a/includes/class-QueryUser.php b/includes/class-QueryUser.php
index d9f62af..ef05f49 100644
--- a/includes/class-QueryUser.php
+++ b/includes/class-QueryUser.php
@@ -1,67 +1,67 @@
.
trait QueryUserTrait {
/**
* Where the user ID is...
*
* @param int $id
* @return self
*/
public function whereUserID( $id ) {
- return $this->whereInt( static::USER_ID, $id );
+ return $this->whereInt( $this->USER_ID, $id );
}
/**
* Where the user is...
*
* @param User $user User object
* @return self
*/
public function whereUser( $user ) {
$id = $user->getUserID();
return $this->whereUserID( $id );
}
}
/**
* Class useful to retrieve User(s)
*/
class QueryUser extends Query {
use QueryUserTrait;
/**
- * Disambigued user ID column name
+ * Univoque User ID column name
*/
- const USER_ID = 'user.user_ID';
+ protected $USER_ID = 'user.user_ID';
/**
* Constructor
*/
public function __construct( $db = null ) {
// choose database and default return class
parent::__construct( $db, User::class );
// choose database table
$this->from( User::T );
}
}
diff --git a/includes/class-QueryUserSkill.php b/includes/class-QueryUserSkill.php
index 6ba074d..239f63d 100644
--- a/includes/class-QueryUserSkill.php
+++ b/includes/class-QueryUserSkill.php
@@ -1,68 +1,74 @@
.
// load dependent traits
class_exists( 'QueryUser', true );
class_exists( 'QuerySkill', true );
+/**
+ * Methods for a QueryUserSkill class
+ */
trait QueryUserSkillTrait {
use QueryUserTrait;
use QuerySkillTrait;
/**
* Where the UserSkill is the specified one
*
* @param object $userskill UserSkill
* @return self
*/
public function whereUserSkill( $userskill ) {
return $this->whereUser( $userskill )
->whereSkill( $userskill );
}
}
+/**
+ * Query UserSkill
+ */
class QueryUserSkill extends Query {
use QueryUserSkillTrait;
/**
* Univoque Skill ID column name
*/
protected $SKILL_ID = 'user_skill.skill_ID';
/**
- * Univoque Skill ID column name
+ * Univoque User ID column name
*/
- const USER_ID = 'user_skill.user_ID';
+ protected $USER_ID = 'user_skill.user_ID';
/**
* Constructor
*
* @param DB $db Database connection
*/
public function __construct( $db = null ) {
// set database and default result class
parent::__construct( $db = null, UserSkill::class );
// set table FROM
$this->from( UserSkill::T );
}
}