Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release last changes on develop branch #76

Merged
merged 15 commits into from
Mar 22, 2019
Merged
2 changes: 0 additions & 2 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
preset: psr2
risky: false
linting: true
finder:
name:
- "*.php"
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ language: php
php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- '7.3'
dist: trusty
sudo: required
addons:
Expand All @@ -20,4 +23,4 @@ before_script:
- composer install
script:
- mkdir -p build/logs
- phpunit
- ./vendor/bin/phpunit
6 changes: 6 additions & 0 deletions src/Field/BasicField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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';
}
}

Expand Down
16 changes: 11 additions & 5 deletions src/Field/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Field/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/FieldFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions tests/ContentFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down