Inheritance: implements ArrayAccess, use trait Webiny\Component\StdLib\StdLibTrait, use trait EntityTrait, use trait Webiny\Component\StdLib\FactoryLoaderTrait
Esempio n. 1
0
 function __construct()
 {
     parent::__construct();
     $this->attr('ip')->char();
     $this->attr('timestamp')->integer()->setDefaultValue(0);
     $this->attr('username')->char();
 }
Esempio n. 2
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('rangeStart')->float();
     $this->attr('rangeEnd')->float();
     $this->attr('geoId')->integer();
 }
Esempio n. 3
0
 /**
  * Create new attribute or get name of current attribute
  *
  * @param null|string $attribute
  *
  * @return EntityAttributeBuilder|string
  */
 public function attr($attribute = null)
 {
     if ($this->isNull($attribute)) {
         return $this->attribute;
     }
     return $this->parent->attr($attribute);
 }
Esempio n. 4
0
 /**
  * Get default list of entity attributes.<br>
  * Only simple and Many2One attributes are considered to be default attributes.
  *
  * @return string
  */
 private function getDefaultAttributes()
 {
     $attributes = ['id'];
     foreach ($this->entity->getAttributes() as $name => $attribute) {
         /* @var AbstractAttribute $attribute */
         if ($attribute->getToArrayDefault()) {
             $attributes[] = $name;
         }
     }
     return $this->arr($attributes)->implode(',')->val();
 }
Esempio n. 5
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('boolean')->boolean()->setValidators('required');
     $this->attr('char')->char()->setValidators('required');
     $this->attr('integer')->integer()->setValidators('required');
     $this->attr('float')->float()->setValidators('required');
     $this->attr('object')->object()->setKeyValidators(['key1' => 'required']);
     $this->attr('many2one')->many2one()->setEntity(Classes::MANY_2_ONE_VALIDATION)->setValidators('required');
     $this->attr('one2many')->one2many('entity')->setEntity(Classes::ONE_2_MANY_VALIDATION)->setValidators('required');
 }
Esempio n. 6
0
 function __construct()
 {
     parent::__construct();
     $this->attr('username')->char();
     $this->attr('loginAttempts')->arr();
     $this->attr('allowedDevices')->arr();
     $this->attr('sessions')->arr();
     $this->attr('blocked')->boolean()->setDefaultValue(false);
     $this->attr('confirmed')->boolean()->setDefaultValue(false);
     $this->attr('confirmationToken')->char();
     $this->attr('lastLogin')->integer();
     $this->attr('forgotPasswordToken')->char();
 }
Esempio n. 7
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('char')->char()->setAfterPopulate()->onSet(function ($value) {
         return 'set-' . $this->number . '-' . $value;
     })->onGet(function ($value) {
         return 'get-' . $value;
     })->onToArray(function () {
         return ['key' => 'value'];
     })->onToDb(function ($value) {
         return 'db-' . $value;
     })->setToArrayDefault();
     $this->attr('number')->integer()->onFromDb(function ($value) {
         return $value * 10;
     });
 }
Esempio n. 8
0
 private function cleanUpRecords($newValues)
 {
     if (!$this->parent->exists()) {
         return;
     }
     $newIds = [];
     foreach ($newValues as $nv) {
         if (isset($nv['id']) && $nv['id'] != '') {
             $newIds[] = Entity::getInstance()->getDatabase()->id($nv['id']);
         }
     }
     $attrValues = $this->getValue();
     foreach ($attrValues as $r) {
         if (!in_array($r->id, $newIds)) {
             $r->delete();
         }
     }
 }
Esempio n. 9
0
 private function cleanUpRecords($newValues)
 {
     if (!$this->parent->exists()) {
         return;
     }
     $newIds = [];
     foreach ($newValues as $nv) {
         if (isset($nv['id']) && $nv['id'] != '') {
             $newIds[] = Entity::getInstance()->getDatabase()->id($nv['id']);
         }
     }
     $where = ['_id' => ['$nin' => $newIds]];
     $where[$this->relatedAttribute] = $this->parent->id;
     $toRemove = call_user_func_array([$this->entityClass, 'find'], [$where]);
     foreach ($toRemove as $r) {
         $r->delete();
     }
 }
