Forums / General / Poll unique vote options - summary and questions

Poll unique vote options - summary and questions

Author Message

Piotrek Karaś

Tuesday 30 October 2007 11:58:52 am

I have just gone through the forum and documentation looking for some details on poll configuration options. What I am basically looking for is any confirmed information on how the eZ Publish poll (info collector) deals with user uniqueness.

I know, that in order for information collection to collect data from users uniquely, we set up:

CollectionUserDataList[poll]=unique

However, the above setting will most probably behave differently depending on whether anonymous votes are allowed or not:

CollectAnonymousDataList[]
CollectAnonymousDataList[poll]=enabled/disabled

I suspect, that if enabled, eZ Publish will use session data/cookies to prevent double votes. <b>What exactly does it look like when only the logged-in users are allowed to vote?</b> I did some testing and eZ Publish doesn't seem to care about the session data and cookies in such case anymore. The question remains: <b>is that permanent? Will my users ever be able to vote again (without having to purge the collected information)? Any config-based way of setting up a time-based block rather than a permanent block?</b>

Wouldn't it be great to have an additional, modified unique mode with a time constrain?

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Piotrek Karaś

Tuesday 30 October 2007 1:36:16 pm

Ok, I took some time and since kernel classes will have the ability of being overwritten soon, decided to dig a bit. The functionality I suggested above turned out to be comparatively easy to implement. I hope some of you take a look at it and if this doesn't violate anything, I'll add this little functionality as a suggestion - I believe many people may find it useful. I hope I didn't reinvent the wheel here ;)

The purpose is to let registered and logged-in users to vote in a poll, but only once over a given period of time.

I started with the settings file, where I declared a <b>new mode</b>:
<i>/settings/override/collect.ini.append.php</i>

CollectionUserDataList[poll]=timeunique

This will not work unless we extend the array a bit deeper:
<i>/kernel/classes/ezinformationcollection.php</i>

static function userDataHandling( $contentObject ) {
(...)
if ( !in_array( $userData, array( 'multiple', 'unique', 'overwrite', 'timeunique' ) ) )
$userData = 'unique';
(...)
}

In the same file we add a new fetching method dedicated for our new mode:

static function fetchByUserIdentifierTimeUnique( $userIdentifier, $contentObjectID = false, $asObject = true, $timeLimit = false ) {
 if ( $timeLimit == false)
  $timeLimit = time() - 86400;
 $conditions = array( 'user_identifier' => $userIdentifier, 'created' => array( '>=', $timeLimit ) );
 if ( $contentObjectID )
  $conditions['contentobject_id'] = $contentObjectID;
 return eZPersistentObject::fetchObject( eZInformationCollection::definition(), null, $conditions, $asObject );
}

All we've got to do now is to teach the content module to use our new fetching method:
<i>/kernel/content/collectinformation.php</i>

(...)
 $newCollection = false;
 $collection = false;
 $userDataHandling = eZInformationCollection::userDataHandling( $object );

 if ( $userDataHandling == 'unique' or
  $userDataHandling == 'overwrite' )
  $collection = eZInformationCollection::fetchByUserIdentifier( eZInformationCollection::currentUserIdentifier(), $object->attribute( 'id' ) );

 if ( $userDataHandling == 'timeunique' ) {
  $collectionTimeLimit = time() - 600; // you can vote every ten minutes
  $collection = eZInformationCollection::fetchByUserIdentifierTimeUnique( eZInformationCollection::currentUserIdentifier(), $object->attribute( 'id' ), $collectionTimeLimit);
}

 if ( ( !$isLoggedIn and !$allowAnonymous ) or
  ( $userDataHandling == 'unique' and $collection ) or 
  ( $userDataHandling == 'timeunique' and $collection) )
  {
(...)

And few lines below we can provide a new error variable for the template, or extend the existing one:

(...)
$tpl->setVariable( 'error_existing_data', ( ( $userDataHandling == 'unique' and $collection ) or ( $userDataHandling == 'timeunique' and $collection ) ) );
(...)

Of course, it would still be nice to move the time declaration (<i>time()-600</i>) out to the settings file and make it possible to declare it separately for each class.

I guess that also answers my own questions, at least some of them ;)

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

eZ debug

Timing: Jan 19 2025 11:54:26
Script start
Timing: Jan 19 2025 11:54:26
Module start 'content'
Timing: Jan 19 2025 11:54:26
Module end 'content'
Timing: Jan 19 2025 11:54:26
Script end

Main resources:

Total runtime0.2246 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 589.0781180.8203
Module start 'content' 0.00700.0089 769.898498.0234
Module end 'content' 0.01590.2087 867.9219527.3750
Script end 0.2245  1,395.2969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00411.8136200.0002
Check MTime0.00150.6769200.0001
Mysql Total
Database connection0.00080.336610.0008
Mysqli_queries0.163172.63661410.0012
Looping result0.00150.68211390.0000
Template Total0.208192.710.2081
Template load0.00090.395710.0009
Template processing0.207292.266810.2072
Override
Cache load0.00060.245310.0006
Sytem overhead
Fetch class attribute can translate value0.00100.423310.0010
XML
Image XML parsing0.00030.129510.0003
General
dbfile0.01235.4647200.0006
String conversion0.00000.002930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs