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(),
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);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.