Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • fusiondirectory-plugins fusiondirectory-plugins
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 50
    • Issues 50
    • List
    • Boards
    • Service Desk
    • Milestones
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • fusiondirectoryfusiondirectory
  • fusiondirectory-pluginsfusiondirectory-plugins
  • Issues
  • #4798
Closed
Open
Issue created May 20, 2016 by mhamant@mhamantReporter

fields() : suggestion on returned array structure

Hi,

Below is an extract of the array returned by fields():

Array
(
    [main] => Array
        (
            [name] => Mail account
            [attrs] => Array
                (
                    [0] => Array
                        (
                            [id] => mail
                            [label] => Primary address
                            [required] => 1
                            [disabled] => 
                            [description] => Primary mail address
                            [value] => test@test.fr
                            [type] => Array
                                (
                                    [0] => MailAttribute
                                    [1] => StringAttribute
                                    [2] => Attribute
                                )

                        )

                    [1] => Array
                        (
                            [id] => gosaMailServer
                            [label] => Server
                            [required] => 
                            [disabled] => 
                            [description] => Specify the mail server where the user will be hosted on
                            [value] => 
(...)

So to access the value of 'mail' attribute, you have to write $fields[main][attrs][0][value], which is not that good for two reasons:

  1. code readability : there is no mention of "mail" or in the array key(s).
  2. reliability : Most important consequence of 1), by using an index '0' there is no garantee that the fetched data will be what you expect to...

A straighforward solution for this would be to put the attribute id (name?) in the array key, so you can access the properties with $fields[main][attrs][][value], like $fields[main][attrs][mail][value] or $fields[main][attrs][mail][description]

(from redmine: issue id 4798, created on 2016-05-20, closed on 2016-05-30)

  • Custom Fields:
    • Bug in version: 1.0.12
Assignee
Assign to
Time tracking