/** * Returns the custom fields by a given group ID * * @param int $groupId The id of the group. * @return array */ public static function getCustomFields($groupId) { // get CM ID for this group $listId = self::getCampaignMonitorID('list', $groupId); // get the custom fields from CM $cmFields = self::getCM()->getCustomFields($listId); // reserve new fields array $newFields = array(); // fields found if (!empty($cmFields)) { // get the custom fields from our database $fields = BackendMailmotorModel::getCustomFields($groupId); // loop the fields foreach ($cmFields as $field) { // check if the field exists already. If not; add it if (!in_array($field['name'], $fields)) { $fields[] = $field['name']; } } // update the fields BackendMailmotorModel::updateCustomFields($fields, $groupId); } // return the results return (array) $fields; }
/** * Load the custom fields */ private function loadCustomFields() { // no groups or subscriptions at this point if (empty($this->group)) { return false; } // reserve counter $i = 0; // if no custom fields were set, we fetch the ones from the groups ourselves $this->group['custom_fields'] = BackendMailmotorModel::getCustomFields($this->id); // no custom fields for this group if (empty($this->group['custom_fields'])) { return false; } // loop the custom fields foreach ($this->group['custom_fields'] as $name) { // set value $value = isset($this->record['custom_fields'][$this->id][$name]) ? $this->record['custom_fields'][$this->id][$name] : ''; // store textfield value $this->customFields[$i]['label'] = $name; $this->customFields[$i]['name'] = SpoonFilter::toCamelCase($name, array('-', '_', ' ')); $this->customFields[$i]['formElements']['txtField'] = $this->frm->addText($this->customFields[$i]['name'], $value); $i++; // unset this field unset($this->customFields[$name]); } // add textfields to form $this->tpl->assign('fields', $this->customFields); }