How to make link of method parameter type in jsDoc - jsdoc

Is there any natural way or special tag to make parameter type as link?
/**
* My js app
* #module app
*/
/**
* Namespace for MYAPP classes and functions.
* #namespace HUMAN_RESOURCE
*/
var HUMAN_RESOURCE = HUMAN_RESOURCE || {};
/**
* #class JustClass
* #constructor
*/
HUMAN_RESOURCE.JustClass = function(){ }
/**
* Constructs Person objects
* #class Person
* #constructor
* #param {String} First name
* #param {String} Last name
*/
HUMAN_RESOURCE.Person = function (first, last) {
/**
* First name of the Person
* #property first_name
* #type String
*/
this.first_name = first;
/**
* #property f_createPerson
* #param {Person} [_person] açıklama
* #return {Person} Person type object
*/
this.f_createPerson = function(_person, _person2){ return new Person() }
};
/**
* Return Person's full name
* #alias getName
* #memberof! HUMAN_RESOURCE.Person#
* #return {String} First name + last name
*/
HUMAN_RESOURCE.Person.prototype.getName = function () {
return this.first_name + ' ' + this.last_name;
};

Fortunately yes, it is just not always obvious what the correct name path is (but you can basically see it at the top of your generated docs)
/**
* #property f_createPerson
* #param {module:app~HUMAN_RESOURCE.Person} [_person] açıklama
* #return {module:app~HUMAN_RESOURCE.Person} Person type object
*/
this.f_createPerson = function(_person, _person2){ return new Person() }

Related

Doctrine Table Inheritance - No identifier/primary key specified for Entity

