/**
  * Reads the properties marked with templateExport from the current object
  *
  * @return void
  */
 private function readPropertiesFromObject()
 {
     $objReflection = new class_reflection($this->objObject);
     $properties = $this->getPropertyNames();
     foreach ($properties as $strOneProperty) {
         $strGetter = $objReflection->getGetter($strOneProperty);
         $strValue = call_user_func(array($this->objObject, $strGetter));
         if ($strValue instanceof class_date) {
             $strValue = date(DateTime::ATOM, $strValue->getTimeInOldStyle());
         }
         $this->arrMapping[$strOneProperty] = $strValue;
     }
 }
 /**
  * Reads the properties marked with templateExport from the current object
  *
  * @return void
  */
 private function readPropertiesFromObject()
 {
     $objReflection = new class_reflection($this->objObject);
     $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_ANNOTATION_TEMPLATEEXPORT);
     foreach (array_keys($arrProperties) as $strOneProperty) {
         $strGetter = $objReflection->getGetter($strOneProperty);
         //get the templatemapper
         $strMapper = $objReflection->getAnnotationValueForProperty($strOneProperty, self::STR_ANNOTATION_TEMPLATEMAPPER);
         if ($strMapper == null) {
             $strMapper = "default";
         }
         $this->addPlaceholder($strOneProperty, call_user_func(array($this->objObject, $strGetter)), $strMapper);
     }
 }
 /**
  * Converts an model into an string representation
  *
  * @param interface_model $objModel
  * @return string
  */
 public static function serialize(interface_model $objModel)
 {
     $objReflection = new class_reflection(get_class($objModel));
     $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN);
     $arrJSON = array();
     foreach ($arrProperties as $strAttributeName => $strAttributeValue) {
         $strGetter = $objReflection->getGetter($strAttributeName);
         if ($strGetter != null) {
             $strValue = $objModel->{$strGetter}();
             if ($strValue instanceof class_date) {
                 $strValue = $strValue->getLongTimestamp();
             }
             $arrJSON[$strAttributeName] = $strValue;
         }
     }
     return json_encode($arrJSON);
 }
 /**
  * Calls the source-objects getter and loads the value.
  * Only used, if the field is not already populated to the
  * global params-array.
  *
  * @throws class_exception
  * @return mixed
  */
 protected function getValueFromObject()
 {
     if ($this->objSourceObject == null) {
         return "";
     }
     //try to get the matching getter
     $objReflection = new class_reflection($this->objSourceObject);
     $strGetter = $objReflection->getGetter($this->strSourceProperty);
     if ($strGetter === null) {
         throw new class_exception("unable to find getter for value-property " . $this->strSourceProperty . "@" . get_class($this->objSourceObject), class_exception::$level_ERROR);
     }
     return call_user_func(array($this->objSourceObject, $strGetter));
 }
