Horde_Kolab_Storage_Object::create PHP Method

create() public method

Create a new object in the backend.
public create ( Horde_Kolab_Storage_Folder $folder, Horde_Kolab_Storage_Object_Writer $data, string $type ) : boolean | string
$folder Horde_Kolab_Storage_Folder The folder to retrieve the data object from.
$data Horde_Kolab_Storage_Object_Writer The data writer.
$type string The type of object to be stored.
return boolean | string The return value of the append operation.
    public function create(Horde_Kolab_Storage_Folder $folder, Horde_Kolab_Storage_Object_Writer $data, $type)
    {
        $this->_folder = $folder->getPath();
        $this->_type = $type;
        $envelope = $this->createEnvelope();
        $envelope->addPart($this->createFreshKolabPart($data->save($this)));
        if (isset($this['_attachments'])) {
            foreach ($this['_attachments'] as $name => $attachment) {
                $part = new Horde_Mime_Part();
                $part->setType($attachment['type']);
                $part->setContents($attachment['content']);
                $part->setName($name);
                $envelope->addPart($part);
            }
        }
        $envelope->buildMimeIds();
        $this->_mime_part_id = Horde_Kolab_Storage_Object_MimeType::matchMimePartToObjectType($envelope, $this->getType());
        return $this->_appendMessage($envelope, $this->createEnvelopeHeaders());
    }

Usage Example

コード例 #1
0
ファイル: NewTest.php プロジェクト: jubinpatel/horde
    public function testStore()
    {
        if (version_compare(PHP_VERSION, '5.5.0', '>=') && version_compare(PHP_VERSION, '5.5.3', '<=')) {
            $this->markTestSkipped('PHP version with broken quoted-printable-encode');
        }
        setlocale(LC_MESSAGES, 'C');
        $factory = new Horde_Kolab_Format_Factory();
        $writer = new Horde_Kolab_Storage_Object_Writer_Format($factory);
        $folder = $this->getMock('Horde_Kolab_Storage_Folder');
        $folder->expects($this->once())->method('getPath')->will($this->returnValue('INBOX'));
        $driver = new Horde_Kolab_Storage_Stub_Driver('user');
        $object = new Horde_Kolab_Storage_Object();
        $object->setDriver($driver);
        $object->setData(array('summary' => 'TEST', 'description' => 'test', 'uid' => 'ABC1234'));
        $object->create($folder, $writer, 'note');
        $result = $driver->messages['INBOX'][0];
        $result = preg_replace(array('/=20/', '/Date: .*/', '/boundary=".*"/', '/--=_.*/', '/<creation-date>[^<]*/', '/<last-modification-date>[^<]*/', '/\\r\\n/', '/=\\n/'), array(' ', 'Date: ', 'boundary=""', '--=_', '<creation-date>', '<last-modification-date>', "\n", ''), $result);
        $this->assertEquals('From: user
To: user
Date: 
Subject: ABC1234
User-Agent: Horde_Kolab_Storage @version@
MIME-Version: 1.0
X-Kolab-Type: application/x-vnd.kolab.note
Content-Type: multipart/mixed; name="Kolab Groupware Data";
 boundary=""
Content-Disposition: attachment; filename="Kolab Groupware Data"

This message is in MIME format.

--=_
Content-Type: text/plain; name="Kolab Groupware Information"; charset=utf-8
Content-Disposition: inline; filename="Kolab Groupware Information"

This is a Kolab Groupware object. To view this object you will need an email client that understands the Kolab Groupware format. For a list of such email clients please visit http://www.kolab.org/content/kolab-clients
--=_
Content-Type: application/x-vnd.kolab.note; name=kolab.xml
Content-Disposition: inline; x-kolab-type=xml; filename=kolab.xml
Content-Transfer-Encoding: quoted-printable

<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<note version=3D"1.0">
  <uid>ABC1234</uid>
  <body></body>
  <categories></categories>
  <creation-date></creation-date>
  <last-modification-date></last-modification-date>
  <sensitivity>public</sensitivity>
  <product-id>Horde_Kolab_Format_Xml-@version@ (api version: 2)</product-id>
  <summary>TEST</summary>
  <background-color>#000000</background-color>
  <foreground-color>#ffff00</foreground-color>
</note>

--=_
', $result);
    }
All Usage Examples Of Horde_Kolab_Storage_Object::create