Author Topic

Georg Franz

Sunday 14 December 2003 5:27:20 pm

Comment39406

Hi Erik,

I've had a similar problem too. I needed unique textstrings.

I've created a new datatype (a copy of ezstring). My idea was: Just use the ezsearch::search to check if an attribute-value is already in use. But that didn't work, because the search-method always checks the current-user for the limitation list.

My second thought: Make an own table like the ezuser table and store there the unique strings ... not a good idea.

My third thought: Just make a query in ezcontentobject_attribute and look if the given text is there already.

So in my new datatype, I've created following code to check, if an attribute exists:

(in the method validateObjectAttributeHTTPInput)

$db =& eZDB::instance();
$db->setIsSQLOutputEnabled( false );
$query =
"SELECT
ezcontentobject_attribute.id
FROM
ezcontentobject_attribute,
ezcontentobject_version
WHERE
LOWER(ezcontentobject_attribute.data_text) = '".$db->escapeString(strtolower($data))."'
AND ezcontentobject_attribute.id <> ".$contentObjectAttribute->attribute( 'id' )."
AND ezcontentobject_attribute.contentclassattribute_id = ".$classAttribute->attribute( "id" )."
AND ezcontentobject_attribute.contentobject_id <> ".$contentObjectAttribute->attribute("contentobject_id")."
AND ezcontentobject_attribute.contentobject_id = ezcontentobject_version.contentobject_id
AND ezcontentobject_version.status = ".EZ_VERSION_STATUS_PUBLISHED."
GROUP BY ezcontentobject_attribute.id";
echo $query;
$existsArray = $db->arrayQuery( $query );

if ($existsArray != NULL or count($existsArray) > 0)
{
$contentObjectAttribute->setValidationError( ezi18n( 'extension/classes/datatypes',
'Already in use. Please try another one' ) );
}

I am not happy making that query (so I think there must be another way) - has anyone a suggestion?

But it works ...

By the way: Creating a new datatype is always an "exciting adventure", although there are tutorials in the documentation area of ez. I've always the feeling like falling in a black hole ;-)

Kind regards,
Emil.

Best wishes,
Georg.

--
http://www.schicksal.com Horoskop website which uses eZ Publish since 2004