2019-08-23 11:39:42 +00:00
< ? php
class DashboardManager {
public static $devices ;
2020-04-21 17:44:30 +00:00
static function getAllDashboards ( $userId ) {
2019-08-23 11:39:42 +00:00
return Db :: loadAll ( " SELECT * FROM dashboard WHERE user_id=? " , array ( $userId ));
}
2020-04-21 17:44:30 +00:00
static function getAllSubDevices ( $userId ) {
2019-08-23 11:39:42 +00:00
return Db :: loadAll ( " SELECT * FROM subdevices WHERE subdevice_id IN (SELECT subdevice_id FROM dashboard WHERE user_id=?) " , array ( $userId ));
}
2020-04-21 17:44:30 +00:00
static function getSubDevice ( $userId , $subDeviceId ) {
2019-08-23 11:39:42 +00:00
return Db :: loadOne ( " SELECT * FROM subdevices WHERE subdevice_id = (SELECT subdevice_id FROM dashboard WHERE user_id=? AND subdevice_id = ? ) " , array ( $userId , $subDeviceId ));
}
2020-04-21 17:44:30 +00:00
static function Add ( $subDeviceId ) {
2019-08-23 11:39:42 +00:00
if ( self :: getSubDevice ( UserManager :: getUserData ( 'user_id' ), $subDeviceId ) == null ){
// to do: pokud existuje nepridej
//
//
$dashboardItem = array (
'user_id' => UserManager :: getUserData ( 'user_id' ),
'subdevice_id' => $subDeviceId ,
);
try {
Db :: add ( 'dashboard' , $dashboardItem );
} catch ( PDOException $error ) {
echo $error -> getMessage ();
die ();
}
}
}
2020-04-21 17:44:30 +00:00
static function Remove ( $subDeviceId ){
2019-08-23 11:39:42 +00:00
$userId = UserManager :: getUserData ( 'user_id' );
Db :: command ( 'DELETE FROM dashboard WHERE subdevice_id=? AND user_id = ?' , array ( $subDeviceId , $userId ));
}
}