CampaignMonitor::getCustomFields PHP Метод

getCustomFields() публичный Метод

Returns all the custom fields available for a list.
public getCustomFields ( string[optional] $listId = null ) : array
$listId string[optional]
Результат array
    public function getCustomFields($listId = null)
    {
        // set ID
        $listId = empty($listId) ? $this->getListId() : $listId;
        // make the call
        $records = (array) $this->doCall('lists/' . $listId . '/customfields');
        // stop here if no records were set
        if (empty($records)) {
            return array();
        }
        // reserve variable
        $results = array();
        // loop the records
        foreach ($records as $key => $record) {
            $results[$key]['name'] = $record['FieldName'];
            $results[$key]['type'] = $record['DataType'];
            // field options found
            if (!empty($record['FieldOptions'])) {
                // loop the options
                foreach ($record['FieldOptions'] as $option) {
                    $results[$key]['options'][] = $option;
                }
            }
        }
        // return the records
        return $results;
    }

Usage Example

Пример #1
0
 /**
  * Load the form
  *
  * @return	void
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('import');
     // fetch the groups
     $this->externalGroups = $this->cm->getListsByClientId();
     // loop the groups
     foreach ($this->externalGroups as &$group) {
         // add subscribers + count to the group stack
         $group['subscribers'] = BackendMailmotorCMHelper::getSubscribers($group['id']);
         $group['subscribers_amount'] = count($group['subscribers']);
         // get the custom fields
         $customFields = $this->cm->getCustomFields($group['id']);
         // skip this if no custom fields were found
         if (!empty($customFields)) {
             // loop the custom fields
             foreach ($customFields as &$field) {
                 // save only field name in a new format
                 $field = $field['name'];
             }
         }
         // add custom fields to the group stack
         $group['custom_fields'] = empty($customFields) ? null : serialize($customFields);
     }
     // parse the groups
     $this->tpl->assign('groups', $this->externalGroups);
 }