Skip to content

Commit a7165c6

Browse files
committed
Add category support
1 parent cf9414a commit a7165c6

6 files changed

Lines changed: 87 additions & 4 deletions

File tree

Config/config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,7 @@
106106
],
107107
],
108108
],
109+
'categories' => [
110+
'plugin:sqlConditions' => 'mautic.sqlConditions',
111+
],
109112
];

Entity/SqlConditions.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class SqlConditions extends FormEntity
2929
*/
3030
protected $id;
3131

32+
/**
33+
* @var \Mautic\CategoryBundle\Entity\Category
34+
**/
35+
private $category;
36+
37+
3238
/**
3339
* @var \DateTime
3440
*/
@@ -60,6 +66,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)
6066
->setCustomRepositoryClass(SqlConditionsRepository::class);
6167
$builder->addIdColumns('name', '');
6268
$builder->addNamedField('sqlQuery', Type::TEXT, 'sql_query');
69+
$builder->addCategory();
6370
}
6471

6572

@@ -76,6 +83,7 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata)
7683
'id',
7784
'name',
7885
'sqlQuery',
86+
'category',
7987
'dateAdded',
8088
]
8189
)
@@ -173,4 +181,24 @@ public function getSqlQuery()
173181
return $this->sqlQuery;
174182
}
175183

184+
185+
/**
186+
* @return \Mautic\CategoryBundle\Entity\Category
187+
*/
188+
public function getCategory()
189+
{
190+
return $this->category;
191+
}
192+
193+
/**
194+
* @param \Mautic\CategoryBundle\Entity\Category $category
195+
*
196+
* @return $this
197+
*/
198+
public function setCategory($category)
199+
{
200+
$this->category = $category;
201+
202+
return $this;
203+
}
176204
}

Entity/SqlConditionsRepository.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,29 @@ public function findOneByAlias($alias)
2929
return parent::findOneBy(['alias'=>$alias], null);
3030
}
3131

32+
/**
33+
* Get a list of entities.
34+
*
35+
* @param array $args
36+
*
37+
* @return Paginator
38+
*/
39+
public function getEntities(array $args = [])
40+
{
41+
$alias = $this->getTableAlias();
42+
43+
$q = $this->_em
44+
->createQueryBuilder()
45+
->select($alias)
46+
->from('MauticSqlConditionsBundle:SqlConditions', $alias, $alias.'.id');
47+
48+
if (empty($args['iterator_mode'])) {
49+
$q->leftJoin($alias.'.category', 'c');
50+
}
51+
52+
$args['qb'] = $q;
53+
54+
return parent::getEntities($args);
55+
}
56+
3257
}

Form/Type/SqlConditionsType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5757
]
5858
);
5959

60+
$builder->add(
61+
'category',
62+
'category',
63+
[
64+
'bundle' => 'plugin:sqlConditions',
65+
]
66+
);
67+
6068
$builder->add('isPublished', 'yesno_button_group');
6169

6270

Views/SqlConditions/form.html.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020

2121

2222
<div class="row">
23-
<div class="col-md-6">
23+
<div class="col-md-5">
2424
<?php echo $view['form']->row($form['name']); ?>
2525
</div>
26-
<div class="col-md-6">
26+
<div class="col-md-5">
27+
<?php echo $view['form']->row($form['category']); ?>
28+
</div>
29+
<div class="col-md-2">
2730
<?php echo $view['form']->row($form['isPublished']); ?>
2831
</div>
2932
</div>

Views/SqlConditions/list.html.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
echo $view->render(
3636
'MauticCoreBundle:Helper:tableheader.html.php',
3737
[
38-
'sessionVar' => 'badge',
38+
'sessionVar' => 'sqlConditions',
3939
'orderBy' => 'e.name',
4040
'text' => 'mautic.core.name',
4141
'class' => 'col-msg-name',
@@ -46,7 +46,17 @@
4646
echo $view->render(
4747
'MauticCoreBundle:Helper:tableheader.html.php',
4848
[
49-
'sessionVar' => 'badge',
49+
'sessionVar' => 'sqlConditions',
50+
'orderBy' => 'c.title',
51+
'text' => 'mautic.core.category',
52+
'class' => 'visible-md visible-lg col-focus-category',
53+
]
54+
);
55+
56+
echo $view->render(
57+
'MauticCoreBundle:Helper:tableheader.html.php',
58+
[
59+
'sessionVar' => 'sqlConditions',
5060
'orderBy' => 'e.id',
5161
'text' => 'mautic.core.id',
5262
'class' => 'col-msg-id visible-md visible-lg',
@@ -92,6 +102,12 @@
92102

93103
</a>
94104
</td>
105+
<td class="visible-md visible-lg">
106+
<?php $category = $item->getCategory(); ?>
107+
<?php $catName = ($category) ? $category->getTitle() : $view['translator']->trans('mautic.core.form.uncategorized'); ?>
108+
<?php $color = ($category) ? '#'.$category->getColor() : 'inherit'; ?>
109+
<span style="white-space: nowrap;"><span class="label label-default pa-4" style="border: 1px solid #d5d5d5; background: <?php echo $color; ?>;"> </span> <span><?php echo $catName; ?></span></span>
110+
</td>
95111
<td class="visible-md visible-lg"><?php echo $item->getId(); ?></td>
96112
</tr>
97113
<?php endforeach; ?>

0 commit comments

Comments
 (0)