Esempio n. 5
0
 /**
  * Returns a short description of the saved content
  * Overwrite if needed
  *
  * @return string
  */
 public function getContentTitle()
 {
     $objAnnotations = new class_reflection($this);
     $arrProperties = $objAnnotations->getPropertiesWithAnnotation(class_element_admin::STR_ANNOTATION_ELEMENTCONTENTTITLE);
     if (count($arrProperties) > 0) {
         $this->loadElementData();
         $arrKeys = array_keys($arrProperties);
         $strGetter = $objAnnotations->getGetter($arrKeys[0]);
         if ($strGetter != null) {
             //explicit casts required? could be relevant, depending on the target column type / database system
             return call_user_func(array($this, $strGetter));
         }
     }
     return "";
 }
 /**
  * Scans the passed object and tries to find all properties marked with the annotation @versionable.
  * @param interface_versionable|class_model $objCurrentObject
  *
  * @return array|null
  */
 private function readVersionableProperties(interface_versionable $objCurrentObject)
 {
     if (!$this->isVersioningAvailable($objCurrentObject)) {
         return null;
     }
     if (validateSystemid($objCurrentObject->getSystemid())) {
         $arrCurrentValues = array();
         $objReflection = new class_reflection($objCurrentObject);
         $arrProperties = $objReflection->getPropertiesWithAnnotation(self::ANNOTATION_PROPERTY_VERSIONABLE);
         foreach ($arrProperties as $strProperty => $strAnnotation) {
             $strValue = "";
             //all prerequisites match, start creating query
             $strGetter = $objReflection->getGetter($strProperty);
             if ($strGetter !== null) {
                 $strValue = call_user_func(array($objCurrentObject, $strGetter));
             }
             if (is_array($strValue) || $strValue instanceof ArrayAccess) {
                 $arrNewValues = array();
                 foreach ($strValue as $objOneValue) {
                     if (is_object($objOneValue) && $objOneValue instanceof class_root) {
                         $arrNewValues[] = $objOneValue->getSystemid();
                     } else {
                         $arrNewValues[] = $objOneValue . "";
                     }
                 }
                 sort($arrNewValues);
                 $strValue = implode(",", $arrNewValues);
             }
             $arrCurrentValues[$strProperty] = $strValue;
         }
         return $arrCurrentValues;
     }
     return null;
 }
 public function setValueToObject()
 {
     $objSourceObject = $this->getObjSourceObject();
     if ($objSourceObject == null) {
         return "";
     }
     $objReflection = new class_reflection($objSourceObject);
     // get database object which we can not change
     $strGetter = $objReflection->getGetter($this->getStrSourceProperty());
     if ($strGetter === null) {
         throw new class_exception("unable to find getter for value-property " . $this->getStrSourceProperty() . "@" . get_class($objSourceObject), class_exception::$level_ERROR);
     }
     $arrObjects = call_user_func(array($objSourceObject, $strGetter));
     $arrNotObjects = array_values(array_filter((array) $arrObjects, function (class_model $objObject) {
         return !$objObject->rightView();
     }));
     // merge objects
     $arrNewObjects = array_merge($this->toObjectArray(), $arrNotObjects);
     // filter double object ids
     $arrObjects = array();
     foreach ($arrNewObjects as $objObject) {
         $arrObjects[$objObject->getStrSystemid()] = $objObject;
     }
     $arrObjects = array_values($arrObjects);
     // set value
     $strSetter = $objReflection->getSetter($this->getStrSourceProperty());
     if ($strSetter === null) {
         throw new class_exception("unable to find setter for value-property " . $this->getStrSourceProperty() . "@" . get_class($objSourceObject), class_exception::$level_ERROR);
     }
     return call_user_func(array($objSourceObject, $strSetter), $arrObjects);
 }
