My 1st Datatype, can be better , check it?

Author Message

Marvix Marx

Wednesday 11 June 2008 9:50:35 am

Hi,

The story starts here : http://ez.no/developer/forum/install_configuration/is_it_possible_to_browse_by_node_id/

Since this modification not done yet, I wrote this datatype based on another datatype (I don`t remember which one).

this DT will create random number which can be used for url_alias, thats all ... I think there is many mistakes ... can you check it ?



<?php


include_once( "kernel/classes/ezdatatype.php" );

               
define( "EZ_DATATYPESTRING_RANDOMID", "ezrandomid" );
define( 'EZ_DATATYPESTRING_RANDOMID_DEFAULT', 'data_text' );
define( 'EZ_DATATYPESTRING_RANDOMID_DEFAULT_EMTPY', 0 );


// include_once( "lib/ezlocale/classes/ezdate.php" );

class eZRandomIdType extends eZDataType
{
	var $MyRadomID="empty";


    function eZRandomIdType()
    {
        $this->eZDataType( EZ_DATATYPESTRING_RANDOMID, ezi18n( 'kernel/classes/datatypes', "Random ID", 'Datatype name' ),
                           array( 'serialize_supported' => true ) );
						   $this->MakeRandomID();
                           
    }
		//////////////////////////
		
		function MakeRandomID($minlength=5, $maxlength=5, $useupper=true, $usespecial=false, $usenumbers=true)  
		{ 

		$key ="";
			//$charset = "abcdefghijklmnopqrstuvwxyz"; 
			if ($useupper)   $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
			if ($usenumbers) $charset .= "0123456789"; 
			//if ($usespecial) $charset .= "~@#$%^*()_+-={}|][";   // Note: using all special characters this reads: "~!@#$%^&*()_+`-={}|\\]?[\":;'><,./"; 
			if ($minlength > $maxlength) $length = mt_rand ($maxlength, $minlength); 
			else                         $length = mt_rand ($minlength, $maxlength); 
			for ($i=0; $i<$length; $i++) $key .= $charset[(mt_rand(0,(strlen($charset)-1)))]; 


		$this->MyRadomID =$key;
		//return strtoupper($newpass.$rn);
		}
		//////////////////////////////    

    /*!
     Validates the input and returns true if the input was
     valid for this datatype.
    */
    function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
    {
       return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
    }

    /*!
     Fetches the http post var integer input and stores it in the data instance.
    */
    function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
    {
			
		$data = $http->postVariable( $base . "_randomid_" . $contentObjectAttribute->attribute( "id" ) );
        eZDebug::writeNotice( $data, 'Random ID' );
        $contentObjectAttribute->setAttribute( "data_text", $data );
        return true;
    }

    /*!
     Returns the content.
    */
    function &objectAttributeContent( &$contentObjectAttribute )
    {	
		$datestr = $contentObjectAttribute->attribute( 'data_text' );
		eZDebug::writeNotice( $datestr, 'Random ID, edit' );
		//return $datestr;
		
		$Rx= $this->MyRadomID;
		eZDebug::writeNotice( $Rx, 'Random ID, new' );
	    //return $Rx;
		
		if(!$datestr) return $Rx; else return $datestr;
		
    }


    /*!
     Sets the default value.
    */
    function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
    {	
		$dataText = $originalContentObjectAttribute->attribute( "data_text" );
         $contentObjectAttribute->setAttribute( "data_text", $dataText );
		 eZDebug::writeNotice( $dataText, 'RandomID, Class edit / initializeObjectAttribute' );
		//$dataText="a__".$this->MyRadomID;
        //$contentObjectAttribute->setAttribute( "data_text", $dataText );
    }

    function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
    {

		$defaultValue=$this->MyRadomID;
		//$classAttribute->setAttribute(  'data_text',  $defaultValue );
		 eZDebug::writeNotice( $defaultValue, 'RandomID, Class edit / fetchClassAttributeHTTPInput' );
        return true;
    }

    /*!
     Returns the meta data used for storing search indeces.
    */
    function metaData( $contentObjectAttribute )
    {
		$x=  $contentObjectAttribute->attribute( 'data_text' );
       eZDebug::writeNotice( $x, 'RandomID, Class edit / Meta' );
		return $x;
		
    }

    /*!
     Returns the date.
    */
    function title( &$contentObjectAttribute )
    {
		 // eZDebug::writeNotice( $x, 'RandomID, Class edit / Title' );
        return $contentObjectAttribute->attribute( "data_text" );
    }
    
    function hasObjectAttributeContent( &$contentObjectAttribute )
    {
        return ( strlen ( $contentObjectAttribute->attribute( "data_text" ) ) > 0 );
    }



    /*!
     \return the collect information action if enabled
    */
    function contentActionList( &$classAttribute )
    {
        if ( $classAttribute->attribute( 'is_information_collector' ) == true )
        {
            return array( array( 'name' => 'Send',
                                 'action' => 'ActionCollectInformation'
                                 ) );
        }
        else
            return array();
    }
    
    function isIndexable()
    {
        return true;
    }

    /*!
     \reimp
    */
    function isInformationCollector()
    {
        return true;
    }
    
}

eZDataType::register( EZ_DATATYPESTRING_RANDOMID, "ezrandomidtype" );

?>

Thanks

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 15:17:46
Script start
Timing: Jan 18 2025 15:17:46
Module start 'layout'
Timing: Jan 18 2025 15:17:46
Module start 'content'
Timing: Jan 18 2025 15:17:48
Module end 'content'
Timing: Jan 18 2025 15:17:48
Script end

Main resources:

Total runtime1.2606 sec
Peak memory usage4,096.0000 KB
Database Queries46

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0046 589.1641152.6406
Module start 'layout' 0.00460.0023 741.804739.4609
Module start 'content' 0.00701.2523 781.2656422.2500
Module end 'content' 1.25930.0013 1,203.515612.1406
Script end 1.2605  1,215.6563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.2460160.0002
Check MTime0.00130.1025160.0001
Mysql Total
Database connection0.00070.058510.0007
Mysqli_queries1.227097.3371460.0267
Looping result0.00040.0351440.0000
Template Total1.232097.720.6160
Template load0.00200.158220.0010
Template processing1.230097.570620.6150
Template load and register function0.00020.011910.0002
states
state_id_array0.00100.079610.0010
state_identifier_array0.00110.086920.0005
Override
Cache load0.00160.128290.0002
Sytem overhead
Fetch class attribute can translate value0.00090.067810.0009
Fetch class attribute name0.00060.050110.0006
XML
Image XML parsing0.00010.008410.0001
class_abstraction
Instantiating content class attribute0.00000.000410.0000
General
dbfile0.00130.1007100.0001
String conversion0.00000.000540.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
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.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: 6
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs