Yii2 - Gridview play next song - html

I have a Gridview in my Yii2 app that loads a HTML5 audio player for each mp3 audio file stored in a folder. Every row of the Gridview has it's own audio player. It does that because the file path of each mp3 file is stored in the database.
Here it is:
<?= GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'id',
'nome',
//'ficheiro',
[
'label' => '',
'format' => 'raw',
'value'=> function ($data){
return "<audio controls='controls'>
<source src='" . $data->ficheiro . "' type='audio/mp3' />
</audio>";
},
],
//'dummy1',
//'dummy2',
// 'dummy3',
// 'dummy4',
// 'dummy5',
['class' => 'yii\grid\ActionColumn', 'template' => ''],
],
]); ?>
At the end of one file playing is there a way to activate the next row audio player and start play the next file?
I've searched but only encounter the solution to play the next file in the same audio player file playlist. Not to activate the next audio player with it's own file.
Many thanks for a possible solution.

Maybe this snippet can help you:
$(function(){
var audio = $('audio');
audio.on('ended', function(){
endedTrackIndex = audio.index(this);
if((endedTrackIndex + 1) >= audio.size()) {
return true;
}
nextTrack = audio.get(endedTrackIndex + 1);
nextTrack.play();
});
});
Read the audio dom reference about methods, properties and events available for audio element

Related

Custom loading MediaWiki skinScripts

