I'm new to PHP Swagger and using the Laravel package L5-Swagger to create documentation for my API. Now I'm trying to let one model contain an array of the other model, an Order can have several OrderItems.
Unfortuantly I cannot get the linking to work. See attached screen shot.
What am I doing wrong?
This is my Order model:
/**
* #SWG\Definition(
* required={"order_id","order_items"},
* type="object",
* #SWG\Xml(name="Order")
* )
*/
class Order
{
/**
* #SWG\Property(example="O-789456123")
* #var string
*/
public $order_id;
/**
* #SWG\Property(type="array", items="$ref:OrderItem")
* #var array
*/
public $order_items = [];
}
This is my OrderItem model:
/**
* #SWG\Definition(
* required={"sku","quantity", "price_including_tax"},
* type="object",
* #SWG\Xml(name="OrderItem")
* )
*/
class OrderItem
{
/**
* #SWG\Property(example="SKU-123")
* #var string
*/
public $sku;
/**
* #SWG\Property(example=2)
* #var integer
*/
public $quantity;
/**
* #SWG\Property(example=199.75)
* #var float
*/
public $price_including_tax;
}
I think items="$ref:OrderItem" should be #SWG\Items(ref="#/definitions/OrderItem")
Ps. Checking the intermediate format (the swagger.json) can provide insight into what going wrong.
I have an entity called Materials with 8 associated entities (with join tables).
When I submit the form to update existing entities/records in the database, it takes up to 24 seconds to finish the process. I read somewhere that I shouldn't use:
$em = $this->getDoctrine()->getManager();
$form->handleRequest($request);
$data = $form->getData();
$em->persist($data);
$em->flush();
Because multiple entities would take too long to persist, but to boost performance I should use the update query:
Exp.
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('ourcodeworldBundle:Posts');
$newCreatedAt = new \DateTime();
$qb = $repo->createQueryBuilder('p');
$qb->update()
->set('p.createdAt', ':newCreatedAt')
->setParameter('newCreatedAt', $newCreatedAt);
$qb->getQuery()->execute();
https://ourcodeworld.com/articles/read/2/5-simple-tips-for-boost-the-database-handling-with-symfony2-and-doctrine
Does anybody know if that is correct and if so, will I have to really update every entity manually? It will take me a long time to write this as queries, since there are so many.
I found the problem.
The form used to fail at $form->handleRequest($request); in my controller:
if ($request->getMethod() == 'POST') {
$req = $request->request->get("material");
$form->handleRequest($request);
...
}
But the real problem was that my Assert statements in my Material class were not well defined. As soon as I corrected them handleRequest no longer slowed down the form submission process.
Here is my updated Material class with the fixed Assert statements:
/**
* #ORM\Table(name="materials")
* #ORM\Entity(repositoryClass="AppBundle\Entity\MaterialRepository")
*/
class Material
{
/**
* #var integer
*
* #ORM\Column(name="materialID", type="integer", nullable=true)
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $materialID;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="lrcID", type="integer", nullable=true)
*/
private $lrcID;
/**
* #var string
*
* #Assert\Type("\string")
* #Assert\Length(max=255)
* #ORM\Column(name="title", type="string", length=255, nullable=false)
*/
private $title;
/**
* #var string
*
* #Assert\Type("\string")
* #ORM\Column(name="description", type="text", nullable=false)
*/
private $description;
/**
* #var string
*
* #Assert\Type("\string")
* #Assert\Length(max=255)
* #ORM\Column(name="author", type="string", length=255, nullable=true)
*/
private $author;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="year", type="integer", nullable=true)
*/
private $year;
/**
* #var File
*
* #Assert\File(
* maxSize = "10M",
* mimeTypes = {"image/jpeg", "image/gif", "image/png", "image/tiff"},
* maxSizeMessage = "The maxmimum allowed file size is 10MB.",
* mimeTypesMessage = "Please, upload the imag as a jpge, gif, png, or tiff file."
* )
* #ORM\Column(name="image", type="string", length=100, nullable=true)
*/
private $image;
/**
* #var \DateTime
*
* #Assert\NotBlank()
* #Assert\Type("\DateTime")
* #ORM\Column(name="dateModified", type="datetime", nullable=true)
*/
private $dateModified;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="isActive", type="integer", nullable=true)
*/
private $isActive;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="isFree", type="integer", nullable=true)
*/
private $isFree;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="sizevalue", type="integer", nullable=true)
*/
private $sizevalue;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="sizeunit", type="integer", nullable=true)
*/
private $sizeunit;
/**
* #var integer
*
* #Assert\Type("\integer")
* #ORM\Column(name="isComplete", type="integer", nullable=true)
*/
private $isComplete;
/**
*
* #Assert\Url(
* checkDNS = true,
* message = "The url '{{ value }}' is not a valid url",
* dnsMessage = "The host '{{ value }}' could not be resolved.",
* )
* #Assert\Length(max=255)
* #ORM\Column(name="url", type="string", length=255, nullable=false)
*/
private $url;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialLanguage")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialLanguage", inversedBy="material")
* #ORM\JoinTable(name="materials_language_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="languageID", referencedColumnName="languageID", nullable=false)})
*/
public $materiallanguage;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialType")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialType", inversedBy="material")
* #ORM\JoinTable(name="materials_type_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="typeID", referencedColumnName="typeID", nullable=false)})
*/
public $materialtype;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialAudience")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialAudience", inversedBy="material")
* #ORM\JoinTable(name="materials_audience_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="audienceID", referencedColumnName="audienceID", nullable=false)})
*/
public $materialaudience;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialLevel")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialLevel", inversedBy="material")
* #ORM\JoinTable(name="materials_level_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="levelID", referencedColumnName="levelID", nullable=false)})
*/
public $materiallevel;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialFormat")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialFormat")
* #ORM\JoinTable(name="materials_format_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="formatid", referencedColumnName="formatid", nullable=false)})
*/
public $materialformat;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialSpecificMedium")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialSpecificMedium")
* #ORM\JoinTable(name="materials_specificmedium_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="specificmediumID", referencedColumnName="specificmediumid", nullable=false)})
*/
public $materialspecificmedium;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialSizeUnits")
* #Assert\Valid()
* #ORM\ManyToOne(targetEntity="MaterialSizeUnits", inversedBy="material")
* #ORM\JoinColumn(name="sizeunit", referencedColumnName="id", nullable=true)
*/
public $materialsizeunits;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialCategory")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialCategory")
* #ORM\JoinTable(name="materials_category_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="categoryID", referencedColumnName="categoryID", nullable=false)})
*/
public $materialcategory;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialKeyword")
* #Assert\Valid()
* #ORM\ManyToMany(targetEntity="MaterialKeyword", inversedBy="material")
* #ORM\JoinTable(name="materials_keyword_map",
* joinColumns={#ORM\JoinColumn(name="materialID", referencedColumnName="materialID", nullable=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="keywordID", referencedColumnName="id", nullable=false)})
*/
public $materialkeyword;
/**
* #Assert\Type(type="AppBundle\Entity\MaterialYear")
* #Assert\Valid()
* #ORM\ManyToOne(targetEntity="MaterialYear")
* #ORM\JoinColumn(name="year", referencedColumnName="yearID")
*/
public $materialyear;
/**
* #Assert\Type(type="AppBundle\Entity\Lrc")
* #Assert\Valid()
* #ORM\ManyToOne(targetEntity="Lrc", inversedBy="material")
* #ORM\JoinColumn(name="lrcID", referencedColumnName="id")
*/
public $lrc;
/**
* Constructor
*/
public function __construct()
{
$this->MaterialLanguage = new ArrayCollection();
$this->MaterialType = new ArrayCollection();
$this->MaterialLevel = new ArrayCollection();
$this->MaterialAudience = new ArrayCollection();
$this->MaterialFormat = new ArrayCollection();
$this->MaterialSpecificMedium = new ArrayCollection();
$this->MaterialSizeUnits = new ArrayCollection();
$this->MaterialCategory = new ArrayCollection();
$this->MaterialKeyword = new ArrayCollection();
$this->MaterialYear = new ArrayCollection();
$this->Lrc = new ArrayCollection();
}
/**
* Set materiallanguage
*
* #param array $materiallanguage
*
*/
public function setMateriallanguage(ArrayCollection $materiallanguage)
{
$this->materiallanguage = $materiallanguage;
}
/**
* Get materiallanguage
*
* #Assert\Type("\array")
* #return array
*/
public function getMateriallanguage()
{
return $this->materiallanguage;
}
/**
* Set materialtype
*
* #param array $materialtype
*
*/
public function setMaterialtype(ArrayCollection $materialtype)
{
$this->materialtype = $materialtype;
}
/**
* Get materialtype
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialtype()
{
return $this->materialtype;
}
/**
* Set materialaudience
*
* #param array $materialaudience
*
*/
public function setMaterialaudience(ArrayCollection $materialaudience)
{
$this->materialaudience = $materialaudience;
}
/**
* Get materialaudience
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialaudience()
{
return $this->materialaudience;
}
/**
* Set materialformat
*
* #param array $materialformat
*
*/
public function setMaterialformat(ArrayCollection $materialformat)
{
$this->materialformat = $materialformat;
}
/**
* Get materialformat
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialformat()
{
return $this->materialformat;
}
/**
* Set materialspecificmedium
*
* #param array $materialspecificmedium
*
*/
public function setMaterialspecificmedium(ArrayCollection $materialspecificmedium)
{
$this->materialspecificmedium = $materialspecificmedium;
}
/**
* Get materialspecificmedium
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialspecificmedium()
{
return $this->materialspecificmedium;
}
/**
* Set materiallevel
*
* #param array $materiallevel
*
*/
public function setMateriallevel(ArrayCollection $materiallevel)
{
$this->materiallevel = $materiallevel;
}
/**
* Get materiallevel
*
* #Assert\Type("\array")
* #return array
*/
public function getMateriallevel()
{
return $this->materiallevel;
}
/**
* Set materialsizeunits
*
* #param array $materialsizeunits
*
*/
public function setMaterialsizeunits(MaterialSizeUnits $materialsizeunits)
{
$this->materialsizeunits = $materialsizeunits;
}
/**
* Get materialsizeunits
*
* #return array
*/
public function getMaterialsizeunits()
{
return $this->materialsizeunits;
}
/**
* Set materialcategory
*
* #param array $materialcategory
*
*/
public function setMaterialcategory(ArrayCollection $materialcategory)
{
$this->materialcategory = $materialcategory;
}
/**
* Get materialcategory
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialcategory()
{
return $this->materialcategory;
}
/**
* Set materialkeyword
*
* #param array $materialkeyword
*
*/
public function setMaterialkeyword(MaterialKeyword $materialkeyword)
{
$this->materialkeyword = $materialkeyword;
}
/**
* Get materialkeyword
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialkeyword()
{
return $this->materialkeyword;
}
/**
* Set materialyear
*
* #param array $materialyear
*
*/
public function setMaterialyear(MaterialYear $materialyear)
{
$this->materialyear = $materialyear;
}
/**
* Get materiallamaterialyear
*
* #Assert\Type("\array")
* #return array
*/
public function getMaterialyear()
{
return $this->materialyear;
}
/**
* Set lrc
*
* #param array $lrc
*
*/
public function setLrc(Lrc $lrc=null)
{
$this->lrc = $lrc;
}
/**
* Get lrc
*
* #Assert\Type("\array")
* #return array
*/
public function getLrc()
{
return $this->lrc;
}
/**
* Set materialID
*
* #param integer $materialID
*
* #return Material
*/
public function setMaterialID($materialID)
{
$this->materialID = $materialID;
return $this;
}
/**
* Get materialID
*
* #return integer
*/
public function getMaterialID()
{
return $this->materialID;
}
/**
* Set lrcID
*
* #param integer $lrcID
*
* #return Material
*/
public function setLrcID($lrcID)
{
$this->lrcID = $lrcID;
return $this;
}
/**
* Get lrcID
*
* #return integer
*/
public function getLrcID()
{
return $this->lrcID;
}
/**
* Set title
*
* #param string $title
*
* #return Material
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* #param string $description
*
* #return Material
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set author
*
* #param string $author
*
* #return Material
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set year
*
* #param integer $year
*
* #return Material
*/
public function setYear($year)
{
$this->year = $year;
return $this;
}
/**
* Get year
*
* #return integer
*/
public function getYear()
{
return $this->year;
}
/**
* Set image
*
* #param string $image
*
* #return Material
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* #return string
*/
public function getImage()
{
return $this->image;
}
/**
* Set dateModified
*
* #param \DateTime $dateModified
*
* #return Material
*/
public function setDateModified(\DateTime $dateModified)
{
$this->dateModified = $dateModified;
return $this;
}
/**
* Get dateModified
*
* #return \DateTime
*/
public function getDateModified()
{
return $this->dateModified;
}
/**
* Set isActive
*
* #param integer $isActive
*
* #return Material
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* #return integer
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set isFree
*
* #param integer $isFree
*
* #return Material
*/
public function setIsFree($isFree)
{
$this->isFree = $isFree;
return $this;
}
/**
* Get isFree
*
* #return integer
*/
public function getIsFree()
{
return $this->isFree;
}
/**
* Set sizevalue
*
* #param integer $sizevalue
*
*/
public function setSizevalue($sizevalue)
{
$this->sizevalue = $sizevalue;
}
/**
* Get sizevalue
*
* #return integer
*/
public function getSizevalue()
{
return $this->sizevalue;
}
/**
* Set sizeunit
*
* #param integer $sizeunit
*
* #return Material
*/
public function setSizeunit($sizeunit)
{
$this->sizeunit = $sizeunit;
return $this;
}
/**
* Get sizeunit
*
* #return integer
*/
public function getSizeunit()
{
return $this->sizeunit;
}
/**
* Set isComplete
*
* #param integer $isComplete
*
* #return Material
*/
public function setIsComplete($isComplete)
{
$this->isComplete = $isComplete;
return $this;
}
/**
* Get isComplete
*
* #return integer
*/
public function getIsComplete()
{
return $this->isComplete;
}
/**
* Set url
*
* #param string $url
*
* #return Material
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* #return string
*/
public function getUrl()
{
return $this->url;
}
}
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.
Is there any step-attribute for the number-input in Joomla!-Forms?
The doc-site for this input-type doesn´t contain any answer yet
enter link description here
I need decimal numbers with step 0.01
You should check the file /libraries/joomla/form/fields/number.php, you can see that there are some parameters to pass to the form field for that purpose:
/**
* The form field type.
*
* #var string
* #since 3.2
*/
protected $type = 'Number';
/**
* The allowable maximum value of the field.
*
* #var float
* #since 3.2
*/
protected $max = null;
/**
* The allowable minimum value of the field.
*
* #var float
* #since 3.2
*/
protected $min = null;
/**
* The step by which value of the field increased or decreased.
*
* #var float
* #since 3.2
*/
protected $step = 0;
I am trying to modify the auto-generated function headers in Eclipse to produce a slightly different format.
I have code that generates this:
/**
* Method Description...
*
* #method testComments
* #author David Gauthier
* #param param1
* #param param2
*/
function testComments(param1, param2) {
}
Here is the code that does it:
/**Method Description...
*
* #method ${enclosing_method}
* #author ${user}
* ${tags}
*/
This is the result I would like:
/**
* Method Description...
*
* #method testComments
* #author David Gauthier
* #param {type} param1 Param Description...
* #param {type} param2 Param Description...
*/
function testComments(param1, param2) {
}
How would I go about doing this?