Add aggregable property to metadata fields

This commit is contained in:
Nicolas Le Goff
2014-09-08 12:00:05 +02:00
parent 792e29a307
commit 0e807b2b0f
6 changed files with 45 additions and 4 deletions

View File

@@ -326,6 +326,7 @@ class Fields implements ControllerProviderInterface
->set_thumbtitle($data['thumbtitle']) ->set_thumbtitle($data['thumbtitle'])
->set_tag(\databox_field::loadClassFromTagName($data['tag'])) ->set_tag(\databox_field::loadClassFromTagName($data['tag']))
->set_business($data['business']) ->set_business($data['business'])
->set_aggregable($data['aggregable'])
->set_indexable($data['indexable']) ->set_indexable($data['indexable'])
->set_required($data['required']) ->set_required($data['required'])
->set_separator($data['separator']) ->set_separator($data['separator'])
@@ -366,7 +367,7 @@ class Fields implements ControllerProviderInterface
private function getMandatoryFieldProperties() private function getMandatoryFieldProperties()
{ {
return [ return [
'name', 'multi', 'thumbtitle', 'tag', 'business', 'indexable', 'name', 'multi', 'thumbtitle', 'tag', 'business', 'indexable', 'aggregable',
'required', 'separator', 'readonly', 'type', 'tbranch', 'report', 'required', 'separator', 'readonly', 'type', 'tbranch', 'report',
'vocabulary-type', 'vocabulary-restricted', 'dces-element', 'labels' 'vocabulary-type', 'vocabulary-restricted', 'dces-element', 'labels'
]; ];

View File

@@ -986,6 +986,7 @@ class databox extends base
->set_separator(isset($field['separator']) ? (string) $field['separator'] : '') ->set_separator(isset($field['separator']) ? (string) $field['separator'] : '')
->set_required((isset($field['required']) && (string) $field['required'] == 1)) ->set_required((isset($field['required']) && (string) $field['required'] == 1))
->set_business((isset($field['business']) && (string) $field['business'] == 1)) ->set_business((isset($field['business']) && (string) $field['business'] == 1))
->set_aggregable((isset($field['aggregable']) && (string) $field['aggregable'] == 1))
->set_type($type) ->set_type($type)
->set_tbranch(isset($field['tbranch']) ? (string) $field['tbranch'] : '') ->set_tbranch(isset($field['tbranch']) ? (string) $field['tbranch'] : '')
->set_thumbtitle(isset($field['thumbtitle']) ? (string) $field['thumbtitle'] : (isset($field['thumbTitle']) ? $field['thumbTitle'] : '0')) ->set_thumbtitle(isset($field['thumbtitle']) ? (string) $field['thumbtitle'] : (isset($field['thumbTitle']) ? $field['thumbTitle'] : '0'))

View File

@@ -117,6 +117,9 @@ class databox_field implements cache_cacheableInterface
* @var boolean * @var boolean
*/ */
protected $Business; protected $Business;
protected $aggregable;
protected $renamed = false; protected $renamed = false;
/** /**
@@ -180,7 +183,7 @@ class databox_field implements cache_cacheableInterface
$sql = "SELECT `thumbtitle`, `separator`, `dces_element`, `tbranch`, $sql = "SELECT `thumbtitle`, `separator`, `dces_element`, `tbranch`,
`type`, `report`, `multi`, `required`, `readonly`, `indexable`, `type`, `report`, `multi`, `required`, `readonly`, `indexable`,
`name`, `src`, `business`, `VocabularyControlType`, `name`, `src`, `business`, `aggregable`, `VocabularyControlType`,
`RestrictToVocabularyControl`, `sorter`, `RestrictToVocabularyControl`, `sorter`,
`label_en`, `label_fr`, `label_de`, `label_nl` `label_en`, `label_fr`, `label_de`, `label_nl`
FROM metadatas_structure WHERE id=:id"; FROM metadatas_structure WHERE id=:id";
@@ -214,6 +217,7 @@ class databox_field implements cache_cacheableInterface
$this->multi = (Boolean) $row['multi']; $this->multi = (Boolean) $row['multi'];
$this->Business = (Boolean) $row['business']; $this->Business = (Boolean) $row['business'];
$this->report = (Boolean) $row['report']; $this->report = (Boolean) $row['report'];
$this->aggregable = (Boolean) $row['aggregable'];
$this->position = (Int) $row['sorter']; $this->position = (Int) $row['sorter'];
$this->type = $row['type'] ? : self::TYPE_STRING; $this->type = $row['type'] ? : self::TYPE_STRING;
$this->tbranch = $row['tbranch']; $this->tbranch = $row['tbranch'];
@@ -261,6 +265,11 @@ class databox_field implements cache_cacheableInterface
return $this->Business; return $this->Business;
} }
public function isAggregable()
{
return $this->aggregable;
}
/** /**
* *
* @param Application $app * @param Application $app
@@ -370,6 +379,7 @@ class databox_field implements cache_cacheableInterface
`separator` = :separator, `separator` = :separator,
`multi` = :multi, `multi` = :multi,
`business` = :business, `business` = :business,
`aggregable` = :aggregable,
`report` = :report, `report` = :report,
`type` = :type, `type` = :type,
`tbranch` = :tbranch, `tbranch` = :tbranch,
@@ -392,6 +402,7 @@ class databox_field implements cache_cacheableInterface
':separator' => $this->separator, ':separator' => $this->separator,
':multi' => $this->multi ? '1' : '0', ':multi' => $this->multi ? '1' : '0',
':business' => $this->Business ? '1' : '0', ':business' => $this->Business ? '1' : '0',
':aggregable' => $this->aggregable ? '1' : '0',
':report' => $this->report ? '1' : '0', ':report' => $this->report ? '1' : '0',
':type' => $this->type, ':type' => $this->type,
':tbranch' => $this->tbranch, ':tbranch' => $this->tbranch,
@@ -443,6 +454,7 @@ class databox_field implements cache_cacheableInterface
$meta->setAttribute('multi', $this->multi ? '1' : '0'); $meta->setAttribute('multi', $this->multi ? '1' : '0');
$meta->setAttribute('report', $this->report ? '1' : '0'); $meta->setAttribute('report', $this->report ? '1' : '0');
$meta->setAttribute('business', $this->Business ? '1' : '0'); $meta->setAttribute('business', $this->Business ? '1' : '0');
$meta->setAttribute('aggregable', $this->aggregable ? '1' : '0');
$meta->setAttribute('type', $this->type); $meta->setAttribute('type', $this->type);
$meta->setAttribute('tbranch', $this->tbranch); $meta->setAttribute('tbranch', $this->tbranch);
if ($this->multi) { if ($this->multi) {
@@ -601,6 +613,7 @@ class databox_field implements cache_cacheableInterface
{ {
$connbas = $this->get_connection(); $connbas = $this->get_connection();
if (null !== $DCES_element) { if (null !== $DCES_element) {
$sql = 'UPDATE metadatas_structure $sql = 'UPDATE metadatas_structure
SET dces_element = null WHERE dces_element = :dces_element'; SET dces_element = null WHERE dces_element = :dces_element';
@@ -695,6 +708,14 @@ class databox_field implements cache_cacheableInterface
return $this; return $this;
} }
public function set_aggregable($boolean)
{
$this->aggregable = ! ! $boolean;
return $this;
}
/** /**
* *
* @param boolean $required * @param boolean $required
@@ -932,6 +953,7 @@ class databox_field implements cache_cacheableInterface
'name' => $this->name, 'name' => $this->name,
'tag' => $this->tag->getTagname(), 'tag' => $this->tag->getTagname(),
'business' => $this->Business, 'business' => $this->Business,
'aggregable' => $this->aggregable,
'type' => $this->type, 'type' => $this->type,
'sorter' => $this->position, 'sorter' => $this->position,
'thumbtitle' => $this->thumbtitle, 'thumbtitle' => $this->thumbtitle,
@@ -975,11 +997,11 @@ class databox_field implements cache_cacheableInterface
$sql = "INSERT INTO metadatas_structure $sql = "INSERT INTO metadatas_structure
(`id`, `name`, `src`, `readonly`, `indexable`, `type`, `tbranch`, (`id`, `name`, `src`, `readonly`, `indexable`, `type`, `tbranch`,
`thumbtitle`, `multi`, `business`, `thumbtitle`, `multi`, `business`, `aggregable`,
`report`, `sorter`) `report`, `sorter`)
VALUES (null, :name, '', 0, 1, 'string', '', VALUES (null, :name, '', 0, 1, 'string', '',
null, :multi, null, :multi,
0, 1, :sorter)"; 0, 0, 1, :sorter)";
$name = self::generateName($name); $name = self::generateName($name);

View File

@@ -2654,6 +2654,14 @@
<default></default> <default></default>
<comment></comment> <comment></comment>
</field> </field>
<field>
<name>aggregable</name>
<type>int(1) unsigned</type>
<null></null>
<extra></extra>
<default>0</default>
<comment></comment>
</field>
<field> <field>
<name>indexable</name> <name>indexable</name>
<type>int(1) unsigned</type> <type>int(1) unsigned</type>

View File

@@ -176,6 +176,14 @@
</label> </label>
</td> </td>
</tr> </tr>
<tr>
<td colspan="2">
<label for="aggregable" class="checkbox">
<input id="aggregable" type="checkbox" <%= field.aggregable ? "checked='checked'" : "" %> />
{% trans %}Aggregable fields{% endtrans %}
</label>
</td>
</tr>
<tr> <tr>
<td><label for="separator">{% trans %}Separator{% endtrans %}</label></td> <td><label for="separator">{% trans %}Separator{% endtrans %}</label></td>
<td><input id="separator" type="text" value="<%= field.separator %>" /></td> <td><input id="separator" type="text" value="<%= field.separator %>" /></td>

View File

@@ -221,6 +221,7 @@ class FieldsTest extends \PhraseanetAuthenticatedWebTestCase
'thumbtitle' => false, 'thumbtitle' => false,
'tag' => 'XMP:XMP', 'tag' => 'XMP:XMP',
'business' => false, 'business' => false,
'aggregable' => false,
'indexable' => true, 'indexable' => true,
'required' => true, 'required' => true,
'labels' => [ 'labels' => [