source: branches/rsr.v5.1.dev/web/app/data/modules/data_search.php @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 2.5 KB
Line 
1<?php
2
3  class data_search extends data
4  {
5
6    function search($match)
7    { $results = array
8      ( "has_results" => false,
9        "match" => $match,
10        "artistes" => array(),
11        "downloads" => array(),
12        "albums" => array()
13      );
14      try
15      { if($match)
16        { $sql =
17           "SELECT id, nom, style, image"
18          ." FROM #--artistes"
19          ." WHERE nom LIKE ".$this->eq("%".$match."%")
20          ." OR style LIKE ".$this->eq("%".$match."%");
21          $rst = $this->sql->query($sql);
22          while($v_rst = $this->sql->fetch_assoc($rst)) $results["artistes"][$v_rst["id"]] = $v_rst;
23          $this->sql->free_result($rst);
24
25          $sql =
26           "SELECT #--downloads.*"
27          .", #--downloads.id as id_download"
28          .", #--downloads.nom as titre"
29          .", #--downloads.date_creation as date_created"
30          .", #--artistes.id as id_artiste"
31          .", #--artistes.nom as auteur"
32          .", #--licences.nom as licence"
33          .", #--licences.lien as licence_url"
34          ." FROM #--artistes"
35          .", #--downloads"
36          .", #--licences"
37          ." WHERE #--downloads.id_artiste=#--artistes.id"
38          ." AND #--downloads.id_licence=#--licences.id"
39          ." AND actif=1"
40          ." AND #--downloads.nom LIKE ".$this->eq("%".$match."%");
41          $rst = $this->sql->query($sql);
42          while($v_rst = $this->sql->fetch_assoc($rst))
43          { $results["downloads"][$v_rst["id"]] = $v_rst;
44            $results["downloads"][$v_rst["id"]]["urls"] = array();
45            $u_sql =
46             "SELECT #--download_urls.*, #--formats.nom as format"
47            ." FROM #--download_urls, #--formats"
48            ." WHERE id_download=".$v_rst["id"]
49            ." AND #--download_urls.id_format=#--formats.id";
50            $u_rst = $this->sql->query($u_sql);
51            while($v_u_rst = $this->sql->fetch_assoc($u_rst))
52            { $results["downloads"][$v_rst["id"]]["urls"][$v_u_rst["id"]] = $v_u_rst;
53              if($v_u_rst["format"] === "mp3")
54              { $results["downloads"][$v_rst["id"]]["mp3_id_url"] = $v_u_rst["id"];
55                $results["downloads"][$v_rst["id"]]["mp3_url"] = $v_u_rst["url"];
56              }
57            }
58            $this->sql->free_result($u_rst);
59          }
60          $this->sql->free_result($rst);
61
62          $results["has_results"] =
63             $results["artistes"]
64          || $results["downloads"]
65          || $results["albums"];
66        }
67      }
68      catch(Exception $_e) { $results = false; }
69      return $results;
70    }
71
72  }
73
74?>
Note: See TracBrowser for help on using the repository browser.