public function updateSettingsFields(FieldList $fields) { $changeFreq = Singleton('Page')->dbObject('ChangeFreq')->enumValues(); $fields->addFieldToTab('Root.Settings', DropDownField::create('ChangeFreq', 'Change Frequency', $changeFreq)); $priority = Singleton('Page')->dbObject('Priority')->enumValues(); $fields->addFieldToTab('Root.Settings', DropDownField::create('Priority', 'Priority', $priority)); }
public function getEditForm($id = null, $fields = null) { $form = parent::getEditForm($id = null, $fields = null); if (Singleton($this->modelClass)->isVersioned) { $listfield = $form->Fields()->fieldByName($this->modelClass); $gridFieldConfig = $listfield->getConfig(); $gridFieldConfig->getComponentByType('GridFieldDetailForm')->setItemRequestClass('VersionedGridFieldDetailForm_ItemRequest'); $gridFieldConfig->removeComponentsByType('GridFieldDeleteAction'); $gridFieldConfig->addComponent(new VersionedGridFieldDeleteAction()); } return $form; }
/** * @return JoinSpecification[] */ public function build() { $specs = array(); $class_name = ClassInfo::baseDataClass($this->base_entity); $relation_name = $this->alias->getName(); $child = $this->relations[$relation_name]; $child_many_many = Config::inst()->get($child, 'many_many'); $child_many_many_classes = array_flip($child_many_many); $component_name = $child_many_many_classes[$class_name]; list($parent_class, $component_class, $child_join_field, $join_field, $join_table) = Singleton($child)->many_many($component_name); $specs[] = new JoinSpecification($join_table, $join_table . '`.' . $join_field . ' = `' . $class_name . '`.ID'); $specs[] = new JoinSpecification($child, $child . '`.ID = `' . $join_table . '`.' . $child_join_field); $this->base_table = $class_name; return $specs; }
public function getAlias($join_type = QueryAlias::INNER) { $join = array(); foreach ($this->alias as $alias) { if ($alias->getJoinType() !== $join_type) { continue; } $child = $alias->getName(); $has_many = Config::inst()->get(get_class($this->base_entity), 'has_many'); $class_name = ClassInfo::baseDataClass($this->base_entity); if (!is_null($has_many)) { $has_many_classes = array_flip($has_many); if (array_key_exists($child, $has_many_classes)) { $tableClasses = ClassInfo::dataClassesFor($child); $baseClass = array_shift($tableClasses); $joinField = $this->base_entity->getRemoteJoinField($has_many_classes[$child], 'has_many'); $join[$baseClass] = $baseClass . '.' . $joinField . ' = ' . $class_name . '.ID'; $this->addAndCondition(QueryCriteria::equal("{$baseClass}.ClassName", $child)); } } $has_many_many = Config::inst()->get(get_class($this->base_entity), 'many_many'); if (!is_null($has_many_many)) { $has_many_many_classes = array_flip($has_many_many); if (array_key_exists($child, $has_many_many_classes)) { $base_entity_name = get_class($this->base_entity); $component = $has_many_many_classes[$child]; $joinTable = "{$base_entity_name}_{$component}"; $parentField = $base_entity_name . "ID"; $childField = $child . "ID"; $join[$joinTable] = $joinTable . '.' . $parentField . ' = ' . $class_name . '.ID'; $join[$child] = $child . '.ID = ' . $joinTable . '.' . $childField; } } $has_one = Config::inst()->get(get_class($this->base_entity), 'has_one'); if (!is_null($has_one)) { if (array_key_exists($child, $has_one)) { $table = $has_one[$child]; $join[$table] = $has_one[$child] . '.ID = ' . $class_name . '.' . $child . 'ID'; } else { $has_one_classes = array_flip($has_one); if (array_key_exists($child, $has_one_classes)) { $join[$child] = $child . '.ID = ' . $class_name . '.' . $has_one_classes[$child] . 'ID'; } } } $belongs_many_many = Config::inst()->get(get_class($this->base_entity), 'belongs_many_many'); if (!is_null($belongs_many_many)) { $belongs_many_many_classes = array_flip($belongs_many_many); if (array_key_exists($child, $belongs_many_many_classes)) { $child_many_many = Config::inst()->get($child, 'many_many'); $child_many_many_classes = array_flip($child_many_many); $component_name = $child_many_many_classes[$class_name]; list($parentClass, $componentClass, $child_join_field, $join_field, $join_table) = Singleton($child)->many_many($component_name); $join[$join_table] = $join_table . '`.' . $join_field . ' = `' . $class_name . '`.ID'; $join[$child] = $child . '`.ID = `' . $join_table . '`.' . $child_join_field; } } if ($alias->hasSubAlias()) { $join = array_merge($join, $alias->subAlias($join_type)); } } return $join; }
public static function get_plural_name() { $obj = Singleton("ProductVariation"); return $obj->i18n_plural_name(); }
/** * Display CMS JSON/XML output visibility configuration. */ public function getCMSFields() { $fields = parent::getCMSFields(); // Hide the data object name and output visibility associated with this configuration. $fields->removeByName('IsFor'); $fields->removeByName('APIwesomeVisibility'); // Grab a single data object. Requirements::css(APIWESOME_PATH . '/css/apiwesome.css'); if (DataObject::get_one($this->IsFor)) { // Grab the appropriate attributes for this data object. $class = is_subclass_of($this->IsFor, 'SiteTree') ? 'SiteTree' : (is_subclass_of($this->IsFor, 'File') ? 'File' : $this->IsFor); $columns = array(); foreach (ClassInfo::subclassesFor($class) as $subclass) { // Prepend the table names. $subclassColumns = array(); foreach (DataObject::database_fields($subclass) as $column => $type) { $subclassColumns["{$subclass}.{$column}"] = $type; } $columns = array_merge($columns, $subclassColumns); } array_shift($columns); $visibility = $this->APIwesomeVisibility ? explode(',', $this->APIwesomeVisibility) : null; // Display the check box fields for JSON/XML output visibility. $configuration = FieldGroup::create('Visibility')->addExtraClass('visibility'); $iteration = 0; foreach ($columns as $name => $type) { // Print the attribute name, including any relationships. $split = explode('.', $name); $printName = substr($name, strlen($name) - 2) === 'ID' && count($split) === 2 && ClassInfo::exists($split[0]) && Singleton($split[0])->hasMethod(substr($split[1], 0, -2)) ? substr($name, 0, -2) : $name; $printName = ltrim(preg_replace(array('/([A-Z][a-z]+)/', '/([A-Z]{2,})/', '/([_.0-9]+)/'), ' $0', $printName)); // Set an already existing attribute visibility. $configuration->push(CheckboxField::create(str_replace('.', '-', "{$name}.APIwesomeVisibility"), "Display <strong>{$printName}</strong>?", count($visibility) === count($columns) && isset($visibility[$iteration]) ? $visibility[$iteration] : 0)); $iteration++; } $fields->addFieldToTab('Root.Main', $configuration); } else { // Display a notice that data objects should first be created. $fields->removeByName('CallbackFunction'); $name = $this->getTitle(); $fields->addFieldToTab('Root.Main', LiteralField::create('ConfigurationNotice', "<p class='apiwesome notice'><strong>No {$name}s Found</strong></p>")); } $this->extend('updateDataObjectOutputConfigurationCMSFields', $fields); return $fields; }
public function getItemsWhere() { if ($filters = $this->getFilterSettings()) { $filter = array(); foreach ($filters as $varName => $settings) { if ($values = $this->getFilterValue($varName)) { $filterTitle = $varName; $relation = Singleton($this->stat('item_class'))->{$varName}(); //If we are a has_many or Many_many we need the . notation "FieldName.ID" if (get_class($relation) == "UnsavedRelationList") { $filterTitle .= ".ID"; } else { $filterTitle .= "ID"; } if ($settings['MatchAll']) { $filterTitle .= ":DataObjectAsPageMatchAll"; } $filter[$filterTitle] = explode(",", $values); } } //Set the type of filter and return return $filter ? array('filter' => $filter) : false; } }
public function updateCMSFields(FieldList $fields) { $fields->addFieldsToTab('Root.GoogleAnalytics', array(DropdownField::create("GoogleAnalyticsType", _t('GoogleAnalyticsExtension.GoogleAnalyticsType', 'Google Analytics Type'), Singleton('SiteConfig')->dbObject('GoogleAnalyticsType')->enumValues())->setRightTitle(_t('GoogleAnalyticsExtension.TypeHelp', "Please select the correct Analytics type according to the setup of your Google Analytics account.")), TextField::create('GoogleAnalyticsID', _t('GoogleAnalyticsExtension.GOOGLEANALYTICSID', 'Google Analytics ID')), TextField::create('GoogleAnalyticsCookieDomain', _t('GoogleAnalyticsExtension.NONSTANDARDCOOKIEDOMAIN', 'Non-Standard Cookie Domain'))->setRightTitle(_t('GoogleAnalyticsExtension.COOKIEDOMAINHELP', "If you want to use a non-standard cookie domain for your tracking, please enter it here. If this field is left empty, 'auto' will be used.")), FieldGroup::create(CheckboxField::create('GoogleAnalyticsUseEventTracking', ''))->setTitle(_t('GoogleAnalyticsExtension.USEEVENTTRACKING', 'Use Event Tracking'))->setName('GAEventTracking')->setRightTitle(_t('GoogleAnalyticsExtension.EVENTTRACKINGHELP', "Activate this box if you want to track events like downloads and clicks on external, email and phone links. ")))); $fields->fieldByName("Root.GoogleAnalytics")->setTitle(_t('GoogleAnalyticsExtension.GOOGLEANALYTICSTAB', 'Google Analytics')); }
public static function get_plural_name() { $obj = Singleton("ProductAttributeValue"); return $obj->i18n_plural_name(); }