Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » [Solved] creating an archive

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 177 Views
  • voodoochile
    Avatar
    Community Member
    52 Posts

    [Solved] creating an archive Link to this post

    Hi All

    i am really stuck, have spent many hours searching for answers and i really need some help.

    I have a data object called quote, this has several functions that return a result on the fly, this works well.
    The problem i have is 2 parts, Part 1 is creating a new record for the archive, this is triggered by a status id in the quote.
    in my quote Dataobject i have the following code.

    public function Createarchive()
    {
       $sid = $this->getStatusID();
       
       if($sid===2)
       {
          $Archive = Archive::get()->filter(array('QuoteID' => $this->ID));
          if (!$Archive) {
             $Archive = new Archive();
             $Archive->QuoteID = $this->ID;
              $Archive->write();   
          }
          }
    }

    this is not working, iam unsure as to why.

    Part 2 is writing the each function result into a field in the archive dataobject, in the archive dataobject there is a field for each function in the quote data object.
    i am unsure asto the best way to get the function result and write it to the archive.

    any help is appereciated

    Thanks

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: [Solved] creating an archive Link to this post

    Just to make sure you didn't miss this: the following will return a DataList:

    $Archive = Archive::get()->filter(array('QuoteID' => $this->ID));

    To get the actual DataObject, do:

    $Archive = Archive::get()->filter(array('QuoteID' => $this->ID))->first();

    Have you tested if your code ever gets to the if(!$Archive) bit?

    Once you get the write going, if I understand this correctly, it should be easy to do something like

    $Archive->someField = $this->someFunction();

  • voodoochile
    Avatar
    Community Member
    52 Posts

    Re: [Solved] creating an archive Link to this post

    Hi Martimiz

    Thanks for the quick reply, i finally had time to play around with this some more.
    I know that it is getting the status ID as i am using that elsewhere, i had this work once when i had it in onafterwrite function but this screwed something else up.
    i don't really know how to test where it is getting to but i would say that if is not getting to the if(!Archive) part wihich would indicate that the

    $Archive = Archive::get()->filter(array('QuoteID' => $this->ID))->first();

    is not working for some reason.
    hopefully i will get time to explore this further over the weekend.

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: [Solved] creating an archive Link to this post

    I usually just place an echo "here"; within the if-statement to see if it gets there. It will appear at the top of your screen somewhere I'm not sure that (!$Archive) would work, as the query probabely always returns an object, be it empty...

  • voodoochile
    Avatar
    Community Member
    52 Posts

    Re: [Solved] creating an archive Link to this post

    Once again Thanks for your help on this i have managed to get it working, i removed the If Statement checking for the statusID and bingo if an archive doesn't exist then it will create a record for it and with a little fiddling around i have managed to get the function writing to the record.

  • camfindlay
    Avatar
    Forum Moderator
    146 Posts

    Re: [Solved] creating an archive Link to this post

    Sound like this is solved nice work, @voodoochile can you edit your original thread to include [solved] at the beginning. It helps others with similar issues know whether a thread is likely to solve their issue too.

  • voodoochile
    Avatar
    Community Member
    52 Posts

    Re: [Solved] creating an archive Link to this post

    @camfindlay no problem, thanks for the prompt, i will know to do this in the future.

    177 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.