Beispiel #1
0
echo "Create Content tag type\n";
$query = "\n  INSERT INTO " . Type::getTableName() . " (\n    parent_id,\n    qname,\n    caption,\n    datecreation\n  ) VALUES (\n    " . $rootTypeNode->getId() . ",\n    'content',\n    'Contenu',\n    NOW()\n  )\n";
$tagDataSource->query($query);
$tagTypeContent = new Type($tagDataSource);
$tagTypeContent->loadBy('qname', 'content');
$tagTypeContent->setValue('data', '{
    "attributes": {
        "image": {
            "caption": "Image",
            "mandatory": false,
            "type": "image",
            "default": null,
            "enable": true
        }
    },
    "rules": []
}');
$tagTypeContent->update();
$tree = new Type();
$tree->setSource($tagDataSource);
$tree->buildTree();
echo "Create root tag \n";
$contentTagType = new Type($tagDataSource);
$contentTagType->loadBy('qname', 'default');
$tag = new Tag();
$tag->setSource($tagDataSource);
$tag->setValue('type_id', $contentTagType->getId());
$tag->setCaption('Tags');
$tag->insert();
$tagDataSource->commit();
$tag->buildTree();
Beispiel #2
0
$model = DataSource::get('tag');
$newModel = DataSource::get('new');
$treeTag = new Tag($newModel);
$rootTag = $treeTag->getRoot();
$query = "\n  SELECT\n    tag.id,\n    tag.parent_id,\n    tag.main_tag_id,\n    tag.keyword,\n    slug.slug\n\n\n  FROM " . EzTag::getTableName() . " tag\n  JOIN pmd_tagslug slug\n    ON slug.id_tag=tag.id\n  ";
$rows = $model->queryAndFetch($query);
$oldTags = array();
foreach ($rows as $row) {
    $oldTags[$row['id']] = $row;
}
$newTagMapping = array();
$newModel->autocommit(false);
foreach ($oldTags as $row) {
    $tag = new Tag();
    $tag->setSource($newModel);
    $tag->setCaption($row['keyword']);
    $tag->setSlug($row['slug']);
    $tag->insert();
    $newTagMapping[$row['id']] = $tag->getId();
    echo $tag->getId() . "\t" . $row['keyword'] . "\n";
}
foreach ($newTagMapping as $oldId => $newId) {
    $tag = new Tag();
    $tag->setSource($newModel);
    $tag->loadById($newId);
    if ($oldTags[$oldId]['main_tag_id']) {
        $oldParentId = $oldTags[$oldId]['main_tag_id'];
    } else {
        $oldParentId = $oldTags[$oldId]['parent_id'];
    }
    $parentTagId = false;