Esempio n. 10
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('boolean')->boolean();
     $this->attr('char')->char()->setToArrayDefault();
     $this->attr('skip')->char()->setSkipOnPopulate();
     $this->attr('after')->char();
     $this->attr('calculation')->integer()->onGet(function ($value, $multiplier = 1) {
         return $value * $multiplier;
     });
     $this->attr('integer')->integer();
     $this->attr('float')->float()->onGet(function ($value, $x = null) {
         return $x ? 2 * $x : $value;
     });
     $this->attr('date')->date()->setToArrayDefault();
     $this->attr('datetime')->datetime()->setToArrayDefault();
     $this->attr('arr')->arr();
     $this->attr('object')->object();
     $this->attr('geoPoint')->geoPoint()->setToArrayDefault();
     $this->attr('dynamic')->dynamic(function () {
         return 'dynamic-value';
     })->setToArrayDefault();
     $this->attr('dynamicDb')->dynamic(function () {
         return 'dynamic-value-db';
     })->setStoreToDb()->setToArrayDefault();
     $this->attr('dynamicWithDefaultParams')->dynamic(function ($multiplier = 2) {
         return $this->integer * $multiplier;
     })->setToArrayDefault();
     $this->attr('dynamicWithParams')->dynamic(function ($multiplier = 1) {
         return $this->integer * $multiplier;
     });
     $this->attr('dynamicEntity')->dynamic(function () {
         return Many2One::findOne(['char' => 'many2oneNew']);
     })->setToArrayDefault();
     $this->attr('dynamicEntityCollection')->dynamic(function () {
         return Many2One::find();
     })->setToArrayDefault();
     $this->attr('many2oneNew')->many2one()->setEntity(Classes::MANY_2_ONE_NO_VALIDATION);
     $this->attr('many2oneExisting')->many2one()->setEntity(Classes::MANY_2_ONE_NO_VALIDATION);
     $this->attr('one2many')->one2many('entity')->setEntity(Classes::ONE_2_MANY_NO_VALIDATION);
     $this->attr('many2many')->many2many('NoValidation_Many2Many2Entity')->setEntity(Classes::MANY_2_MANY_NO_VALIDATION);
 }
Esempio n. 11
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('char')->char()->setValidators('minLength:3,maxLength:5,in:abc:def');
     $this->attr('integer')->integer()->setValidators('integer,gt:2,lt:5');
     $this->attr('float')->float()->setValidators('gte:2,lte:5');
     $this->attr('object')->object()->setKeyValidators(['key1' => 'required', 'key2' => 'email']);
     $this->attr('geoPoint')->geoPoint();
     $this->attr('many2one')->many2one()->setEntity(Classes::MANY_2_ONE_VALIDATION);
     $this->attr('one2many')->one2many('entity')->setEntity(Classes::ONE_2_MANY_VALIDATION)->setValidators('minLength:2');
     $this->attr('many2many')->many2many('Whatever')->setEntity(Classes::MANY_2_MANY_NO_VALIDATION)->setValidators('minLength:2');
     $this->attr('vatNumber')->char()->setValidators('euVatNumber');
     $this->attr('creditCardNumber')->char()->setValidators('creditCardNumber');
     $this->attr('email')->char()->setValidators('email');
     $this->attr('number')->char()->setValidators('number');
     $this->attr('password')->char()->setValidators('password');
     $this->attr('url')->char()->setValidators('url');
     $this->attr('phone')->char()->setValidators('phone');
     $this->attr('regex')->char()->setValidators('regex:/^[-+0-9()]+$/');
     $this->attr('unique')->char()->setValidators('unique');
 }
Esempio n. 12
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('char')->char()->setToArrayDefault();
     $this->attr('entity')->many2one()->setEntity(Classes::ENTITY_NO_VALIDATION);
 }
Esempio n. 13
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('geoId')->integer()->attr("continentCode")->char()->attr("continentName")->char()->attr("countryCode")->char()->attr("countryName")->char()->attr("subdivision1Name")->char()->attr("subdivision1Code")->char()->attr("subdivision2Name")->char()->attr("subdivision2Code")->char()->attr("cityName")->char()->attr("timeZone")->char();
 }
Esempio n. 14
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('char')->char()->setValidators('required');
 }
Esempio n. 15
0
 public function __construct()
 {
     parent::__construct();
     $this->attr('char')->char()->setValidators('required');
     $this->attr('entity')->many2one()->setEntity(Classes::ENTITY_VALIDATION);
 }