xoops-rb-framework


some useful functions and class method for Xoops developer (PHP5)

latest version here http://xoops.svn.sourceforge.net/viewvc/xoops/XoopsModules/rbsns/

Currently Xoops CRUD handler

After xoops 2.3.0 had a new powerful CRUD handler XoopsPersistableObjectHandler, and combination Criteria handler manipulation MySQL do CRUD or ORM work like below code $article_handler =& xoops_getmodulehandler('article', 'news'); $criteria = new CriteriaCompo(new Criteria('uid', 1)); $criteria->add(new Criteria('status', 1)); $criteria->setLimit(10); $criteria->setStart(0); $criteria->setSort('created', 'DESC'); $articles = $article_handler->getObjects($criteria, true);

With RB CRUD handler you can write like

Chain Object

RbCrudHandler only one file, but write less do more $article_handler =& xoops_getmodulehandler('article', 'news'); $articles = $article_handler->where('uid = 1 AND status = 1')->order_by('created DESC')->limit(10, 0)->getObjects();

Or

$article_handler =& xoops_getmodulehandler('article', 'news'); $article_handler->where('uid = 1'); $article_handler->where('status = 1'); $article_handler->order_by('created DESC'); $article_handler->limit(10, 0); $articles = $article_handler->getObjects();

Or

``` $condition = array(); $condition[] = 'uid = 1'; $condition[] = 'status = 1';

$article_handler =& xoops_getmodulehandler('article', 'news'); $article_handler->where($condition)->order_by('created DESC')->limit(10, 0); $articles = $article_handler->getObjects(); ```

Or

``` $condition = array(); $condition[] = 'uid = 1'; $condition[] = 'status = 1';

$article_handler =& xoops_getmodulehandler('article', 'news'); $articles = $article_handler->getObjects($condition, 'created DESC', 10 ,0); ```

will get the same result

Write less

XoopsPersistableObjectHandler insert data smaple $pm_handler =& xoops_gethandler('privmessage'); $pm =& $pm_handler->create(); $pm->setVar("subject", $_POST['subject']); $pm->setVar("msg_text", $_POST['message']); $pm->setVar("to_userid", $_POST['to_userid']); $pm->setVar("from_userid", $xoopsUser->getVar("uid")); if (!$pm_handler->insert($pm)) { echo "Error"; } else { echo "successful"; }

RbCrudHandler insert data smaple $pm_handler =& xoops_gethandler('privmessage'); $pm_handler->data(array('from_userid' => $xoopsUser->getVar("uid"))); if (!$pm_handler->insertRow($_POST)) { echo "Error"; } else { echo "successful"; }

How to use in my module

First you must know how to planing your module DB table and define XoopsObject constructor, if not rbTool can help you create a module prototype ```

if( ! defined( 'XOOPS_ROOT_PATH' ) ) die('root path not defined');

include XOOPS_ROOT_PATH.'/Frameworks/rb/class.crud.php';

class NewsArticle extends RbCrud { // constructor function __construct() { $this->initVar('art_id', XOBJ_DTYPE_INT, null, false); $this->initVar('cat_id', XOBJ_DTYPE_INT, null, false); $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 255); $this->initVar('content', XOBJ_DTYPE_TXTAREA, null, false); $this->initVar('created', XOBJ_DTYPE_INT, 0, false); $this->initVar('uid', XOBJ_DTYPE_INT, 0, false); $this->initVar('ip', XOBJ_DTYPE_TXTBOX, null, false, 15); }

function NewsArticle()
{
    $this->__construct();
}

}

class NewsArticleHandler extends RbCrudHandler { function __construct(&$db) { parent::__construct($db, 'news_article', 'NewsArticle', 'art_id', 'created DESC'); }

function NewsArticleHandler(&$db)
{
    $this->__construct($db);
}

}

?> ```

RB Tool

Xoops Class Maker, require install RB Framework

this module can make you selected database tables be a class file read more see rbTool

Project Information

Labels:
PHP5 XOOPS Framework Tool Module Object prototype_maker class_maker openid