Skip to content

Instantly share code, notes, and snippets.

@Tapha
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save Tapha/9fec855e2d2fd39bb3c8 to your computer and use it in GitHub Desktop.

Select an option

Save Tapha/9fec855e2d2fd39bb3c8 to your computer and use it in GitHub Desktop.
Podcast Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Podcasts extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('ion_auth');
$this->load->model('Podcast');
$this->load->helper('url');
}
public function index()
{
if ($this->ion_auth->logged_in())
{
//check for user type to direct to right backend.
//redirect them to the login page
redirect('auth', 'refresh');
}
$this->load->helper('url');
$this->load->view('main');
//check in auth user type then direct to appropriate dash
}
public function unpublish()
{
$ep_id = $this->uri->segment(3);
$this->Podcast->unpublish($ep_id);
}
public function set_published()
{
$ep_id = $this->uri->segment(3);
$this->Podcast->set_published($ep_id);
}
public function new_episode()
{
if (!$this->ion_auth->logged_in())
{
//check for user type to direct to right backend.
//redirect them to the login page
redirect('auth', 'refresh');
}
$this->load->helper('url');
$user = $this->ion_auth->user()->row();
$user_id = $user->id;
$pod_id = $this->Podcast->get_pod_id($user_id);
$episode_name = $this->input->post('episode_name');
$data['no_episodes'] = 0;
//Add Firebase Hash & Firebase URL
//Create Hash
$firebase_hash = substr(md5(rand()),0,2).$pod_id.$user_id.random_string('alnum', 4).$user_id.$pod_id.substr(md5(rand()),0,2);
$firebase_url = 'https://vivid-fire-570.firebaseio.com/';
//See if hash already exists
$query = $this->db->get_where('episodes', array('firebase_hash' => $firebase_hash));
if ($query->num_rows() > 0) {
$time = date('Y-m-d H:i:s', strtotime('-1 hour'));
$firebase_hash = substr(md5(rand()),0,2).$pod_id.$user_id.random_string('alnum', 4).$user_id.$pod_id.substr(md5(rand()),0,2);
$firebase_url = 'https://vivid-fire-570.firebaseio.com/';
$data2 = array(
'published' => 0,
'meeting_duration' => 30,
'name' => $episode_name,
'firebase_hash' => $firebase_hash,
'firebase_url' => $firebase_url.$firebase_hash,
'user_id' => $user_id,
'pod_id' => $pod_id,
'created_at' => $time
);
$this->Podcast->add_episode($data2);
} else {
//Add
$time = date('Y-m-d H:i:s', strtotime('-1 hour'));
$data2 = array(
'published' => 0,
'name' => $episode_name,
'firebase_hash' => $firebase_hash,
'firebase_url' => $firebase_url.$firebase_hash,
'user_id' => $user_id,
'pod_id' => $pod_id,
'created_at' => $time
);
$this->Podcast->add_episode($data2);
}
$data['pod_det'] = $this->Podcast->get_podcast($pod_id);
$data['pod_dets'] = $this->Podcast->get_podcasts($user_id, $pod_id);
$data['episode_data'] = $this->Podcast->get_episodes($pod_id, $user_id);
$this->load->view('members/main', $data);
//check in auth user type then direct to appropriate dash
}
public function add()
{
if (!$this->ion_auth->logged_in())
{
//check for user type to direct to right backend.
//redirect them to the login page
redirect('auth', 'refresh');
}
$this->load->helper('url');
$user = $this->ion_auth->user()->row();
$user_id = $user->id;
$podcast_name = $this->input->post('podcast_name');
$data3 = array(
'name' => $podcast_name,
'user_id' => $user_id,
);
$this->Podcast->add_podcast($data3);
$pod_id = $this->db->insert_id();
//switch context
$this->Podcast->change_context($user_id, $pod_id);
$data['no_episodes'] = 0;
$data['pod_det'] = $this->Podcast->get_podcast($pod_id);
$data['pod_dets'] = $this->Podcast->get_podcasts($user_id, $pod_id);
$data['episode_data'] = $this->Podcast->get_episodes($pod_id, $user_id);
$this->load->view('members/main', $data);
//check in auth user type then direct to appropriate dash
}
public function episode()
{
if (!$this->ion_auth->logged_in())
{
//check for user type to direct to right backend.
//redirect them to the login page
redirect('auth', 'refresh');
}
$this->load->helper('url');
$episode_id = $this->uri->segment(3);
$user = $this->ion_auth->user()->row();
$user_id = $user->id;
$pod_id = $this->Podcast->get_pod_id($user_id);
$data['no_episodes'] = 0;
$data['pod_det'] = $this->Podcast->get_podcast($pod_id);
$data['pod_dets'] = $this->Podcast->get_podcasts($user_id, $pod_id);
$data['episode_data'] = $this->Podcast->get_episode($episode_id);
$data['firebase_url'] = $this->Podcast->get_firebase_url($episode_id);
$this->load->view('members/episode', $data);
//check in auth user type then direct to appropriate dash
}
}
/* End of file Podcast.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment