File modules/cms/action/pageelement/PageelementAllAction.class.php
Last commit: Wed Apr 17 00:34:07 2024 +0200 Jan Dankert New: Inputfields for coordinates; coordinates are stored in the now 64bit-number-field of the value.
1 <?php 2 namespace cms\action\pageelement; 3 4 use cms\action\Method; 5 use cms\action\PageelementAction; 6 use cms\base\Language as L; 7 use cms\generator\PageContext; 8 use cms\generator\PageGenerator; 9 use cms\generator\Producer; 10 use cms\generator\Publisher; 11 use cms\generator\PublishOrder; 12 use cms\model\BaseObject; 13 use cms\model\Content; 14 use cms\model\Element; 15 use cms\model\Folder; 16 use cms\model\Language; 17 use cms\model\PageContent; 18 use cms\model\Permission; 19 use cms\model\Project; 20 use cms\model\Value; 21 use language\Messages; 22 use logger\Logger; 23 use util\exception\SecurityException; 24 use util\Session; 25 use util\Text; 26 27 28 /** 29 * Edit values for all languages. 30 */ 31 class PageelementAllAction extends PageelementAction implements Method { 32 33 public function getRequiredPermission() { 34 return Permission::ACL_WRITE; 35 } 36 37 38 public function view() 39 { 40 $elements = []; 41 42 foreach( $this->getLanguageIds() as $languageId ) { 43 44 $language = new Language($languageId); 45 $language->load(); 46 47 $this->setTemplateVar('value_time',time() ); 48 $this->setTemplateVar('writable' ,$this->page->hasRight( Permission::ACL_WRITE ) ); 49 50 $element = $this->element; 51 $element->load(); 52 53 $pageContent = new PageContent(); 54 $pageContent->elementId = $element->elementid; 55 $pageContent->pageId = $this->page->pageid; 56 $pageContent->languageid = $languageId; 57 $pageContent->load(); 58 59 if ( $pageContent->isPersistent() ) { 60 $value = new Value(); 61 $value->contentid = $pageContent->contentId; 62 $value->load(); 63 } 64 else { 65 // There is no content yet, so creating an empty value. 66 $value = new Value(); 67 } 68 69 $output = []; 70 $output += $element->getProperties(); 71 $output += $value->getProperties(); 72 $output['label'] = $language->getName(); 73 74 $content = ''; 75 76 switch( $element->typeid) { 77 78 case Element::ELEMENT_TYPE_DATE: 79 $output['date']=date('Y-m-d',$value->date ); 80 $output['time']=date('H:i' ,$value->date ); 81 break; 82 83 case Element::ELEMENT_TYPE_LINK: 84 $project = new Project($this->page->projectid); 85 $output['rootfolderid'] = $project->getRootObjectId(); 86 87 // Ermitteln, welche Objekttypen verlinkt werden d�rfen. 88 $type = $element->subtype; 89 90 if (substr($type, 0, 5) == 'image') 91 $type = 'file'; 92 93 if (!in_array($type, array('file', 'page', 'link', 'folder'))) 94 $types = array('file', 'page', 'link'); // Fallback: Der Link kann auf Seiten,Dateien und Verknüpfungen zeigen 95 else 96 $types = array($type); // gewünschten Typ verwenden 97 98 $oid = $value->linkToObjectId; 99 $name = ''; 100 101 if ($oid) { 102 $o = new BaseObject($oid); 103 $o->load(); 104 $name = $o->filename; 105 } 106 107 $output['objects'] = array(); 108 $output['linkobjectid']= $oid; 109 $content = $oid; 110 $output['linkname']= $name; 111 112 $output['types'] = implode(',', $types); 113 114 break; 115 116 case Element::ELEMENT_TYPE_SELECT: 117 $output['items'] = $element->getSelectItems(); 118 $content = $value->text; 119 break; 120 121 case Element::ELEMENT_TYPE_INSERT: 122 // Auswahl ueber alle Elementtypen 123 $objects = array(); 124 //Änderung der möglichen Types 125 $types = array('file', 'page', 'link'); 126 $objects[0] = \cms\base\Language::lang('LIST_ENTRY_EMPTY'); // Wert "nicht ausgewählt" 127 128 $project = new Project($this->page->projectid); 129 $folder = new Folder($project->getRootObjectId()); 130 $folder->load(); 131 132 //Auch Dateien dazu 133 foreach ($project->getAllObjectIds($types) as $id) { 134 $f = new Folder($id); 135 $f->load(); 136 137 $objects[$id] = \cms\base\Language::lang($f->getType()) . ': '; 138 $objects[$id] .= implode(' » ', $f->parentObjectNames(false, true)); 139 } 140 141 foreach ($project->getAllFolders() as $id) { 142 $f = new Folder($id); 143 $f->load(); 144 145 $objects[$id] = \cms\base\Language::lang($f->getType()) . ': '; 146 $objects[$id] .= implode(' » ', $f->parentObjectNames(false, true)); 147 } 148 149 asort($objects); // Sortieren 150 151 $output['objects'] = $objects; 152 $content = $value->linkToObjectId; 153 154 break; 155 156 case Element::ELEMENT_TYPE_NUMBER: 157 $content = $value->number / pow(10, $element->decimals); 158 break; 159 160 case Element::ELEMENT_TYPE_CHECKBOX: 161 $content = $value->number; 162 break; 163 164 case Element::ELEMENT_TYPE_LONGTEXT: 165 if ($requestedFormat = $this->request->getText('format')) 166 // Individual format from request. 167 $format = $requestedFormat; 168 elseif ($value->format != null) 169 $format = $value->format; 170 else 171 // There is no saved value. Get the format from the template element. 172 $format = $element->format; 173 174 $output['format'] = $format; 175 $output['editor'] = Element::getAvailableFormats()[$format]; 176 177 $content = $this->linkifyOIDs($value->text); 178 break; 179 180 case Element::ELEMENT_TYPE_TEXT: 181 case Element::ELEMENT_TYPE_DATA: 182 183 $content = $value->text; 184 break; 185 186 case Element::ELEMENT_TYPE_COORD: 187 $output['lat' ] = $value->number >> 32; 188 $output['long'] = $value->number << 32 >> 32; 189 break; 190 } 191 192 $output[ 'name' ] = $language->isoCode; 193 $output[ 'value' ] = $content; 194 //$this->setTemplateVar( $language->getId(), $content ); 195 196 $elements[ $language->getId() ] = $output; 197 } 198 199 if ($this->page->hasRight(Permission::ACL_RELEASE)) 200 $this->setTemplateVar('release', true); 201 if ($this->page->hasRight(Permission::ACL_PUBLISH)) 202 $this->setTemplateVar('publish', false); 203 204 $this->setTemplateVar('elements', $elements ); 205 } 206 207 208 209 public function post() 210 { 211 if ( !$this->page->hasRight( Permission::ACL_WRITE )) 212 throw new SecurityException(); 213 214 $element = $this->element; 215 $element->load(); 216 217 foreach( $this->getLanguageIds() as $languageid ) { 218 219 $language = new Language($languageid); 220 $language->load(); 221 222 $language = new Language($languageid); 223 $language->load(); 224 225 $pageContent = new PageContent(); 226 $pageContent->elementId = $element->elementid; 227 $pageContent->pageId = $this->page->pageid; 228 $pageContent->languageid = $languageid; 229 $pageContent->load(); 230 $pageContent->persist(); // Create the content if it does not exist yet. 231 232 $value = new Value(); 233 $value->contentid = $pageContent->contentId; 234 235 $oldValue = clone $value; 236 $oldValue->load(); 237 238 switch ($element->typeid) { 239 240 case Element::ELEMENT_TYPE_TEXT: 241 case Element::ELEMENT_TYPE_DATA: 242 $value->text = $this->request->getText($language->isoCode); 243 break; 244 case Element::ELEMENT_TYPE_COORD: 245 $value->number = $this->request->getNumber($language->isoCode.'_lat') << 32 | $this->request->getNumber($language->isoCode.'_long'); 246 break; 247 case Element::ELEMENT_TYPE_LONGTEXT: 248 $value->text = $this->compactOIDs($this->request->getText($language->isoCode)); 249 $value->format = $oldValue->format; // keep the format 250 break; 251 252 case Element::ELEMENT_TYPE_DATE: 253 $value->date = strtotime($this->request->getText($language->isoCode . '_date') . $this->request->getText($language->isoCode . '_time')); 254 break; 255 256 case Element::ELEMENT_TYPE_SELECT: 257 $value->text = $this->request->getText($language->isoCode); 258 break; 259 case Element::ELEMENT_TYPE_LINK: 260 case Element::ELEMENT_TYPE_INSERT: 261 $value->linkToObjectId = $this->request->getNumber($language->isoCode); 262 break; 263 264 case Element::ELEMENT_TYPE_NUMBER: 265 $value->number = $this->request->getText($language->isoCode) * pow(10, $element->decimals); 266 break; 267 case Element::ELEMENT_TYPE_CHECKBOX: 268 $value->number = $this->request->getText($language->isoCode)?1:0; 269 break; 270 default: 271 throw new \LogicException('Unknown element type: ' . $element->getTypeName()); 272 } 273 274 275 // Inhalt sofort freigegeben, wenn 276 // - Recht vorhanden 277 // - Freigabe gewuenscht 278 $value->publish = $this->page->hasRight(Permission::ACL_RELEASE) && $this->request->isTrue('release'); 279 280 // Up-To-Date-Check 281 $content = new Content( $pageContent->contentId ); 282 $lastChangeTime = $content->getLastChangeSinceByAnotherUser($this->request->getNumber('value_time'), $this->getCurrentUserId()); 283 if ($lastChangeTime) 284 $this->addWarningFor($value, Messages::CONCURRENT_VALUE_CHANGE, array('last_change_time' => date(L::lang('DATE_FORMAT'), $lastChangeTime))); 285 286 // Check if anything has changed 287 if ( $oldValue->text == $value->text && 288 $oldValue->linkToObjectId == $value->linkToObjectId && 289 $oldValue->format == $value->format && 290 $oldValue->number == $value->number && 291 $oldValue->date == $value->date && 292 !(!$oldValue->publish && $value->publish) 293 ) 294 continue; // nothing has changed. 295 296 // Inhalt speichern 297 $value->persist(); 298 299 // Wenn Inhalt in allen Sprachen gleich ist, dann wird der Inhalt 300 // fuer jede Sprache einzeln gespeichert. 301 if ($element->allLanguages) { 302 $project = new Project($this->page->projectid); 303 foreach ($project->getLanguageIds() as $languageid) { 304 if ($languageid != $pageContent->languageid) { 305 $otherPageContent = clone $pageContent; 306 $otherPageContent->languageid = $languageid; 307 $otherPageContent->contentId = null; 308 $otherPageContent->load(); 309 if (!$otherPageContent->contentId) 310 $otherPageContent->persist(); // create pagecontent if it does not exist. 311 312 $otherValue = clone $value; 313 $otherValue->contentid = $otherPageContent->contentId; 314 $otherValue->persist(); 315 } 316 } 317 } 318 } 319 320 // Falls ausgewaehlt die Seite sofort veroeffentlichen 321 if ($this->page->hasRight(Permission::ACL_PUBLISH) && $this->request->isTrue('publish')) { 322 $this->publishPage( $languageid ); 323 } 324 325 $this->page->setTimestamp(); // "Letzte Aenderung" setzen 326 327 $this->addNoticeFor($this->page, Messages::SAVED); 328 } 329 330 /** 331 * @return int[] 332 */ 333 protected function getLanguageIds() 334 { 335 return $this->page->getProject()->getLanguageIds(); 336 } 337 338 }
Downloadmodules/cms/action/pageelement/PageelementAllAction.class.php
History Wed, 17 Apr 2024 00:34:07 +0200 Jan Dankert New: Inputfields for coordinates; coordinates are stored in the now 64bit-number-field of the value. Wed, 15 Feb 2023 00:22:28 +0100 Jan Dankert Fix: Changing the Longtext format was not possible. Mon, 27 Jun 2022 02:54:38 +0200 Jan Dankert Fix: Editing of dates was broken, do not know why the code was missing up to now... Mon, 27 Jun 2022 02:22:50 +0200 Jan Dankert Fix: Saving links in PageallAction and PageelementAllAction. Mon, 13 Jun 2022 22:40:05 +0200 Jan Dankert Fix: Edit texts in all-languages-mode was completely broken. Thu, 2 Jun 2022 01:04:54 +0200 Jan Dankert New: Element type "checkbox" Wed, 1 Jun 2022 01:05:34 +0200 Jan Dankert New: Element types for "coordinates" and "data" Wed, 1 Jun 2022 00:11:40 +0200 Jan Dankert New: DSL as a filter for number values Sun, 10 Apr 2022 12:10:24 +0200 dankert Fix: Pagecontent must be created if the value of a pageelement is stored for the first time. Fri, 11 Mar 2022 11:32:38 +0100 dankert New: Edit all languages for a page element.