In Doctrine 2/Symfony 3 with Postgres as the database I am trying to create a table with following fields:
**actions-reviews**
id
action_id
action_task_id
document_id
review_to
review_date
review_description
review_by
is_effective
The table is either linked to a doc_id which is foreign key for an entity called Document or action_task_id for entity called ActionTask. In order to achieve this I am using inheritance mapping via the use of discriminator. In skipper the entity relationship look like this:
As you can see both the ActionTask and ActionReview are sub-set of Action entity.
My issue is when create the entities and run php bin/console doctrine:schema:update --force I get the following error:
[Doctrine\ORM\Mapping\MappingException]
No identifier/primary key specified for Entity "AppBundle\Entity\ActionTask
Review". Every Entity must have an identifier/primary key.
Reading the forums I add #ORM/Id to ActionTaskReview entity and then it updates the DB without any errors. However when I look at the postgres table only the document_id field is there not the action_task_id field. What I am doing wrong as the document_id does not throw the same error when I exclude #ORM/Id?
My Doctrine entities look like:
ActionReview.php
/**
* #ORM\Entity
* #ORM\Table(name="actions_reviews")
* #ORM\InheritanceType("SINGLE_TABLE")
* #ORM\DiscriminatorColumn(name="owner", type="string")
* #ORM\DiscriminatorMap({"document":"AppBundle\Entity\DocumentActionReview","action_task":"AppBundle\Entity\ActionTaskReview"})
* #Discriminator(field = "owner", map = {"document": "AppBundle\Entity\DocumentActionReview", "action_task": "AppBundle\Entity\ActionTaskReview"})
*/
abstract class ActionReview
{
/**
* #ORM\Id
* #ORM\Column(type="guid")
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="datetime", nullable=true)
*/
private $review_date;
/**
* #ORM\Column(type="text", nullable=true)
*/
private $review_description;
/**
* #ORM\Column(type="boolean", nullable=true)
*/
private $is_effective;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Action", inversedBy="action_review")
* #ORM\JoinColumn(name="action_id", referencedColumnName="id")
*/
private $action;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Employee")
* #ORM\JoinColumn(name="review_to", referencedColumnName="id")
*/
private $review_to;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Employee")
* #ORM\JoinColumn(name="review_by", referencedColumnName="id")
*/
private $review_by;
/**
* Get id
*
* #return guid
*/
public function getId()
{
return $this->id;
}
/**
* Set reviewDate
*
* #param \DateTime $reviewDate
*
* #return ActionReview
*/
public function setReviewDate($reviewDate)
{
$this->review_date = $reviewDate;
return $this;
}
/**
* Get reviewDate
*
* #return \DateTime
*/
public function getReviewDate()
{
return $this->review_date;
}
/**
* Set reviewDescription
*
* #param string $reviewDescription
*
* #return ActionReview
*/
public function setReviewDescription($reviewDescription)
{
$this->review_description = $reviewDescription;
return $this;
}
/**
* Get reviewDescription
*
* #return string
*/
public function getReviewDescription()
{
return $this->review_description;
}
/**
* Set isEffective
*
* #param boolean $isEffective
*
* #return ActionReview
*/
public function setIsEffective($isEffective)
{
$this->is_effective = $isEffective;
return $this;
}
/**
* Get isEffective
*
* #return boolean
*/
public function getIsEffective()
{
return $this->is_effective;
}
/**
* Set action
*
* #param \AppBundle\Entity\Action $action
*
* #return ActionReview
*/
public function setAction(\AppBundle\Entity\Action $action = null)
{
$this->action = $action;
return $this;
}
/**
* Get action
*
* #return \AppBundle\Entity\Action
*/
public function getAction()
{
return $this->action;
}
/**
* Set reviewTo
*
* #param \AppBundle\Entity\Employee $reviewTo
*
* #return ActionReview
*/
public function setReviewTo(\AppBundle\Entity\Employee $reviewTo = null)
{
$this->review_to = $reviewTo;
return $this;
}
/**
* Get reviewTo
*
* #return \AppBundle\Entity\Employee
*/
public function getReviewTo()
{
return $this->review_to;
}
/**
* Set reviewBy
*
* #param \AppBundle\Entity\Employee $reviewBy
*
* #return ActionReview
*/
public function setReviewBy(\AppBundle\Entity\Employee $reviewBy = null)
{
$this->review_by = $reviewBy;
return $this;
}
/**
* Get reviewBy
*
* #return \AppBundle\Entity\Employee
*/
public function getReviewBy()
{
return $this->review_by;
}
}
ActionTaskReview.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
/**
* ActionTaskReview
* #ORM\Entity
*/
class ActionTaskReview
{
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\ActionTask", inversedBy="action_review")
* #ORM\JoinColumn(name="action_task_id", referencedColumnName="id") \AppBundle\Entity\ActionTask
*/
private $action_task;
/**
* Set actionTask
*
* #param \AppBundle\Entity\ActionTask $actionTask
*
* #return ActionTaskReview
*/
public function setActionTask(\AppBundle\Entity\ActionTask $actionTask = null)
{
$this->action_task = $actionTask;
return $this;
}
/**
* Get actionTask
*
* #return \AppBundle\Entity\ActionTask
*/
public function getActionTask()
{
return $this->action_task;
}
}
DocumentActionReview.php
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="documents_actions_reviews")
*/
class DocumentActionReview extends \AppBundle\Entity\ActionReview
{
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Document", inversedBy="action_review")
* #ORM\JoinColumn(name="document_id", referencedColumnName="id")
*/
private $document;
/**
* Set document
*
* #param \AppBundle\Entity\Document $document
*
* #return DocumentActionReview
*/
public function setDocument(\AppBundle\Entity\Document $document = null)
{
$this->document = $document;
return $this;
}
/**
* Get document
*
* #return \AppBundle\Entity\Document
*/
public function getDocument()
{
return $this->document;
}
}
First of all, your ActionTaskReview should extend ActionReview:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
/**
* ActionTaskReview
* #ORM\Entity
*/
class ActionTaskReview extends ActionReview
{
...
}
Than I am not sure what you want to achieve, as you are using Single Table Inheritance but are setting the #ORM\Table(name="documents_actions_reviews") annotation on the DocumentActionReview class. Either switch to Class Table Inheritance if you need own tables for your inherited entities or remove the annotation.
Every entity class must have an identifier/primary key. You can select the field that serves as the identifier with the #Id annotation.
`/**
* #ORM\Column(type="integer")
* #ORM\Id
* #GeneratedValue
*/
private $id;`

