Search

Hi there.

I’m building a voting app and became extremely dumb about how to increment the ‘votes’ number for the given entry. Had already looked at the ‘Increment number field’, but it is not quite, what i need, because this field is also queried, when the poll is loading in the frontend. If only it could be modified to increment, when “touched” by an event instead of DS.

Custom event (how?), or i need to mess around with TOOLKIT’s event.section.php (preferable?). I’m a bit paranoid yet, to dive that deep into stuff outside ‘workspace’.

Any directions or ideas will be truly apreciated.

Best wishes, Komb

Sorry, why couldn’t you just use a normal field and event?

Komb:

i recently had to tangle with a voting app as well. Each vote itself was a separate entry in a ‘votes’ section, then i wrote a custom data source to tally up the votes for each option

it may not be the best way to do it, but i’d be happy to share my code with you.

Yeah I also implemented it with individual vote entries, since I was recording device IDs to manage duplicate voting.

I was recording device IDs

How did you do it? What made up a “device ID”?

Thanks for your input.

Each vote itself was a separate entry in a ‘votes’ section, then i wrote a custom data source to tally up the votes for each option

and

Yeah I also implemented it with individual votes, since I was recording device IDs to manage duplicate voting.

Since my frontend is in flash (animating pie-charts, etc), I chose to use “flash cookie” (shared object, as they call it), to prevent duplicates. ShOb doesn’t get deleted, when cleaning browser cache and remains in effect, when switching browsers on the same machine. It’s handy to store chunks of custom data on user’s machine - voting history, preferences, etc.

I ‘truly’ don’t want to flood some symphony section with every voter’s entry, also bearing in mind, that polls will change on a regular basis (previous one then goes into archive). I can(‘t) imagine, how this vote-entry section will look like after a year, or so.

Sorry, why couldn’t you just use a normal field and event?

Incrementing in frontend has some huge disadvantages. It ‘could’ be done relatively safe, but would involve extra DB querying and data traffic between back and front - seriously uncool - almost like giving a hug to a wet poodle. Especially, when comparing to just one required sql query to do the job:

simplified:
UPDATE table SET votes=votes+1 WHERE id=POST[id];

So, the question remains open - how to write custom event, which, when called, pulls data value with POST[id] - increments it’s value - pushes new value back into DB. Or just does that one line above.

Help :)

k.

Noone? :(

@michael-e

The clients were iPhone & Android apps, not browsers.

@Komb: Give it a few days. Hopefully someone will be able to give you some suggestions.

Hi, everyone.

After digging up the guts of numerous extensions and symphony classes, i came up with my own solution to my own problem.

Replaced event’s load() function with this one:

public function load(){

if(isset($_POST['action']['submitpoll']) && isset($_POST['id']) ) { 
    $id = $_POST['id'];

    $query = "SELECT value FROM nrv_entries_data_87 WHERE entry_id = $id LIMIT 1";
    $data = Symphony::Database()->fetch($query);

    $_POST['fields']['votes'] = ((int) $data[0]['value']) + 1;

    return $this->__trigger();
}
}

Anyway, some technical expertise on this is still welcomed. Especially i was not sure about hardcoding the table name, but didn’t found the way to get this ‘87’ dynamically.

Also i became curious about what are those ‘Parent’ and ‘env’ variables(?) in event classes constructor. Maybe they are of some good use?

NB: PHP’s OOP looks a bit bizarre to me :) - i’m more like an ECMA-ish guy.

k.

To grab the table name dynamically, you could do something similar to what the Forum Ensemble does, using the Forum extension. Add a select element to the preferences page by using the appendpreferences() method to add the field to the System : Preferences page. This field can be used to select the field and save the setting to the configuration file.

http://github.com/bauhouse/forum/blob/master/extension.driver.php#L255

Then the custom data source can retrieve this information from the configuration file

http://github.com/bauhouse/sym-forum/blob/master/workspace/data-sources/data.forum_edit_discussion.php#L31

And use the ID of the field to run the query, which will translate the table prefix tbl to whatever you have chosen for your table prefix.

http://github.com/bauhouse/sym-forum/blob/master/workspace/data-sources/data.forum_edit_discussion.php#L34

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details