/**
  * Creates a new tag (if not already existing) and assigns the tag to the passed system-record
  *
  * @return string
  * @permissions view
  */
 protected function actionSaveTag()
 {
     $strReturn = "";
     $strSystemid = $this->getParam("systemid");
     $strAttribute = $this->getParam("attribute");
     $arrTags = explode(",", $this->getParam("tagname"));
     $bitError = false;
     foreach ($arrTags as $strOneTag) {
         if (trim($strOneTag) == "") {
             continue;
         }
         //load the tag itself
         $objTag = class_module_tags_tag::getTagByName($strOneTag);
         if ($objTag == null) {
             $objTag = new class_module_tags_tag();
             $objTag->setStrName($strOneTag);
             $objTag->updateObjectToDb();
         }
         //add the connection itself
         if (!$objTag->assignToSystemrecord($strSystemid, $strAttribute)) {
             $bitError = true;
         }
         class_carrier::getInstance()->getObjDB()->flushQueryCache();
     }
     if (!$bitError) {
         $strReturn .= "<success>assignment succeeded</success>";
     } else {
         $strReturn .= "<error>assignment failed</error>";
     }
     return $strReturn;
 }
Ejemplo n.º 2
0
 public function testTagAssignment()
 {
     if (class_module_system_module::getModuleByName("pages") === null) {
         return true;
     }
     $strName = generateSystemid();
     $arrPages = class_module_pages_page::getAllPages();
     if (count($arrPages) == 0) {
         return;
     }
     $objTag = new class_module_tags_tag();
     $objTag->setStrName($strName);
     $objTag->updateObjectToDb();
     foreach ($arrPages as $objOnePage) {
         $objTag->assignToSystemrecord($objOnePage->getSystemid());
         break;
     }
     $arrFolder = class_module_pages_folder::getFolderList();
     foreach ($arrFolder as $objOneFolder) {
         $objTag->assignToSystemrecord($objOneFolder->getSystemid());
         break;
     }
     $this->flushDBCache();
     $objTag = class_module_tags_tag::getTagByName($strName);
     $this->assertEquals($objTag->getIntAssignments(), 2);
     $arrPlainAssignments = $objTag->getListOfAssignments();
     $this->assertEquals(count($arrPlainAssignments), 2);
     $arrAssignment = $objTag->getArrAssignedRecords();
     $this->assertEquals(count($arrAssignment), 2);
     $this->assertTrue($arrAssignment[0] instanceof class_module_pages_page || $arrAssignment[0] instanceof class_module_pages_folder);
     $this->assertTrue($arrAssignment[1] instanceof class_module_pages_page || $arrAssignment[1] instanceof class_module_pages_folder);
     $strOldSysid = $objTag->getSystemid();
     $objTag->copyObject();
     $this->assertNotEquals($strOldSysid, $objTag->getSystemid());
     $this->assertEquals($objTag->getStrName(), $strName . "_1");
     $this->assertEquals($objTag->getIntAssignments(), 2);
     $arrAssignment = $objTag->getArrAssignedRecords();
     $this->assertEquals(count($arrAssignment), 2);
     $this->assertTrue($arrAssignment[0] instanceof class_module_pages_page || $arrAssignment[0] instanceof class_module_pages_folder);
     $this->assertTrue($arrAssignment[1] instanceof class_module_pages_page || $arrAssignment[1] instanceof class_module_pages_folder);
     $objTag->deleteObjectFromDatabase();
 }
 public function testIndexEvent()
 {
     if (class_module_system_module::getModuleByName("tags") == null || class_module_system_module::getModuleByName("system") == null) {
         return;
     }
     $strSearchKey1 = generateSystemid();
     $objAspect = new class_module_system_aspect();
     $objAspect->setStrName($strSearchKey1);
     $objAspect->updateObjectToDb();
     $objSearchCommons = new class_module_search_commons();
     $objSearchParams = new class_module_search_search();
     $objSearchParams->setStrQuery($strSearchKey1);
     $arrResult = $objSearchCommons->doIndexedSearch($objSearchParams, null);
     $this->assertEquals(count($arrResult), 1);
     $this->assertEquals($arrResult[0]->getObjObject()->getStrSystemid(), $objAspect->getStrSystemid());
     $strSearchKey2 = generateSystemid();
     $objTag = new class_module_tags_tag();
     $objTag->setStrName($strSearchKey2);
     $objTag->updateObjectToDb();
     $objSearchParams = new class_module_search_search();
     $objSearchParams->setStrQuery($strSearchKey2);
     $arrResult = $objSearchCommons->doIndexedSearch($objSearchParams, null);
     $this->assertEquals(count($arrResult), 1);
     $this->assertEquals($arrResult[0]->getObjObject()->getStrSystemid(), $objTag->getStrSystemid());
     $objTag->assignToSystemrecord($objAspect->getStrSystemid());
     $arrResult = $objSearchCommons->doIndexedSearch($objSearchParams, null);
     $this->assertEquals(count($arrResult), 2);
     $objSearchParams->setStrInternalFilterModules(_system_modul_id_);
     $arrResult = $objSearchCommons->doIndexedSearch($objSearchParams, null);
     $this->assertEquals(count($arrResult), 1);
     $this->assertEquals($arrResult[0]->getObjObject()->getStrSystemid(), $objAspect->getStrSystemid());
     $objTag->removeFromSystemrecord($objAspect->getStrSystemid());
     //the aspect itself should not be found any more
     $objSearchParams = new class_module_search_search();
     $objSearchParams->setStrQuery($strSearchKey2);
     $arrResult = $objSearchCommons->doIndexedSearch($objSearchParams, null);
     $this->assertEquals(count($arrResult), 1);
     $this->assertEquals($arrResult[0]->getObjObject()->getStrSystemid(), $objTag->getStrSystemid());
     $objAspect->deleteObjectFromDatabase();
     $objTag->deleteObjectFromDatabase();
 }