save something to an object

20 views
Skip to first unread message

kevin uittenbosch

unread,
Feb 13, 2015, 8:18:23 AM2/13/15
to ariad...@googlegroups.com
Hi muze, 

I'm curious, can i save a custom property to an object like ppage without updating the mtime of it?

kind regards,

kevin

Auke van Slooten

unread,
Feb 13, 2015, 10:49:27 AM2/13/15
to ariad...@googlegroups.com
kevin uittenbosch schreef op 13-2-2015 om 14:18:
> Hi muze,
>
> I'm curious, can i save a custom property to an object like ppage
> without updating the mtime of it?

Hi,

The short answer is no.

The mtime is always updated by the save method in
ariadne/lib/objects/ariadne_object.php

The only exception is when importing objects from an export file, the
mtime is then set to whatever it was in the export file.

I'm kind of curious to know why you would want this?

regards,
Auke van Slooten
Muze

kevin uittenbosch

unread,
Feb 14, 2015, 9:58:43 AM2/14/15
to ariad...@googlegroups.com

I have a tree of objects, like so:
Site > section > article

Now within the article i got a dir wich contain page objects, these are created when someone makes a comment on the article.

Now, when someone comments on am article i touch the article so it updates the mtime, i need this to properly show the last article with that comment, because i made my query to order the articles on mtime. But here is the deal, every time someone hits the article its saves a custom data field on it to show how many times it's viewed and to do a query on 'most viewed', but this query is also ordering on mtime and has to be because otherwise the results are not correct. Now these 2 functionalities are conflicting because of the mtime. I found a php line tot touch the object en write you own mtime date on it, tried this in ariadne like; touch() but this gives me a 500 internal server error, so i tried the touch.phtml template, wich works to update the mtime but can't set the mtime, there is no way tot fix this?

Kind regards,

Kevin


--
Je hebt dit bericht ontvangen, omdat je je hebt aangemeld bij een onderwerp in de groep "Ariadne" van Google Discussiegroepen.
Als je je wilt afmelden bij dit onderwerp, ga je naar https://groups.google.com/d/topic/ariadne-cms/lNPJHBwGEMM/unsubscribe.
Als je je wilt afmelden bij deze groep en alle onderwerpen van de groep, stuur je een e-mail naar ariadne-cms+unsubscribe@googlegroups.com.
Bezoek voor meer opties https://groups.google.com/d/optout.

Auke Van Slooten

unread,
Feb 17, 2015, 4:26:09 AM2/17/15
to ariad...@googlegroups.com
Op zaterdag 14 februari 2015 15:58:43 UTC+1 schreef kevin uittenbosch:

I have a tree of objects, like so:
Site > section > article

Now within the article i got a dir wich contain page objects, these are created when someone makes a comment on the article.

Now, when someone comments on am article i touch the article so it updates the mtime, i need this to properly show the last article with that comment, because i made my query to order the articles on mtime. But here is the deal, every time someone hits the article its saves a custom data field on it to show how many times it's viewed and to do a query on 'most viewed', but this query is also ordering on mtime and has to be because otherwise the results are not correct. Now these 2 functionalities are conflicting because of the mtime. I found a php line tot touch the object en write you own mtime date on it, tried this in ariadne like; touch() but this gives me a 500 internal server error, so i tried the touch.phtml template, wich works to update the mtime but can't set the mtime, there is no way tot fix this?


The mtime property is specifically meant to show when the last change to an object was made. So it will update on any change and this is fairly low-level behaviour. There are a lot of things depending on this, so it is best not to mess with it.

Of the top of my head there are two ways around this: either you save the number of views somewhere else, or you add your own 'last changed' timestamp. I think the last one is the best, you can decide what constitutes a change, e.g. editing a post in your own UI, and only update the timestamp when that happens.

kevin uittenbosch

unread,
Feb 24, 2015, 5:09:33 AM2/24/15
to ariad...@googlegroups.com
Okay so i fixed this with you solution on my own data field. thanks for that, 
But now i have a slightly different problem to it. 

I want to order them by number like in mysql. but i can't quite figure it out how this works in ariadne.

Here is what i do $query = "object.type='ppage' and object.priority>-1 and object.parent='".$path."' order by my.customvalue desc;

my.customvalue = INT number. but ariadne gives me wrong results. 
for example: 
100 
10000
10060
10077
10077
101

how can I do something like SQL - ORDER BY CAST(my.customvalue as INT)

kind regards

kevin

Auke Van Slooten

unread,
Feb 25, 2015, 4:18:28 AM2/25/15
to ariad...@googlegroups.com
Op dinsdag 24 februari 2015 11:09:33 UTC+1 schreef kevin uittenbosch:

I want to order them by number like in mysql. but i can't quite figure it out how this works in ariadne.

Here is what i do $query = "object.type='ppage' and object.priority>-1 and object.parent='".$path."' order by my.customvalue desc;

my.customvalue = INT number. but ariadne gives me wrong results. 
for example: 
100 
10000
10060
10077
10077
101

how can I do something like SQL - ORDER BY CAST(my.customvalue as INT?

Hi,

Casting properties is not supported in Ariadne, but there is another solution.

The simple but ugly way: pad your numbers with '0'. This will fix the problem, but isn't optimal.

The less simple but maybe incorrect way: use the priority property, by calling 'system.save.priority.phtml' with your number, then order by object.priority.

Finally instead of storing the number in the custom.value property, which is a string, you can store it in a property with the correct type. There are a few properties which may fit the bill here:

priority.value
as mentioned above

article.start
article.end
these are both meant as timestamps, in the unix format, so (int). These are used by newspaper articles

timeframe.start
timeframe.end
the same, used by calendar items

published.value
not currently used by anything

I'll use the published property in this example.

You can save any variable in any property in Ariadne, but you need some code to do it. If you control the saving, e.g. you call save() directly, it becomes easy:

    <pinp>
         // set your object data
         $this->data->myDateTime = time();
         // create property data
         // below equivalent to $properties['published'][0]['value'] = $this->data->myDateTime
         $properties = array(
               'published' => array(
                    array( 'value' => $this->data->myDateTime )
               )
         );
         if ( !save($properties) ) {
             echo 'Saving failed';
         }
     </pinp>

If you don't control the save(), e.g. saving is done using the default save dialog in Ariadne, you can hook into the onBeforeSave event.
You'll need to set that up in a config.ini template and you'll probably want to limit it to a specific type or subtype of objects.
Since you're working with properties here and this is non-trivial in the onbeforesave event in recent Ariadne releases - because of a bug in how the property value was handled - I'll use the user.workflow.pre.html template instead:

ppage.mysubtype::user.workflow.pre.html
    <pinp>
        $this->data->myDateTime = time();
        $properties = array(
              'published' => array(
                   array( 'value' => $this->data->myDateTime )
              )
        );
        return $properties;
    </pinp>

This will add your own myDateTime to the stored data, as well as add the published.value property.
This property is stored as a number, so you can sort your data on it the correct way.

Hope this helps,
Auke van Slooten
Muze
Reply all
Reply to author
Forward
0 new messages