diff --git a/readme.md b/readme.md index d718b9f..1c3c4bd 100644 --- a/readme.md +++ b/readme.md @@ -70,7 +70,7 @@ First we should create the fields classes and the test cases. After we have to s - Implement the `Flexible Content` field with unit tests (done!); - Improve performance. Currently the plugin makes one SQL query for each field. This goal is to improve that using `whereIn()` clauses. - Some fields are still missing (check table below and contribute). + ## Fields @@ -96,7 +96,7 @@ First we should create the fields classes and the test cases. After we have to s | Relationship | ok | [@jgrossi](http://github.com/jgrossi) | `Corcel\Post` or `Collection` of `Post` | | Taxonomy | ok | [@jgrossi](http://github.com/jgrossi) | `Corcel\Term` or `Collection` of `Term` | | User | ok | [@jgrossi](http://github.com/jgrossi) | `Corcel\User` | -| Google Map | missing | | +| Google Map | ok | [@naeemz] (http://github.com/naeemz) | `array` | | Date Picker | ok | [@jgrossi](http://github.com/jgrossi) | `Carbon\Carbon` | | Date Time Picker | ok | [@jgrossi](http://github.com/jgrossi) | `Carbon\Carbon` | | Time Picker | ok | [@jgrossi](http://github.com/jgrossi) | `Carbon\Carbon` | diff --git a/src/Field/BasicField.php b/src/Field/BasicField.php index 5b39971..bae10ae 100644 --- a/src/Field/BasicField.php +++ b/src/Field/BasicField.php @@ -7,6 +7,8 @@ use Corcel\Model\Meta\PostMeta; use Corcel\Model\Term; use Corcel\Model\Meta\TermMeta; +use Corcel\Model\User; +use Corcel\Model\Meta\UserMeta; /** * Class BasicField. @@ -63,6 +65,8 @@ public function __construct(Model $post) $this->postMeta = new PostMeta(); } elseif ($post instanceof Term) { $this->postMeta = new TermMeta(); + } elseif ($post instanceof User) { + $this->postMeta = new UserMeta(); } $this->postMeta->setConnection($post->getConnectionName()); @@ -151,6 +155,8 @@ public function getKeyName() return 'post_id'; } elseif ($this->post instanceof Term) { return 'term_id'; + } elseif ($this->post instanceof User) { + return 'user_id'; } } diff --git a/src/Field/Gallery.php b/src/Field/Gallery.php index b1bb286..a8a9a31 100644 --- a/src/Field/Gallery.php +++ b/src/Field/Gallery.php @@ -35,10 +35,12 @@ public function process($field) $metaDataValues = $this->fetchMultipleMetadataValues($attachments); foreach ($attachments as $attachment) { - $image = new Image($this->post); - $image->fillFields($attachment); - $image->fillMetadataFields($metaDataValues[$attachment->ID]); - $this->images[] = $image; + if (array_key_exists($attachment->ID, $metaDataValues)) { + $image = new Image($this->post); + $image->fillFields($attachment); + $image->fillMetadataFields($metaDataValues[$attachment->ID]); + $this->images[] = $image; + } } } } diff --git a/src/Field/GoogleMap.php b/src/Field/GoogleMap.php new file mode 100644 index 0000000..ae387a9 --- /dev/null +++ b/src/Field/GoogleMap.php @@ -0,0 +1,34 @@ + + */ +class GoogleMap extends BasicField implements FieldInterface +{ + /** + * @var Array + */ + protected $cords; + + /** + * @param string $fieldName + */ + public function process($fieldName) + { + $this->cords = $this->fetchValue($fieldName); + } + + /** + * @return Array + */ + public function get() + { + return $this->cords; + } +} diff --git a/src/FieldFactory.php b/src/FieldFactory.php index 13d881f..0d394ee 100644 --- a/src/FieldFactory.php +++ b/src/FieldFactory.php @@ -56,6 +56,7 @@ public static function make($name, Model $post, $type = null) case 'number': case 'email': case 'url': + case 'link': case 'password': case 'wysiwyg': case 'editor': @@ -107,6 +108,9 @@ public static function make($name, Model $post, $type = null) case 'flexible_content': $field = new FlexibleContent($post); break; + case 'google_map': + $field = new GoogleMap($post); + break; default: return null; }