/**
  *
  * @param string $strEventName
  * @param array $arrArguments
  *
  * @return bool
  */
 public function handleEvent($strEventName, array $arrArguments)
 {
     //unwrap arguments
     list($strSystemid, $strSourceClass) = $arrArguments;
     if ($strSourceClass == "class_module_system_aspect") {
         //if we have just one aspect remaining, set this one as default
         if (class_module_system_aspect::getObjectCount() == 1) {
             /** @var class_module_system_aspect[] $arrObjAspects */
             $arrObjAspects = class_module_system_aspect::getObjectList();
             $objOneAspect = $arrObjAspects[0];
             $objOneAspect->setBitDefault(1);
             return $objOneAspect->updateObjectToDb();
         }
     }
     return true;
 }
 public function testLogicalDelete()
 {
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::INCLUDED());
     $intCountTotal = class_module_system_aspect::getObjectCount();
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUDED());
     $intCountActive = class_module_system_aspect::getObjectCount();
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUSIVE());
     $intCountDeleted = class_module_system_aspect::getObjectCount();
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUDED());
     echo "Creating aspect\n";
     $objAspect1 = new class_module_system_aspect();
     $objAspect1->setStrName("Dummy");
     $objAspect1->updateObjectToDb();
     $objAspect = new class_module_system_aspect();
     $objAspect->setStrName("logical delete");
     $objAspect->updateObjectToDb();
     $strAspectId = $objAspect->getSystemid();
     $this->assertEquals($intCountActive + 2, class_module_system_aspect::getObjectCount());
     $arrAspects = class_module_system_aspect::getObjectList();
     $arrAspects = array_filter($arrAspects, function (class_module_system_aspect $objAspect) use($strAspectId) {
         return $objAspect->getSystemid() == $strAspectId;
     });
     $this->assertEquals(1, count($arrAspects));
     echo "Deleting logically\n";
     $this->assertEquals($objAspect->getIntRecordDeleted(), 0);
     $objAspect->deleteObject();
     $this->assertEquals($objAspect->getIntRecordDeleted(), 1);
     $this->assertEquals($objAspect->getIntSort(), -1);
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUDED());
     echo "Loading non-deleted only\n";
     $this->assertEquals($intCountActive + 1, class_module_system_aspect::getObjectCount());
     $arrAspects = class_module_system_aspect::getObjectList();
     $arrAspects = array_filter($arrAspects, function (class_module_system_aspect $objAspect) use($strAspectId) {
         return $objAspect->getSystemid() == $strAspectId;
     });
     $this->assertEquals(0, count($arrAspects));
     echo "Loading deleted only\n";
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUSIVE());
     $arrAspects = class_module_system_aspect::getObjectList();
     $arrAspects = array_filter($arrAspects, function (class_module_system_aspect $objAspect) use($strAspectId) {
         return $objAspect->getSystemid() == $strAspectId;
     });
     $this->assertEquals($intCountDeleted + 1, class_module_system_aspect::getObjectCount());
     $this->assertEquals(1, count($arrAspects));
     echo "Loading mixed deleted and non-deleted\n";
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::INCLUDED());
     $arrAspects = class_module_system_aspect::getObjectList();
     $arrAspects = array_filter($arrAspects, function (class_module_system_aspect $objAspect) use($strAspectId) {
         return $objAspect->getSystemid() == $strAspectId;
     });
     $this->assertEquals($intCountTotal + 2, class_module_system_aspect::getObjectCount());
     $this->assertEquals(1, count($arrAspects));
     echo "Deleting from database\n";
     $objAspect->deleteObjectFromDatabase();
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUDED());
     echo "Loading non-deleted only\n";
     $this->assertEquals($intCountActive + 1, class_module_system_aspect::getObjectCount());
     $arrAspects = class_module_system_aspect::getObjectList();
     $arrAspects = array_filter($arrAspects, function (class_module_system_aspect $objAspect) use($strAspectId) {
         return $objAspect->getSystemid() == $strAspectId;
     });
     $this->assertEquals(0, count($arrAspects));
     echo "Loading deleted only\n";
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUSIVE());
     $arrAspects = class_module_system_aspect::getObjectList();
     $arrAspects = array_filter($arrAspects, function (class_module_system_aspect $objAspect) use($strAspectId) {
         return $objAspect->getSystemid() == $strAspectId;
     });
     $this->assertEquals($intCountDeleted, class_module_system_aspect::getObjectCount());
     $this->assertEquals(0, count($arrAspects));
     echo "Deleting dummy node directly\n";
     $objAspect1->deleteObjectFromDatabase();
     echo "Loading non-deleted only\n";
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUDED());
     $this->assertEquals($intCountActive, class_module_system_aspect::getObjectCount());
     echo "Loading deleted only\n";
     class_orm_base::setObjHandleLogicalDeletedGlobal(class_orm_deletedhandling_enum::EXCLUSIVE());
     $this->assertEquals($intCountDeleted, class_module_system_aspect::getObjectCount());
 }
 /**
  * saves the current object with all its params back to the database
  *
  * @return bool
  */
 protected function updateStateToDb()
 {
     //if no other aspect exists, we have a new default aspect
     if (class_module_system_aspect::getObjectCount() == 0) {
         $this->setBitDefault(1);
     }
     if ($this->getBitDefault() == 1) {
         self::resetDefaultAspect();
     }
     return parent::updateStateToDb();
 }
 /**
  * Renders the list of aspects available
  *
  * @return string
  * @autoTestable
  * @permissions right5
  */
 protected function actionAspects()
 {
     $objIterator = new class_array_section_iterator(class_module_system_aspect::getObjectCount());
     $objIterator->setPageNumber($this->getParam("pv"));
     $objIterator->setArraySection(class_module_system_aspect::getObjectList("", $objIterator->calculateStartPos(), $objIterator->calculateEndPos()));
     return $this->renderList($objIterator, false, "aspectList");
 }