Menus

Wednesday, 20 September 2023

Yii2 Gridview Dataprovider create with relationship

 

In Yii2, if you want to create a GridView with a DataProvider that includes related models and additional select columns, you can do the following:

  1. Create a Query with Related Models and Additional Select Columns:

$query = YourModel::find()

    ->select(['your_table.*', 'related_table.column AS alias'])

    ->joinWith('relatedRelation')

    ->where(['your_condition'])

    ->asArray();


Create a DataProvider using the Query:


$dataProvider = new \yii\data\ActiveDataProvider([

    'query' => $query,

    'pagination' => [

        'pageSize' => 20, // Set your desired page size

    ],

]);


Configure GridView to use the DataProvider:


<?= \yii\grid\GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'attribute1',
        'attribute2',
        // ... other attributes from your model ...
        'alias', // Access the added select column
        [
            'class' => 'yii\grid\ActionColumn',
            // ... configure action buttons ...
        ],
    ],
]); ?>


Make sure to replace 'your_table', 'related_table', 'alias', 'relatedRelation', and 'attribute1', 'attribute2' with actual table and attribute names from your application.

Keep in mind that this assumes you have properly set up your models, relations, and database tables in Yii2.

Remember to adjust the column names, relations, and conditions to match your specific application. This code serves as a template and may need to be customized based on your specific requirements.

Monday, 31 July 2023

Number System Conversion



 Decimal to Octal




















Saturday, 22 October 2022

How to Swap Two Arrays In C Language

 

#include<stdio.h>

void main()

{


  int a[5] = {5,6,7,8,9};

  int b[5] = {1,2,3,4,5};

  

  int i,swap;


  for(i=0;i<5;i++)

  {


    swap = a[i];

    a[i] = b[i];

    b[i] = swap;


  } 


  printf("A = ");

  for(i=0;i<5;i++)

    printf("%d ",a[i]);


  printf("\nB = ");

  for(i=0;i<5;i++)

    printf("%d ",b[i]); 


  printf("\n");

}







Saturday, 23 April 2022

Largest of three numbers in C

 #include <stdio.h>

int main()

{

 int x,y,z;

 clrscr();

 printf("Enter three numbers :");

 scanf("%d,%d,%d",&x,&y,&z);


 if(x>y)

 {

   if(x>z)

     printf("Largest value : %d ",x);

   else

     printf("Largest value : %d ",z);

 }

 else

 {

   if(y>z)

     printf("Largest value : %d",y);

   else

     printf("Largest value : %d",z);

 }


 getch();

}

Saturday, 5 March 2022

C language MCQ (Multiple Choise Questions)

Art of C Programming


1 . Address stored in the pointer variable is of type __________
 
 
 
 

 

2. "*" is called as ___________
 
 
 
 


3. Comment on the following pointer declaration?

     int *ptr, p;
 
 
 
 


4. Which of the following are correct syntaxes to send an array as a parameter to function

 
 
 
 


5. Which of the following is not possible in C?

 
 
 
 


 

Answers

1. Integer

2.  

3. ptr is a pointer to integer, p is not.

4. func(&array);

5. None of the mentioned



Wednesday, 23 February 2022

Printing Pattern in C | Inverted Half Pyramid

 


#include<stdio.h>

void main()

{

int i,j,r=6;

clrscr();


  for(i=1;i<=r;i++)

  {

   for(j=r;j>=i;j--)

   {

     printf("*");

   }

   printf("\n");

  }


getch();

}





Friday, 24 September 2021

How to integrate vimeo videos to android app

 

Vimeo-Player Using Exoplayer   


This sample demonstrates how to use the vimeo video with exoplayer

 


 

Prerequisites

 


Source Code

 

activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

/>

</androidx.constraintlayout.widget.ConstraintLayout>


MainActivity.java

package com.logiclab.vimeo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ui.PlayerView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;
import com.vimeo.networking.Configuration;
import com.vimeo.networking.VimeoClient;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import cz.msebera.android.httpclient.Header;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private static final String VIMEO_ACCESS_TOKEN = "access token";
private static final String VIMDEO_ID = "Your video id";

private PlayerView playerView;
private SimpleExoPlayer player;

//Release references
private boolean playWhenReady = false; //If true the player auto play the media
private int currentWindow = 0;
private long playbackPosition = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Reference exoplayer view
playerView = findViewById(R.id.video_view);
Button playBtn = findViewById(R.id.button2);

playBtn.setOnClickListener(this);

//Build vimeo configuration
configVimeoClient();

} //onCreate


private void createMediaItem(String url) {
MediaItem mediaItem = MediaItem.fromUri(url);
player.setMediaItem(mediaItem);
}


private void initializePlayer() {

//To play streaming media, you need an ExoPlayer object.
//SimpleExoPlayer is a convenient, all-purpose implementation of the ExoPlayer interface.
player = new SimpleExoPlayer.Builder(this).build();
playerView.setPlayer(player);

callVimeoAPIRequest();

//Supply the state information you saved in releasePlayer to your player during initialization.
player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow, playbackPosition);
player.prepare();
}


private void callVimeoAPIRequest() {

String videolink = "https://player.vimeo.com/video/" + VIMDEO_ID +"/config";

AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
//params.put("key", "value");
// params.put("more", "data");
client.get(videolink, params, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String res) {
// called when response HTTP status is "200 OK"
try {

JSONObject jsonObject = new JSONObject(res);
JSONObject req = jsonObject.getJSONObject("request");
JSONObject files = req.getJSONObject("files");
JSONArray progressive = files.getJSONArray("progressive");

JSONObject array1 = progressive.getJSONObject(1);
String v_url=array1.getString("url");

Log.d("URLL ",v_url);

createMediaItem(v_url);

} catch (JSONException e){
e.printStackTrace();
}
}

@Override
public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
}
}
);
}

private void configVimeoClient() {
Configuration.Builder configBuilder =
new Configuration.Builder(MainActivity.VIMEO_ACCESS_TOKEN) //Pass app access token
.setCacheDirectory(this.getCacheDir());
VimeoClient.initialize(configBuilder.build());
}

@Override
public void onClick(View v) {
player.setPlayWhenReady(true);
}

@Override
public void onStart() {
super.onStart();
initializePlayer();
}

}


Android Manifest.xml

set permissions

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />



build.gradle(:app)

add

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
 
 dependencies
//Vimeo Network
implementation "com.vimeo.networking:vimeo-networking:1.1.3"
//Full ExoPlayer library
implementation 'com.google.android.exoplayer:exoplayer:2.12.0'
//Android Async Http Client
implementation 'com.loopj.android:android-async-http:1.4.9' 






 

 

 

 

 

 https://guides.codepath.com/android/Using-Android-Async-Http-Client


Sending a Network Request

Now, we just create an AsyncHttpClient, and then execute a request specifying an anonymous class as a callback:

import com.loopj.android.http.*;
import cz.msebera.android.httpclient.Header;

AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("key", "value");
params.put("more", "data");
client.get("http://www.google.com", params, new TextHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, String res) {
            // called when response HTTP status is "200 OK"
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
            // called when response HTTP status is "4XX" (eg. 401, 403, 404)
        }	
    }
);

This will automatically execute the request asynchronously and fire the onSuccess when the response returns a success code and onFailure if the response does not.