Add count function for images herited
This commit is contained in:
@@ -98,12 +98,15 @@ class Articles
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$specie = $variety->specie;
|
||||
$description = empty($specie->description) ? '' : $specie->description . '<br><br>';
|
||||
$description .= empty($variety->description) ? '' : $variety->description . '<br><br>';
|
||||
$description = $specie->description . $variety->description;
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
$description = empty($specie->description) ? '' : $specie->description . '<br><br>';
|
||||
$description = $specie->description;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product;
|
||||
$description = $merchandise->description;
|
||||
break;
|
||||
default:
|
||||
$description = '';
|
||||
@@ -210,7 +213,6 @@ class Articles
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$data['article'] = self::getArticleEdit($id);
|
||||
@@ -385,6 +387,46 @@ class Articles
|
||||
return Article::find($id);
|
||||
}
|
||||
|
||||
public static function getFullImagesByArticleId($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
return $article ? self::getFullImagesByArticle($article) : false;
|
||||
}
|
||||
|
||||
public static function countFullImagesByArticleId($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
return $article ? self::countFullImagesByArticle($article) : 0;
|
||||
}
|
||||
|
||||
public static function countFullImagesByArticle($article)
|
||||
{
|
||||
return count(self::getFullImagesByArticle($article));
|
||||
}
|
||||
|
||||
public static function getFullImagesByArticle($article)
|
||||
{
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$specie = $variety->specie;
|
||||
$images = count($variety->images) ? $variety->images : [];
|
||||
$images = count($specie->images) ? $images->push($specie->images) : $images;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
$images = count($specie->images) ? $specie->images : [];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product;
|
||||
$images = count($merchandise->images) ? $merchandise->images : [];
|
||||
break;
|
||||
default:
|
||||
$images = [];
|
||||
}
|
||||
$images = count($article->images) ? $images->push($article->images) : $images;
|
||||
return $images;
|
||||
}
|
||||
|
||||
public static function getFullImageById($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Shop\TagGroup;
|
||||
use App\Models\Shop\Tag;
|
||||
|
||||
@@ -69,6 +70,7 @@ class TagGroups
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
return TagGroup::create($data);
|
||||
}
|
||||
|
||||
@@ -76,6 +78,7 @@ class TagGroups
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$model = self::get($id);
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
$model->update($data);
|
||||
return $model;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Models\Shop\Tag;
|
||||
|
||||
class Tags
|
||||
@@ -27,9 +25,9 @@ class Tags
|
||||
|
||||
public static function getOptionsFullName()
|
||||
{
|
||||
$tags = Tag::with('group')->get()->toArray();
|
||||
$tags = Tag::with('tag_group')->get()->toArray();
|
||||
foreach ($tags as $tag) {
|
||||
$data[$tag['id']] = $tag['group']['name'] . '-' . $tag['name'];
|
||||
$data[$tag['id']] = $tag['tag_group']['name'] . '-' . $tag['name'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@@ -41,8 +39,13 @@ class Tags
|
||||
|
||||
public static function getFullname($id)
|
||||
{
|
||||
$tag = Tag::with('group')->find($id);
|
||||
return $tag->group->name . '-' . $tag->name;
|
||||
$tag = Tag::with('tag_group')->find($id);
|
||||
return $tag ? self::getFullnameByTag($tag) : false;
|
||||
}
|
||||
|
||||
public static function getFullnameByTag($tag)
|
||||
{
|
||||
return $tag->tag_group->name . '-' . $tag->name;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
|
||||
Reference in New Issue
Block a user