chopin Posted May 10, 2016 Share Posted May 10, 2016 This is a question about the file attachment array variable. I want to capture the array variables for file uploads, because I want to add an HTML5 mp3 player for mp3s, and a pdf viewer for PDFS to forum topics. So I've created my own Class file in System/Custom/Custom.php. It seems that I can successfully pass the $title and $url variables from the attachedFile template, into my custom function like so: {expression="\IPS\Custom::MP3Player($title, $url)"} But the issue is I have to figure out when the loop terminates. The best way to do this is to capture "counts" of each file type within a topic, so that I can properly close tags for mp3s and pdfs (for example, a list using <ul>. But it seems there is an iterator function elsewhere that captures the array variable for attachments. So let's assume I have 4 mp3s and 4 pdfs, pseudocode is as follows: if mp3 count = 1 then "<ul>" if mp3 > 1 and mp3 < 4 then "<li>" if mp3 = 4 then "</ul>" And the same goes for file types of pdf. Any help would be appreciated! Link to comment Share on other sites More sharing options...
chopin Posted May 10, 2016 Author Share Posted May 10, 2016 I figured out how to accomplish what I need: $tid = topic id; //Get the sql select statement and convert into an array $sql = iterator_to_array(\IPS\Db::i()->select( array('attachment_id', 'id1', 'attach_ext', 'attach_file', 'attach_date'), 'core_attachments_map', 'id1 = $tid', 'attach_ext, attach_date ASC' ) -> join('core_attachments', 'attach_id = attachment_id' ) ); //Now iterate through the attachments for this particular post foreach ($sql as $row){ // use $row['attachment_id'], $row['id1'], $row['attach_ext'] etc // Now we can close our tags since we have more control } For the level of control that I needed, I think an sql statement was the only way. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.