function batchInitializeObjectAttributeData($classAttribute)
 {
     $numRows = $classAttribute->attribute('data_int1');
     $matrix = new eZMatrix('', $numRows, $classAttribute->attribute('content'));
     $db = eZDB::instance();
     return array('data_text' => "'" . $db->escapeString($matrix->xmlString()) . "'");
 }
Beispiel #2
0
    function updateContentObjectAttributes( $params )
    {
        $objectID = $params['object_id'];
        $attributesData = $params['attributes_data'];

        $contentObject = eZContentObject::fetch( $objectID );
        if( !is_object( $contentObject ) )
        {
            $this->reportError( "Content object with id '$objectID' doesn't exist." , 'eZSiteInstaller::updateContentObjectAttributes' );
            return;
        }

        $dataMap = $contentObject->dataMap();
        foreach( $attributesData as $attrIdentifier => $attrData )
        {
            $attribute = $dataMap[$attrIdentifier];
            if( !is_object( $attribute ) )
            {
                $this->reportError( "Warning: could not acquire attribute with identifier '$attrIdentifier'.",
                                    'eZSiteInstaller::updateContentObjectAttributes',
                                    eZSiteInstaller::ERR_CONTINUE );
                continue;
            }

            //get datatype name
            $datatypeString = $attribute->attribute( 'data_type_string' );

            switch( $datatypeString )
            {
                case 'ezstring':
                {
                    $attribute->setAttribute( "data_text", $attrData['DataText']);
                } break;

                case 'ezxmltext':
                {
                    $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n".
                           '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"'."\n".
                           '         xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"'."\n".
                           '         xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">'."\n".
                           '  <section>'."\n";
                    {
                        $xml .= '    <paragraph>';
                        $numSentences = mt_rand( ( int ) $attributeParameters['min_sentences'], ( int ) $attributeParameters['max_sentences'] );
                        for( $sentence = 0; $sentence < $numSentences; $sentence++ )
                        {
                            if( $sentence != 0 )
                            {
                                $xml .= ' ';
                            }
                        }
                        $xml .= "</paragraph>\n";
                    }
                    $xml .= "  </section>\n</section>\n";

                    $attribute->setAttribute( 'data_text', $xml );
                } break;

                case 'eztext':
                {
                    $attribute->setAttribute( 'data_text', $attrData['DataText'] );
                } break;

                case 'ezmatrix':
                {
                    $columnsCount = count( $attrData["MatrixDefinition"]->attribute( 'columns' ) );
                    if( $columnsCount > 0 )
                    {
                        $rowsCount = count( $attrData["MatrixCells"] ) / $columnsCount;

                        $tempMatrix = new eZMatrix( $attrData["MatrixTitle"], $rowsCount, $attrData["MatrixDefinition"] );
                        $tempMatrix->Cells = $attrData["MatrixCells"];

                        $attribute->setAttribute( 'data_text', $tempMatrix->xmlString() );
                        $tempMatrix->decodeXML( $attribute->attribute( 'data_text' ) );

                        $attribute->setContent( $tempMatrix );
                    }
                    else
                    {
                        $this->reportError( "Number of columns in 'ezmatrix' should be greater then zero",
                                            'eZSiteInstaller::updateContentObjectAttributes',
                                            eZSiteInstaller::ERR_CONTINUE );
                    }

                } break;

                case 'ezboolean':
                {
                    $attribute->setAttribute( 'data_int', $attrData['DataInt'] );
                } break;

                case 'ezinteger':
                {
                    $attribute->setAttribute( 'data_int', $attrData['DataInt'] );
                } break;

                case 'ezfloat':
                {
                    $power = 100;
                    $float = mt_rand( $power * ( int ) $attrData['Min'], $power * ( int ) $attrData['Max'] );
                    $float = $float / $power;
                    $attribute->setAttribute( 'data_float', $float );
                } break;

                case 'ezprice':
                {
                    $power = 10;
                    $price = mt_rand( $power * ( int ) $attrData['Min'], $power * ( int ) $attrData['Max'] );
                    $price = $price / $power;
                    $attribute->setAttribute( 'data_float', $price );
                } break;

                case 'ezurl':
                {
                    $attribute->setContent( $attrData['Content'] );
                    $attribute->setAttribute( "data_text", $attrData['DataText']);
                } break;

                case 'ezuser':
                {
                    $user = $attribute->content();
                    if( $user === null )
                    {
                        $user = eZUser::create( $objectID );
                    }

                    $user->setInformation( $objectID,
                                           md5( time() . '-' . mt_rand() ),
                                           md5( time() . '-' . mt_rand() ) . '@ez.no',
                                           'publish',
                                           'publish' );
                    $user->store();
                } break;
            }
            $attribute->store();
        }

        $contentObject->store();
    }