I'm about to set up some custom JS and CSS using something like this in LocalSettings.php, from here: https://www.mediawiki.org/wiki/Snippets/Load_an_additional_JavaScript_or_stylesheet_file_on_all_pages#Code
$wgResourceModules['zzz.customizations'] = array(
'styles' => "skin.css", // Stylesheet to be loaded in all skins
// Custom styles to apply only to Vector skin. Remove if you don't use it
'skinStyles' => array(
'vector' => 'skin-vector.css',
),
// End custom styles for vector
'scripts' => "skin.js", // Script file to be loaded in all skins
'localBasePath' => "$IP/customizations/",
'remoteBasePath' => "$wgScriptPath/customizations/"
);
function efCustomBeforePageDisplay( &$out, &$skin ) {
$out->addModules( array( 'zzz.customizations' ) );
}
This code shows a custom CSS that's loaded only for the vector skin, and another that's always loaded. I want to do the same with with the JavaScript, that is, load a JS file that's only for the vector skin as well as one that is always loaded.
I see from that documentation (https://www.mediawiki.org/wiki/Manual:$wgResourceModules) that skinScripts is supported, but I don't know how it would fit into the above code. Could anyone show me how to modify the above code to make that happen? Thanks.
The documentation you linked says:
skinScripts
Scripts to include in specific skin contexts.
Array keyed by skin name containing file path string or array of file path strings.
That isn't much different from the skinStyles entry, so I'd assume that something like this would work:
$wgResourceModules['zzz.customizations'] = array(
'styles' => "skin.css", // Stylesheet to be loaded in all skins
// Custom styles to apply only to Vector skin. Remove if you don't use it
'skinStyles' => array(
'vector' => 'skin-vector.css',
),
// End custom styles for vector
'scripts' => "skin.js", // Script file to be loaded in all skins
'skinScripts' => array(
'vector' => 'skin-vector.js',
),
'localBasePath' => "$IP/customizations/",
'remoteBasePath' => "$wgScriptPath/customizations/"
);
function efCustomBeforePageDisplay( &$out, &$skin ) {
$out->addModules( array( 'zzz.customizations' ) );
}
Where vector is the name of the skin, and skin-vector.js is the JavaScript file that only goes with that skin.

How to convert HTML page to PDF in YII framework

this is my output I need to convert my HTML page to PDF format in YII framework.
I have tried HTML2PDF where it gives me this error.
[ERROR] It seems that HTML2PDF dependencies are not installed… you must install them with composer install
Then I have installed composer also. But the error is same.
Suggest me solution of this or give any new idea.
this is my view code..
<tr>
<?php echo "<td>".$record->inv_article."</td>" ?>
<?php echo "<td>".$record->inv_no."</td>" ?>
<?php echo "<td >".$record->inv_weight."</td>" ?>
<?php echo "<td >".$record->inv_amt."</td>" ?>
<?php echo "<td >".$record->inv_freight."</td>" ?>
<?php echo "<td >".$record->inv_bilticharges."</td>" ?>
<?php echo "<td >".$record->inv_bilticharges."</td>" ?>
<?php $i++; ?>
</tr>
Here is my controller in my project
public function actionGeneratePDF($id){
$mpdf1 = Yii::app()->ePdf->mpdf();
$myhtml=$this->renderPartial('lorryprint', array(
'model'=>$model,'invid'=>$id), true);
$mpdf1->WriteHTML($myhtml);
$file_name= $id.'.pdf';
ob_end_clean();
$mpdf1->Output($file_name,EYiiPdf::OUTPUT_TO_DOWNLOAD );
}
CHECK OUT HERE
I have the same problem couple of months ago, I wanted to convert the html page into pdf in Yii Framework. It took me 3 days to find out how to use it properly. So there are two ways to generate PDF from html by using PHP classes below:
HTML2PDF
mPDF
I have used both but I will prefer you to use mPDF. it is much better than HTML2PDF. Here is method on How to use mPDF in Yii Framework.
First of all you need
YiiPDF - Small Yii extension, that wraps a few PHP libraries (mPDF and HTML2PDF so far) to convert HTML to PDF.
mPDF - is a PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support.
I have used mPDF Version 5.7 Because you don't need a composer to install it.
So just download Yii PDF and mPDF from above links and extract them and then Rename the folders to yii-pdf and mpdf and place them into your project in protected\extensions.
Then open your protected/config/main.php and add the below code.
'components'=>array(
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.extensions.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
/*'defaultParams' => array( // More info: http://mpdf1.com/manual/index.php?tid=184
'mode' => '', // This parameter specifies the mode of the new document.
'format' => 'A4', // format A4, A5, ...
'default_font_size' => 0, // Sets the default document font size in points (pt)
'default_font' => '', // Sets the default font-family for the new document.
'mgl' => 15, // margin_left. Sets the page margins for the new document.
'mgr' => 15, // margin_right
'mgt' => 16, // margin_top
'mgb' => 16, // margin_bottom
'mgh' => 9, // margin_header
'mgf' => 9, // margin_footer
'orientation' => 'P', // landscape or portrait orientation
)*/
)
),
),
Please note: In above code 'class' => 'ext.yii-pdf.EYiiPdf', means that you have a file called EYiiPdf in protected/extensions/yii-pdf/ and similarly that mPDF extension 'librarySourcePath' => 'application.extensions.mpdf.*', exists in protected/extensions/mpdf
Then you can create a function in your controller.
public function actionGeneratePDF($id){
$model = AsfiUsers::model()->findByPk($id);
$mpdf1 = Yii::app()->ePdf->mpdf();
$myhtml=$this->renderPartial('ProfileView', array(
'personal_info'=>$model), true);
$mpdf1->WriteHTML($myhtml);
$file_name= $id.'.pdf';
ob_end_clean();
$mpdf1->Output($file_name,EYiiPdf::OUTPUT_TO_DOWNLOAD );
}
So in my View in ProfileView I have added a button at the top of it.
<?php echo CHtml::link('PDF Version',array('AsfiUser/GeneratePDF','id'=>$this->id), array('class'=>'btn btn-info btn-sm')); ?>
After click on that button, It will download the PDF of that html page. My Profile View has tables too so Thats why I have used mPDF not Html2PDF. In html2pdf, It doesnot give much options to adjust tables margin etc. But in mpdf it is automatically adjust and will be a perfect PDF.
FOR HTML2PDF
In case if you want to use HTML2PDF, all the steps are same. Just download Old version of html2pdf, New version will have problem like dependencies are not installed. Just like you have them now.
All steps are same, just add this into your protected/config/main.php below the mPDF class in yii-pdf component array.
'HTML2PDF' => array(
'librarySourcePath' => 'application.extensions.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
/*'defaultParams' => array( // More info: http://wiki.spipu.net/doku.php?id=html2pdf:en:v4:accueil
'orientation' => 'P', // landscape or portrait orientation
'format' => 'A4', // format A4, A5, ...
'language' => 'en', // language: fr, en, it ...
'unicode' => true, // TRUE means clustering the input text IS unicode (default = true)
'encoding' => 'UTF-8', // charset encoding; Default is UTF-8
'marges' => array(5, 5, 5, 8), // margins by default, in order (left, top, right, bottom)
)*/
)
and then your controller function will be same just replace the name with mPDF.
public function actionGeneratePDF($id){
$model = AsfiUsers::model()->findByPk($id);
$html2pdf= Yii::app()->ePdf->HTML2PDF();
$myhtml=$this->renderPartial('ProfileView', array(
'personal_info'=>$model), true);
$html2pdf->WriteHTML($myhtml);
$file_name= $id.'.pdf';
ob_end_clean();
$html2pdf->Output($file_name,EYiiPdf::OUTPUT_TO_DOWNLOAD );
}
and create the same button in view for it. I hope it will work for you. I have used the same and working perfectly.
UPDATED:
This code works, just try to check you haven't made any mistake and secondly add this below code at the top of your html view file.
<?php
ob_start(); //started buffering
?>
<?php echo CHtml::link('PDF Version',array('AsfiUser/GeneratePDF','id'=>$this->id), array('class'=>'btn btn-info btn-sm')); ?>
It will add the button on the page which u want to make PDF, when u click on the button, it will download the file while it will take few seconds to a minute depending on page size.
Updated 2
add this line to ur controller
$myhtml=preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $myhtml);
So your controller will be like this
public function actionGeneratePDF($id){
$mpdf1 = Yii::app()->ePdf->mpdf();
$myhtml=$this->renderPartial('lorryprint', array(
'model'=>$model,'invid'=>$id), true);
$myhtml=preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $myhtml);
$mpdf1->WriteHTML($myhtml);
$file_name= $id.'.pdf';
ob_end_clean();
$mpdf1->Output($file_name,EYiiPdf::OUTPUT_TO_DOWNLOAD );
}
OR
If the above controller part doesnot work then fix ur code.
Your this line says $model
$myhtml=$this->renderPartial('lorryprint', array(
'model'=>$model,'invid'=>$id), true);
and in ur view you are using $record instead of $model, Have u done it properly in ur loop. Is ur View file showing results or not?
If it is showing properly,then ur view file lorryprint should be like this. add <td> outside the php tag.
<?php
ob_start(); //started buffering
?>
<?php echo CHtml::link('PDF Version',array('AsfiUser/GeneratePDF','id'=>$this->id), array('class'=>'btn btn-info btn-sm')); ?>
//more code here
<td><?php echo $record->inv_article;?></td>
<td><?php echo $record->inv_no;?></td>
<td><?php echo $record->inv_weight;?></td>
<td><?php echo $record->inv_amt;?></td>
<td><?php echo $record->inv_freight;?></td>
<td><?php echo $record->inv_bilticharges;?></td>
<td><?php echo $record->inv_bilticharges;?></td>
<?php $i++; ?>

