Exemple #1
0
 protected function getDataFromEntity(Entity $entity)
 {
     $data = $entity->toArray();
     $fieldDefs = $entity->getFields();
     $fieldList = array_keys($fieldDefs);
     foreach ($fieldList as $field) {
         $type = null;
         if (!empty($fieldDefs[$field]['type'])) {
             $type = $fieldDefs[$field]['type'];
         }
         if ($type == Entity::DATETIME) {
             if (!empty($data[$field])) {
                 $data[$field] = $this->dateTime->convertSystemDateTime($data[$field]);
             }
         } else {
             if ($type == Entity::DATE) {
                 if (!empty($data[$field])) {
                     $data[$field] = $this->dateTime->convertSystemDate($data[$field]);
                 }
             } else {
                 if ($type == Entity::JSON_ARRAY) {
                     if (!empty($data[$field])) {
                         $list = $data[$field];
                         $newList = [];
                         foreach ($list as $item) {
                             $v = $item;
                             if ($item instanceof \StdClass) {
                                 $v = get_object_vars($v);
                             }
                             foreach ($v as $k => $w) {
                                 $v[$k] = $this->format($v[$k]);
                             }
                             $newList[] = $v;
                         }
                         $data[$field] = $newList;
                     }
                 } else {
                     if ($type == Entity::JSON_OBJECT) {
                         if (!empty($data[$field])) {
                             $value = $data[$field];
                             if ($value instanceof \StdClass) {
                                 $data[$field] = get_object_vars($value);
                             }
                             foreach ($data[$field] as $k => $w) {
                                 $data[$field][$k] = $this->format($data[$field][$k]);
                             }
                         }
                     }
                 }
             }
         }
         if (array_key_exists($field, $data)) {
             $data[$field] = $this->format($data[$field]);
         }
     }
     return $data;
 }
Exemple #2
0
 protected function getFieldFromEntityForExport(Entity $entity, $field)
 {
     $defs = $entity->getFields();
     if (!empty($defs[$field]) && !empty($defs[$field]['type'])) {
         $type = $defs[$field]['type'];
         switch ($type) {
             case 'jsonArray':
                 $value = $entity->get($field);
                 if (is_array($value)) {
                     return implode(',', $value);
                 } else {
                     return null;
                 }
                 break;
             case 'password':
                 return null;
                 break;
         }
     }
     return $entity->get($field);
 }
Exemple #3
0
 protected function parseValue(Entity $entity, $field, $value, $params = array())
 {
     $decimalMark = '.';
     if (!empty($params['decimalMark'])) {
         $decimalMark = $params['decimalMark'];
     }
     $defaultCurrency = 'USD';
     if (!empty($params['defaultCurrency'])) {
         $defaultCurrency = $params['defaultCurrency'];
     }
     $dateFormat = 'Y-m-d';
     if (!empty($params['dateFormat'])) {
         if (!empty($this->dateFormatsMap[$params['dateFormat']])) {
             $dateFormat = $this->dateFormatsMap[$params['dateFormat']];
         }
     }
     $timeFormat = 'H:i';
     if (!empty($params['timeFormat'])) {
         if (!empty($this->timeFormatsMap[$params['timeFormat']])) {
             $timeFormat = $this->timeFormatsMap[$params['timeFormat']];
         }
     }
     $fieldDefs = $entity->getFields();
     if (!empty($fieldDefs[$field])) {
         $type = $fieldDefs[$field]['type'];
         switch ($type) {
             case Entity::DATE:
                 $dt = \DateTime::createFromFormat($dateFormat, $value);
                 if ($dt) {
                     return $dt->format('Y-m-d');
                 }
                 break;
             case Entity::DATETIME:
                 $dt = \DateTime::createFromFormat($dateFormat . ' ' . $timeFormat, $value);
                 if ($dt) {
                     return $dt->format('Y-m-d H:i');
                 }
                 break;
             case Entity::FLOAT:
                 $currencyField = $field . 'Currency';
                 if ($entity->hasField($currencyField)) {
                     if (!$entity->has($currencyField)) {
                         $entity->set($currencyField, $defaultCurrency);
                     }
                 }
                 $a = explode($decimalMark, $value);
                 $a[0] = preg_replace('/[^A-Za-z0-9\\-]/', '', $a[0]);
                 if (count($a) > 1) {
                     return $a[0] . '.' . $a[1];
                 } else {
                     return $a[0];
                 }
                 break;
         }
     }
     return $value;
 }
Exemple #4
0
 protected function parseText($type, Entity $entity, $text)
 {
     $fieldList = array_keys($entity->getFields());
     $fieldList[] = $id;
     foreach ($fieldList as $field) {
         $value = $entity->get($field);
         if (is_object($value)) {
             continue;
         }
         if ($entity->fields[$field]['type'] == 'date') {
             $value = $this->getDateTime()->convertSystemDateToGlobal($value);
         } else {
             if ($entity->fields[$field]['type'] == 'datetime') {
                 $value = $this->getDateTime()->convertSystemDateTimeToGlobal($value);
             }
         }
         $text = str_replace('{' . $type . '.' . $field . '}', $value, $text);
     }
     return $text;
 }
Exemple #5
0
 protected function parseText($type, Entity $entity, $text)
 {
     $fieldList = array_keys($entity->getFields());
     foreach ($fieldList as $field) {
         $value = $entity->get($field);
         if (is_object($value)) {
             continue;
         }
         $fieldType = $this->getMetadata()->get('entityDefs.' . $entity->getEntityType() . '.fields.' . $field . '.type');
         if ($fieldType === 'enum') {
             $value = $this->getLanguage()->translateOption($value, $field, $entity->getEntityType());
         } else {
             if ($entity->fields[$field]['type'] == 'date') {
                 $value = $this->getDateTime()->convertSystemDateToGlobal($value);
             } else {
                 if ($entity->fields[$field]['type'] == 'datetime') {
                     $value = $this->getDateTime()->convertSystemDateTimeToGlobal($value);
                 }
             }
         }
         $text = str_replace('{' . $type . '.' . $field . '}', $value, $text);
     }
     return $text;
 }
 protected function parseText($type, Entity $entity, $text)
 {
     $fields = array_keys($entity->getFields());
     foreach ($fields as $field) {
         $text = str_replace('{' . $type . '.' . $field . '}', $entity->get($field), $text);
     }
     return $text;
 }