GitHub PullRequestReviewCommentEvent at 2014-01-16 22:33:42
Repository: DoctrinePHPCRBundle
Actor: dbu
Payload: {"comment":{"url":"https://api.github.com/repos/doctrine/DoctrinePHPCRBundle/pulls/comments/8950457","id":8950457,"diff_hunk":"@@ -54,37 +56,128 @@ public function guessType($class, $property)\n             return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);\n         }\n \n+        /** @var ClassMetadata $metadata */\n+        /** @var DocumentManager $documentManager */\n         list($metadata, $documentManager) = $ret;\n \n         if ($metadata->hasAssociation($property)) {\n-            $multiple = $metadata->isCollectionValuedAssociation($property);\n             $mapping = $metadata->getAssociation($property);\n \n-            return new TypeGuess('phpcr_document', array(\n-                'class' => $mapping['targetDocument'],\n-                'multiple' => $multiple\n-                ),\n-                Guess::HIGH_CONFIDENCE\n-            );\n+            switch($mapping['type']) {\n+                case 'parent':\n+                    return new TypeGuess('phpcr_odm_path', array(), Guess::MEDIUM_CONFIDENCE);\n+\n+                case 'mixedreferrers':\n+                    $options = array(\n+                        'read_only' => true,\n+                        'type' => 'phpcr_odm_path',\n+                    );\n+\n+                    return new TypeGuess('collection', $options, Guess::LOW_CONFIDENCE);\n+\n+                case 'referrers':\n+                    return new TypeGuess('phpcr_document', array(\n+                            'class' => $mapping['referringDocument'],\n+                            'multiple' => true\n+                        ),\n+                        Guess::HIGH_CONFIDENCE\n+                    );\n+\n+                case ClassMetadata::MANY_TO_MANY:\n+                case ClassMetadata::MANY_TO_ONE:\n+                    $options = array(\n+                        'multiple' => $metadata->isCollectionValuedAssociation($property),\n+                    );\n+                    if (isset($mapping['targetDocument'])) {\n+                        $options['class'] = $mapping['targetDocument'];\n+                    }\n+\n+                    return new TypeGuess('phpcr_document', $options, Guess::HIGH_CONFIDENCE);\n+\n+                case 'child':\n+                    $options = array(\n+                        'read_only' => true,\n+                    );\n+\n+                    return new TypeGuess('phpcr_odm_path', $options, Guess::LOW_CONFIDENCE);\n+\n+                case 'children':\n+                    $options = array(\n+                        'read_only' => true,\n+                        'type' => 'phpcr_odm_path',\n+                    );\n+\n+                    return new TypeGuess('collection', $options, Guess::LOW_CONFIDENCE);\n+\n+                default:\n+                    return null;\n+            }\n+        }\n+\n+        $mapping = $metadata->getField($property);\n+        if (! empty($mapping['assoc'])) {\n+            // TODO https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/92 (should be part of phpcr-bundle\n+            return null;\n         }\n \n+        $options = array();\n         switch ($metadata->getTypeOfField($property)) {\n             case 'boolean':\n-                return new TypeGuess('checkbox', array(), Guess::HIGH_CONFIDENCE);\n+                $type = 'checkbox';\n+                break;\n             case 'binary':\n-                return new TypeGuess('file', array(), Guess::HIGH_CONFIDENCE);\n+                // the file type only works on documents like the File document,\n+                // not directly on properties with raw binary data.\n+                return null;\n+            case 'node':\n+                // editing the phpcr node has no meaning\n+                return null;\n             case 'date':\n-                return new TypeGuess('datetime', array(), Guess::HIGH_CONFIDENCE);\n+                $type = 'datetime';\n+                break;\n             case 'double':\n-                return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE);\n+                $type = 'number';\n+                break;\n             case 'long':\n             case 'integer':\n-                return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE);\n+                $type = 'integer';\n+                break;\n             case 'string':\n-                return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE);\n+                if ($metadata->isIdentifier($property)\n+                    || $metadata->isUuid($property)\n+                ) {\n+                    $options['read_only'] = true;\n+                }\n+                $type = 'text';\n+                break;\n+            case 'nodename':\n+                $type = 'text';\n+                break;\n+            case 'locale':\n+                $locales = $documentManager->getLocaleChooserStrategy();\n+                $type = 'choice';\n+                $options['choices'] = array_combine($locales->getDefaultLocalesOrder(), $locales->getDefaultLocalesOrder());\n+                break;\n+            case 'versionname':\n+            case 'versioncreated':\n             default:\n-                return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);\n+                $options['read_only'] = true;\n+                $options['required'] = false;\n+                $type = 'text';\n+                break;\n+        }\n+\n+        if (!empty($mapping['multivalue'])) {\n+            $options['type'] = $type;\n+            $type = 'collection';\n         }\n+\n+        if (!empty($mapping['translated'])) {\n+            $options['attr'] = array('class' => 'translated');\n+        }","path":"Form/PHPCRTypeGuesser.php","position":145,"original_position":145,"commit_id":"fe8ec4943f714a517320c3a9a64203ab5e130159","original_commit_id":"fe8ec4943f714a517320c3a9a64203ab5e130159","user":{"login":"dbu","id":76576,"avatar_url":"https://gravatar.com/avatar/c9f4f8ce2c2936bacaf49500b5a127dc?d=https%3A%2F%2Fidenticons.github.com%2F8b3432e34d73182c191e65586b395c06.png&r=x","gravatar_id":"c9f4f8ce2c2936bacaf49500b5a127dc","url":"https://api.github.com/users/dbu","html_url":"https://github.com/dbu","followers_url":"https://api.github.com/users/dbu/followers","following_url":"https://api.github.com/users/dbu/following{/other_user}","gists_url":"https://api.github.com/users/dbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbu/subscriptions","organizations_url":"https://api.github.com/users/dbu/orgs","repos_url":"https://api.github.com/users/dbu/repos","events_url":"https://api.github.com/users/dbu/events{/privacy}","received_events_url":"https://api.github.com/users/dbu/received_events","type":"User","site_admin":false},"body":"unfortunately, we don't get the actual instance injected, only the class name and property name. otherwise we could also look up the current locale of the class with the dm and add a class indicating the current locale. on the other hand, that is a document wide information, so maybe we can recommend the user to do that, and have a css that says `.locale-en .translated {background-image: 'en.png';}` or something like that.","created_at":"2014-01-16T22:33:42Z","updated_at":"2014-01-16T22:33:42Z","html_url":"https://github.com/doctrine/DoctrinePHPCRBundle/pull/93#discussion_r8950457","pull_request_url":"https://api.github.com/repos/doctrine/DoctrinePHPCRBundle/pulls/93","_links":{"self":{"href":"https://api.github.com/repos/doctrine/DoctrinePHPCRBundle/pulls/comments/8950457"},"html":{"href":"https://github.com/doctrine/DoctrinePHPCRBundle/pull/93#discussion_r8950457"},"pull_request":{"href":"https://api.github.com/repos/doctrine/DoctrinePHPCRBundle/pulls/93"}}}}