示例#1
0
 /**
  * constructor
  */
 public function __construct($id = null, $searchtype = 'song')
 {
     $this->searchtype = $searchtype;
     if ($id) {
         $info = $this->get_info($id);
         foreach ($info as $key => $value) {
             $this->{$key} = $value;
         }
         $this->rules = unserialize($this->rules);
     }
     // Define our basetypes
     $this->basetypes['numeric'][] = array('name' => 'gte', 'description' => T_('is greater than or equal to'), 'sql' => '>=');
     $this->basetypes['numeric'][] = array('name' => 'lte', 'description' => T_('is less than or equal to'), 'sql' => '<=');
     $this->basetypes['numeric'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '<=>');
     $this->basetypes['numeric'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => '<>');
     $this->basetypes['numeric'][] = array('name' => 'gt', 'description' => T_('is greater than'), 'sql' => '>');
     $this->basetypes['numeric'][] = array('name' => 'lt', 'description' => T_('is less than'), 'sql' => '<');
     $this->basetypes['boolean'][] = array('name' => 'true', 'description' => T_('is true'));
     $this->basetypes['boolean'][] = array('name' => 'false', 'description' => T_('is false'));
     $this->basetypes['text'][] = array('name' => 'contain', 'description' => T_('contains'), 'sql' => 'LIKE', 'preg_match' => array('/^/', '/$/'), 'preg_replace' => array('%', '%'));
     $this->basetypes['text'][] = array('name' => 'notcontain', 'description' => T_('does not contain'), 'sql' => 'NOT LIKE', 'preg_match' => array('/^/', '/$/'), 'preg_replace' => array('%', '%'));
     $this->basetypes['text'][] = array('name' => 'start', 'description' => T_('starts with'), 'sql' => 'LIKE', 'preg_match' => '/$/', 'preg_replace' => '%');
     $this->basetypes['text'][] = array('name' => 'end', 'description' => T_('ends with'), 'sql' => 'LIKE', 'preg_match' => '/^/', 'preg_replace' => '%');
     $this->basetypes['text'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '=');
     $this->basetypes['text'][] = array('name' => 'sounds', 'description' => T_('sounds like'), 'sql' => 'SOUNDS LIKE');
     $this->basetypes['text'][] = array('name' => 'notsounds', 'description' => T_('does not sound like'), 'sql' => 'NOT SOUNDS LIKE');
     $this->basetypes['boolean_numeric'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '<=>');
     $this->basetypes['boolean_numeric'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => '<>');
     $this->basetypes['boolean_subsearch'][] = array('name' => 'equal', 'description' => T_('is'), 'sql' => '');
     $this->basetypes['boolean_subsearch'][] = array('name' => 'ne', 'description' => T_('is not'), 'sql' => 'NOT');
     $this->basetypes['date'][] = array('name' => 'lt', 'description' => T_('before'), 'sql' => '<');
     $this->basetypes['date'][] = array('name' => 'gt', 'description' => T_('after'), 'sql' => '>');
     $this->basetypes['multiple'] = array_merge($this->basetypes['text'], $this->basetypes['numeric']);
     switch ($searchtype) {
         case 'song':
             $this->types[] = array('name' => 'anywhere', 'label' => T_('Any searchable text'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'title', 'label' => T_('Title'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'album', 'label' => T_('Album'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'artist', 'label' => T_('Artist'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'composer', 'label' => T_('Composer'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'comment', 'label' => T_('Comment'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'label', 'label' => T_('Label'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'album_tag', 'label' => T_('Album tag'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'file', 'label' => T_('Filename'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'year', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'time', 'label' => T_('Length (in minutes)'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             if (AmpConfig::get('ratings')) {
                 $this->types[] = array('name' => 'rating', 'label' => T_('Rating'), 'type' => 'numeric', 'widget' => array('select', array('1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars')));
             }
             if (AmpConfig::get('show_played_times')) {
                 $this->types[] = array('name' => 'played_times', 'label' => T_('# Played'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             }
             $this->types[] = array('name' => 'bitrate', 'label' => T_('Bitrate'), 'type' => 'numeric', 'widget' => array('select', array('32', '40', '48', '56', '64', '80', '96', '112', '128', '160', '192', '224', '256', '320')));
             $this->types[] = array('name' => 'played', 'label' => T_('Played'), 'type' => 'boolean', 'widget' => array('input', 'hidden'));
             $this->types[] = array('name' => 'added', 'label' => T_('Added'), 'type' => 'date', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'updated', 'label' => T_('Updated'), 'type' => 'date', 'widget' => array('input', 'text'));
             $catalogs = array();
             foreach (Catalog::get_catalogs() as $catid) {
                 $catalog = Catalog::create_from_id($catid);
                 $catalog->format();
                 $catalogs[$catid] = $catalog->f_name;
             }
             $this->types[] = array('name' => 'catalog', 'label' => T_('Catalog'), 'type' => 'boolean_numeric', 'widget' => array('select', $catalogs));
             $playlists = array();
             foreach (Playlist::get_playlists() as $playlistid) {
                 $playlist = new Playlist($playlistid);
                 $playlist->format();
                 $playlists[$playlistid] = $playlist->f_name;
             }
             $this->types[] = array('name' => 'playlist', 'label' => T_('Playlist'), 'type' => 'boolean_numeric', 'widget' => array('select', $playlists));
             $this->types[] = array('name' => 'playlist_name', 'label' => T_('Playlist Name'), 'type' => 'text', 'widget' => array('input', 'text'));
             $playlists = array();
             foreach (Search::get_searches() as $playlistid) {
                 // Slightly different from the above so we don't instigate
                 // a vicious loop.
                 $playlists[$playlistid] = Search::get_name_byid($playlistid);
             }
             $this->types[] = array('name' => 'smartplaylist', 'label' => T_('Smart Playlist'), 'type' => 'boolean_subsearch', 'widget' => array('select', $playlists));
             $metadataFields = array();
             $metadataFieldRepository = new \Lib\Metadata\Repository\MetadataField();
             foreach ($metadataFieldRepository->findAll() as $metadata) {
                 $metadataFields[$metadata->getId()] = $metadata->getName();
             }
             $this->types[] = array('name' => 'metadata', 'label' => T_('Metadata'), 'type' => 'multiple', 'subtypes' => $metadataFields, 'widget' => array('subtypes', array('input', 'text')));
             $licenses = array();
             foreach (License::get_licenses() as $license_id) {
                 $license = new License($license_id);
                 $licenses[$license_id] = $license->name;
             }
             if (AmpConfig::get('licensing')) {
                 $this->types[] = array('name' => 'license', 'label' => T_('Music License'), 'type' => 'boolean_numeric', 'widget' => array('select', $licenses));
             }
             break;
         case 'album':
             $this->types[] = array('name' => 'title', 'label' => T_('Title'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'artist', 'label' => T_('Artist'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'year', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'image width', 'label' => T_('Image Width'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'image height', 'label' => T_('Image Height'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             if (AmpConfig::get('ratings')) {
                 $this->types[] = array('name' => 'rating', 'label' => T_('Rating'), 'type' => 'numeric', 'widget' => array('select', array('1 Star', '2 Stars', '3 Stars', '4 Stars', '5 Stars')));
             }
             $catalogs = array();
             foreach (Catalog::get_catalogs() as $catid) {
                 $catalog = Catalog::create_from_id($catid);
                 $catalog->format();
                 $catalogs[$catid] = $catalog->f_name;
             }
             $this->types[] = array('name' => 'catalog', 'label' => T_('Catalog'), 'type' => 'boolean_numeric', 'widget' => array('select', $catalogs));
             $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'video':
             $this->types[] = array('name' => 'filename', 'label' => T_('Filename'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'artist':
             $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'yearformed', 'label' => T_('Year'), 'type' => 'numeric', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'placeformed', 'label' => T_('Place'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'tag', 'label' => T_('Tag'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'playlist':
             $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'label':
             $this->types[] = array('name' => 'name', 'label' => T_('Name'), 'type' => 'text', 'widget' => array('input', 'text'));
             $this->types[] = array('name' => 'category', 'label' => T_('Category'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
         case 'user':
             $this->types[] = array('name' => 'username', 'label' => T_('Username'), 'type' => 'text', 'widget' => array('input', 'text'));
             break;
     }
     // end switch on searchtype
 }