How to use Catalog rule "Conditions_serialized" to validate product attribute?

I have define a condition the which product as product attribute "Hot" equal to "yes" on my table "product_label".
How to use \Magento\CatalogRule\Model\Rule\Condition... to validate $product with my condition?
The condition is record as following
a:7:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition
\Combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_
processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:
{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition
\Product";s:9:"attribute";s:7:"hkt_hot";s:8:"operator";s:2:"==";s:5:"value";
s:1:"1";s:18:"is_value_processed";b:0;}}}
Thanks
Norman
Without coding you can make this check using the system already in place:
Your "hot" attribute property is_used_for_promo_rules must be set to 1.
Additionally, the function Mage_Catalog_Model_Resource_Eav_Attribute::isAllowedForRuleCondition() sets the following prerequisites:
An attribute must be visible (attribute property is_visible must be equal 1).
The frontend_input property must be one of the following types: ‘text’, ‘multiselect’, ‘textarea’, ‘date’, ‘datetime’, ‘select’, ‘boolean’, ‘price’.
You may find the list of product IDs satisfying the serialized conditions.
Create model Vendor/Module/Model/Rule.php
<?php
namespace Vendor\Module\Model;
class Rule extends \Magento\CatalogRule\Model\Rule
{
/**
* Prefix of model events names
*
* #var string
*/
protected $_eventPrefix = 'catalogrule_rule';
/**
* Parameter name in event
*
* In observe method you can use $observer->getEvent()->getRule() in this case
*
* #var string
*/
protected $_eventObject = 'rule';
/**
* Store matched product Ids
*
* #var array
*/
protected $_productIds;
/**
* Limitation for products collection
*
* #var int|array|null
*/
protected $_productsFilter = null;
/**
* Store current date at "Y-m-d H:i:s" format
*
* #var string
*/
protected $_now;
/**
* Cached data of prices calculated by price rules
*
* #var array
*/
protected static $_priceRulesData = [];
/**
* Catalog rule data
*
* #var \Magento\CatalogRule\Helper\Data
*/
protected $_catalogRuleData;
/**
*
* #var \Magento\Framework\App\Cache\TypeListInterface
*/
protected $_cacheTypesList;
/**
*
* #var array
*/
protected $_relatedCacheTypes;
/**
*
* #var \Magento\Framework\Stdlib\DateTime
*/
protected $dateTime;
/**
*
* #var \Magento\Framework\Model\ResourceModel\Iterator
*/
protected $_resourceIterator;
/**
*
* #var \Magento\Customer\Model\Session
*/
protected $_customerSession;
/**
*
* #var \Magento\CatalogRule\Model\Rule\Condition\CombineFactory
*/
protected $_combineFactory;
/**
*
* #var \Magento\CatalogRule\Model\Rule\Action\CollectionFactory
*/
protected $_actionCollectionFactory;
/**
*
* #var \Magento\Catalog\Model\ProductFactory
*/
protected $_productFactory;
/**
*
* #var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
*
* #var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
*/
protected $_productCollectionFactory;
/**
*
* #var \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
*/
protected $_ruleProductProcessor;
/**
*
* #var Data\Condition\Converter
*/
protected $ruleConditionConverter;
/**
* Rule constructor.
*
* #param \Magento\Framework\Model\Context $context
* #param \Magento\Framework\Registry $registry
* #param \Magento\Framework\Data\FormFactory $formFactory
* #param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* #param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
* #param \Magento\Store\Model\StoreManagerInterface $storeManager
* #param Rule\Condition\CombineFactory $combineFactory
* #param Rule\Action\CollectionFactory $actionCollectionFactory
* #param \Magento\Catalog\Model\ProductFactory $productFactory
* #param \Magento\Framework\Model\ResourceModel\Iterator $resourceIterator
* #param \Magento\Customer\Model\Session $customerSession
* #param \Magento\CatalogRule\Helper\Data $catalogRuleData
* #param \Magento\Framework\App\Cache\TypeListInterface $cacheTypesList
* #param \Magento\Framework\Stdlib\DateTime $dateTime
* #param Indexer\Rule\RuleProductProcessor $ruleProductProcessor
* #param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* #param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* #param array $relatedCacheTypes
* #param array $data
*
* #SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogRule\Model\Rule\Condition\CombineFactory $combineFactory, \Magento\CatalogRule\Model\Rule\Action\CollectionFactory $actionCollectionFactory, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Framework\Model\ResourceModel\Iterator $resourceIterator, \Magento\Customer\Model\Session $customerSession, \Magento\CatalogRule\Helper\Data $catalogRuleData, \Magento\Framework\App\Cache\TypeListInterface $cacheTypesList, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor $ruleProductProcessor, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $relatedCacheTypes = [], array $data = [])
{
parent::__construct($context, $registry, $formFactory, $localeDate, $productCollectionFactory, $storeManager, $combineFactory, $actionCollectionFactory, $productFactory, $resourceIterator, $customerSession, $catalogRuleData, $cacheTypesList, $dateTime, $ruleProductProcessor, $resource, $resourceCollection, $relatedCacheTypes, $data);
}
/**
* Init resource model and id field
*
* #return void
*/
protected function _construct()
{
parent::_construct();
$this->_init('Magento\CatalogRule\Model\ResourceModel\Rule');
$this->setIdFieldName('rule_id');
}
/**
* Getter for rule conditions collection
*
* #return \Magento\Rule\Model\Condition\Combine
*/
public function getConditionsInstance()
{
return $this->_combineFactory->create();
}
/**
* Getter for rule actions collection
*
* #return \Magento\CatalogRule\Model\Rule\Action\Collection
*/
public function getActionsInstance()
{
return $this->_actionCollectionFactory->create();
}
public function toArray(array $arrAttributes = array())
{
return parent::toArray($arrAttributes);
}
public function getListProductIds()
{
$productCollection = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Catalog\Model\ResourceModel\Product\Collection');
$productFactory = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Catalog\Model\ProductFactory');
$this->_productIds = [];
$this->setCollectedAttributes([]);
$this->getConditions()->collectValidatedAttributes($productCollection);
\Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Framework\Model\ResourceModel\Iterator')->walk($productCollection->getSelect(), [
[
$this,
'callbackValidateProduct'
]
], [
'attributes' => $this->getCollectedAttributes(),
'product' => $productFactory->create()
]);
return $this->_productIds;
}
/**
* Callback function for product matching
*
* #param array $args
* #return void
*/
public function callbackValidateProduct($args)
{
$product = clone $args['product'];
$product->setData($args['row']);
$websites = $this->_getWebsitesMap();
foreach ($websites as $websiteId => $defaultStoreId) {
$product->setStoreId($defaultStoreId);
if ($this->getConditions()->validate($product)) {
$this->_productIds[] = $product->getId();
}
}
}
/**
* Prepare website map
*
* #return array
*/
protected function _getWebsitesMap()
{
$map = [];
$websites = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Store\Model\StoreManagerInterface')->getWebsites();
foreach ($websites as $website) {
// Continue if website has no store to be able to create catalog rule for website without store
if ($website->getDefaultStore() === null) {
continue;
}
$map[$website->getId()] = $website->getDefaultStore()->getId();
}
return $map;
}
}
Then, wherever you'd like to find the product IDs. Use below code snippet.
...
private $ruleModel;
...
...
private function getRuleModel()
{
if($this->ruleModel === null) {
$this->ruleModel = $this->objectManager->create('Vendor\Module\Model\Rule');
$this->ruleModel->setName('name')
->setDescription('description')
->setWebsiteIds($this->objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId());
}
return $this->ruleModel;
}
...
...
// somewhere in your method
$matchedProductIds = $this->getRuleModel()
->setData('conditions_serialized', $conditions_serialized)->getListProductIds();
...

