Step-attribute JForm field type number - numbers

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;

Related

Share data format spec with multiple functions in Doxygen

Given something like this:
/**
* #brief FuncA
*
* Data format:
* INT32 Date
* INT32 Time
* FLOAT Value
*
*/
void funcA()
{}
/**
* #brief FuncB
*
* Data format:
* INT32 Date
* INT32 Time
* FLOAT Value
*
*/
void funcB()
{}
How can I factor out the data format spec so it's not duplicated in multiple places? What I want is something like this:
/**
* #magictag Data Format
*
* INT32 Date
* INT32 Time
* FLOAT Value
*/
/**
* #brief FuncA
*
* Data format:
* #ref DataFormat
*
*/
void funcA()
{}
/**
* #brief FuncB
*
* Data format:
* #ref DataFormat
*
*/
void funcB()
{}
I just want to have a generic blob of documentation that I can reference from any number of places. Thanks.
The current version of doxygen is 1.8.16, it is advised to upgrade to this version. With version 1.8.11 the \snippetdoc does not work (command didn't exist in this version).
An example with \copydetails:
/** \file */
/**
* #brief FuncA
*
* Data format:
* - INT32 Date
* - INT32 Time
* - FLOAT Value
*
*/
void funcA();
/**
* #brief FuncB
*
* #copydetails funcA
*/
void funcB();
An example with \snippetdoc:
/** \file */
/**
* #brief FuncC
*
* #snippetdoc this snip_data
*
*/
void funcC();
/**
* #brief FuncD
*
* #snippetdoc this snip_data
*/
void funcD();
/*
[snip_data]
Data format:
- INT32 Date
- INT32 Time
- FLOAT Value
[snip_data]
*/

Swagger annotations with linked property array

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.

Symfony Validation with Data-Transformers

I have a form for a Product entity and I'm putting tags inside it.
I followed the documentation and used a data-transformer : the user enter a space-separated string which is exploded into a Tag collection.
I now want to validate the string that is transformed into the collection so it cannot use meta-characters.
I tried this, but it doesn't work : (cf. symfony2 entity validation regexp a-z A-Z 0-9)
//AppBundle\Entity\Product.php
/**
* #ORM\ManyToMany(targetEntity="Tag", cascade={"persist", "remove"})
* #Assert\Regex(
* pattern="/[\w\s]+/",
* match=true,
* message="Your property should match my damn regex !"
* )
* #ORM\JoinTable(
* name="contenus_tags",
* joinColumns={#ORM\JoinColumn(name="contenu_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="tag_id", referencedColumnName="id")}
* )
*/
private $tags;
How can I make this ?
Add a validation in the tag class on its name, and a "valid" assertion on tags in your product class:
//AppBundle\Entity\Tag.php
/**
* #Assert\Regex(
* pattern="/^[a-Z0-9]+$/",
* match=true,
* message="Your property should match my damn regex !"
* )
*/
private $name;
//AppBundle\Entity\Product.php
/**
* #ORM\ManyToMany(targetEntity="Tag", cascade={"persist", "remove"})
* #Assert\Valid()
* #Assert\Regex(
* pattern="/[\w\s]+/",
* match=true,
* message="Your property should match my damn regex !"
* )
* #ORM\JoinTable(
* name="contenus_tags",
* joinColumns={#ORM\JoinColumn(name="contenu_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="tag_id", referencedColumnName="id")}
* )
*/
private $tags;

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();
...

ZF2 Annotation Validators NotEmpty and Int not working?

I'm building a form in ZF2 from an entity and everything seems to work fine, except 2 of my validators are ignored for some reason. The Entity looks like this:
/**
* #var string $name
*
* #ORM\Column(name="name", type="string", length=255, nullable=true)
* #Annotation\Attributes({"type":"text"})
* #Annotation\Validator({"name":"NotEmpty"}) // duplicate
* #Annotation\Options({"label":"Name:"})
*/
private $name;
/**
* #var integer $sort
*
* #ORM\Column(name="sort", type="integer")
* #Annotation\Attributes({"type":"text"})
* #Annotation\Validator({"name":"Int"})
* #Annotation\Validator({"name":"NotEmpty"})
* #Annotation\Options({"label":"Sort:"})
*/
private $sort;
Yet I can submit the form without any values. I can enter a string in the SORT input, I can leave both fields empty. Why is this not working, why is there no errormessage when I leave the fields empty?
okay, it's partially because I'm STUPID.
Problem 1: notempty not working is because I defined nullable as true. Seems to override the "notempty" validator. duh.
Problem 2: I still don't know WHY that works, but if I declare the column type as string (instead of integer), suddenly the int validation works.
So here's the right code:
/**
* #var string $name
*
* #ORM\Column(name="name", type="string", length=255)
* #Annotation\Attributes({"type":"text"})
* #Annotation\Validator({"name":"NotEmpty"})
* #Annotation\Options({"label":"Name:"})
*/
private $name;
/**
* #var integer $sort
*
* #ORM\Column(name="sort", type="string")
* #Annotation\Attributes({"type":"text"})
* #Annotation\Validator({"name":"Int"})
* #Annotation\Validator({"name":"NotEmpty"})
* #Annotation\Options({"label":"Sort:"})
*/
private $sort;