a quick search result cache object

<?php 
class SearchRes
{
    protected 
$_resultsPerPage     5;
    static 
$_searches            = array();
    protected static 
$_array_name='tvdb-searches';

    public 
$query                null;
    public 
$pages                = array();
    public 
$num_results            null;
    
    public 
$_results             null;
    
    public static function 
getCache($query=null) {
        if(
$query==null)
            return 
false;
            
        if(empty(
self::$_searches))
            
self::$_searches $_SESSION[self::$_array_name];
            
        if(isset(
self::$_searches[$query]))
            return 
self::$_searches[$query];
        return 
false;
    }

    public static function 
addCache(&$selfobj) {
        
self::$_searches[$selfobj->query] = $selfobj;
        
$_SESSION[self::$_array_name]    = self::$_searches;
    }
    
    public function 
__construct($query=null$showsres=null) {
        if(
$query && $showsres) {
            
$this->query $query;
            
//$this->_results = $showsres;
            
$this->pages array_chunk($showsres$this->_resultsPerPage);
            
$this->num_results count($showsres);

            
SearchRes::addCache($this);
        }
    }
    
    public function 
setResultsPerPage($num=null) {
        if(
$num) {
            
$this->_resultsPerPage $num;
        }
    }    
}

?>

Tags · · · ·

Comments (0) September 02, 2011 2:50 am

I am "committed" ... as in subversion

Just committed my latest changes to my project with subversion. The subversion plugins for Nautilus and Gedit work pretty good. Ran into a huge set of conflicts earlier, overwrote some changes but have it all in place moving forward now.

And then there was ActiveRecord. So I have had my own Database Class for years. Just wrapped mysql functions and kept the connection. Was very useful and I used it on almost every project. Then I modified it to use the new mysql functions and the new OOP way of doing it. As soon as things went OOP with the DB is when I started using my own model objects as Data Mappers. This worked great for using a Record as an object, if you don't mind initially setting up the map from DB fields to your vars.
With ActiveRecord you don't have to worry about this stuff. It handles the reflection for you.

a quick example of old usage and new active record usage

<?php // old - straight db class
$db = new mydb;
$db->query("SELECT * FROM users");
while(
$db->next_record()) {
  
// do something with each record
}

// old - model class
$user = new User();
$users $user->getList();
foreach(
$users as $user) {
  
// do something for each record/object
}

// new - active record model
$users User::all() // User::find('all');
foreach($users as $user) {
  
// do something for each record/object
}


// saving //

// old
$db->query('insert into users (...) values (...)');

// old - model class
$user = new User();
$user->name='bob';
$user->save();    // would know to insert because no id field set

// new - active record
$user User::create(array('name'=>'bob'));
// or
$user = new User();
$user->name 'bob';
$user->save();
// or
$user = new User(array('name'=>'bob'));?>

The real power of ActiveRecord comes with the relationships and dynamic finds/creates

<?php 
$user 
User::find_by_name('bob');
$user User::find(1);
$user User::find_by_id(1);
// this gets nifty
$user User::find_or_create_by_name('bob');
// if no user is fond with name bob ... create

$user User::find_by_pet('cat');

// relationship

User has Posts

$posts 
$user->posts;
$user $posts[0]->user;


$user->create_post('some post');
?>

Needless to say, PHP ActiveRecord will be going into my framework. I am ditching my DB abstraction and models for this ActiveRecord system. The transition is easy and it is giving me more flexibility. I have removed duplicated code and haven't had to create wrapper classes and tons of functions to deal with the relationships and objects.

Tags · · · · ·

Comments (0) September 01, 2011 4:10 pm

quickbit new test project

starting a new project. gonna give eclipse with the php plugins a shot. also going to use subversion after it is up.

while "borrowing" a template. i needed to rewrite some file names of the images used. they all had a string on the front with a '_' seperator. time for some zsh shell:

zsh
autoload -U zmv
zmv 'something_(*)' '${1}'

done

Tags · · · ·

Comments (1) August 13, 2011 4:29 am

Hyzerflip Coming Shortly

Hyzerfip is up as a first version. Pretty much just to show what the site is looking like. Products aren't up but the homepage gives you the feel of the site.

More work will be coming shortly and always under construction.

Hyzerflip

This site is using my framework and we will see how far I can stretch it.

Tags · · · ·

Comments (0) December 16, 2009 3:03 am

Find Rocky Lockridge

I am trying to find Rocky Lockridge. Former Boxing Champion, now living on the streets in Camden, NJ. If anyone has any information of his whereabouts or knows anyone that knows how to contact him, please inform me pronto.

Star Ledger - Former boxing champ Rocky Lockridge living on streets of Camden, estranged from family, abusing drugs and alcohol

Tags · · ·

Comments (0) December 16, 2009 1:22 am

<< First < Previous [1 / 4] Next > Last >>