public function updateCMSFlexiTabs(TabSet $fields, TabSet $settings_tab, $flexi)
 {
     parent::updateCMSFlexiTabs($fields, $settings_tab, $flexi);
     $mailchimp_tab = new Tab('MailChimp', 'MailChimp');
     $fields->insertBefore($mailchimp_tab, 'Settings');
     $client = new FlexiFormMailChimpClient($flexi->FlexiFormSetting('MailChimpApiKey')->getValue());
     foreach ($this->stat('handler_settings') as $component => $class) {
         $field_name = $this->getSettingFieldName($component);
         $field = $this->augmentMailChimpField($settings_tab->fieldByName($field_name), $component, $client);
         // Move Settings to designated MailChimp Tab
         $settings_tab->removeByName($field_name);
         $mailchimp_tab->push($field);
     }
     // integrate list groups
     if ($list_id = $flexi->FlexiFormSetting('MailChimpListID')->getValue()) {
         $field = new CheckboxSetField('FlexiFormMailChimpGroups', 'List Groups');
         if ($list_groups = $this->getInterestGroups($list_id, $client)) {
             $field->setSource($list_groups->map('id', 'name'));
             $field->setValue($flexi->FlexiFormFields()->filter('ClassName', 'FlexiMailChimpInterestGroupField')->column('InterestGroupID'));
             $field->description = 'Checked groups are added to your form Fields. Groups are refreshed every 10 minutes.';
         } else {
             $field = $field->performReadonlyTransformation();
             $field->setValue('This list has no Interest Groups');
         }
         $mailchimp_tab->push($field);
     }
     $mailchimp_tab->push(new LiteralField('MailChimpRefresh', '<br /><hr />NOTE: list and group selections are cached from mailchimp for up to 10 minutes. changing the API Key or list will cause a refresh.'));
 }
