You are here

class ZencoderJob in Video 7

Hierarchy

Expanded class hierarchy of ZencoderJob

File

modules/video_zencoder/includes/Zencoder.php, line 28

View source
class ZencoderJob {
  var $new_job_url = "https://app.zencoder.com/api/jobs";

  //https://app.zencoder.com/api/jobs

  //https://zencoder-staging.heroku.com/api/jobs
  var $new_job_params = array();
  var $new_job_json;
  var $created = false;
  var $errors = array();

  // Attributes
  var $id;
  var $outputs = array();

  // Initialize
  function ZencoderJob($params, $options = array()) {

    // Build using params if not sending request
    if ($options["build"]) {
      $this
        ->update_attributes($params);
      return true;
    }
    $this->new_job_params = $params;
    $this->created = $this
      ->create();
  }

  // Send Job Request to API
  function create() {

    // Send request
    $request = new ZencoderRequest($this->new_job_url, false, $this->new_job_params);
    if ($request->successful) {
      $this
        ->update_attributes($request->results);
      return true;
    }
    else {
      $this->errors = array_merge($this->errors, $request->errors);
      return false;
    }
  }

  // Add/Update attributes on the job object.
  function update_attributes($attributes = array()) {
    foreach ($attributes as $attr_name => $attr_value) {

      // Create output file objects
      if ($attr_name == "outputs" && is_array($attr_value)) {
        $this
          ->create_outputs($attr_value);
      }
      elseif (!function_exists($this->{$attr_name})) {
        $this->{$attr_name} = $attr_value;
      }
    }
  }

  // Create output file objects from returned parameters.
  // Use the Label for the key if avaiable.
  function create_outputs($outputs = array()) {
    foreach ($outputs as $output_attrs) {
      if ($output_attrs["label"]) {
        $this->outputs[$output_attrs["label"]] = new ZencoderOutputFile($output_attrs);
      }
      else {
        $this->outputs[] = new ZencoderOutputFile($output_attrs);
      }
    }
  }

}

Members