/** * Returns HAS_ONE relation attributes * and non-relation attributes in an array * mapping attribute names to 'attributeLabel' to the * attribute label. Also returns 'isRequired' and 'isAudited' information. */ public function getAttributes() { $attributes = array(); ModelAttributeCollectionUtil::populateCollection($attributes, 'id', $this->model->getAttributeLabel('id'), 'Text'); $modelMetadata = $this->model->getMetadata(); foreach ($this->model->attributeNames() as $attributeName) { if (!$this->model->isRelation($attributeName) || $this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE || $this->model->getRelationType($attributeName) == RedBeanModel::HAS_MANY_BELONGS_TO) { if ($this->model instanceof Item) { $isAudited = $this->model->isAttributeAudited($attributeName); } else { $isAudited = false; } $customFieldName = null; if ($this->model->isRelation($attributeName) && $this->model->{$attributeName} instanceof BaseCustomField) { foreach ($modelMetadata as $modelClassName => $modelClassMetadata) { if (isset($modelMetadata[$modelClassName]['customFields']) && isset($modelMetadata[$modelClassName]['customFields'][$attributeName])) { $customFieldName = $modelMetadata[$modelClassName]['customFields'][$attributeName]; } } } ModelAttributeCollectionUtil::populateCollection($attributes, $attributeName, $this->model->getAttributeLabel($attributeName), ModelAttributeToDesignerTypeUtil::getDesignerType($this->model, $attributeName), $this->model->isAttributeRequired($attributeName), $this->model->isAttributeReadOnly($attributeName), $isAudited, $customFieldName); } } return $attributes; }
public static function createAttributeFormByAttributeName(RedBeanModel $model, $attributeName) { assert('$model !== null'); assert('is_string($attributeName) && $attributeName != ""'); $designerType = ModelAttributeToDesignerTypeUtil::getDesignerType($model, $attributeName); $attributeFormClass = $designerType . 'AttributeForm'; return new $attributeFormClass($model, $attributeName); }
protected static function getValueTypeDropDownArray() { $data = array('' => Zurmo::t('DesignerModule', 'Select a field type')); $attributeTypes = ModelAttributeToDesignerTypeUtil::getAvailableCustomAttributeTypes(); foreach ($attributeTypes as $attributeType) { $attributeFormClassName = AttributesFormFactory::getFormClassNameByAttributeType($attributeType); $data[$attributeType] = $attributeFormClassName::getAttributeTypeDisplayName(); } return $data; }
/** * Sanitizes data for date and date time attributes by converting them to the proper * format and timezone for saving. * @return - array sanitized data */ public static function sanitizeDataByDesignerTypeForSavingModel($model, $data) { assert('$model instanceof RedBeanModel || $model instanceof ModelForm'); assert('is_array($data)'); foreach ($data as $attributeName => $value) { if ($value !== null && static::isNotMarkedSkipped($attributeName)) { if (!is_array($value)) { if ($model->isAttribute($attributeName) && $model->isAttributeSafe($attributeName)) { $designerType = ModelAttributeToDesignerTypeUtil::getDesignerType($model, $attributeName); if ($designerType == 'Date' && !empty($value)) { $data[$attributeName] = DateTimeUtil::resolveValueForDateDBFormatted($value); } if ($designerType == 'DateTime' && !empty($value)) { $data[$attributeName] = DateTimeUtil::convertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero($value); } $data[$attributeName] = static::purifyHtml($data[$attributeName]); } } else { try { $designerType = ModelAttributeToDesignerTypeUtil::getDesignerType($model, $attributeName); } catch (NotImplementedException $e) { //In the event that a designer type does not exist. $designerType = null; } if ($model->isAttributeSafe($attributeName) && $designerType != 'TagCloud') { if ($designerType == 'MixedDateTypesForSearch' && isset($value['firstDate']) && $value['firstDate'] != null) { $data[$attributeName]['firstDate'] = DateTimeUtil::resolveValueForDateDBFormatted($value['firstDate']); } if ($designerType == 'MixedDateTypesForSearch' && isset($value['secondDate']) && $value['secondDate'] != null) { $data[$attributeName]['secondDate'] = DateTimeUtil::resolveValueForDateDBFormatted($value['secondDate']); } } elseif (isset($value['values']) && is_string($value['values']) && $designerType == 'TagCloud') { if ($data[$attributeName]['values'] == '') { $data[$attributeName]['values'] = array(); } else { $data[$attributeName]['values'] = explode(',', $data[$attributeName]['values']); // Not Coding Standard } } if ($designerType == 'CheckBox') { $data[$attributeName] = $value['value']; } else { array_walk_recursive($data[$attributeName], array(get_called_class(), 'purifyHtmlAndModifyInput')); } } } } return $data; }
/** * @return array of place-able attributes */ public function getAttributes() { $attributes = array(); foreach ($this->model->attributeNames() as $attributeName) { if (!$this->model->isRelation($attributeName) || $this->model->isOwnedRelation($attributeName) && $this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE) { if ($this->model instanceof Item) { $isAudited = $this->model->isAttributeAudited($attributeName); } else { $isAudited = false; } ModelAttributeCollectionUtil::populateCollection($attributes, $attributeName, $this->model->getAttributeLabel($attributeName), ModelAttributeToDesignerTypeUtil::getDesignerType($this->model, $attributeName), $this->model->isAttributeRequired($attributeName), $this->model->isAttributeReadOnly($attributeName), $isAudited); } } return $attributes; }
/** * Returns list of available designer types including * attribute types available for creating custom fields * and designer types for standard collection attributes that * are not necessarily available types for custom fields. * */ public static function getAvailableDesignerTypes() { if (self::$availableDesignerTypes != null) { return self::$availableDesignerTypes; } $modules = Module::getModuleObjects(); $designerTypes = array(); foreach ($modules as $module) { $formsClassNames = $module::getAllClassNamesByPathFolder('forms'); foreach ($formsClassNames as $formClassName) { $classToEvaluate = new ReflectionClass($formClassName); if (is_subclass_of($formClassName, 'AttributeForm') && !$classToEvaluate->isAbstract()) { $designerTypes[] = substr($formClassName, 0, strlen($formClassName) - strlen('AttributeForm')); } } } self::$availableDesignerTypes = $designerTypes; return self::$availableDesignerTypes; }
/** * @param $attributeName * @param $value * @return string */ public static function sanitizeHiddenAttributeValue($attributeName, $value) { $designerType = ModelAttributeToDesignerTypeUtil::getDesignerType(new Contact(false), $attributeName); $sanitizedAttributeValue = $value; if ($designerType == 'Date' && !empty($value)) { $sanitizedAttributeValue = DateTimeUtil::resolveValueForDateDBFormatted($value); } if ($designerType == 'DateTime' && !empty($value)) { $sanitizedAttributeValue = DateTimeUtil::convertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero($value); } return DataUtil::purifyHtml($sanitizedAttributeValue); }