New Class for a new table

Hi,

I created the following table.


– Table structure for table oxobject2manufacturer

DROP TABLE IF EXISTS oxobject2manufacturer;
CREATE TABLE IF NOT EXISTS oxobject2manufacturer (
OXID char(32) COLLATE utf8_unicode_ci NOT NULL,
OXOBJECTID char(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT ‘’,
OXMANUFID char(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT ‘’,
OXMANUFDESC text COLLATE utf8_unicode_ci NOT NULL,
OXTIME int(11) NOT NULL DEFAULT ‘0’,
PRIMARY KEY (OXID),
KEY OXOBJECTID (OXOBJECTID),
KEY OXMAINIDX (OXMANUFID,OXOBJECTID)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

How can I create a class for this table with basic function in OXID. So I may handle the insert/updates/delete/fetching from the table.

Looking forward to a quick reply.

Thanks,
Ahtasham

Hi Ahtasham,

the question is: What do you want to do with this table, which aim to achieve?

Cheers

Hi Marco,

Actually we have description for categories and when that category(and the products in that category) is being viewed by a user, the category description is displayed on the left column. Now what I want to do is that I want to establish category description for each manufacturer. So if the user is on category C1 link the description of that category C1 is displayed. But staying in that category if the user filter for a manufacturer X then the description of C1-X will be displayed…and staying in the same category C1 if the user filters for manufacturer Y then the description of C1-Y will be displayed…and for that I have the table shown above…

In the above table OXOBJECTID is the category ID…the OXMANUFID is the manufacturer ID and OXMANUFDESC is the description for that category and manufacturer PAIR.

for that I am doing some changes in the following files…

/out/admin/tpl/category_text.tpl
/admin/category_text.php

but I cant seem to follow the code pattern of OXID…and the question was how I can interact with this table as I will have to load description from that table and insert into it and update it…I can do that with normal query but I saw that I dont need to write query but just play with the objects and call the function.

And the documentation is not that easy or enough to follow it. So I will be glad if you can help me out here.

Thanks,
Ahtasham

Hi Marco,

To add a little more on the problem…look right now the category description is updater like this…


1.		        $iCatLang = oxConfig::getParameter("catlang");
2.			$oCategory = oxNew( "oxcategory" );
3.			$iCatLang = $iCatLang ? $iCatLang : 0;
4.	
5.			if ( $soxId != "-1" ) {
6.				$oCategory->loadInLang( $iCatLang, $soxId );
7.			} else {
8.				$aParams['oxcategories__oxid'] = null;
9.			}
10.	
11.			$oCategory->setLanguage(0);
12.			$oCategory->assign( $aParams );
13.			$oCategory->setLanguage( $iCatLang );
14.			$oCategory->save();

What I understood is that at line 2 it is creating the object of oxcategory then checking the language parameter on line 6 it is loading the record from DB if we are updating the description (Cat ID = $soxId). Line 8 is that the data is inserted first time. Line 12 setting the parameters that were posted via form. Line 13 is setting the language. and 14 is saving it.

So as you can see to do all this stuff I need to have a category object which is related to the table oxcategories…and now I have to do this stuff with my new table which is “oxobject2manufacturer” and for that I created the following class by looking at the “oxCategory” class…(I dont know if this is correct)


class oxObjManuf extends oxI18n
{
    /**
     * Current class name
     *
     * @var string
     */
    protected $_sClassName = 'oxobjmanuf';

    /**
     * Class constructor, initiates parent constructor (parent::oxI18n()).
     */
    public function __construct()
    {
        parent::__construct();
        $this->init( 'oxobject2manufacturer' );
    }

    /**
     * Loads and assigns object data from DB.
     *
     * @param mixed $dbRecord database record array
     *
     * @return null
     */
    public function assign( $dbRecord )
    {

        parent::assign( $dbRecord );
		
	}
}

So now if you want to comment…that will be great…I just need to put the record in this “oxobject2manufacturer”. (INSERT/UPDATE/DELETE).

Looking forward to your reply.

Ahtasham