Esempio n. 8
0
 /**
  * @dataProvider additionProvider
  */
 public function testGetGetters($a)
 {
     $objReflection = new class_reflection(new A());
     $this->assertEquals(strtolower("getLongPropertyA1"), strtolower($objReflection->getGetter("propertyA1")));
     $objReflection = new class_reflection(new B());
     $this->assertEquals(strtolower("getLongPropertyA1"), strtolower($objReflection->getGetter("propertyA1")));
     $this->assertEquals(strtolower("getBitPropertyB1"), strtolower($objReflection->getGetter("propertyB1")));
 }
 /**
  * Internal helper to fetch the values of an assignment property.
  * Capable of handling both, objects and systemids.
  *
  * @param string $strPropertyName
  * @param string[]|null $arrClassFilter
  * @return array
  */
 private function getAssignmentValuesFromObject($strPropertyName, $arrClassFilter)
 {
     $objReflection = new class_reflection($this->getObjObject());
     $strGetter = $objReflection->getGetter($strPropertyName);
     $arrValues = array();
     if ($strGetter !== null) {
         $arrValues = call_user_func(array($this->getObjObject(), $strGetter));
         if (!is_array($arrValues) && !$arrValues instanceof ArrayObject) {
             $arrValues = array();
         }
     }
     $arrReturn = array();
     foreach ($arrValues as $objOneValue) {
         if (is_object($objOneValue) && $objOneValue instanceof class_model) {
             if ($arrClassFilter == null || count(array_filter($arrClassFilter, function ($strSingleClass) use($objOneValue) {
                 return $objOneValue instanceof $strSingleClass;
             })) > 0) {
                 $arrReturn[] = $objOneValue->getSystemid();
             }
         } else {
             if (is_string($objOneValue) && validateSystemid($objOneValue)) {
                 $arrReturn[] = $objOneValue;
             }
         }
     }
     return $arrReturn;
 }
 /**
  * Adds a new field to the current form.
  * Therefore, the current source-object is inspected regarding the passed propertyname.
  * So it is essential to provide the matching getters and setters in order to have all
  * set up dynamically.
  *
  * @param string $strPropertyName
  * @return class_formentry_base|interface_formentry
  * @throws class_exception
  */
 public function addDynamicField($strPropertyName)
 {
     //try to get the matching getter
     $objReflection = new class_reflection($this->objSourceobject);
     $strGetter = $objReflection->getGetter($strPropertyName);
     if ($strGetter === null) {
         throw new class_exception("unable to find getter for property " . $strPropertyName . "@" . get_class($this->objSourceobject), class_exception::$level_ERROR);
     }
     //load detailed properties
     $strType = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_TYPE_ANNOTATION);
     $strValidator = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_VALIDATOR_ANNOTATION);
     $strMandatory = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_MANDATORY_ANNOTATION);
     $strLabel = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_LABEL_ANNOTATION);
     $strHidden = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_HIDDEN_ANNOTATION);
     $strReadonly = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_READONLY_ANNOTATION);
     if ($strType === null) {
         $strType = "text";
     }
     $strStart = uniSubstr($strPropertyName, 0, 3);
     if (in_array($strStart, array("int", "bit", "str", "arr", "obj"))) {
         $strPropertyName = uniStrtolower(uniSubstr($strPropertyName, 3));
     }
     $strStart = uniSubstr($strPropertyName, 0, 4);
     if (in_array($strStart, array("long"))) {
         $strPropertyName = uniStrtolower(uniSubstr($strPropertyName, 4));
     }
     $strStart = uniSubstr($strPropertyName, 0, 5);
     if (in_array($strStart, array("float"))) {
         $strPropertyName = uniStrtolower(uniSubstr($strPropertyName, 5));
     }
     $objField = $this->getFormEntryInstance($strType, $strPropertyName);
     if ($strLabel !== null) {
         $objField->updateLabel($strLabel);
     }
     $bitMandatory = false;
     if ($strMandatory !== null && $strMandatory !== "false") {
         $bitMandatory = true;
     }
     $objField->setBitMandatory($bitMandatory);
     $bitReadonly = false;
     if ($strReadonly !== null && $strReadonly !== "false") {
         $bitReadonly = true;
     }
     $objField->setBitReadonly($bitReadonly);
     if ($strValidator !== null) {
         $objField->setObjValidator($this->getValidatorInstance($strValidator));
     }
     $this->addField($objField, $strPropertyName);
     if ($strHidden !== null) {
         $this->addFieldToHiddenGroup($objField);
     }
     return $objField;
 }
