TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Some input a new data model (http://www.talkphp.com/advanced-php-programming/4958-some-input-new-data-model.html)

Enfernikus 09-19-2009 03:55 AM

Some input a new data model
 
Well more correctly a new way of accessing data, perhaps not new I've seen things like this on other scripts and just want to know what you all thought of it

php Code:
<?php

$blog = new TCKObject;
$blog->setSubtype('blog_post')
     ->addRelationship($_POST['BlogCategoryGUID'], 'blog_category')
     ->searchableTags($_POST['tags'], ',')
     ->setOwner($_SESSION['user']);
$blog->title = $_POST['title'];
$blog->post  = $_POST['blog_body'];
$blog->dataToBeRemovedBecauseItsToLong = 'LOOOOOOOOOOOOOOOOOOOOOOOOOONNNNNNNNNNNGGGGGGGGGGGGG';
if( $blog->save() )
{
    if( $blog->dataToBeRemovedBecauseItsToLong->length > 0 )
    {
        $blog->dataToBeRemoved->delete();
    }
   
    header('location: page.php?guid=' . $blog->getGUID() );
}

/** A user object with specific functions **/
class TCKUser extends TCKObject
{
   
        public function __construct($guid = null)
        {
            parent::__construct($guid);
           
            //Define the type of object
            $this->setType('user');
        }
       
        public function addFriend( $guid )
        {
            $this->addRelationship($guid, 'friend');
        }
       
        public function retrieveFriends($count = false)
        {
            return $arrayOfFriends;
        }
       
        public static function getPopularUsers()
        {
            //Parameters: metastring name, metastrings value, the type of object,
            //and the owner of the object since we don't know 0 the default will suffice
            //null ( default ) returns all and finally if you just want
            //a count - set the fourth to true
            $users = parent::search('popular', true, 'user', 0, null, false);
            if( $users )
                return $users; //I just returns X number of objects representing his friends
        }
}

//GUID Of loggedin user
$user = new TCKUser(102);
if( $user->retrieveFriends(true) > 50 )
{
    $user->popular = true;
    $user->save();
}


//Retrieve all popular users
$popularUsers = TCKUsers::getPopularUsers();


All times are GMT. The time now is 11:40 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0