예제 #1
0
 /**
  * Load entity data by ID
  *
  * @param int|null $id
  * @return $this
  */
 public function loadEntityData($id = null)
 {
     if (is_null($id)) {
         return $this;
     }
     $this->model = $this->model->getOrm()->whereEq($this->model->getIdField(), $id)->fetchModel();
     if (empty($this->model)) {
         return $this;
     }
     $this->setFormValues($this->model->asArray());
     foreach ($this->scaffold->getEntityFields($this->entity) as $field) {
         $fieldConfig = $this->scaffold->getEntityFieldConfig($this->entity, $field);
         if ((bool) (string) $fieldConfig->allow_null) {
             if (is_null($this->model->{$field})) {
                 $checkboxNull = $this->getElementByName("set-null[{$field}]");
                 if ($checkboxNull instanceof \Magelight\Webform\Blocks\Elements\Checkbox) {
                     $checkboxNull->setChecked();
                 }
             }
         }
     }
     return $this;
 }
예제 #2
0
 public function testGetFlatCollection()
 {
     $collectionMock = $this->getMock(\Magelight\Db\Collection::class, [], [], '', false);
     \Magelight\Db\Collection::forgeMock($collectionMock);
     $this->assertEquals($collectionMock, \Magelight\Model::getFlatCollection());
 }
예제 #3
0
 /**
  * Before save handler
  *
  * @return \Magelight\Model|void
  */
 public function beforeSave()
 {
     if (!is_int($this->time)) {
         $this->time = strtotime($this->time);
     }
     if (!is_int($this->ip)) {
         $this->ip = ip2long($this->ip);
     }
     return parent::beforeSave();
 }