Component Creation : where to persist the additional data ?

Adrien Allemand Posted in Component Development 5 years ago

I am trying to make a simple component to learn how ossn works:
My component will allow any user registered to save pritvate memos (title, text and timestamp) to their account. No sharing features, three simple save, edit, delete buttons, nothing fancy.

I have globaly understood how to make the pages and the client-server communication but how to integrate my data to the database withoud modifying it's scheme is a mystery.

I know we are not supposed to alter the core files (including the database) but i don't understant how different component (messages for example) have their own class in the database as if they were generated by ossn on installation of the component.

Is what i want to achieve possible with the ossn database or must i make a secondary database for my data (annoying) ?

Good day

Adrien

Replies
ch Adrien Allemand Replied 5 years ago

Thanks for the quick answer, i'm afraid i don't understant where to put the "declaration" of my new fields :

$object->data->additional_field_one = '123';
$object->data->additional_field_two = '234';

and for the corresponding update function ? do i update the "data" field ?

public function updateMemo($title ='', $text = '') {
     ...
    $params['names']  = array(
        '??????',   // what goes here to update $memo->data->lastupdate
        'title',
        'description'
    );
    $params['values'] = array(
        time(),
        $title,
        $text

    );
    ...
}

EDIT:
found out i can use the save() to update
EDIT 2:
I'm still struggling with the declaration part though

Indonesian Arsalan Shah Replied 5 years ago

Here you go

$object->data->additional_field_one = '123';
$object->data->additional_field_two = '234';

Once this created you may access directlyusing echo $memo->additional_field...

ch Adrien Allemand Replied 5 years ago

Thank you both for your answers, i made my Memo plugin basing it on the blog example and it works ! I made my class Memo extend OssnObject and stored the title in title and the text in description.

Now i'd like to add additional informations on my memos : a list of tags and a separate entry for the last edition date and the creation date.

Where would you put such additional information as OssnObject only have limited number of fields ?

us Rishi B Replied 5 years ago

There are several existing tables you can use to hold your data if you don't want to modify the db schema by adding a table or a column to an existing table. As Arsalan pointed out, the Blog component will show you how to use some of these. The tables you'd potentially want to look at are ossnentities, ossnentitiesmetadata, ossnobject and maybe ossn_annotations. The other component that might be useful to look at is the Files component if you have that.

Indonesian Arsalan Shah Replied 5 years ago

Best example is : https://www.opensource-socialnetwork.org/component/view/1653/blog (you can remove some of functions like public blogs etc) Please take a look if you didn't understand let us know.