How to implement multiple file upload in TYPO3 Front End Extension

My requirement is to implement a multiple fileupload field in TYPO3 Front-end Extension. Here is what I've used for a single file upload.
My Fields in Model
/**
* angebotuploaden
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $angebotuploaden = NULL;
/**
* Returns the angebotuploaden
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $angebotuploaden
*/
public function getAngebotuploaden() {
return $this->angebotuploaden;
}
/**
* Sets the angebotuploaden
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $angebotuploaden
* #return void
*/
public function setAngebotuploaden(\TYPO3\CMS\Extbase\Domain\Model\FileReference $angebotuploaden) {
$this->angebotuploaden = $angebotuploaden;
}
Now I face issues in implementing multiple file-uploads for this field. Please help me to sort it out.
Use ObjectStorage to get an 1:n-Relation to the FileReference model. In your model that could look like this:
/**
* uploadFiles
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
* #cascade remove
*/
protected $uploadFiles = NULL;
/**
* __construct
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* #return void
*/
protected function initStorageObjects() {
$this->uploadFiles = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Adds a UploadFile
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $uploadFile
* #return void
*/
public function addUploadFile(\TYPO3\CMS\Extbase\Domain\Model\FileReference $uploadFile) {
$this->uploadFiles->attach($uploadFile);
}
/**
* Removes a UploadFile
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $uploadFileToRemove The UploadFile to be removed
* #return void
*/
public function removeUploadFile(\TYPO3\CMS\Extbase\Domain\Model\FileReference $uploadFileToRemove) {
$this->uploadFiles->detach($uploadFileToRemove);
}
/**
* Returns the uploadFiles
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $uploadFiles
*/
public function getUploadFiles() {
return $this->uploadFiles;
}
/**
* Sets the uploadFiles
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $uploadFiles
* #return void
*/
public function setUploadFiles(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $uploadFiles) {
$this->uploadFiles = $uploadFiles;
}
There're still more things to do, especially in TCA, but I don't know them in detail because I didn't use that yet. See Hemult Hummels Upload Example an this question for more detailed information.

Editing Slug using Gedmo TreeSlugHandler

I have an entity that is hierarchical using the Gedmo Tree Doctrine extension in Symfony 2. The code for the Category entity is:
<?php
namespace MD\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use MD\Entity\Extension\Treeable;
/**
* Category
*
* #ORM\Entity(repositoryClass="MD\Entity\Repository\CategoryRepository")
*
* #Gedmo\Tree(type="nested")
*/
class Category
{
/**
* Entity Extensions
*/
use Treeable;
/**
* The ID of the category
*
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* The title of the category
*
* #var string
*
* #ORM\Column(type="string", length=255)
*
* #Assert\NotBlank(message="category.title.not_blank")
* #Assert\Length(
* max=255,
* maxMessage="category.title.length.max"
* )
*/
protected $title;
/**
* The description of the category
*
* #var string
*
* #ORM\Column(type="text")
*
* #Assert\NotBlank(message="category.description.not_blank")
*/
protected $description;
/**
* The parent of the category
*
* #var Category
*
* #ORM\ManyToOne(targetEntity="Category", inversedBy="children")
* #ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*
* #Gedmo\TreeParent
*/
protected $parent;
/**
* The children of the category
*
* #var ArrayCollection
*
* #ORM\OneToMany(targetEntity="Category", mappedBy="parent", cascade={"persist"})
* #ORM\OrderBy({"left" = "ASC"})
*/
protected $children;
/**
* The slug of the category
*
* #var string
*
* #ORM\Column(type="string", length=255, unique=true)
*
* #Gedmo\Slug(handlers={
* #Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={
* #Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"),
* #Gedmo\SlugHandlerOption(name="separator", value="/")
* })
* }, fields={"title"})
*/
protected $slug;
/**
* Constructor
*/
public function __construct()
{
$this->children = new ArrayCollection();
}
/**
* Get the ID of the category
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set the title of the category
*
* #param string $title
*
* #return $this
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get the title of the category
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set the description of the category
*
* #param string $description
*
* #return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get the description of the category
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set the parent of the category
*
* #param Category $parent
*
* #return $this
*/
public function setParent(Category $parent = null)
{
$this->parent = $parent;
if (null !== $parent) {
$parent->addChild($this);
}
return $this;
}
/**
* Get the parent of the category
*
* #return Category
*/
public function getParent()
{
return $this->parent;
}
/**
* Add a child to the category
*
* #param Category $child
*
* #return $this
*/
public function addChild(Category $child = null)
{
if (!$this->children->contains($child)) {
$this->children->add($child);
$child->setParent($this);
}
return $this;
}
/**
* Get the children of the category
*
* #return ArrayCollection
*/
public function getChildren()
{
return $this->children;
}
/**
* Set the slug of the category
*
* #param string $slug
*
* #return $this
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get the slug of the category
*
* #return string
*/
public function getSlug()
{
return $this->slug;
}
/** Magic Methods */
/**
* Return a string representation of the category
*
* #return string
*/
public function __toString()
{
return $this->getTitle();
}
}
Given a category with a title of Bands and a sub-category with a title of Rock, the latter category, on creation, has a slug of bands/rock. This works as expected.
When I add the slug field to a form, however, when I edit the entity, I initially get bands/rock added to the form field. If I change this to bands/rock-and-roll and submit the form, the slug gets updated to bands/bands-rock-and-roll and not bands/rock-and-roll as I'd expect.
If I edit the category and set the slug field to rock-and-roll, then submit the form, the slug gets updated to bands/rock-and-roll. I'd expect the slug to be rock-and-roll after update.
What do I need to do to fix this behaviour? I essentially want the slug to be auto-generated with the handler if it's not provided, but to be set to exactly what I provide if I do provide it.
Thanks
looking at the docs of the Gedmo Tree Doctrine extension and it's relative code, it's not a wrong behaviour because the slug is composed accordingly with the "TreeSlugHandler" method = parentFieldName/field-You-Have-Inserted (that happens every time you edit the slug).
If you need at the same moment of a slug for a specific category and of another that follows the category tree you can add another property (ex: cat_slug) with the simple annotation: #Gedmo\Slug(fields={"fieldYouWantToSlug"}).
Remember that every time (using the "TreeSlugHandler" method) you edit the slug (changing the precedent), every subcategory will be updated with the new slug.
I hope I was helpful

EntityNotFoundException in doctrine 2 proxy class

What are the possible causes of EntityNotFoundException while accessing the proxy class properties in doctrine 2? Anyway, the following is my entities' structure:
/**
* #ORM\Table(name="comments")
*
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="comment_type", type="smallint")
* #ORM\DiscriminatorMap({
* 1 = "VisitorComment",
* 2 = "MemberComment"
* })
*/
class Comment
{
//with common properties of its subclasses
}
subclasses are as follows:
/**
* #ORM\Table(name="member_comments")
*/
class MemberComment extends Comment
{
/**
* owning side
*
* #var Member $author
*
* #ORM\ManyToOne(targetEntity="Member")
* #ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false)
*/
private $author;
/**
* Set author
*
* #param Member $author
*/
public function setAuthor($author)
{
$this->author = $author;
}
/**
* Get author
*
* #return Member
*/
public function getAuthor()
{
return $this->author;
}
}
/**
* #ORM\Table(name="visitor_comments")
*/
class VisitorComment extends Comment
{
/**
* owning side
*
* #var Visitor $author
*
* #ORM\ManyToOne(targetEntity="Visitor")
* #ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false)
*/
private $author;
/**
* Set author
*
* #param string $author
*/
public function setAuthor($author)
{
$this->author = $author;
}
/**
* Get author
*
* #return Visitor
*/
public function getAuthor()
{
return $this->author;
}
}
The exception occurs when I call $comment->getAuthor()->getFirstName() <assuming that author which is either a Member or Visitor entity has firstName property>. The getAuthor() in this case returns a proxy class of either VisitorProxy or MemberProxy.
Kindly help me. I'm still new to doctrine.
As Floricel found out, this can be caused by an invalid foreign key in a column that's points to the table that the Proxy class references.
#Dave Lancea is right I changed a FK to not Null and then started getting this error, manually updated a broken record, making it point to an existing entity and problem gone.