Esempio n. 11
0
 /**
  * A default implementation for copy-operations.
  * Overwrite this method if you want to execute additional statements.
  * Please be aware that you are working on the new object afterwards!
  *
  * @param string $strNewPrevid
  * @param bool $bitChangeTitle
  * @param bool $bitCopyChilds
  *
  * @throws class_exception
  * @return bool
  */
 public function copyObject($strNewPrevid = "", $bitChangeTitle = true, $bitCopyChilds = true)
 {
     $this->objDB->transactionBegin();
     $strOldSysid = $this->getSystemid();
     if ($strNewPrevid == "") {
         $strNewPrevid = $this->strPrevId;
     }
     //any date-objects to copy?
     if ($this->objStartDate != null || $this->objEndDate != null || $this->objSpecialDate != null) {
         $this->bitDatesChanges = true;
     }
     //check if there's a title field, in most cases that could be used to change the title
     if ($bitChangeTitle) {
         $objReflection = new class_reflection($this);
         $strGetter = $objReflection->getGetter("strTitle");
         $strSetter = $objReflection->getSetter("strTitle");
         if ($strGetter != null && $strSetter != null) {
             $strTitle = call_user_func(array($this, $strGetter));
             if ($strTitle != "") {
                 call_user_func(array($this, $strSetter), $strTitle . "_copy");
             }
         }
     }
     //prepare the current object
     $this->unsetSystemid();
     $this->arrInitRow = null;
     $bitReturn = $this->updateObjectToDb($strNewPrevid);
     //call event listeners
     $bitReturn = $bitReturn && class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_system_eventidentifier::EVENT_SYSTEM_RECORDCOPIED, array($strOldSysid, $this->getSystemid(), $this));
     if ($bitCopyChilds) {
         //process subrecords
         //validate, if there are subrecords, so child nodes to be copied to the current record
         $arrChilds = $this->objDB->getPArray("SELECT system_id FROM " . _dbprefix_ . "system where system_prev_id = ? ORDER BY system_sort ASC", array($strOldSysid));
         foreach ($arrChilds as $arrOneChild) {
             if (validateSystemid($arrOneChild["system_id"])) {
                 $objInstance = class_objectfactory::getInstance()->getObject($arrOneChild["system_id"]);
                 if ($objInstance !== null) {
                     $objInstance->copyObject($this->getSystemid(), false);
                 }
             }
         }
     }
     if ($bitReturn) {
         $this->objDB->transactionCommit();
     } else {
         $this->objDB->transactionRollback();
     }
     $this->objDB->flushQueryCache();
     $bitReturn = $bitReturn && class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_system_eventidentifier::EVENT_SYSTEM_RECORDCOPYFINISHED, array($strOldSysid, $this->getSystemid(), $this));
     return $bitReturn;
 }
 /**
  * Triggers the indexing of a single object.
  *
  * @param class_model $objInstance
  *
  * @return void
  */
 public function indexObject(class_model $objInstance = null)
 {
     if (!self::isIndexAvailable()) {
         return;
     }
     if ($objInstance != null && $objInstance instanceof class_module_pages_pageelement) {
         $objInstance = $objInstance->getConcreteAdminInstance();
         if ($objInstance != null) {
             $objInstance->loadElementData();
         }
     }
     if ($objInstance == null) {
         return;
     }
     $objSearchDocument = new class_module_search_document();
     $objSearchDocument->setDocumentId(generateSystemid());
     $objSearchDocument->setStrSystemId($objInstance->getSystemid());
     if ($objInstance instanceof interface_search_portalobject) {
         $objSearchDocument->setBitPortalObject(true);
         $objSearchDocument->setStrContentLanguage($objInstance->getContentLang());
     }
     $objReflection = new class_reflection($objInstance);
     $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_ANNOTATION_ADDSEARCHINDEX);
     foreach ($arrProperties as $strPropertyName => $strAnnotationValue) {
         $getter = $objReflection->getGetter($strPropertyName);
         $strContent = $objInstance->{$getter}();
         $objSearchDocument->addContent($strPropertyName, $strContent);
     }
     //trigger event-listeners
     class_core_eventdispatcher::getInstance()->notifyGenericListeners(class_search_eventidentifier::EVENT_SEARCH_OBJECTINDEXED, array($objInstance, $objSearchDocument));
     $this->updateSearchDocumentToDb($objSearchDocument);
 }