how are pk's sequenced in c5 database

Permalink
I'm building an external script that sets a custom value in the table atNumber.
But first I need to know how the avID in userAttributeValues is set, whenever a new custom value is added to the database.
Does C5 use db identities or any other sequence types for PK's? (maybe getMAX + 1 in a php script?)
Can't find anything on the DB side.

Thanks.

maartenfb
 
Mnkras replied on at Permalink Reply
Mnkras
avID = attribute value id,

the avid corresponds to other tables, if you want to add to c5's db, use c5's methods to do it,
maartenfb replied on at Permalink Reply
maartenfb
Thanks for replying.
I understand the DB structure and was also checking the api but I don't understand all the classes yet. (I know how OOP works, but I'm a newbie to php)
Could you give me a code snippet how I would add a custom value to a user in the atNumber table (using the API)
Shouldn't be too hard I guess.

Thanks.
Mnkras replied on at Permalink Reply
Mnkras
atNumber is just an attribute type,

something like:

CollectionAttributeKey::add($boolt, array('akHandle' => 'exclude_sitemapxml', 'akName' => t('Exclude From sitemap.xml'), 'akIsSearchable' => true, null));

thats just an example,
the docs should have actual examples
kino replied on at Permalink Reply
kino
sample code.
The code below is part of the 'kino's import user'.
(http://www.concrete5.org/marketplace/addons/kinos-import-users/... )
function adduser_with_tel($username,$email,$password,$tel=''){
   $uak = UserAttributeKey::getByHandle('tel');
   $error = $this->check_userinfo($username,$email,$password);
   if(!$error){
      $data = array('uName' => $username, 'uPassword' => $password, 'uEmail' => $email);
      $uo = UserInfo::add($data);
      //         $uo = UserInfo::getByUserName($username);
      if (is_object($uo)) {
         if($tel!=''){
            $uo->setAttribute($uak, $tel);
         }
         $result = t('%s (%s) was imported successfully.', $username,$email);
      }
   } else {
      $result = t('           import error %s (%s)', $username,$email);
maartenfb replied on at Permalink Reply
maartenfb
That's a great example.
Thank you very much!
maartenfb replied on at Permalink Reply
maartenfb
About calling this function:
Where would be the best place to store this function in the c5 dir?
What's the best way to call it? (Does c5 support restful webservice or should I pass args through a url to a php file?

Thanks.
kino replied on at Permalink Reply
kino
It's sample.
This code will not work alone.

The code that I have more present, so I do not know what you want to create a program that you can not.
maartenfb replied on at Permalink Reply
maartenfb
HI,
I've set up a small php file for accepting two arguments. (located in tools folder)
Arguments come in ok, however the $uak and $uo objects don't seem to work.
Any ideas?
Thanks.

<?php 
if ($_REQUEST['uName'] && $_REQUEST['uServoyId']) 
{
   $username = $_REQUEST['uName'];
   $servoy_id = $_REQUEST['uServoyId'];
   echo ("<p>user: ".$username."</p>");
   echo ("<p>servoy: ".$servoy_id."</p>");
   $uak = UserAttributeKey::getByHandle('servoy_id');
   echo ("<p>uak: ".$uak."</p>");
   $uo = UserInfo::getByUserName($username);
   echo ("<p>uo: ".$uo."   </p>");
    if (is_object($uo)) 
   {
         $uo->setAttribute($uak, $servoy_id);
     }
kino replied on at Permalink Best Answer Reply
kino
Hi,

ex.)
http://c7.tktools.jp/index.php/tools/test.php?uName=username1&u...

<?php 
if ($_REQUEST['uName'] && $_REQUEST['uServoyId'])
{
   Loader::model('attribute/categories/user');
   $username = $_REQUEST['uName'];
   $servoy_id = $_REQUEST['uServoyId'];
   echo ("<p>user: ".$username."</p>");
   echo ("<p>servoy: ".$servoy_id."</p>");
   $uak = UserAttributeKey::getByHandle('servoy_id');
//   echo ("<p>uak: ".$uak."</p>");
   var_dump($uak );
   $uo = UserInfo::getByUserName($username);
//   echo ("<p>uo: ".$uo."   </p>");
   var_dump($uo );
   if (is_object($uo))
maartenfb replied on at Permalink Reply
maartenfb
Great !!! :-))
A couple lines of code says more than a 1000 words. :-)
Thanks.

off topic:
My thoughts go out to all the people suffering from the disaster in your country. Really hope al is well in the area you live.
kino replied on at Permalink Reply
kino
Thank you.

I live in Kyoto, so there is no damage.

Has sent you a prayer of people around the world.
We are thrilled to.

I think we'll help the forefront of a revival.
kino replied on at Permalink Reply
kino
 
jordanlev replied on at Permalink Reply
jordanlev
So this is a script that will be called outside the context of a content page, correct?

In C5, the usual way to do this is in a tools file (which runs code and has some resources like the database available, but doesn't bring in the overhead of a page/theme/template/etc.).

Inside the tools file, you can respond to things however you want. C5 does not provide built-in tools for responding in a REST-ful way, but you could code up your own response based on availability of GET/POST (and phony PUT/DELETE in hidden fields or querystring). But it's probably not worth the trouble unless you're building a public API that other people are going to be using (which you're probably not doing because I can't imagine C5 making sense as a platform in that context).

So... yeah... I would just pass args in the url.

-Jordan