示例#1
0
 public function handleSave(array $params, rex_sql $sqlFields)
 {
     if (rex_request_method() != 'post') {
         return $params;
     }
     $article = rex_sql::factory();
     // $article->setDebug();
     $article->setTable(rex::getTablePrefix() . 'article');
     $article->setWhere('id=:id AND clang_id=:clang', ['id' => $params['id'], 'clang' => $params['clang']]);
     parent::fetchRequestValues($params, $article, $sqlFields);
     // do the save only when metafields are defined
     if ($article->hasValues()) {
         $article->update();
     }
     // Artikel nochmal mit den zusätzlichen Werten neu generieren
     rex_article_cache::generateMeta($params['id'], $params['clang']);
     return $params;
 }
示例#2
0
 /**
  * Return an rex_structure_element object based on an id.
  * The instance will be cached in an instance-pool and therefore re-used by a later call.
  *
  * @param int $id    the article id
  * @param int $clang the clang id
  *
  * @return static A rex_structure_element instance typed to the late-static binding type of the caller
  */
 public static function get($id, $clang = null)
 {
     $id = (int) $id;
     if ($id <= 0) {
         return null;
     }
     if (!$clang) {
         $clang = rex_clang::getCurrentId();
     }
     $class = get_called_class();
     return static::getInstance([$id, $clang], function ($id, $clang) use($class) {
         $article_path = rex_path::addonCache('structure', $id . '.' . $clang . '.article');
         // generate cache if not exists
         if (!file_exists($article_path)) {
             rex_article_cache::generateMeta($id, $clang);
         }
         // article is valid, if cache exists after generation
         if (file_exists($article_path)) {
             // load metadata from cache
             $metadata = rex_file::getCache($article_path);
             // create object with the loaded metadata
             return new $class($metadata);
         }
         return null;
     });
 }