Пример #1
0
 /**
  * Adds a translation in language $newLanguageCode for object
  *
  * @param string $newLanguageCode
  * @param mixed $translationData array( attribute identifier => attribute value )
  * @return void
  */
 public function addTranslation($newLanguageCode, $translationData)
 {
     // Make sure to refresh the objects data.
     $this->refresh();
     $this->object->cleanupInternalDrafts();
     $version = $this->object->createNewVersionIn($newLanguageCode);
     $version->setAttribute('status', eZContentObjectVersion::STATUS_INTERNAL_DRAFT);
     $version->store();
     $newVersion = $this->object->version($version->attribute('version'));
     $newVersionAttributes = $newVersion->contentObjectAttributes($newLanguageCode);
     $versionDataMap = self::createDataMap($newVersionAttributes);
     // Start updating new version
     $version->setAttribute('modified', time());
     $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
     $db = eZDB::instance();
     $db->begin();
     $version->store();
     // @TODO: Add generic datatype support here
     foreach ($translationData as $attr => $value) {
         if ($versionDataMap[$attr]->attribute('data_type_string') == "ezxmltext") {
             $value = $this->processXmlTextData($value, $versionDataMap[$attr]);
         }
         $versionDataMap[$attr]->setAttribute('data_text', $value);
         $versionDataMap[$attr]->store();
     }
     $db->commit();
     //Update the content object name
     $db->begin();
     $this->object->setName($this->class->contentObjectName($this->object, $version->attribute('version'), $newLanguageCode), $version->attribute('version'), $newLanguageCode);
     $db->commit();
     // Finally publish object
     self::publishContentObject($this->object, $version);
 }
 /**
  * Returns current draft for current content object.
  * If there is no current draft, a new one will be created in provided language.
  * @param string|bool $lang Valid locale xxx-XX. If not provided, default edit language will be used
  * @see eZContentObject::createNewVersionIn()
  * @return eZContentObjectVersion
  */
 public function getCurrentDraft($lang = false)
 {
     $currentDraft = null;
     $db = eZDB::instance();
     // First check if we already have a draft
     $aFilter = array('contentobject_id' => $this->contentObject->attribute('id'), 'status' => array(array(eZContentObjectVersion::STATUS_DRAFT, eZContentObjectVersion::STATUS_INTERNAL_DRAFT)));
     $res = eZContentObjectVersion::fetchFiltered($aFilter, null, null);
     if (count($res) > 0 && $res[0] instanceof eZContentObjectVersion) {
         $currentDraft = $res[0];
         // FIXME : Fetch may result several drafts. We should take the last one (highest version)
         $currentDraft->setAttribute('modified', eZDateTime::currentTimeStamp());
         $currentDraft->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
         $currentDraft->store();
     } else {
         $db->begin();
         $currentDraft = $this->contentObject->createNewVersionIn($lang, false, $this->contentObject->attribute('current_version'));
         $currentDraft->store();
         $db->commit();
     }
     return $currentDraft;
 }