diff --git a/.styleci.yml b/.styleci.yml index 1ef97e9..9bc74a9 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,6 +1,4 @@ preset: psr2 -risky: false -linting: true finder: name: - "*.php" \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 6d35bdb..ffc5199 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: php php: - '5.6' - '7.0' + - '7.1' + - '7.2' + - '7.3' dist: trusty sudo: required addons: @@ -20,4 +23,4 @@ before_script: - composer install script: - mkdir -p build/logs - - phpunit \ No newline at end of file + - ./vendor/bin/phpunit \ No newline at end of file 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..95bff71 100644 --- a/src/Field/Gallery.php +++ b/src/Field/Gallery.php @@ -30,15 +30,21 @@ public function process($field) { if ($ids = $this->fetchValue($field)) { $connection = $this->post->getConnectionName(); - $attachments = Post::on($connection)->whereIn('ID', $ids)->get(); + + $ids_ordered = implode(',', $ids); + + $attachments = Post::on($connection)->whereIn('ID', $ids) + ->orderByRaw("FIELD(ID, $ids_ordered)")->get(); $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/Repeater.php b/src/Field/Repeater.php index 356779e..0ad0ac0 100644 --- a/src/Field/Repeater.php +++ b/src/Field/Repeater.php @@ -76,7 +76,7 @@ protected function fetchPostsMeta($fieldName, $post) { $count = (int) $this->fetchValue($fieldName); - if ($this->postMeta instanceof \Corcel\TermMeta) { + if ($this->postMeta instanceof \Corcel\Model\Meta\TermMeta) { $builder = $this->postMeta->where('term_id', $post->term_id); } else { $builder = $this->postMeta->where('post_id', $post->ID); diff --git a/src/FieldFactory.php b/src/FieldFactory.php index 13d881f..2709458 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': diff --git a/tests/ContentFieldsTest.php b/tests/ContentFieldsTest.php index 21995cb..c45ced5 100644 --- a/tests/ContentFieldsTest.php +++ b/tests/ContentFieldsTest.php @@ -97,8 +97,8 @@ public function testGalleryFieldValue() $this->assertTrue(strlen($image->url) > 0); } - // Testing the image in the 6th position - $image = $gallery->get()->get(6); + // Testing the image in the 0th position + $image = $gallery->get()->get(0); $this->assertEquals(1920, $image->width); $this->assertEquals(1080, $image->height); }