Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word2007 writer does not reset PHPWord_Media::_sectionMedia #19

Closed
juzi opened this issue Mar 12, 2013 · 18 comments
Closed

Word2007 writer does not reset PHPWord_Media::_sectionMedia #19

juzi opened this issue Mar 12, 2013 · 18 comments

Comments

@juzi
Copy link

juzi commented Mar 12, 2013

I'm using the GIT branch "custom-numbered-lists" of your PHPWord code.
I'm generating several docx documents in a row inside my php module. The documents contain images. I realised that when generating the second document the PHPWord_Writer_Word2007 tried to access the images of the first document. I think this is due to the fact that the static information in PHPWord_Media is not reset.
I wrote a simple reset function and now everything works as expected.

public static function resetMedia() {
    self::$_sectionMedia = array(
            'images' => array(),
            'embeddings' => array(),
            'links' => array());
    self::$_headerMedia = array();
    self::$_footerMedia = array();
}

I suppose such a method should actually be called when calling
PHPWord_IOFactory::createWriter(..., 'Word2007');

I don't know if this also affects other branches of the code.

@Progi1984
Copy link
Member

Hi @juzi, where did you have this branch ? I haven't found it.

Could you give a me a code for testing your problem ? Thanks for advance.

@juzi
Copy link
Author

juzi commented Mar 12, 2014

Sorry for the late reply, I think I got the branch from
https://github.com/RLovelett/PHPWord2/commit/1a6c6851f0d2444245f457c245d717ab18084672

at least that's what an e-mail from August 2013 says...

@Progi1984 Progi1984 mentioned this issue Mar 12, 2014
5 tasks
@ivanlanin
Copy link
Contributor

@Progi1984 I'll test this

@ivanlanin
Copy link
Contributor

I've tested the bug with the current develop branch. The code behaved as expected. No bug found. Below is the test code.

The test code try to mimic the retrieval of records from database and create individual document for each record. I mixed records that have images and not. If PHPWord_Media does not reset, the subsequent document should still have images from the previous document.

// First document

$rows = array(
    array(
        'name' => 'Progi1984',
        'avatar' => 'http:https://gravatar.com/avatar/16023066ffed311303d907c9d9b756b1'
    ),
    array('name' => 'Ivan Lanin'),
    array(
        'name' => 'Gabriel Bull',
        'avatar' => 'http:https://gravatar.com/avatar/7324439ccd29915db5c69f1caac65503'
    ),
    array('name' => 'Roman Syroeshko'),
    array(
        'name' => 'Brandon Skrtich',
        'avatar' => 'http:https://gravatar.com/avatar/2120eee8d13f0b9be90de3706e837f61'
    ),
);
$i = 0;
foreach ($rows as $row) {
    $PHPWord = new PHPWord();
    $section = $PHPWord->createSection();
    $section->addText($row['name']);
    $section->addTextBreak();
    if (isset($row['avatar'])) {
        $section->addMemoryImage($row['avatar']);
    } else {
        $section->addText('No avatar.');
    }
    $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
    $objWriter->save((++$i) . '-' . $row['name'] . '.docx');
}

@Progi1984
Copy link
Member

@juzi Could you test your code with the develop branch and feedback us ?

@juzi
Copy link
Author

juzi commented Mar 14, 2014

Yes, will do.
It's a year ago I had the problem, so I'll first have to get back into it.
thanks for your efforts.

@ivanlanin
Copy link
Contributor

Thanks @juzi. We're trying to get PHPWord development running again :)

@juzi
Copy link
Author

juzi commented Mar 14, 2014

Need a little help. My code produces

Fatal error: Call to undefined method PHPWord_Style_Paragraph::setIndentions() in /home/jzimmer/git/25/mod/offlinequiz/docxlib.php on line 425

maybe that was a special feature in the GIT branch "custom-numbered-lists"?
The code that produces the error is:

// Define custom list item style for question answers
$level1 = new PHPWord_Style_Paragraph();
$level1->setTabs(new PHPWord_Style_Tabs(array(
        new PHPWord_Style_Tab('clear', 720),
        new PHPWord_Style_Tab('num', 360)
)));

$level1->setIndentions(new PHPWord_Style_Indentation(array(
        'left' => 360,
        'hanging' => 360
)));

@ivanlanin
Copy link
Contributor

Use:

$level1->setIndent(360);
$level1->setHanging(360);

@juzi
Copy link
Author

juzi commented Mar 14, 2014

Next problem. The following classes and methods are missing:

class PHPWord_Numbering_AbstractNumbering
was in my old code in PHPWord/Numbering/AbstractNumbering.php

method
PHPWord::addNumbering()

was in my old code in PHPWord.php

So it looks like the "custom-numbered-lists" has not been merged into develop.
How do we proceed?

Cheers

@ivanlanin
Copy link
Contributor

We better call @RLovelett to the discussion :)
The best way is to have him fetch the latest version of develop branch, merge it with his fork, and submit a pull request.
I'm not promising anything, but I'll look at his fork.

@gabrielbull
Copy link
Member

I'm moving this issue to next milestone because we are scheduling for release soon.

@gabrielbull gabrielbull modified the milestones: 0.8.0, 0.8.1 Mar 14, 2014
@ivanlanin ivanlanin self-assigned this Mar 16, 2014
@Progi1984 Progi1984 modified the milestones: 0.9.0, 0.8.1 Mar 17, 2014
@Progi1984 Progi1984 removed this from the 0.9.0 milestone Mar 24, 2014
@Progi1984
Copy link
Member

Some news from @RLovelett ?

@Progi1984 Progi1984 added this to the 0.9.1 milestone Mar 26, 2014
@RLovelett
Copy link
Contributor

Sorry for not seeing this. Unfortunately, I am not following what the problem is. Is the problem that PHPWord::addNumbering no longer exists?

(Also, yeah its been a bit since I have worked on the code. I will have to look at it for a bit to get back up to speed).

@ivanlanin
Copy link
Contributor

Issue #10 still not resolved :) I'll look at your code and see how we can integrate it with the current PHPWord. Thanks.

@juzi
Copy link
Author

juzi commented Mar 27, 2014

@RLovelett: The problem is that I took the code mentioned above from your fork, but, accidentally, submitted the Issue in the main project, i.e. here. However, your branch "custom-numbered-lists" has not been integrated.

@ALL: my code is working right now and I don't necessarily need to upgrade. So don't spend too much time and energy into this. Of course, it would be nice to have the latest version of PHPWord, but I can wait.

@ivanlanin
Copy link
Contributor

I close this issue and will try to work on one of the oldest issue for PHPWord: #10. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants