Heimdall/app/Item.php

229 lines
7.5 KiB
PHP
Raw Normal View History

2018-01-29 12:41:57 +00:00
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\ClassLoader\ClassMapGenerator;
2018-02-03 15:46:14 +00:00
use Illuminate\Database\Eloquent\SoftDeletes;
2018-01-29 12:41:57 +00:00
class Item extends Model
{
2018-02-03 15:46:14 +00:00
use SoftDeletes;
2018-01-29 12:41:57 +00:00
//
2018-02-01 14:45:59 +00:00
protected $fillable = [
2018-10-12 13:57:46 +00:00
'title', 'url', 'colour', 'icon', 'description', 'pinned', 'order', 'type', 'user_id'
2018-02-01 14:45:59 +00:00
];
2018-02-03 15:46:14 +00:00
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
public static function supportedList()
{
return [
2018-03-17 05:48:40 +00:00
'AirSonic' => \App\SupportedApps\AirSonic::class,
2018-03-21 15:25:31 +00:00
'Cardigann' => \App\SupportedApps\Cardigann::class,
2018-03-12 03:47:31 +00:00
'CouchPotato' => \App\SupportedApps\CouchPotato::class,
2018-09-13 07:43:21 +00:00
'Bazarr' => \App\SupportedApps\Bazarr::class,
2018-06-04 23:10:22 +00:00
'Booksonic' => \App\SupportedApps\Booksonic::class,
2018-07-18 20:17:33 +00:00
'BookStack' => \App\SupportedApps\BookStack::class,
'Deluge' => \App\SupportedApps\Deluge::class,
'Dokuwiki' => \App\SupportedApps\Dokuwiki::class,
2018-02-07 15:43:29 +00:00
'Duplicati' => \App\SupportedApps\Duplicati::class,
'Emby' => \App\SupportedApps\Emby::class,
2018-06-05 16:18:49 +00:00
'Flood' => \App\SupportedApps\Flood::class,
2018-07-19 18:55:21 +00:00
'FreshRSS' => \App\SupportedApps\FreshRSS::class,
'Gitea' => \App\SupportedApps\Gitea::class,
'Glances' => \App\SupportedApps\Glances::class,
2018-03-25 04:35:23 +00:00
'Grafana' => \App\SupportedApps\Grafana::class,
2018-02-16 17:37:09 +00:00
'Graylog' => \App\SupportedApps\Graylog::class,
2018-06-04 23:11:11 +00:00
'Headphones' => \App\SupportedApps\Headphones::class,
2018-02-14 13:20:02 +00:00
'Home Assistant' => \App\SupportedApps\HomeAssistant::class,
'Jackett' => \App\SupportedApps\Jackett::class,
'Jdownloader' => \App\SupportedApps\Jdownloader::class,
2018-03-13 16:38:29 +00:00
'Krusader' => \App\SupportedApps\Krusader::class,
2018-06-04 23:12:02 +00:00
'LibreNMS' => \App\SupportedApps\LibreNMS::class,
'Lidarr' => \App\SupportedApps\Lidarr::class,
'Mcmyadmin' => \App\SupportedApps\Mcmyadmin::class,
'Medusa' => \App\SupportedApps\Medusa::class,
2018-06-04 23:12:24 +00:00
'MusicBrainz' => \App\SupportedApps\MusicBrainz::class,
2018-06-04 23:13:08 +00:00
'Mylar' => \App\SupportedApps\Mylar::class,
2018-02-13 18:29:15 +00:00
'NZBGet' => \App\SupportedApps\Nzbget::class,
'Netdata' => \App\SupportedApps\Netdata::class,
'Nextcloud' => \App\SupportedApps\Nextcloud::class,
2018-05-01 18:43:56 +00:00
'Now Showing' => \App\SupportedApps\NowShowing::class,
'Nzbhydra' => \App\SupportedApps\Nzbhydra::class,
2018-02-14 20:47:49 +00:00
'OPNSense' => \App\SupportedApps\Opnsense::class,
'Ombi' => \App\SupportedApps\Ombi::class,
'Openhab' => \App\SupportedApps\Openhab::class,
2018-03-17 06:05:32 +00:00
'OpenMediaVault' => \App\SupportedApps\OpenMediaVault::class,
2018-02-07 15:43:29 +00:00
'Pihole' => \App\SupportedApps\Pihole::class,
2018-02-05 20:59:38 +00:00
'Plex' => \App\SupportedApps\Plex::class,
2018-02-09 21:06:19 +00:00
'Plexpy' => \App\SupportedApps\Plexpy::class,
'Plexrequests' => \App\SupportedApps\Plexrequests::class,
2018-02-07 15:43:29 +00:00
'Portainer' => \App\SupportedApps\Portainer::class,
'Proxmox' => \App\SupportedApps\Proxmox::class,
2018-02-14 13:20:02 +00:00
'Radarr' => \App\SupportedApps\Radarr::class,
2018-06-04 23:13:30 +00:00
'Rancher' => \App\SupportedApps\Rancher::class,
2018-02-26 02:41:19 +00:00
'Runeaudio' => \App\SupportedApps\Runeaudio::class,
2018-02-08 22:02:28 +00:00
'Sabnzbd' => \App\SupportedApps\Sabnzbd::class,
'Sickrage' => \App\SupportedApps\Sickrage::class,
2018-02-14 13:20:02 +00:00
'Sonarr' => \App\SupportedApps\Sonarr::class,
2018-04-04 05:26:08 +00:00
'Syncthing' => \App\SupportedApps\Syncthing::class,
2018-03-13 19:58:37 +00:00
'Tautulli' => \App\SupportedApps\Tautulli::class,
2018-03-02 04:41:28 +00:00
'Transmission' => \App\SupportedApps\Transmission::class,
'Traefik' => \App\SupportedApps\Traefik::class,
'tt-rss' => \App\SupportedApps\Ttrss::class,
2018-07-18 19:45:40 +00:00
'TVheadend' => \App\SupportedApps\TVheadend::class,
'UniFi' => \App\SupportedApps\Unifi::class,
2018-04-29 00:30:45 +00:00
'unRAID' => \App\SupportedApps\Unraid::class,
'pfSense' => \App\SupportedApps\Pfsense::class,
2018-03-21 15:06:33 +00:00
'pyLoad' => \App\SupportedApps\pyLoad::class,
'ruTorrent' => \App\SupportedApps\ruTorrent::class,
2018-03-18 13:18:27 +00:00
'Watcher3' => \App\SupportedApps\Watcher3::class,
2018-03-17 05:19:30 +00:00
'WebTools' => \App\SupportedApps\WebTools::class,
];
}
public static function supportedOptions()
{
return array_keys(self::supportedList());
}
/**
* Scope a query to only include pinned items.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePinned($query)
{
return $query->where('pinned', 1);
}
2018-02-06 20:41:29 +00:00
public function getConfigAttribute()
{
$output = null;
2018-02-09 08:28:20 +00:00
$view = null;
2018-02-06 20:41:29 +00:00
if(isset($this->description) && !empty($this->description)){
$output = json_decode($this->description);
$output = is_object($output) ? $output : new \stdClass();
2018-02-06 20:41:29 +00:00
if(isset($output->type) && !empty($output->type)) {
$class = $output->type;
$sap = new $class();
$view = $sap->configDetails();
2018-02-08 20:00:24 +00:00
$output->view = $view;
2018-02-06 20:41:29 +00:00
}
if(!isset($output->dataonly)) $output->dataonly = '0';
2018-06-05 16:18:49 +00:00
2018-02-06 20:41:29 +00:00
}
return (object)$output;
}
public static function checkConfig($config)
{
if(empty($config)) {
$config = null;
} else {
$store = false;
2018-02-09 00:05:37 +00:00
//die(var_dump($config));
foreach($config as $key => $check) {
if($key == 'type') continue;
2018-02-09 00:05:37 +00:00
if($key == 'dataonly') continue;
if(!empty($check) && $check != '0') {
$store = true;
break;
}
}
2018-02-09 00:05:37 +00:00
//die(var_dump($store))
2018-06-05 16:18:49 +00:00
$config['enabled'] = ($store) ? true : false;
$config = json_encode($config);
}
return $config;
}
2018-02-17 00:13:38 +00:00
public function parents()
{
return $this->belongsToMany('App\Item', 'item_tag', 'item_id', 'tag_id');
}
public function children()
{
return $this->belongsToMany('App\Item', 'item_tag', 'tag_id', 'item_id');
}
public function getLinkAttribute()
{
if((int)$this->type === 1) {
return '/tag/'.$this->url;
} else {
return $this->url;
}
}
public function getDroppableAttribute()
{
if((int)$this->type === 1) {
return ' droppable';
} else {
return '';
}
}
2018-02-19 23:15:09 +00:00
public function getLinkTargetAttribute()
2018-02-17 00:13:38 +00:00
{
2018-06-07 21:35:01 +00:00
$target = Setting::fetch('window_target');
if((int)$this->type === 1 || $target === 'current') {
2018-02-17 00:13:38 +00:00
return '';
} else {
return ' target="' . $target . '"';
2018-02-17 00:13:38 +00:00
}
}
2018-02-18 17:04:18 +00:00
public function getLinkIconAttribute()
{
if((int)$this->type === 1) {
return 'fa-tag';
} else {
return 'fa-arrow-alt-to-right';
}
}
2018-02-18 17:23:05 +00:00
public function getLinkTypeAttribute()
{
if((int)$this->type === 1) {
return 'tags';
} else {
return 'items';
}
}
2018-02-18 17:04:18 +00:00
2018-02-17 00:13:38 +00:00
public function scopeOfType($query, $type)
{
switch($type) {
case 'item':
$typeid = 0;
break;
case 'tag':
$typeid = 1;
break;
}
return $query->where('type', $typeid);
}
2018-10-12 13:57:46 +00:00
/**
* Get the user that owns the item.
*/
public function user()
{
return $this->belongsTo('App\User');
}
2018-02-17 00:13:38 +00:00
2018-01-29 12:41:57 +00:00
}