PHP code example of kaliop / ezobjectwrapperbundle

1. Go to this page and download the library: Download kaliop/ezobjectwrapperbundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kaliop / ezobjectwrapperbundle example snippets


new \Kaliop\eZObjectWrapperBundle\KaliopeZObjectWrapperBundle(),

$entityManager = $this->container->get('ezobject_wrapper.entity_manager');
$repository = $entityManager->getRepository('article');
$articleEntity = $repository->loadEntityFromLocationId(2);
echo 'Article entity 2 is named: ' . $articleEntity->content()->contentInfo->name;
echo 'Article entity 2 has parent Id: ' . $articleEntity->location()->parentLocationId;

    namespace Acme\AcmeBundle\Entity;
    use Kaliop\eZObjectWrapperBundle\Core\Entity as BaseEntity;

    class Newsletter extends BaseEntity
    {
    }
    

    namespace Acme\AcmeBundle\Repository;
    use Kaliop\eZObjectWrapperBundle\Core\Repository as BaseRepository;

    class Newsletter extends BaseRepository
    {
        protected $entityClass = '\Acme\AcmeBundle\Entity\Newsletter';
    }
    

    $entityManager = $this->container->get('ezobject_wrapper.entity_manager');
    $repository = $entityManager->getRepository('newsletter');
    

    namespace Acme\AcmeBundle\Repository;
    use ...;

    class Newsletter extends BaseRepository
    {
        protected $entityClass = '\Acme\AcmeBundle\Entity\Newsletter';

        /**
         * @return \Acme\AcmeBundle\Entity\Newsletter[]
         */
        public function getAllNewsletters()
        {
            $query = new Query();
            $query->filter = new Criterion\LogicalAnd(array(
                new Criterion\ContentTypeIdentifier($this->contentTypeIdentifier),
                new Criterion\Subtree('/1/2/212') // root node where all newsletters are located
            ));
            $query->performCount = false;
            $query->limit = PHP_INT_MAX-1;
            $query->offset = 0;
            // A helper method made available from the base repository class
            return $this->loaddEntitiesFromSearchResults(
                $this->getSearchService()->findContent($query)
            );
        }
    }

    namespace Acme\AcmeBundle\Entity;
    use ...;

    class Newsletter extends BaseEntity
    {
        protected $issueTypeIdentifier = 'newsletter_issue';

        /**
         * @return \DateTime
         */
        public function getLatestIssueDate()
        {
            $query = new Query();
            $query->filter = new Criterion\LogicalAnd(array(
                new Criterion\ContentTypeIdentifier($this->issueTypeIdentifier),
                new Criterion\Subtree($this->location()->pathString)
            ));
            $query->performCount = false;
            $query->limit = 1;
            $query->offset = 0;
            $query->sortClauses = array(new DatePublished(Query::SORT_DESC));
            $result = $this->repository->getSearchService()->findContent($query);
            if (count($result->searchHits) > 0) {
                $latest = $result->searchHits[0];
                return $latest->valueObject->contentInfo->publishedDate;
            }
            return new \DateTime("@0");
        }
    }
    

    ...
    $query->filter = new Criterion\LogicalAnd(array(
        new Criterion\ContentTypeIdentifier($this->contentTypeIdentifier),
        new Criterion\Subtree($this->settings['newsletter_location_path']) // root node where all newsletters are located
    ));
    ...

namespace Acme\AcmeBundle\Repository;
use ...;

class Newsletter extends BaseRepository
{
    protected $entityClass = '\Acme\AcmeBundle\Entity\Newsletter';

    /**
     * @return \Acme\AcmeBundle\Entity\Newsletter[]
     */
    protected function enrichEntityAtLoad($entity)
    {
        $entity = parent::enrichEntityAtLoad($entity);
        return $entity->setIssueTypeIdentifier('newsletter_issue');
    }
}

namespace Acme\AcmeBundle\Entity;
use ...;

class Newsletter extends BaseEntity
{
    protected $issueTypeIdentifier;

    /**
     * @return $this
     */
    public function setIssueTypeIdentifier($issueTypeIdentifier)
    {
        $this->issueTypeIdentifier = $issueTypeIdentifier;
        return $this;
    }
}

namespace Acme\AcmeBundle\Repository;
use ...;

class Newsletter extends BaseRepository
{
    use Kaliop\eZObjectWrapperBundle\Core\Traits\RouterInjectingRepository;
}

namespace Acme\AcmeBundle\Entity;
use ...;

class Newsletter extends BaseEntity
{
    use Kaliop\eZObjectWrapperBundle\Core\Traits\UrlGeneratingEntity;

    /**
     * To be used when absolute urls to this Location have to be generated, and there is no twig template or routing service available
     * @return string
     */
    public function absoluteUrl()
    {
        return $this->getUrlAlias(true);
    }
}

namespace Acme\AcmeBundle\Repository;
use ...;

class Newsletter extends BaseRepository
{
    use \Kaliop\eZObjectWrapperBundle\Core\Traits\RichTextConverterInjectingRepository;
}

namespace Acme\AcmeBundle\Entity;
use ...;

class Newsletter extends BaseEntity
{
    use \Kaliop\eZObjectWrapperBundle\Core\Traits\RichTextConvertingEntity;

    /**
     * @return string
     */
    public function bodyAsHtml()
    {
        return $this->getHtml($this->content()->getField('body')->xml);
    }
}