Yii2 Set selected value to dropdown which depends on another dropdown

I have a form in which there are two selectboxes, The second selectbox depends of the first one.
All form data are saved in session because there is a back button in order user to be able to change things after firs submitting.
So when user click's the back button I am able to assign the session value to the first dropdown but not to the second one which depends from the first one.
if(isset($session['form_1']['state_code']))
{ $state_code = $session['form_1']['form_1'];
$this->registerJs('$("select#state_select").trigger("change");');} else { $state_code = " "; }
echo $form->field($model, 'state_code')->dropDownList($states,
[ 'prompt' => ' Select state...',
'options' => [$state_code => ['Selected'=>'selected']],
'onchange' => '
$.get("'.Yii::$app->urlManager->createUrl('city?id=').
'"+$(this).val(),function( data ) {
$("select#city").html( data );
});'
]);
This code works for the first drop down
And the bellow code you can see the other drop down which does not work:
if(isset($session['form_2']['city_select']))
{ $c_id = $session['form_2']['city_select']; }
else{ $c_id = ''; }
echo $form->field($model, 'city_select')->dropDownList(['0' => 'Please select state..'],
[
'options' => [$c_id => ['Selected'=>'selected']],
]);
Any Idea ?
As an alternative you can use Kartik extension which solve your problem.

cmb2 tinymce menu bar not showing

I'm using CMB2 to allow for front end submissions using a custom post type. The code works well but the problem is that it doesn't support menu bar. There's the textarea, submit button and the title but menu bar is not showing. What could be the problem?
Below is my code:
$cmb->add_field( array(
'name' => __( 'New Post Content', 'wds-post-submit' ),
'id' => 'submitted_post_content',
'type' => 'wysiwyg',
'options' => array(
'wpautop' => true, // use wpautop?
'media_buttons' => true, // show insert/upload button(s)
'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
'tabindex' => true,
'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the `<style>` tags, can use "scoped".
'editor_class' => '', // add extra class(es) to the editor textarea
'teeny' => false, // output the minimal editor config used in Press This
'dfw' => false, // replace the default fullscreen with DFW (needs specific css)
'tinymce' => array(
'menubar' => true;
), // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
),
) );
A little late, but: change
'menubar' => true;
to
'menubar' => true,

Wordpress Customizer not Saving Data

I have a function to add a option to the wordpress customiser, its uploading an image to a header as well as a control for changing the color. the problem im having is that while i can upload and preview a color or image, after refreshing the page the change is removed, so i assume its not saving correctly?
below is the code in the functions file.
// ADD HEADER IMAGE AND COLOR TO CUSTOMIZER
function customizer_header ( $wp_customize ) {
// ADD SECTIONS
$wp_customize->add_section( 'header_section', array(
'title' => __( 'Navigation Bar', 'dc_header' ),
'priority' => 80,
) );
// ADD SETTINGS
$wp_customize->add_setting( 'header_color',
array(
'default' => '',
'sanitize_callback' => '',
) );
$wp_customize->add_setting( 'header_image',
array(
'default' => '',
'sanitize_callback' => '',
) );
// ADD CONTROLS
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize, 'header_color',
array(
'label' => __( 'Header Color' ),
'section' => 'header_section',
'settings' => 'header_color',
) ) );
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize, 'header_image',
array(
'label' => __( 'Header Image', 'dc_header' ),
'section' => 'header_section',
'settings' => 'header_image',
) ) );
}
add_action( 'customize_register', 'customizer_header' );
I saw another post where someone was using this snippet, do i need to use this?
ive had it working without this in the past though but unsure whats the best way.
// ADD TO FRONTEND
function dc_header_frontend() {
?>
<style type="text/css">
#custom-header { background: <?php echo get_theme_mod( 'header_color' ); ?>; }
</style>
<?php
}
UPDATE: Found the problem to this, is was the allocated memory kept running out so upped the amount in the htaccess file, this has resolved the problem for anyone else experiencing it.