Tag: php

Zend_Service_Netflix Release 1 Available.

So about a month after initially starting on the code, I finally released two versions of the Zend_Service_Netflix wrapper for the Zend Framework, submitted a proposal to the Zend Framework Team, and changed the status on my proposal from “New” to “Ready for Review”.  Pheww was that hard work put to good use.  It feels good to get this off and running with the initial release.

What’s included in the release?
Like I mentioned before i created 2 releases.  One release contains only the catalog functionality.  It allows developers to use title search, title auto complete which can be used in conjunction with AJAX to create a autocomplete search box, retrieve detailed title information, and search actors/directors.  This package is intended for developers that want to use the extensive Netflix catalog on their own web site without the added functionality found in the full version of the release.

The second release, the FULL release, contains not only the catalog functionality but also allows developers to manage user queues, manage user ratings, retrieve user reviews, and most importantly create the request access url, the URL which users NEED to click that allows their app to retrieve restricted content.  So if the developer wanted to create a Zend Framework powered app that allowed users to add, delete, and update their “Watch Queue” or “Instant Watch Queue” they can do this by calling a simple method within this package.

Where can i get the release?
I committed the releases to the Google Code site Located here, Zend Framework Netflix.  The packages are properly named so you wont have trouble distinguishing which one you need.

Whats next?
The next steps for this project is to have the Zend Framework team review some of the code, my submitted outline, and hopefully approve it.  On my end I will continue to work on the code.  There are 2 items which i need to iron out, Updating Ratings, Deleting an Item from the users Queue, and updating the code to support the SIGNITURE METHOD HMAC-SHA1.  I will place these items and other “gotchas” on the google code twiki to continue to track my progress.  I will also clean up my PHPUnit tests.

I would like to also create a small set of examples for the user to refer to, as well as a small application users can see the code in use. Again i will provide the details on the google code twiki and here as well.

I’m anxious to hear back from anyone that’s using it how i can improve on it and what they think is a better approach.

Armando Padilla

Links of interest?  Maybe?

Zend Framework & Netflix – Zend_Service_Netflix

I popped on the headphones, slipped a Thievery Corporation track and started to read the new Netflix REST API. A few hours later and a mad rush to code, I created a pre-pre-pre-pre-alpha release package for the Zend Framework.  It’s a rough implementation that has much to be done to it and has not been flushed out that well. It currently supports only one REST call, “/catalog/title”, but I have plans to support the entire gambit of REST calls open by Netflix for this package.

For those interested in the netflix api check this page out.  It’s basically the netflix documentation. Its pretty straight-forward and should be an easy and fun read.  I was surprised they opened up their ‘predicted rating’ api. Nice touch 🙂 I can see A LOT of things developers can do with just the prediction REST api.

And for those that want to check out the Zend_Service_Netflix code i currently have, here is the Google Code Project Page link.  

I plan to finish the package by Sunday evening.  Here is my attack plan.

Attack Plan:

  1. Finish the concrete classes. (ETA Friday evening) 
  2. Finish Up the remaining REST calls (ETA Saturday Evening)
  3. Create test using PHPUnit. (ETA. as I go)
  4. Documentation.  (ETA Sunday evening) 
Ok so its like almost 2am and spent all evening reading and coding ill have move updates tomorrow evening.

Armando Padilla
PS.  Yes i know, the code looks like ass..sue me (no don’t that would suck) I did all that in a few (3) hours. 

Zend_Paginator and Your Result Set.

The day was cloudy, it rained last night (i love rain), so it placed me into one of those, “damn about time”, moods.  Then I popped open Chrome and came to one of my usual stomping grounds on the net.  I clicked on the thread. Read how a few people were having an issue I grappled with earlier when dealing with Zend_Paginator and decided to write. The issue, How to use the Zend_Paginator on a database result set without having to fetch ALL of the records.

