fetch Information Collection information

Author Message

Michael Scofield

Thursday 26 June 2008 6:37:01 pm

I have a form (using information collection) that collects the e-mail of the internaut.

I would like to query the database (inside PHP code, not in template code) to know if a determined e-mail address is already collected.

What's the best way to do that?

Should I use eZPersistentObject::fetchObjectList()? If so, how?

Thank you
Michael

Piotrek Karaƛ

Thursday 26 June 2008 10:01:27 pm

For (almost) any db table (set) there is a corresponding dedicated PHP class extending eZPersistentObject, providing API for all the key operations on this particular dataset. If you want to be consistent, use that. For collected info, you have eZInformationCollection and eZInformationCollectionAttribute classes. You can extend them to write your own fetches or direct SQL queries - and it would be your decision which ones you use and for what purpose.

Much as I appreciate the idea behind quick and general purpose information collection, in most cases I find dedicated tables and classes encapsulated within custom extension a better choice.

Cheers,
Piotrek

--
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

Michael Scofield

Thursday 26 June 2008 10:20:05 pm

I just did it.

I will write the code I used in hope that it will help someone:

// gets DB instance			
$db = eZDB::instance();
				
// SQL
$sql = "
   SELECT 
      count( ezinfocollection_attribute.id ) as count 
   FROM 
      ezinfocollection_attribute
   WHERE 
      ezinfocollection_attribute.contentobject_attribute_id = '" . $contentObjectAttribute->attribute('id') . "'
      AND ezinfocollection_attribute.contentclass_attribute_id = '" . $contentObjectAttribute->attribute('contentclassattribute_id') . "'
      AND ezinfocollection_attribute.data_text LIKE '" . addslashes($email) . "'
				";
				
// executes query
$resArray = $db->arrayQuery( $sql );
				
// verifies if the e-mail was found
if (intval($resArray[0]['count']) > 0) {
   // found

}
// not found

Michael

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 18 2025 11:13:53
Script start
Timing: Jan 18 2025 11:13:53
Module start 'layout'
Timing: Jan 18 2025 11:13:53
Module start 'content'
Timing: Jan 18 2025 11:13:53
Module end 'content'
Timing: Jan 18 2025 11:13:53
Script end

Main resources:

Total runtime0.7558 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 588.0469152.6406
Module start 'layout' 0.00800.0029 740.687539.4766
Module start 'content' 0.01090.7439 780.1641535.6484
Module end 'content' 0.75480.0010 1,315.812512.1250
Script end 0.7558  1,327.9375 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.4760160.0002
Check MTime0.00150.1954160.0001
Mysql Total
Database connection0.00080.111910.0008
Mysqli_queries0.705493.3288570.0124
Looping result0.00050.0711550.0000
Template Total0.720395.320.3602
Template load0.00210.273720.0010
Template processing0.718295.025620.3591
Template load and register function0.00020.031910.0002
states
state_id_array0.00090.117410.0009
state_identifier_array0.00080.106220.0004
Override
Cache load0.00170.2306200.0001
Sytem overhead
Fetch class attribute can translate value0.00070.096220.0004
Fetch class attribute name0.00150.194040.0004
XML
Image XML parsing0.00080.099520.0004
class_abstraction
Instantiating content class attribute0.00000.001040.0000
General
dbfile0.00080.0994170.0000
String conversion0.00000.001240.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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs