Support playlist management
[infodrom/musiikki-web.git] / class / cache.class.php
index 9cd885a..89b3ca8 100644 (file)
@@ -11,11 +11,24 @@ class Cache {
        $this->db = new PDO('sqlite:/'.$cache);
     }
 
+    public function getRelativePath($id)
+    {
+       $media_dir = Config::main()->get('media_dir_A');
+
+       $sql = sprintf("SELECT path FROM details WHERE id = %d", $id);
+       $sth = $this->db->query($sql);
+       if ($sth === false) return null;
+
+       $row = $sth->fetchObject();
+       $path = substr($row->PATH, strlen($media_dir)+1);
+       return $path;
+    }
+
     public function findTitles($keyword)
     {
        $media_dir = Config::main()->get('media_dir_A');
        $results = array('count' => 0, 'list' => []);
-       $sql = sprintf("SELECT path, title, timestamp, size FROM details WHERE path LIKE %s AND mime IS NOT NULL",
+       $sql = sprintf("SELECT id, path, title, timestamp, size FROM details WHERE path LIKE %s AND mime IS NOT NULL",
                       $this->db->quote('%'.$keyword.'%'));
 
        $sth = $this->db->query($sql);
@@ -41,7 +54,14 @@ class Cache {
 
            if (!array_key_exists($section, $results['list']))
                $results['list'][$section] = [];
-           $results['list'][$section][] = ['path' => dirname($path), 'name' => basename($path), 'title' => $row->TITLE];
+
+           $item = ['path' => dirname($path), 'name' => basename($path), 'title' => $row->TITLE];
+           if (array_key_exists('playlist', $_SESSION))
+               $item['id'] = $row->ID;
+           else
+               $item['id'] = '';
+
+           $results['list'][$section][] = $item;
        }
 
        return $results;