What is the Pagination?  
A bit of an intro. What’s Pagination.  Pagination is simply a way in which developers allow users visiting a site to scroll through a long list of records be it 10 at at time, 100 at a time, or <your arbitrary number here> at a time.  Im sure you’ve seen it around the web but might not have called it by the fancy-smancy “Pagination” name.  Hell I call it, “that next and previous button thinggie”, or “that 1 2 3 4 5 page selector stuff”.  Lets continue. 

Pagination used to be an tedious but necessary task for developers.  I wont go into al the steps to create your own custom pagination code base but let me just tell you it sucked. Thank you Zend_Paginator for less stress in my life.

Zend_Paginator a public service announcement.
In its newest installment, Zend Framework 1.6, the developers at Zend added in a pagination component, Zend_Paginator.  This allowed developers like you and me to create Pagination features on the fly (it took me 1 minute to implement when i timed it)  Lets take a quick example.

<?php
require_once “Zend/Loader.php”;
Zend_Loader::loadClass(“Zend_Paginator”);

//Intialize records. This is what th user will paginate through.
$myRecords = array(“Armando Padilla”,
“Monica R.”,
“Elisa P.”,
“Francisca P.”,
“Guillermo P.”,
“Some awesome person in my family”);

//Create Paginator Object
$Paginator = Zend_Paginator::factory($myRecords);

//Set the current page were on.
$Paginator->setCurrentPageNumber($currentPage);

//Set the number of records to show per page
$Paginator->setItemCountPerPage(3);

//Save Paginator as View var.
$this->view->paginator = $Paginator;
?>

Going through the code above, we initialize our array of records which will be paginated by the user in the variable $myRecords.  I then create a Zend_Paginator object and pass in $myRecords into the factory method.  The Zend Framework then hooks everything else up for us behind the scenes and all we have to do is make sure we pass in the $currentPage the user is currently on and display the pagination links on our page.  

The Problem
So wheres the problem?  Well the problem lies in how users of the Zend_Paginator object are using it.  Many developers are using the Zend_Paginator object with database records errounously.  They hit the database, return ALL the records, store them into memory, and then allow Zend_Paginator to handle these potential HUGE record sets in the backend. Bleh  

Wrong way of doing it Example:

<?php
require_once “Zend/Loader.php”;
Zend_Loader::loadClass(“Zend_Paginator”);

//Initialize of DB object
$db = new Zend_Db::factory() //Paraphrasing here.
$statement = “SELECT * FROM Player”;
$myRecords = $db->fetchAll($statement);

//Create Paginator Object
$Paginator = Zend_Paginator::factory($myRecords);

//Set the current page were on.
$Paginator->setCurrentPageNumber($currentPage);

//Set the number of records to show per page
$Paginator->setItemCountPerPage(3);

//Save Paginator as View var.
$this->view->paginator = $Paginator; 
?>

Very inefficient.  

The Solution
We don’t have to select ALL the records in the Db but allow Zend_Paginator to select and use small manageable pieces at a time for us.  How?  If we had a table with 1000000 records we dont have to select all records but construct a Zend_Db_Select object with the appropriate criteria, and then pass that into the factory instead of the array.  Lets take a look how this is done using the same Players table.

The right way of doing it

<?php
require_once “Zend/Loader.php”;
Zend_Loader::loadClass(“Zend_Paginator”);

//Initialize of DB object
Zend_Loader::loadClass(“Zend_Db”);
$db = new Zend_Db::factory() //Paraphrasing here. 

//Create Select Object
Zend_Loader::loadClass(“Zend_Db_Select”);
$selectStatement = $db->select()->from(“Players”);

//Create Paginator Object
$Paginator = Zend_Paginator::factory($selectStatement);

//Set the current page were on.
$Paginator->setCurrentPageNumber($currentPage);

//Set the number of records to show per page
$Paginator->setItemCountPerPage(3);

//Save Paginator as View var.
$this->view->paginator = $Paginator;
?>

Thats all there is too it.  Less memory consumption because we dont have fetch ALL our records at a time and allows the Zend Framework to do the heavy lifting for us. Hope this helps a few people looking for the answer to this.