예제 #2
0
	function testSaveWithArrayValueSet() {
		$article = $this->objFromFixture('CheckboxSetFieldTest_Article', 'articlewithouttags');
		$articleWithTags = $this->objFromFixture('CheckboxSetFieldTest_Article', 'articlewithtags');
		$tag1 = $this->objFromFixture('CheckboxSetFieldTest_Tag', 'tag1');
		$tag2 = $this->objFromFixture('CheckboxSetFieldTest_Tag', 'tag2');
		
		/* Create a CheckboxSetField with 2 items selected.  Note that the array is in the format (key) => (selected) */
		$field = new CheckboxSetField("Tags", "Test field", DataObject::get("CheckboxSetFieldTest_Tag")->map());
		$field->setValue(array(
			$tag1->ID => true,
			$tag2->ID => true
		));
		
		/* Saving should work */
		$field->saveInto($article);
		
		$this->assertEquals(
			array($tag1->ID,$tag2->ID), 
			DB::query("SELECT \"CheckboxSetFieldTest_TagID\"
				FROM \"CheckboxSetFieldTest_Article_Tags\"
				WHERE \"CheckboxSetFieldTest_Article_Tags\".\"CheckboxSetFieldTest_ArticleID\" = $article->ID
			")->column(),
			'Data shold be saved into CheckboxSetField manymany relation table on the "right end"'
		);	
		$this->assertEquals(
			array($articleWithTags->ID,$article->ID), 
			DB::query("SELECT \"CheckboxSetFieldTest_ArticleID\"
				FROM \"CheckboxSetFieldTest_Article_Tags\"
				WHERE \"CheckboxSetFieldTest_Article_Tags\".\"CheckboxSetFieldTest_TagID\" = $tag1->ID
			")->column(),
			'Data shold be saved into CheckboxSetField manymany relation table on the "left end"'
		);	
	}
 public function testSavingIntoTextField()
 {
     $field = new CheckboxSetField('Content', 'Content', array('Test' => 'Test', 'Another' => 'Another', 'Something' => 'Something'));
     $article = new CheckboxSetFieldTest_Article();
     $field->setValue(array('Test' => 'Test', 'Another' => 'Another'));
     $field->saveInto($article);
     $article->write();
     $dbValue = DB::query(sprintf('SELECT "Content" FROM "CheckboxSetFieldTest_Article" WHERE "ID" = %s', $article->ID))->value();
     $this->assertEquals('Test,Another', $dbValue);
 }
 /**
  * Load a value into this CheckboxSetField
  */
 public function setValue($value, $obj = null)
 {
     // If we're not passed a value directly, we can look for it in a relation method on the object passed as a
     // second arg
     if (!$value && $obj && $obj instanceof DataObject && $obj->hasMethod($this->name)) {
         $funcName = $this->name;
         $join = $obj->{$funcName}();
         if ($join) {
             $join = $join->sort($this->getSortField());
             $value = $join->getIDList();
         } else {
             $value = array();
         }
     }
     parent::setValue($value, $obj);
     return $this;
 }
 public function updateCMSFields(FieldList $fields)
 {
     if ($this->owner->ID <= 0) {
         return;
     }
     $p = $this->owner->Parent();
     $d = $this->owner->getParent();
     if (!($allSchemas = DataObject::get('MetadataSchema'))) {
         return;
     }
     $tabName = 'Root.Metadata';
     $rootTab = $fields->fieldByName('Root');
     $newFields = array(new HeaderField('MetadataInfoHeader', 'Metadata Information'), new MetadataSetField($this->owner, 'MetadataRaw'), new HeaderField('MetadataSchemasHeader', 'Metadata Schemas'), $linkedSchemas = new CheckboxSetField('MetadataSchemas', '', $allSchemas));
     $inherited = $this->getInheritedSchemas()->map('ID', 'ID');
     $linkedSchemas->setValue($this->getAttachedSchemas()->map('ID', 'ID'));
     $linkedSchemas->setDefaultItems($inherited);
     $linkedSchemas->setDisabledItems($inherited);
     $canApply = $this->owner->extendedCan('canApplySchemas', Member::currentUser());
     if ($canApply === false) {
         $linkedSchemas->setDisabled(true);
     }
     if ($this->owner->hasExtension('Hierarchy')) {
         $newFields[] = new LiteralField('SchemaAppliedToChildrenNote', '<p>Any metadata schemas selected will also be applied to this' . " item's children.</p>");
     }
     if (!$rootTab) {
         foreach ($newFields as $f) {
             $fields->push($f);
         }
     } else {
         $fields->addFieldsToTab($tabName, $newFields);
     }
 }
 /**
  * Load a value into this CheckboxSetField
  */
 public function setValue($value, $obj = null)
 {
     // If we're not passed a value directly, we can look for it in a relation method on the object passed as a second arg
     //		if(!$value && $obj && $obj instanceof DataObject && $obj->hasMethod($this->name)) {
     //			$funcName = $this->name;
     //			$selected = $obj->$funcName();
     //			$value = $selected->toDropdownMap('ID', 'ID');
     //		}
     parent::setValue($value, $obj);
 }
 public function setValue($value, $obj = null)
 {
     if ($this->fieldType == 'CheckboxSetField') {
         CheckboxSetField::setValue($value, $obj);
     } else {
         parent::setValue($value);
     }
 }
예제 #8
0
 /**
  * STANDARD SILVERSTRIPE STUFF
  **/
 function scaffoldSearchFields()
 {
     $fieldSet = parent::scaffoldSearchFields();
     if ($statusOptions = self::get_order_status_options()) {
         $createdOrderStatusID = 0;
         $preSelected = array();
         if ($createdOrderStatus = DataObject::get_one("OrderStep")) {
             $createdOrderStatusID = $createdOrderStatus->ID;
         }
         $arrayOfStatusOptions = $statusOptions->toDropDownMap();
         if (count($arrayOfStatusOptions)) {
             foreach ($arrayOfStatusOptions as $key => $value) {
                 $count = DB::query("SELECT COUNT(\"ID\") FROM \"Order\" WHERE \"StatusID\" = " . intval($key) . ";")->value();
                 if ($count < 1) {
                     unset($arrayOfStatusOptions[$key]);
                 } else {
                     $arrayOfStatusOptions[$key] .= " ({$count})";
                 }
                 //we use 100 here because if there is such a big list, an additional filter should be added
                 if ($count > 100) {
                 } else {
                     if ($key != $createdOrderStatusID) {
                         $preSelected[$key] = $key;
                     }
                 }
             }
         }
         $statusField = new CheckboxSetField("StatusID", "Status", $arrayOfStatusOptions);
         $statusField->setValue($preSelected);
         $fieldSet->push($statusField);
     }
     $fieldSet->push(new DropdownField("CancelledByID", "Cancelled", array(-1 => "(Any)", 1 => "yes", 0 => "no")));
     return $fieldSet;
 }
 /**
  * Load a value into this CheckboxSetField
  */
 public function setValue($value, $obj = null)
 {
     if (!empty($value) && !is_array($value) && !empty($this->value)) {
         $this->value[] = $value;
     } else {
         parent::setValue($value, $obj);
     }
     return $this;
 }
 function setValue($value, $obj = null)
 {
     // If we're not passed a value directly, we can look for it in a relation method on the object passed as a
     // second arg
     if (!$value && $obj && $obj instanceof DataObject && $obj->hasMethod($this->name)) {
         $funcName = $this->name;
         $value = $obj->{$funcName}()->getIDList();
     } else {
         if (is_string($value)) {
             $value = explode(",", $value);
         }
     }
     parent::setValue($value, $obj);
     // We need to sort the fields according to the $value, so that the list of
     // fields apparing in the right order.
     $sortedSource = array();
     $sourceKeys = array_keys($this->source);
     foreach ($this->value as $item) {
         if (in_array($item, $sourceKeys)) {
             $sortedSource[$item] = $this->source[$item];
         }
     }
     $this->source = array_merge($sortedSource, $this->source);
     if (count($this->extra)) {
         foreach ($this->extra as $field => $type) {
             if ($obj && isset($obj->{$field})) {
                 $this->extraValue[$field] = $obj->{$field};
             }
         }
     }
     return $this;
 }
 public function setValue($val, $obj = null)
 {
     $values = array();
     if (is_array($val)) {
         foreach ($val as $id => $text) {
             if (preg_match('/^__new__/', $id)) {
                 $id = $this->source->newObject(array($this->labelField => $text))->write();
             }
             $values[$id] = $text;
         }
         parent::setValue($values, $obj);
     } else {
         parent::setValue($val, $obj);
     }
 }