public function purge() { $deletedChildren = $this->deleteChildren(); $typeIds = array(); foreach ($deletedChildren as $child) { $typeIds[] = $this->escape($child->getId()); } $typeIds[] = $this->escape($this->getId()); $query = "\n SELECT id FROM " . Tag::getTableName() . " tag\n WHERE type_id IN (" . implode($typeIds) . ")\n "; $rows = $this->queryAndFetch($query); $tagsId = array(); foreach ($rows as $values) { $tagsId[] = $this->escape($values['id']); } $query = "\n SELECT id FROM " . Tag::getTableName() . " tag\n WHERE tag.mastertag_id IN (" . implode(',', $tagsId) . ")\n "; $rows = $this->queryAndFetch($query); foreach ($rows as $values) { $tagsId[] = $this->escape($values['id']); } //suppression des tags $query = "\n DELETE tag FROM " . Tag::getTableName() . " tag\n WHERE\n tag.mastertag_id IN (" . implode(',', $tagsId) . ")\n OR tag.id IN (" . implode(',', $tagsId) . ")\n "; $this->query($query); //suppression des associations $query = "\n DELETE association FROM " . Association::getTableName() . " association\n WHERE association.tag_id IN (" . implode(',', $tagsId) . ")\n "; $this->query($query); //supression des types $query = "\n DELETE type FROM " . Type::getTableName() . " type\n WHERE type.id IN (" . implode(',', $typeIds) . ")\n "; $this->query($query); }
public function delete($nodeId) { $tagCategory = new Type($this->getDataSource()); $tagCategory->autocommit(false); $tagCategory->loadById($nodeId); $tagCategory->purge(); $tagCategory->commit(); $tagCategory->buildTree(null, true); return $tagCategory->getValues(); }
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();
<?php use PMD\Capital\Configuration\DataSource; use PMD\Capital\Module\Tag\Model\Tag; use PMD\Capital\Model\ObjectType; use PMD\Capital\Module\Tag\Model\Type; use PMD\Capital\Module\Tag\Model\Association; use PMD\Capital\Module\Tag\Model\AssociationType; $tagDataSource = DataSource::get('new'); $tagTypeTree = new Type($tagDataSource); $tagTypeTree->loadBy('qname', 'company'); $attributes = $tagTypeTree->getInheritableAttributes(); print_r($attributes); /* $parents=$tagTypeTree->getParents(); foreach ($parents as $parent) { print_r($parent->loadAttributes()); } */
"type": "text", "default": null, "enable": true, "scopes":["system"] }, "cofisemId": { "caption" : "Cofisem ID", "mandatory": false, "type": "integer", "default": null, "enable": true, "scopes":["system"] } }, "rules": [] }' . "'\n )\n"; $tagDataSource->query($query); echo "Create ISIN tag type\n"; $entrepriseTagType = new Type($tagDataSource); $entrepriseTagType->loadBy('qname', 'company'); $query = "\n INSERT INTO " . Type::getTableName() . " (\n parent_id,\n qname,\n caption,\n datecreation\n ) VALUES (\n " . $contentTagId . ",\n 'isin',\n 'Code ISIN',\n NOW()\n )\n"; $tagDataSource->query($query); echo "Create Person tag type\n"; $query = "\n INSERT INTO " . Type::getTableName() . " (\n parent_id,\n qname,\n caption,\n datecreation\n ) VALUES (\n " . $contentTagId . ",\n 'person',\n 'Personnalité',\n NOW()\n )\n"; $tagDataSource->query($query); echo "Reconstruction de l'arbre des type des tag\n"; $tree = new Type(); $tree->setSource($tagDataSource); $tree->reset(); $tree->buildTree(); $tagDataSource->commit();
<?php use PMD\Capital\Configuration\DataSource; use PMD\Capital\Module\Tag\Model\Tag; use PMD\Capital\Model\ObjectType; use PMD\Capital\Module\Tag\Model\Type; use PMD\Capital\Module\Tag\Model\Association; use PMD\Capital\Module\Tag\Model\AssociationType; $tagDataSource = DataSource::get('new'); $tagDataSource->query('DROP TABLE ' . Tag::getTableName() . ''); $tagDataSource->query('DROP TABLE ' . ObjectType::getTableName() . ''); $tagDataSource->query('DROP TABLE ' . Type::getTableName() . ''); $tagDataSource->query('DROP TABLE ' . Association::getTableName() . ''); $tagDataSource->query('DROP TABLE ' . AssociationType::getTableName() . ''); echo "Create pmd_tag table\n"; $query = "\n CREATE TABLE `" . Tag::getTableName() . "` (\n `id` INT(32) UNSIGNED NOT NULL AUTO_INCREMENT,\n `parent_id` INT(32),\n `mastertag_id` INT(32),\n `type_id` INT(32) UNSIGNED,\n `caption` VARCHAR(100) NOT NULL,\n `leftbound` INT(32) UNSIGNED,\n `rightbound` INT(32) UNSIGNED,\n `datecreation` DATETIME,\n `datemodification` DATETIME,\n `slug` VARCHAR(100) NOT NULL,\n `data` TEXT,\n PRIMARY KEY (`id`),\n INDEX `pmdtag_parentid` (`parent_id`),\n INDEX `pmdtag_mastertagid` (`mastertag_id`),\n INDEX `pmdtag_bounds` (`leftbound`, `rightbound`),\n INDEX `pmdtag_keyword` (`caption`),\n INDEX `pmdtag_slug` (`slug`)\n )\n COLLATE='utf8_general_ci'\n ENGINE=InnoDB\n;\n"; $tagDataSource->query($query); echo "Create pmd_tagtype table\n"; $query = "\n CREATE TABLE `" . Type::getTableName() . "` (\n `id` INT(32) UNSIGNED NOT NULL AUTO_INCREMENT,\n `parent_id` INT(32),\n `caption` VARCHAR(100) NOT NULL,\n `qname` VARCHAR(100) NOT NULL,\n `leftbound` INT(32) UNSIGNED,\n `rightbound` INT(32) UNSIGNED,\n `datecreation` DATETIME,\n `datemodification` DATETIME,\n `data` TEXT,\n PRIMARY KEY (`id`),\n INDEX `pmdtagtype_parentid` (`parent_id`),\n INDEX `pmdtagtype_qname` (`qname`),\n INDEX `pmdtagtype_bounds` (`leftbound`, `rightbound`),\n INDEX `pmdtagtype_caption` (`caption`)\n )\n COLLATE='utf8_general_ci'\n ENGINE=InnoDB\n;\n"; $tagDataSource->query($query); echo "Create pmd_tagassociation table\n"; $query = "\n CREATE TABLE `" . Association::getTableName() . "` (\n `id` INT(32) UNSIGNED NOT NULL AUTO_INCREMENT,\n `tag_id` INT(32) UNSIGNED NOT NULL,\n `object_id` INT(32) UNSIGNED NOT NULL,\n `objecttype_id` INT(32) UNSIGNED NOT NULL,\n `type_id` INT(32) UNSIGNED NOT NULL,\n `datecreation` DATETIME,\n `datemodification` DATETIME,\n PRIMARY KEY (`id`),\n INDEX `pmdtagassociation_tagid` (`tag_id`),\n INDEX `pmdtagassociation_objectid` (`object_id`),\n INDEX `pmdtagassociation_objecttypeid` (`objecttype_id`)\n )\n COLLATE='utf8_general_ci'\n ENGINE=InnoDB\n;\n"; $tagDataSource->query($query); echo "Create pmd_objecttype table\n"; $query = "\n CREATE TABLE `" . ObjectType::getTableName() . "` (\n `id` INT(32) UNSIGNED NOT NULL AUTO_INCREMENT,\n `parent_id` INT(32),\n `qname` VARCHAR(100) NOT NULL,\n `caption` VARCHAR(100) NOT NULL,\n `leftbound` INT(32) UNSIGNED,\n `rightbound` INT(32) UNSIGNED,\n `datecreation` DATETIME,\n `datemodification` DATETIME,\n `data` TEXT,\n PRIMARY KEY (`id`),\n INDEX `pmdobjecttype_parentid` (`parent_id`),\n INDEX `pmdobjecttype_qname` (`qname`),\n INDEX `pmdobjecttype_caption` (`caption`),\n INDEX `pmdobjecttype_bounds` (`leftbound`, `rightbound`)\n )\n COLLATE='utf8_general_ci'\n ENGINE=InnoDB\n;\n"; $tagDataSource->query($query); echo "Create pmd_tagassociationtype table\n"; $query = "\n CREATE TABLE `" . AssociationType::getTableName() . "` (\n `id` INT(32) UNSIGNED NOT NULL AUTO_INCREMENT,\n `qname` VARCHAR(100) NOT NULL,\n `caption` VARCHAR(100) NOT NULL,\n `datecreation` DATETIME,\n `datemodification` DATETIME,\n PRIMARY KEY (`id`),\n INDEX `pmdassociationtype_qname` (`qname`),\n INDEX `pmdassociationtype_caption` (`caption`)\n )\n COLLATE='utf8_general_ci'\n ENGINE=InnoDB\n;\n"; $tagDataSource->query($query);