/**
  * Maps a ObjectRelation object contained in a recordset to an object representation
  *
  * @param $rs Recordset filled with the object data
  * @return objeto Mapped ObjectRelation object
  */
 function &mapOne($rs)
 {
     if ($rs == null) {
         return null;
     }
     $object = new ObjectRelation();
     $object->setId($rs->fields["ID"]);
     $object->setParentID($rs->fields["parentID"]);
     $object->setChildID($rs->fields["childID"]);
     $object->setPosition($rs->fields["position"]);
     return $object;
 }
Esempio n. 2
0
 /**
  * Collects the Object sent by HTTP. This method also fills the controller messages with the appropiate errors.
  * @param $object Object - object to update, if not supplied a new one is created
  * @return Object - Object collected, it there was problems collecting, it will return null
  */
 function collectObject($object = null)
 {
     // Signal -> if true, there was an error, so do not save
     $save = true;
     // Get languages
     $languageMapper = new LanguageMapper();
     $languageArray = $languageMapper->getAll();
     // Collect data from attributes for each language
     $frontAttributeArray = array();
     $objectAttributeArray = array();
     foreach ($languageArray as $language) {
         $attributeArray = $this->class->getAttributesForLanguage($language);
         foreach ($attributeArray as $attribute) {
             // Get the ObjectAttribute if it was already saved (it could be new...)
             if (is_null($object) == false) {
                 $objectAttribute = $object->getAttributeForLanguage($attribute->getId(), $language->getId());
                 if ($objectAttribute != null) {
                     $attribute = $objectAttribute;
                 }
             }
             // Create his GUI representation
             $frontAttribute = FrontAttributeFactory::newInstance($language, $attribute);
             // Collect it
             $frontAttribute->collectWidget();
             if ($frontAttribute->isValid() == false) {
                 $this->frontAttributeNotValidMessage($frontAttribute);
                 $save = false;
             }
             array_push($frontAttributeArray, $frontAttribute);
             array_push($objectAttributeArray, $frontAttribute->toObjectAttribute());
         }
     }
     // Collect object relations
     $classRelationArray = $this->class->getClassRelations();
     $objectRelationArray = array();
     foreach ($classRelationArray as $classRelation) {
         /* @var $classRelation ClassRelation */
         $name = "classRelation" . $classRelation->getId() . "Select";
         $valueArray = $_POST[$name];
         if (is_null($valueArray) == false && $valueArray != "") {
             foreach ($valueArray as $value) {
                 $objectRelation = new ObjectRelation();
                 $objectRelation->setChildId($value);
                 $objectRelation->setPosition($classRelation->getPosition());
                 array_push($objectRelationArray, $objectRelation);
             }
         } else {
             if ($classRelation->getIsRequired()) {
                 // It was required, notify the user
                 $this->dataNotValidMessage($classRelation->getTitle());
                 $save = false;
             }
         }
     }
     // Collect publishing info
     // Get date format
     $dateFormat = DateFormatFactory::getDateFormat();
     $publishCheckbox = $_REQUEST["publishCheckbox"];
     $publish = 0;
     if ($publishCheckbox == "-1") {
         $publish = true;
     }
     // Only get publishing dates if the user issued publish in true
     $publishFromDateString = null;
     $publishToDateString = null;
     if ($publish == true) {
         // Get ISO dateFormat for the database
         $isoDateFormat = new IsoDateFormat();
         // Get publishFrom/to checking if they are available first
         $publishFrom = $_REQUEST["publishFromText"];
         if ($publishFrom != null && $publishFrom != "") {
             $publishFromDate = $dateFormat->parseDate($publishFrom);
             if ($publishFromDate == null) {
                 $this->dataNotValidMessage($this->text["from"]);
                 $save = false;
             } else {
                 $publishFromDateString = $isoDateFormat->toDatetimeString($publishFromDate);
             }
         }
         $publishTo = $_REQUEST["publishToText"];
         if ($publishTo != null && $publishTo != "") {
             $publishToDate = $dateFormat->parseDate($publishTo);
             if ($publishToDate == null) {
                 $this->dataNotValidMessage($this->text["to"]);
                 $save = false;
             } else {
                 $publishToDateString = $isoDateFormat->toDatetimeString($publishToDate);
             }
         }
     }
     $hits = $_REQUEST["hitsText"];
     // Get tree references
     $folders = $_REQUEST["folders"];
     $objectFolderArray = array();
     $folderMapper = new FolderMapper();
     if ($folders != null && $folders != "") {
         $folderIdArray = split(",", $folders);
         foreach ($folderIdArray as $folderId) {
             $folder = $folderMapper->get($folderId);
             /* @var $folder Folder */
             $objectFolderPosition = $folder->getNextObjectFolderPosition();
             $objectFolder = new ObjectFolder(null, $folderId);
             $objectFolder->setPosition($objectFolderPosition);
             array_push($objectFolderArray, $objectFolder);
         }
     }
     if ($save == false) {
         return null;
     }
     // My new object
     if ($object == null) {
         $object = new Object();
     }
     $object->setId($this->objectId);
     $object->setClassID($this->classId);
     $object->setIsPublished($publish);
     $object->setStartPublishing($publishFromDateString);
     $object->setEndPublishing($publishToDateString);
     $object->setHits($hits);
     // Attributes
     $object->setAttributes($objectAttributeArray);
     // Folders
     $object->setObjectFolders($objectFolderArray);
     // Relationships
     $object->setObjectRelations($objectRelationArray);
     // Save attached data, if any
     /* @var $frontAttribute FrontAttribute */
     foreach ($frontAttributeArray as $frontAttribute) {
         $frontAttribute->saveAttachedData();
     }
     // Return the object
     return $object;
 }