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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 00:25:45
Script start
Timing: Jan 19 2025 00:25:45
Module start 'layout'
Timing: Jan 19 2025 00:25:45
Module start 'content'
Timing: Jan 19 2025 00:25:46
Module end 'content'
Timing: Jan 19 2025 00:25:46
Script end

Main resources:

Total runtime0.7191 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 588.0391152.6406
Module start 'layout' 0.00530.0026 740.679739.4766
Module start 'content' 0.00790.7097 780.1563514.3516
Module end 'content' 0.71760.0015 1,294.507816.1250
Script end 0.7191  1,310.6328 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.5197160.0002
Check MTime0.00150.2120160.0001
Mysql Total
Database connection0.00080.117510.0008
Mysqli_queries0.665892.5929520.0128
Looping result0.00040.0615500.0000
Template Total0.688095.720.3440
Template load0.00210.296520.0011
Template processing0.685995.377920.3429
Template load and register function0.00010.013910.0001
states
state_id_array0.00130.184510.0013
state_identifier_array0.00070.104120.0004
Override
Cache load0.00180.2480300.0001
Sytem overhead
Fetch class attribute can translate value0.00050.074210.0005
Fetch class attribute name0.00110.150130.0004
XML
Image XML parsing0.00050.076110.0005
class_abstraction
Instantiating content class attribute0.00000.001540.0000
General
dbfile0.00090.1302170.0001
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs