/**
  * @access public
  */
 function getFiles()
 {
     if ($this->_files === null) {
         $this->_files = array();
         $qry = 'SELECT file_id FROM ' . OOMedia::_getTableName() . ' WHERE category_id = ' . $this->getId();
         $sql = new rex_sql();
         $sql->setQuery($qry);
         $result = $sql->getArray();
         if (is_array($result)) {
             foreach ($result as $line) {
                 $this->_files[] =& OOMedia::getMediaById($line['file_id']);
             }
         }
     }
     return $this->_files;
 }
 /**
  * @access public
  */
 function getMediaByFileName($name)
 {
     $query = 'SELECT file_id FROM ' . OOMedia::_getTableName() . ' WHERE filename = "' . $name . '"';
     $sql = new rex_sql();
     $result = $sql->getArray($query);
     if (is_array($result)) {
         foreach ($result as $line) {
             return OOMedia::getMediaById($line['file_id']);
         }
     }
     return null;
 }
 /**
  * @access public
  */
 function searchMediaByFileName($name)
 {
     $query = 'SELECT file_id FROM ' . OOMedia::_getTableName() . ' WHERE filename = "' . addslashes($name) . '"';
     $sql = new sql();
     $result = $sql->get_array($query);
     $media = array();
     foreach ($result as $line) {
         $media[] = OOMedia::getMediaById($line['file_id']);
     }
     return $media;
 }
/**
 * Generiert eine Liste mit allen Media einer Dateiendung
 *
 * @param $extension Dateiendung der zu generierenden Liste
 *
 * @return TRUE bei Erfolg, sonst FALSE
 */
function rex_generateMediaExtensionList($extension)
{
    global $REX;
    $query = 'SELECT filename FROM ' . OOMedia::_getTableName() . ' WHERE SUBSTRING(filename,LOCATE( ".",filename)+1) = "' . $extension . '"';
    $sql = rex_sql::factory();
    $sql->setQuery($query);
    $content = '<?php' . "\n";
    for ($i = 0; $i < $sql->getRows(); $i++) {
        $content .= '$REX[\'MEDIA\'][\'EXTENSION\'][\'' . $extension . '\'][' . $i . '] = \'' . $sql->getValue('filename') . '\';' . "\n";
        $sql->next();
    }
    $content .= '?>';
    $list_file = $REX['GENERATED_PATH'] . "/files/{$extension}.mextlist";
    if (rex_file::put($list_file, $content)) {
        return true;
    }
    return false;
}
 /**
  * @access public
  * @deprecated 20.02.2010
  * Stattdessen getMediaByFileName() nutzen
  */
 function getMediaById($id)
 {
     global $REX;
     $id = (int) $id;
     if ($id == 0) {
         return null;
     }
     $sql = rex_sql::factory();
     // $sql->debugsql = true;
     $sql->setQuery('SELECT filename FROM ' . OOMedia::_getTableName() . ' WHERE file_id=' . $id);
     if ($sql->getRows() == 1) {
         return OOMedia::getMediaByFileName($sql->getValue('filename'));
     }
     return NULL;
 }