From 2b5e8d796897bf1fbe020bb64b45163401c8fcea Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sun, 7 Jun 2020 19:29:38 +0200 Subject: [PATCH 01/19] #364 - Initial import --- .../extensions/k2/model/articles.php | 195 ++++++++++++ .../extensions/k2/model/attachments.php | 67 ++++ .../extensions/k2/model/categories.php | 85 +++++ .../extensions/k2/model/entity/abstract.php | 190 ++++++++++++ .../extensions/k2/model/entity/article.php | 293 ++++++++++++++++++ .../extensions/k2/model/entity/attachment.php | 49 +++ .../extensions/k2/model/entity/category.php | 106 +++++++ .../extensions/k2/model/entity/field.php | 44 +++ .../resources/extensions/k2/model/fields.php | 79 +++++ 9 files changed, 1108 insertions(+) create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/articles.php create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/attachments.php create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/categories.php create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/entity/abstract.php create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/entity/article.php create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/entity/attachment.php create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/entity/category.php create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/entity/field.php create mode 100644 code/site/components/com_pages/resources/extensions/k2/model/fields.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/articles.php b/code/site/components/com_pages/resources/extensions/k2/model/articles.php new file mode 100644 index 000000000..48407f8b0 --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/articles.php @@ -0,0 +1,195 @@ +getState() + ->insert('id' , 'cmd', null, true) + ->insert('category' , 'cmd') + ->insert('tags' , 'cmd') + + ->insert('published' , 'bool') + ->insert('archived' , 'bool') + ->insert('trashed' , 'bool') + ->insert('featured' , 'bool') + + ->insert('author' , 'string') + ->insert('editor' , 'string') + ->insert('access' , 'cmd', array_unique($this->getObject('user')->getRoles())) + ; + } + + protected function _initialize(KObjectConfig $config) + { + $config->append(array( + 'persistable' => false, + 'type' => 'articles', + 'entity' => 'article', + 'table' => 'k2_items', + )); + parent::_initialize($config); + } + + public function fetchData($count = false) + { + $state = $this->getState(); + + $query = $this->getObject('database.query.select') + ->table(array('tbl' => $this->getTable()->getName())); + + //#__tags + $query->columns([ + 'tags' => $this->getObject('database.query.select') + ->table(array('t' => 'k2_tags')) + ->columns('GROUP_CONCAT(t.name)') + ->join(['m' => 'k2_tags_xref'], 'm.tagID = t.id') + ->where('m.itemID = tbl.id') + ->where('(t.published = :published)')->bind(['published' => 1]) + ]); + + //#__content + if(!$count) + { + $query->columns([ + 'id' => 'tbl.id', + 'title' => 'tbl.title', + 'slug' => 'tbl.alias', + 'summary' => 'tbl.metadesc', + 'content' => 'CONCAT_WS("", tbl.introtext, IF(LENGTH(tbl.fulltext), tbl.fulltext ,NULL))', + 'category' => 'tbl.catid', + + 'published' => 'tbl.published', + 'archived' => 'IF(tbl.publish_down > CURRENT_TIMESTAMP, 1, 0)', + 'trashed' => 'tbl.trash', + 'featured' => 'tbl.featured', + + 'author' => 'tbl.created_by', + 'editor' => 'GREATEST(tbl.created_by, tbl.modified_by)', + + 'date' => 'tbl.created', + 'edited_date' => 'GREATEST(tbl.created, tbl.modified)', + 'published_date' => 'tbl.publish_up', + 'archived_date' => 'tbl.publish_down', + + 'fields' => 'tbl.extra_fields', + 'parameters' => 'tbl.params', + 'impressions' => 'tbl.hits', + + //Protected properties (for getters) + '_metadata' => 'tbl.metadata', + '_image_caption' => 'tbl.image_caption', + ]); + } + else $query->columns('COUNT(*)'); + + //Joins + $query + ->join(['c' => 'k2_categories'] , 'tbl.catid = c.id') + ->join(['g' => 'usergroups'] , 'tbl.access = g.id') + ->join(['m' => 'k2_tags_xref'] , 'tbl.id = m.itemID') + ->join(['t' => 'k2_tags'] , 't.id = m.tagID'); + + if(!is_null($state->id)) + { + if(is_string($state->id)) { + $articles = array_unique(explode(',', $state->id)); + } else { + $articles = (array) $state->id; + } + + $query->where('(tbl.id IN :articles)')->bind(['articles' => $articles]); + } + + if(!is_null($state->category)) + { + if(is_string($state->category)) { + $categories = array_unique(explode(',', $state->category)); + } else { + $categories = (array) $state->category; + } + + $query->where('(tbl.catid IN :category)')->bind(['category' => $categories]); + } + + if(!is_null($state->tags)) + { + if(is_string($state->tags)) { + $tags = array_unique(explode(',', $state->tags)); + } else { + $tags = (array) $state->tags; + } + + $query->where('(t.title IN :tags)')->bind(['tags' => $tags]); + } + + if(!is_null($state->author)) + { + if(is_string($state->author)) { + $users = array_unique(explode(',', $state->author)); + } else { + $users = (array) $state->author; + } + + $query->where('(tbl.created_by IN :authors)')->bind(['authors' => $users]); + } + + if (!is_null($state->editor)) + { + if(is_string($state->editor)) { + $users = array_unique(explode(',', $state->editor)); + } else { + $users = (array) $state->editor; + } + + $query->where('(tbl.modified_by IN :editors)')->bind(['editors' => $users]); + } + + if (!is_null($state->access)) + { + if(is_string($state->access)) { + $access = array_unique(explode(',', $state->access)); + } else { + $access = (array) $state->access; + } + + //If user doesn't have access to the category, he doesn't have access to the articles + $query->where('(tbl.access IN :access)')->bind(['access' => $access]); + $query->where('(c.access IN :access)')->bind(['access' => $access]); + } + + if (!is_null($state->published)) + { + if($state->published) { + $query->where('(tbl.published = 1)'); + } else { + $query->where('(tbl.published = 0'); + } + } + + if (!is_null($state->trashed)) + { + if($state->trashed) { + $query->where('(tbl.trash = 1)'); + } else { + $query->where('(tbl.trash = 0)'); + } + } + + if (!is_null($state->archived)) + { + if($state->archived) { + $query->where('(tbl.publish_down > CURRENT_TIMESTAMP)'); + } else { + $query->where('(tbl.publish_down < CURRENT_TIMESTAMP)'); + } + } + + if (!is_null($state->featured)) { + $query->where('(tbl.featured = :featured)')->bind(['featured' => (bool) $state->featured]); + } + + return $query; + } +} diff --git a/code/site/components/com_pages/resources/extensions/k2/model/attachments.php b/code/site/components/com_pages/resources/extensions/k2/model/attachments.php new file mode 100644 index 000000000..171e624b5 --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/attachments.php @@ -0,0 +1,67 @@ +getState() + ->insert('id', 'cmd', null, true) + ->insert('article', 'int'); + } + + protected function _initialize(KObjectConfig $config) + { + $config->append(array( + 'persistable' => false, + 'type' => 'article_attachments', + 'entity' => 'attachment', + 'table' => 'k2_attachments', + )); + parent::_initialize($config); + } + + public function fetchData($count = false) + { + $state = $this->getState(); + + $query = $this->getObject('database.query.select') + ->table(array('tbl' => $this->getTable()->getName())); + + if(!$count) + { + $query->columns([ + 'id' => 'tbl.id', + 'title' => 'tbl.title', + 'url' => 'tbl.filename', + 'alt' => 'tbl.titleAttribute', + 'impressions' => 'tbl.hits', + ]); + } + else $query->columns('COUNT(*)'); + + if(!is_null($state->id)) + { + if(is_string($state->id)) { + $articles = array_unique(explode(',', $state->id)); + } else { + $articles = (array) $state->id; + } + + $query->where('(tbl.id IN :articles)')->bind(['articles' => $articles]); + } + + if(!is_null($state->article)) + { + if(is_string($state->article)) { + $articles = array_unique(explode(',', $state->article)); + } else { + $articles = (array) $state->article; + } + + $query->where('(tbl.itemID IN :articles)')->bind(['articles' => $articles]); + } + + return $query; + } +} diff --git a/code/site/components/com_pages/resources/extensions/k2/model/categories.php b/code/site/components/com_pages/resources/extensions/k2/model/categories.php new file mode 100644 index 000000000..146915d25 --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/categories.php @@ -0,0 +1,85 @@ +getState() + ->insert('id' , 'cmd', null, true) + ->insert('published' , 'bool') + ->insert('access' , 'cmd', array_unique($this->getObject('user')->getRoles())) + ; + } + + protected function _initialize(KObjectConfig $config) + { + $config->append(array( + 'persistable' => false, + 'type' => 'article_categories', + 'entity' => 'category', + 'table' => 'k2_categories', + )); + parent::_initialize($config); + } + + public function fetchData($count = false) + { + $state = $this->getState(); + + $query = $this->getObject('database.query.select') + ->table(array('tbl' => $this->getTable()->getName())); + + //#__k2_categories + if(!$count) + { + $query->columns([ + 'id' => 'tbl.id', + 'title' => 'tbl.name', + 'slug' => 'tbl.alias', + 'parent' => 'IF(tbl.parent > 0, tbl.parent, NULL)', + 'content' => 'tbl.description', + 'image' => 'tbl.image', + + 'published' => 'tbl.published', + + 'parameters' => 'tbl.params', + ]); + } + else $query->columns('COUNT(*)'); + + if(!is_null($state->id)) + { + if(is_string($state->id)) { + $categories = array_unique(explode(',', $state->id)); + } else { + $categories = (array) $state->id; + } + + $query->where('(tbl.id IN :categories)')->bind(['categories' => $categories]); + } + + if (!is_null($state->access)) + { + if(is_string($state->access)) { + $access = array_unique(explode(',', $state->access)); + } else { + $access = (array) $state->access; + } + + //If user doesn't have access to the category, he doesn't have access to the articles + $query->where('(tbl.access IN :access)')->bind(['access' => $access]); + } + + if (!is_null($state->published)) + { + if($state->published) { + $query->where('(tbl.published = 1)'); + } else { + $query->where('(tbl.published = 0'); + } + } + + return $query; + } +} diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/abstract.php b/code/site/components/com_pages/resources/extensions/k2/model/entity/abstract.php new file mode 100644 index 000000000..44ebe260b --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/entity/abstract.php @@ -0,0 +1,190 @@ + + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + +abstract class ExtK2ModelEntityAbstract extends ComPagesModelEntityItem +{ + protected function _initialize(KObjectConfig $config) + { + $config->append([ + 'data' => [ + 'id' => '', + 'slug' => '', + 'name' => '', + 'title' => '', + 'summary' => '', + 'text' => '', + 'date' => 'now', + 'author' => '', + 'image' => [ + 'url' => '', + 'alt' => '', + 'caption' => '', + ], + 'metadata' => [ + 'og:type' => 'website', + 'og:title' => null, + 'og:url' => null, + 'og:image' => null, + 'og:description' => null, + ], + 'parameters' => [], + 'direction' => 'auto', + 'language' => 'en-GB', + ], + 'internal_properties' => ['content', 'text', 'parameters'], + 'base_path' => $this->getObject('request')->getBasePath(), + ]); + + parent::_initialize($config); + } + + public function get($property, $default = null) + { + if($this->hasProperty($property)) { + $result = $this->getProperty($property); + } else { + $result = $default; + } + + return $result; + } + + public function getPropertyName() + { + if(empty($name)) { + $name = ucwords(str_replace(array('_', '-'), ' ', $this->slug)); + } + + return $name; + } + + public function getPropertyText() + { + return $this->getContent(); + } + + public function getPropertyMetadata() + { + //Get the raw metadata + $metadata = $this->_metadata; + + if(is_string($metadata)) { + $metadata = array_filter((array) json_decode($metadata, true)); + } + + //Remove empty values + $metadata = new KObjectConfigJson($metadata); + $metadata->append($this->getConfig()->data->metadata); + + if(!isset($metadata->description) && $this->summary) { + $metadata->set('description', $this->summary); + } + + //Only set one image (give priority to the text image) + if($this->image && $this->image->url) { + $metadata->set('og:image', $this->image->url); + } + + //Type and image are required. If they are not set remove any opengraph properties + if(!empty($metadata->get('og:type')) && $metadata->has('og:image')) + { + if($this->title) { + $metadata->set('og:title', $this->title); + } + + if($this->summary) { + $metadata->set('og:description', $this->summary); + } + + if($this->language) { + $metadata->set('og:locale', $this->language); + } + } + else + { + foreach($metadata as $name => $value) + { + if(strpos($name, 'og:') === 0 || strpos($name, 'twitter:') === 0) { + $metadata->remove($name); + } + } + } + + return $metadata; + } + + public function setPropertyDate($value) + { + if(is_integer($value)) { + $date = $this->getObject('date')->setTimestamp($value); + } else { + $date = $this->getObject('date', array('date' => trim($value))); + } + + return $date; + } + + public function setPropertyParameters($value) + { + return new KObjectConfigJson($value); + } + + public function getBasePath() + { + return $this->getConfig()->base_path; + } + + public function getAuthor() + { + $user = $this->getObject('user.provider')->load($this->author); + return $user; + } + + public function getContent() + { + static $prepared; + + //Prepare the content + if(!$prepared) + { + JPluginHelper::importPlugin('content'); + + $content = new stdClass; + $content->text = $this->content; + $params = (object) $this->parameters->toArray(); + $name = $this->getIdentifier()->getName(); + + JEventDispatcher::getInstance()->trigger( + 'onContentPrepare', + ['com_pages.'.$name, &$content, &$params, 0] + ); + + $this->content = $content->text; + + $prepared = true; + } + + return $this->content; + } + + public function getContentType() + { + return 'text/html'; + } + + public function getHash() + { + return hash("crc32b", $this->getContent()); + } + + public function __toString() + { + return $this->getContent(); + } +} diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/article.php b/code/site/components/com_pages/resources/extensions/k2/model/entity/article.php new file mode 100644 index 000000000..2b976713f --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/entity/article.php @@ -0,0 +1,293 @@ + + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + +class ExtK2ModelEntityArticle extends ExtJoomlaModelEntityAbstract +{ + protected function _initialize(KObjectConfig $config) + { + $config->append([ + 'data' => [ + 'id' => '', + 'slug' => '', + 'name' => '', + 'title' => '', + 'summary' => '', + 'excerpt' => '', + 'text' => '', + 'category' => '', + 'tags' => '', + 'date' => 'now', + 'edited_date' => '', + 'published_date' => '', + 'archived_date' => '', + 'author' => '', + 'editor' => '', + 'image' => [ + 'url' => '', + 'alt' => '', + 'caption' => '', + ], + 'metadata' => [ + 'og:type' => 'article', + 'og:title' => null, + 'og:url' => null, + 'og:image' => null, + 'og:description' => null, + + //http://ogp.me/ns/article + 'article:published_time' => null, + 'article:modified_time' => null, + 'article:expiration_time' => null, + 'article:tag' => [], + ], + 'fields' => [], + 'parameters' => [], + 'impressions' => 0, + 'direction' => 'auto', + 'language' => 'en-GB', + ], + 'internal_properties' => [ 'excerpt'], + ]); + + parent::_initialize($config); + } + + public function getPropertyExcerpt() + { + $parts = preg_split('##i', $this->getContent(), 2); + + if(count($parts) > 1) { + $excerpt = $parts[0]; + } else { + $excerpt = ''; + } + + return $excerpt; + } + + public function getPropertyText() + { + $parts = preg_split('##i', $this->getContent(), 2); + + if(count($parts) > 1) { + $text = $parts[1]; + } else { + $text = $parts[0]; + } + + return $text; + } + + public function getPropertyImage() + { + //Normalize images + $image = array(); + + $hash = md5("Image".$this->id); + $path = '/media/k2/items/src/'.$hash.'.jpg'; + + if(file_exists(JPATH_ROOT.$path)) + { + $url = $this->getBasePath().$path; + $url = $this->getObject('lib:http.url')->setUrl($url); + + $image = [ + 'url' => $url, + 'alt' => '', + 'caption' => $this->_image_caption ?? '' + ]; + } + + return new KObjectConfigJson($image); + } + + public function getPropertyMetadata() + { + $metadata = parent::getPropertyMetadata(); + + if(!empty($this->published_date)) { + $metadata->set('article:published_time', (string) $this->published_date); + } + + if(!empty($this->edited_date)) { + $metadata->set('article:modified_time', (string) $this->edited_date); + } + + if(!empty($this->archived_date)) { + $metadata->set('article:expiration_time', (string) $this->archived_date); + } + + if(count($this->tags)) { + $metadata->set('article:tag', implode(',', $this->tags->toArray())); + } + + return $metadata; + } + + public function getPropertyAttachments() + { + $attachments = array(); + + //Get the single category + $rows = $this->getObject('ext:k2.model.attachments') + ->article($this->id) + ->fetch(); + + foreach($rows as $row) { + $attachments[] = $row; + } + + return $attachments; + } + + public function setPropertyTags($value) + { + if($value) + { + if(is_string($value)) { + $value = explode(',', $value); + } + } + else $value = []; + + return new KObjectConfigJson($value); + } + + public function setPropertyCategory($value) + { + if($value) + { + //Get the single category + $value = $this->getObject('ext:k2.model.categories') + ->id($value) + ->fetch() + ->find($value); + } + + return $value; + } + + public function setPropertyEditedDate($value) + { + $date = null; + + if($value && $value != '0000-00-00 00:00:00') + { + if(is_integer($value)) { + $date = $this->getObject('date')->setTimestamp($value); + } else { + $date = $this->getObject('date', array('date' => trim($value))); + } + } + + return $date; + } + + public function setPropertyPublishedDate($value) + { + $date = null; + + if($value && $value != '0000-00-00 00:00:00') + { + if(is_integer($value)) { + $date = $this->getObject('date')->setTimestamp($value); + } else { + $date = $this->getObject('date', array('date' => trim($value))); + } + } + + return $date; + } + + public function setPropertyArchivedDate($value) + { + $date = null; + + if($value && $value != '0000-00-00 00:00:00') + { + if(is_integer($value)) { + $date = $this->getObject('date')->setTimestamp($value); + } else { + $date = $this->getObject('date', array('date' => trim($value))); + } + } + + return $date; + } + + public function setPropertyFields($value) + { + $fields = null; + + if($value) + { + if(is_string($value)) { + $value = json_decode($value, true); + } + + if(!empty($value)) + { + //Get the single field + $rows = $this->getObject('ext:k2.model.fields') + ->id(array_column($value, 'id')) + ->fetch(); + + foreach($value as $v) + { + if($field = $rows->find($v['id'])) + { + //Set the value + $field->value = $v['value']; + + //Add the field + $fields[] = $field; + } + } + } + } + + return $fields; + } + + public function setPropertyParameters($value) + { + if(is_string($value)) { + $value = json_decode($value, true); + } + + //$params = JComponentHelper::getParams('com_k2')->toArray(); + + $config = new KObjectConfigJson(/*$params*/); + $config->merge($value); // Override global params with specific params + + return $config; + } + + public function getEditor() + { + $user = $this->getObject('user.provider')->load($this->editor); + return $user; + } + + public function getImages() + { + $hash = md5("Image".$this->id); + $path = '/media/k2/items/cache/'.$hash; + + $images = [ + 'XS' => $path.'_XS.jpg', + 'S' => $path.'_S.jpg', + 'M' => $path.'_M.jpg', + 'L' => $path.'_L.jpg', + 'XL' => $path.'_XL.jpg', + ]; + + return $images; + } +} diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/attachment.php b/code/site/components/com_pages/resources/extensions/k2/model/entity/attachment.php new file mode 100644 index 000000000..8ce26b2c8 --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/entity/attachment.php @@ -0,0 +1,49 @@ + + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + +class ExtK2ModelEntityAttachment extends ComPagesModelEntityItem +{ + protected function _initialize(KObjectConfig $config) + { + $config->append([ + 'data' => [ + 'id' => '', + 'title' => '', + 'url' => '', + 'alt' => '', + 'impressions' => 0, + ], + 'internal_properties' => [ 'id'], + 'base_path' => $this->getObject('request')->getBasePath(), + ]); + + parent::_initialize($config); + } + + public function setPropertyUrl($value) + { + if($value) + { + $path = '/media/k2/attachments/'.$value; + + if(file_exists(JPATH_ROOT.$path)) + { + $url = $this->getBasePath().$path; + $value = $this->getObject('lib:http.url')->setUrl($url); + } + } + + return $value; + } + + public function getBasePath() + { + return $this->getConfig()->base_path; + } +} diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/category.php b/code/site/components/com_pages/resources/extensions/k2/model/entity/category.php new file mode 100644 index 000000000..d593596f4 --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/entity/category.php @@ -0,0 +1,106 @@ + + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + +class ExtK2ModelEntityCategory extends ExtJoomlaModelEntityAbstract +{ + protected function _initialize(KObjectConfig $config) + { + $config->append([ + 'data' => [ + 'id' => '', + 'slug' => '', + 'name' => '', + 'title' => '', + 'summary' => '', + 'text' => '', + 'date' => 'now', + 'author' => '', + 'image' => [ + 'url' => '', + 'alt' => '', + 'caption' => '', + ], + 'metadata' => [ + 'og:type' => 'website', + 'og:title' => null, + 'og:url' => null, + 'og:image' => null, + 'og:description' => null, + ], + 'parameters' => [], + 'impressions' => null, + 'direction' => 'auto', + 'language' => 'en-GB', + ], + //metatags are used internally for calculating metadata through getter + 'internal_properties' => [], + ]); + + parent::_initialize($config); + } + + public function getPropertySummary() + { + return $this->parameters->catMetaDesc; + } + + public function getPropertyAuthor() + { + return $this->parameters->catMetaAuthor; + } + + public function getPropertyMetadata() + { + $metadata = parent::getPropertyMetadata(); + + if($robots = $this->parameters->get('catMetaRobots')) { + $metadata->robots = $robots; + } + + return $metadata; + } + + public function setPropertyImage($value) + { + $image = array(); + + if($value) + { + $path = '/media/k2/categories/'.$value; + + if(file_exists(JPATH_ROOT.$path)) + { + $url = $this->getBasePath().$path; + $url = $this->getObject('lib:http.url')->setUrl($url); + + $image = [ + 'url' => $url, + 'alt' => '', + 'caption' => '', + ]; + } + } + + return new KObjectConfigJson($image); + } + + public function setPropertyParameters($value) + { + if(is_string($value)) { + $value = json_decode($value, true); + } + + //$params = JComponentHelper::getParams('com_k2')->toArray(); + + $config = new KObjectConfigJson(/*$params*/); + $config->merge($value); // Override global params with article specific params + + return $config; + } +} diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/field.php b/code/site/components/com_pages/resources/extensions/k2/model/entity/field.php new file mode 100644 index 000000000..dbe5f0bf6 --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/entity/field.php @@ -0,0 +1,44 @@ + + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + +class ExtK2ModelEntityField extends ComPagesModelEntityItem +{ + protected function _initialize(KObjectConfig $config) + { + $config->append([ + 'data' => [ + 'id' => '', + 'name' => '', + 'title' => '', + ], + ]); + + parent::_initialize($config); + } + + public function getPropertyName() + { + $value = null; + + if($this->_value) + { + if(is_string($this->_value)) { + $value = array_pop(json_decode($this->_value, true)); + } + + if($value['alias']) { + $value = $value['alias']; + } else { + $value = ucwords(str_replace(array('_', '-'), ' ', $this->title)); + } + } + + return $value; + } +} diff --git a/code/site/components/com_pages/resources/extensions/k2/model/fields.php b/code/site/components/com_pages/resources/extensions/k2/model/fields.php new file mode 100644 index 000000000..6741db686 --- /dev/null +++ b/code/site/components/com_pages/resources/extensions/k2/model/fields.php @@ -0,0 +1,79 @@ +getState() + ->insert('id', 'cmd', null, true) + ->insert('group' , 'int') + ->insert('published' , 'bool'); + } + + protected function _initialize(KObjectConfig $config) + { + $config->append(array( + 'persistable' => false, + 'type' => 'article_fields', + 'entity' => 'field', + 'table' => 'k2_extra_fields', + )); + parent::_initialize($config); + } + + public function fetchData($count = false) + { + $state = $this->getState(); + + $query = $this->getObject('database.query.select') + ->table(array('tbl' => $this->getTable()->getName())); + + if(!$count) + { + $query->columns([ + 'id' => 'tbl.id', + 'title' => 'tbl.name', + 'type' => 'tbl.type', + 'published' => 'tbl.published', + + //Protected properties (for getters) + '_value' => 'tbl.value', + ]); + } + else $query->columns('COUNT(*)'); + + if(!is_null($state->id)) + { + if(is_string($state->id)) { + $fields = array_unique(explode(',', $state->id)); + } else { + $fields = (array) $state->id; + } + + $query->where('(tbl.id IN :fields)')->bind(['fields' => $fields]); + } + + if(!is_null($state->group)) + { + if(is_string($state->group)) { + $groups = array_unique(explode(',', $state->group)); + } else { + $groups = (array) $state->group; + } + + $query->where('(tbl.group IN :groups)')->bind(['groups' => $groups]); + } + + if (!is_null($state->published)) + { + if($state->published) { + $query->where('(tbl.published = 1)'); + } else { + $query->where('(tbl.published = 0'); + } + } + + return $query; + } +} From bdcb8819a6c925205c30c45571a7a5ea8b593578 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Mon, 8 Jun 2020 19:23:00 +0200 Subject: [PATCH 02/19] #364 - Move to /contrib/k2 --- .../resources/extensions => contrib}/k2/model/articles.php | 0 .../resources/extensions => contrib}/k2/model/attachments.php | 0 .../resources/extensions => contrib}/k2/model/categories.php | 0 .../resources/extensions => contrib}/k2/model/entity/abstract.php | 0 .../resources/extensions => contrib}/k2/model/entity/article.php | 0 .../extensions => contrib}/k2/model/entity/attachment.php | 0 .../resources/extensions => contrib}/k2/model/entity/category.php | 0 .../resources/extensions => contrib}/k2/model/entity/field.php | 0 .../resources/extensions => contrib}/k2/model/fields.php | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/articles.php (100%) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/attachments.php (100%) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/categories.php (100%) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/entity/abstract.php (100%) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/entity/article.php (100%) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/entity/attachment.php (100%) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/entity/category.php (100%) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/entity/field.php (100%) rename {code/site/components/com_pages/resources/extensions => contrib}/k2/model/fields.php (100%) diff --git a/code/site/components/com_pages/resources/extensions/k2/model/articles.php b/contrib/k2/model/articles.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/articles.php rename to contrib/k2/model/articles.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/attachments.php b/contrib/k2/model/attachments.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/attachments.php rename to contrib/k2/model/attachments.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/categories.php b/contrib/k2/model/categories.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/categories.php rename to contrib/k2/model/categories.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/abstract.php b/contrib/k2/model/entity/abstract.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/entity/abstract.php rename to contrib/k2/model/entity/abstract.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/article.php b/contrib/k2/model/entity/article.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/entity/article.php rename to contrib/k2/model/entity/article.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/attachment.php b/contrib/k2/model/entity/attachment.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/entity/attachment.php rename to contrib/k2/model/entity/attachment.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/category.php b/contrib/k2/model/entity/category.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/entity/category.php rename to contrib/k2/model/entity/category.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/entity/field.php b/contrib/k2/model/entity/field.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/entity/field.php rename to contrib/k2/model/entity/field.php diff --git a/code/site/components/com_pages/resources/extensions/k2/model/fields.php b/contrib/k2/model/fields.php similarity index 100% rename from code/site/components/com_pages/resources/extensions/k2/model/fields.php rename to contrib/k2/model/fields.php From 161f9fe226050a1f58e9293f4eaca3463e9a245c Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Thu, 11 Jun 2020 04:12:17 +0200 Subject: [PATCH 03/19] #364 - Do not included trashed items --- contrib/k2/model/articles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/k2/model/articles.php b/contrib/k2/model/articles.php index 48407f8b0..6d14589fd 100644 --- a/contrib/k2/model/articles.php +++ b/contrib/k2/model/articles.php @@ -12,7 +12,7 @@ public function __construct(KObjectConfig $config) ->insert('published' , 'bool') ->insert('archived' , 'bool') - ->insert('trashed' , 'bool') + ->insert('trashed' , 'bool', false) ->insert('featured' , 'bool') ->insert('author' , 'string') From cd2d47ba310c6d7f5f26b4382998cab175cbfa02 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Fri, 19 Jun 2020 00:36:51 +0200 Subject: [PATCH 04/19] #364 - Fix typos and add class docblock --- contrib/k2/model/articles.php | 400 ++++++++++++++++--------------- contrib/k2/model/attachments.php | 8 + contrib/k2/model/categories.php | 144 +++++------ contrib/k2/model/fields.php | 134 ++++++----- 4 files changed, 364 insertions(+), 322 deletions(-) diff --git a/contrib/k2/model/articles.php b/contrib/k2/model/articles.php index 6d14589fd..085e163cf 100644 --- a/contrib/k2/model/articles.php +++ b/contrib/k2/model/articles.php @@ -1,195 +1,213 @@ + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + class ExtK2ModelArticles extends ComPagesModelDatabase { - public function __construct(KObjectConfig $config) - { - parent::__construct($config); - - $this->getState() - ->insert('id' , 'cmd', null, true) - ->insert('category' , 'cmd') - ->insert('tags' , 'cmd') - - ->insert('published' , 'bool') - ->insert('archived' , 'bool') - ->insert('trashed' , 'bool', false) - ->insert('featured' , 'bool') - - ->insert('author' , 'string') - ->insert('editor' , 'string') - ->insert('access' , 'cmd', array_unique($this->getObject('user')->getRoles())) - ; - } - - protected function _initialize(KObjectConfig $config) - { - $config->append(array( - 'persistable' => false, - 'type' => 'articles', - 'entity' => 'article', - 'table' => 'k2_items', - )); - parent::_initialize($config); - } - - public function fetchData($count = false) - { - $state = $this->getState(); - - $query = $this->getObject('database.query.select') - ->table(array('tbl' => $this->getTable()->getName())); - - //#__tags - $query->columns([ - 'tags' => $this->getObject('database.query.select') - ->table(array('t' => 'k2_tags')) - ->columns('GROUP_CONCAT(t.name)') - ->join(['m' => 'k2_tags_xref'], 'm.tagID = t.id') - ->where('m.itemID = tbl.id') - ->where('(t.published = :published)')->bind(['published' => 1]) - ]); - - //#__content - if(!$count) - { - $query->columns([ - 'id' => 'tbl.id', - 'title' => 'tbl.title', - 'slug' => 'tbl.alias', - 'summary' => 'tbl.metadesc', - 'content' => 'CONCAT_WS("", tbl.introtext, IF(LENGTH(tbl.fulltext), tbl.fulltext ,NULL))', - 'category' => 'tbl.catid', - - 'published' => 'tbl.published', - 'archived' => 'IF(tbl.publish_down > CURRENT_TIMESTAMP, 1, 0)', - 'trashed' => 'tbl.trash', - 'featured' => 'tbl.featured', - - 'author' => 'tbl.created_by', - 'editor' => 'GREATEST(tbl.created_by, tbl.modified_by)', - - 'date' => 'tbl.created', - 'edited_date' => 'GREATEST(tbl.created, tbl.modified)', - 'published_date' => 'tbl.publish_up', - 'archived_date' => 'tbl.publish_down', - - 'fields' => 'tbl.extra_fields', - 'parameters' => 'tbl.params', - 'impressions' => 'tbl.hits', - - //Protected properties (for getters) - '_metadata' => 'tbl.metadata', - '_image_caption' => 'tbl.image_caption', - ]); - } - else $query->columns('COUNT(*)'); - - //Joins - $query - ->join(['c' => 'k2_categories'] , 'tbl.catid = c.id') - ->join(['g' => 'usergroups'] , 'tbl.access = g.id') - ->join(['m' => 'k2_tags_xref'] , 'tbl.id = m.itemID') - ->join(['t' => 'k2_tags'] , 't.id = m.tagID'); - - if(!is_null($state->id)) - { - if(is_string($state->id)) { - $articles = array_unique(explode(',', $state->id)); - } else { - $articles = (array) $state->id; - } - - $query->where('(tbl.id IN :articles)')->bind(['articles' => $articles]); - } - - if(!is_null($state->category)) - { - if(is_string($state->category)) { - $categories = array_unique(explode(',', $state->category)); - } else { - $categories = (array) $state->category; - } - - $query->where('(tbl.catid IN :category)')->bind(['category' => $categories]); - } - - if(!is_null($state->tags)) - { - if(is_string($state->tags)) { - $tags = array_unique(explode(',', $state->tags)); - } else { - $tags = (array) $state->tags; - } - - $query->where('(t.title IN :tags)')->bind(['tags' => $tags]); - } - - if(!is_null($state->author)) - { - if(is_string($state->author)) { - $users = array_unique(explode(',', $state->author)); - } else { - $users = (array) $state->author; - } - - $query->where('(tbl.created_by IN :authors)')->bind(['authors' => $users]); - } - - if (!is_null($state->editor)) - { - if(is_string($state->editor)) { - $users = array_unique(explode(',', $state->editor)); - } else { - $users = (array) $state->editor; - } - - $query->where('(tbl.modified_by IN :editors)')->bind(['editors' => $users]); - } - - if (!is_null($state->access)) - { - if(is_string($state->access)) { - $access = array_unique(explode(',', $state->access)); - } else { - $access = (array) $state->access; - } - - //If user doesn't have access to the category, he doesn't have access to the articles - $query->where('(tbl.access IN :access)')->bind(['access' => $access]); - $query->where('(c.access IN :access)')->bind(['access' => $access]); - } - - if (!is_null($state->published)) - { - if($state->published) { - $query->where('(tbl.published = 1)'); - } else { - $query->where('(tbl.published = 0'); - } - } - - if (!is_null($state->trashed)) - { - if($state->trashed) { - $query->where('(tbl.trash = 1)'); - } else { - $query->where('(tbl.trash = 0)'); - } - } - - if (!is_null($state->archived)) - { - if($state->archived) { - $query->where('(tbl.publish_down > CURRENT_TIMESTAMP)'); - } else { - $query->where('(tbl.publish_down < CURRENT_TIMESTAMP)'); - } - } - - if (!is_null($state->featured)) { - $query->where('(tbl.featured = :featured)')->bind(['featured' => (bool) $state->featured]); - } - - return $query; - } + public function __construct(KObjectConfig $config) + { + parent::__construct($config); + + $this->getState() + ->insert('id' , 'cmd', null, true) + ->insert('slug' , 'cmd', null, true) + ->insert('category' , 'cmd') + ->insert('tags' , 'cmd') + + ->insert('published' , 'boolean') + ->insert('archived' , 'boolean') + ->insert('trashed' , 'boolean', false) + ->insert('featured' , 'boolean') + + ->insert('author' , 'string') + ->insert('editor' , 'string') + ->insert('access' , 'cmd', array_unique($this->getObject('user')->getRoles())) + ; + } + + protected function _initialize(KObjectConfig $config) + { + $config->append(array( + 'persistable' => false, + 'type' => 'articles', + 'entity' => 'article', + 'table' => 'k2_items', + 'aliases' => array() + )); + parent::_initialize($config); + } + + public function getAliases() + { + return $this->getConfig()->aliases; + } + + public function fetchData($count = false) + { + $state = $this->getState(); + + $query = $this->getObject('database.query.select') + ->table(array('tbl' => $this->getTable()->getName())); + + //#__tags + $query->columns([ + 'tags' => $this->getObject('database.query.select') + ->table(array('t' => 'k2_tags')) + ->columns('GROUP_CONCAT(t.name)') + ->join(['m' => 'k2_tags_xref'], 'm.tagID = t.id') + ->where('m.itemID = tbl.id') + ->where('(t.published = :published)')->bind(['published' => 1]) + ]); + + //#__content + if(!$count) + { + $query->columns([ + 'id' => 'tbl.id', + 'title' => 'tbl.title', + 'slug' => 'tbl.alias', + 'summary' => 'tbl.metadesc', + 'content' => 'CONCAT_WS("", tbl.introtext, IF(LENGTH(tbl.fulltext), tbl.fulltext ,NULL))', + 'category' => 'tbl.catid', + + 'published' => 'tbl.published', + 'archived' => 'IF(tbl.publish_down > CURRENT_TIMESTAMP, 1, 0)', + 'trashed' => 'tbl.trash', + 'featured' => 'tbl.featured', + + 'author' => 'tbl.created_by', + 'editor' => 'GREATEST(tbl.created_by, tbl.modified_by)', + + 'date' => 'tbl.created', + 'edited_date' => 'GREATEST(tbl.created, tbl.modified)', + 'published_date' => 'tbl.publish_up', + 'archived_date' => 'tbl.publish_down', + + 'fields' => 'tbl.extra_fields', + 'parameters' => 'tbl.params', + 'impressions' => 'tbl.hits', + + //Protected properties (for getters) + '_metadata' => 'tbl.metadata', + '_image_caption' => 'tbl.image_caption', + ]); + } + else $query->columns('COUNT(*)'); + + //Joins + $query + ->join(['c' => 'k2_categories'] , 'tbl.catid = c.id') + ->join(['g' => 'usergroups'] , 'tbl.access = g.id') + ->join(['m' => 'k2_tags_xref'] , 'tbl.id = m.itemID') + ->join(['t' => 'k2_tags'] , 't.id = m.tagID'); + + if(!is_null($state->id)) + { + if(is_string($state->id)) { + $articles = array_unique(explode(',', $state->id)); + } else { + $articles = (array) $state->id; + } + + $query->where('(tbl.id IN :articles)')->bind(['articles' => $articles]); + } + else if(!is_null($state->slug)) { + $query->where('(tbl.alias = :article)')->bind(['article' => $state->slug]); + } + + if(!is_null($state->category)) + { + if(is_string($state->category)) { + $categories = array_unique(explode(',', $state->category)); + } else { + $categories = (array) $state->category; + } + + $query->where('(tbl.catid IN :category)')->bind(['category' => $categories]); + } + + if(!is_null($state->tags)) + { + if(is_string($state->tags)) { + $tags = array_unique(explode(',', $state->tags)); + } else { + $tags = (array) $state->tags; + } + + $query->where('(t.title IN :tags)')->bind(['tags' => $tags]); + } + + if(!is_null($state->author)) + { + if(is_string($state->author)) { + $users = array_unique(explode(',', $state->author)); + } else { + $users = (array) $state->author; + } + + $query->where('(tbl.created_by IN :authors)')->bind(['authors' => $users]); + } + + if (!is_null($state->editor)) + { + if(is_string($state->editor)) { + $users = array_unique(explode(',', $state->editor)); + } else { + $users = (array) $state->editor; + } + + $query->where('(tbl.modified_by IN :editors)')->bind(['editors' => $users]); + } + + if (!is_null($state->access)) + { + if(is_string($state->access)) { + $access = array_unique(explode(',', $state->access)); + } else { + $access = (array) $state->access; + } + + //If user doesn't have access to the category, he doesn't have access to the articles + $query->where('(tbl.access IN :access)')->bind(['access' => $access]); + $query->where('(c.access IN :access)')->bind(['access' => $access]); + } + + if (!is_null($state->published)) + { + if($state->published) { + $query->where('(tbl.published = 1)'); + } else { + $query->where('(tbl.published = 0)'); + } + } + + if (!is_null($state->trashed)) + { + if($state->trashed) { + $query->where('(tbl.trash = 1)'); + } else { + $query->where('(tbl.trash = 0)'); + } + } + + if (!is_null($state->archived)) + { + if($state->archived) { + $query->where('(tbl.publish_down > CURRENT_TIMESTAMP)'); + } else { + $query->where('(tbl.publish_down < CURRENT_TIMESTAMP)'); + } + } + + if (!is_null($state->featured)) { + $query->where('(tbl.featured = :featured)')->bind(['featured' => (bool) $state->featured]); + } + + return $query; + } } diff --git a/contrib/k2/model/attachments.php b/contrib/k2/model/attachments.php index 171e624b5..33deb7e42 100644 --- a/contrib/k2/model/attachments.php +++ b/contrib/k2/model/attachments.php @@ -1,4 +1,12 @@ + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + class ExtK2ModelAttachments extends ComPagesModelDatabase { public function __construct(KObjectConfig $config) diff --git a/contrib/k2/model/categories.php b/contrib/k2/model/categories.php index 146915d25..b81baea0d 100644 --- a/contrib/k2/model/categories.php +++ b/contrib/k2/model/categories.php @@ -1,85 +1,93 @@ + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + class ExtK2ModelCategories extends ComPagesModelDatabase { - public function __construct(KObjectConfig $config) - { - parent::__construct($config); + public function __construct(KObjectConfig $config) + { + parent::__construct($config); - $this->getState() - ->insert('id' , 'cmd', null, true) - ->insert('published' , 'bool') - ->insert('access' , 'cmd', array_unique($this->getObject('user')->getRoles())) - ; - } + $this->getState() + ->insert('id' , 'cmd', null, true) + ->insert('published' , 'boolean') + ->insert('access' , 'cmd', array_unique($this->getObject('user')->getRoles())) + ; + } - protected function _initialize(KObjectConfig $config) - { - $config->append(array( - 'persistable' => false, - 'type' => 'article_categories', - 'entity' => 'category', - 'table' => 'k2_categories', - )); - parent::_initialize($config); - } + protected function _initialize(KObjectConfig $config) + { + $config->append(array( + 'persistable' => false, + 'type' => 'article_categories', + 'entity' => 'category', + 'table' => 'k2_categories', + )); + parent::_initialize($config); + } - public function fetchData($count = false) - { - $state = $this->getState(); + public function fetchData($count = false) + { + $state = $this->getState(); - $query = $this->getObject('database.query.select') - ->table(array('tbl' => $this->getTable()->getName())); + $query = $this->getObject('database.query.select') + ->table(array('tbl' => $this->getTable()->getName())); - //#__k2_categories - if(!$count) - { - $query->columns([ - 'id' => 'tbl.id', - 'title' => 'tbl.name', - 'slug' => 'tbl.alias', - 'parent' => 'IF(tbl.parent > 0, tbl.parent, NULL)', - 'content' => 'tbl.description', - 'image' => 'tbl.image', + //#__k2_categories + if(!$count) + { + $query->columns([ + 'id' => 'tbl.id', + 'title' => 'tbl.name', + 'slug' => 'tbl.alias', + 'parent' => 'IF(tbl.parent > 0, tbl.parent, NULL)', + 'content' => 'tbl.description', + 'image' => 'tbl.image', - 'published' => 'tbl.published', + 'published' => 'tbl.published', - 'parameters' => 'tbl.params', - ]); - } - else $query->columns('COUNT(*)'); + 'parameters' => 'tbl.params', + ]); + } + else $query->columns('COUNT(*)'); - if(!is_null($state->id)) - { - if(is_string($state->id)) { - $categories = array_unique(explode(',', $state->id)); - } else { - $categories = (array) $state->id; - } + if(!is_null($state->id)) + { + if(is_string($state->id)) { + $categories = array_unique(explode(',', $state->id)); + } else { + $categories = (array) $state->id; + } - $query->where('(tbl.id IN :categories)')->bind(['categories' => $categories]); - } + $query->where('(tbl.id IN :categories)')->bind(['categories' => $categories]); + } - if (!is_null($state->access)) - { - if(is_string($state->access)) { - $access = array_unique(explode(',', $state->access)); - } else { - $access = (array) $state->access; - } + if (!is_null($state->access)) + { + if(is_string($state->access)) { + $access = array_unique(explode(',', $state->access)); + } else { + $access = (array) $state->access; + } - //If user doesn't have access to the category, he doesn't have access to the articles - $query->where('(tbl.access IN :access)')->bind(['access' => $access]); - } + //If user doesn't have access to the category, he doesn't have access to the articles + $query->where('(tbl.access IN :access)')->bind(['access' => $access]); + } - if (!is_null($state->published)) - { - if($state->published) { - $query->where('(tbl.published = 1)'); - } else { - $query->where('(tbl.published = 0'); - } - } + if (!is_null($state->published)) + { + if($state->published) { + $query->where('(tbl.published = 1)'); + } else { + $query->where('(tbl.published = 0)'); + } + } - return $query; - } + return $query; + } } diff --git a/contrib/k2/model/fields.php b/contrib/k2/model/fields.php index 6741db686..01ae21348 100644 --- a/contrib/k2/model/fields.php +++ b/contrib/k2/model/fields.php @@ -1,79 +1,87 @@ + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + class ExtK2ModelFields extends ComPagesModelDatabase { - public function __construct(KObjectConfig $config) - { - parent::__construct($config); + public function __construct(KObjectConfig $config) + { + parent::__construct($config); - $this->getState() - ->insert('id', 'cmd', null, true) - ->insert('group' , 'int') - ->insert('published' , 'bool'); - } + $this->getState() + ->insert('id', 'cmd', null, true) + ->insert('group' , 'int') + ->insert('published' , 'boolean'); + } - protected function _initialize(KObjectConfig $config) - { - $config->append(array( - 'persistable' => false, - 'type' => 'article_fields', - 'entity' => 'field', - 'table' => 'k2_extra_fields', - )); - parent::_initialize($config); - } + protected function _initialize(KObjectConfig $config) + { + $config->append(array( + 'persistable' => false, + 'type' => 'article_fields', + 'entity' => 'field', + 'table' => 'k2_extra_fields', + )); + parent::_initialize($config); + } - public function fetchData($count = false) - { - $state = $this->getState(); + public function fetchData($count = false) + { + $state = $this->getState(); - $query = $this->getObject('database.query.select') - ->table(array('tbl' => $this->getTable()->getName())); + $query = $this->getObject('database.query.select') + ->table(array('tbl' => $this->getTable()->getName())); - if(!$count) - { - $query->columns([ - 'id' => 'tbl.id', - 'title' => 'tbl.name', - 'type' => 'tbl.type', - 'published' => 'tbl.published', + if(!$count) + { + $query->columns([ + 'id' => 'tbl.id', + 'title' => 'tbl.name', + 'type' => 'tbl.type', + 'published' => 'tbl.published', - //Protected properties (for getters) - '_value' => 'tbl.value', - ]); - } - else $query->columns('COUNT(*)'); + //Protected properties (for getters) + '_value' => 'tbl.value', + ]); + } + else $query->columns('COUNT(*)'); - if(!is_null($state->id)) - { - if(is_string($state->id)) { - $fields = array_unique(explode(',', $state->id)); - } else { - $fields = (array) $state->id; - } + if(!is_null($state->id)) + { + if(is_string($state->id)) { + $fields = array_unique(explode(',', $state->id)); + } else { + $fields = (array) $state->id; + } - $query->where('(tbl.id IN :fields)')->bind(['fields' => $fields]); - } + $query->where('(tbl.id IN :fields)')->bind(['fields' => $fields]); + } - if(!is_null($state->group)) - { - if(is_string($state->group)) { - $groups = array_unique(explode(',', $state->group)); - } else { - $groups = (array) $state->group; - } + if(!is_null($state->group)) + { + if(is_string($state->group)) { + $groups = array_unique(explode(',', $state->group)); + } else { + $groups = (array) $state->group; + } - $query->where('(tbl.group IN :groups)')->bind(['groups' => $groups]); - } + $query->where('(tbl.group IN :groups)')->bind(['groups' => $groups]); + } - if (!is_null($state->published)) - { - if($state->published) { - $query->where('(tbl.published = 1)'); - } else { - $query->where('(tbl.published = 0'); - } - } + if (!is_null($state->published)) + { + if($state->published) { + $query->where('(tbl.published = 1)'); + } else { + $query->where('(tbl.published = 0)'); + } + } - return $query; - } + return $query; + } } From 415edf88757f7990c251f284f36b2c88fef53184 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Fri, 19 Jun 2020 00:39:36 +0200 Subject: [PATCH 05/19] #364 - Add article template method to easily retrieve a single article by id, or alias --- contrib/k2/template/function/article.php | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 contrib/k2/template/function/article.php diff --git a/contrib/k2/template/function/article.php b/contrib/k2/template/function/article.php new file mode 100644 index 000000000..7f0859277 --- /dev/null +++ b/contrib/k2/template/function/article.php @@ -0,0 +1,27 @@ + + * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository + */ + +return function($id) +{ + static $entities; + + if(!isset($entities[$id])) + { + //Check if an alias exists + $id = $this->getObject('ext:k2.model.articles')->getAliases()->get($id, $id); + + if(is_numeric($id)) { + $entities[$id] = $this->getObject('ext:k2.model.articles')->id($id)->fetch(); + } else { + $entities[$id] = $this->getObject('ext:k2.model.articles')->slug($id)->fetch(); + } + } + + return $entities[$id]; +}; From 737f33670a5265a9e222a170a72436c12b1769a3 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sat, 29 Aug 2020 02:52:00 +0200 Subject: [PATCH 06/19] Fix issue with count queries Do not include the tags when counting --- contrib/k2/model/articles.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/contrib/k2/model/articles.php b/contrib/k2/model/articles.php index 085e163cf..39d601caa 100644 --- a/contrib/k2/model/articles.php +++ b/contrib/k2/model/articles.php @@ -54,19 +54,20 @@ public function fetchData($count = false) $query = $this->getObject('database.query.select') ->table(array('tbl' => $this->getTable()->getName())); - //#__tags - $query->columns([ - 'tags' => $this->getObject('database.query.select') - ->table(array('t' => 'k2_tags')) - ->columns('GROUP_CONCAT(t.name)') - ->join(['m' => 'k2_tags_xref'], 'm.tagID = t.id') - ->where('m.itemID = tbl.id') - ->where('(t.published = :published)')->bind(['published' => 1]) - ]); - //#__content if(!$count) { + //#__tags + $query->columns([ + 'tags' => $this->getObject('database.query.select') + ->table(array('t' => 'k2_tags')) + ->columns('GROUP_CONCAT(t.name)') + ->join(['m' => 'k2_tags_xref'], 'm.tagID = t.id') + ->where('m.itemID = tbl.id') + ->where('(t.published = :published)')->bind(['published' => 1]) + ]); + + $query->columns([ 'id' => 'tbl.id', 'title' => 'tbl.title', From f8f7e67a37189538f957480415878b45ebc49e57 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Thu, 15 Oct 2020 10:41:36 +0200 Subject: [PATCH 07/19] Fix typo --- contrib/k2/model/entity/article.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/k2/model/entity/article.php b/contrib/k2/model/entity/article.php index 2b976713f..4d0fc694b 100644 --- a/contrib/k2/model/entity/article.php +++ b/contrib/k2/model/entity/article.php @@ -7,7 +7,7 @@ * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository */ -class ExtK2ModelEntityArticle extends ExtJoomlaModelEntityAbstract +class ExtK2ModelEntityArticle extends ExtK2ModelEntityAbstract { protected function _initialize(KObjectConfig $config) { From 8029049d20183bff2b83456ed01d8f5f47ba1520 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Thu, 15 Oct 2020 10:42:07 +0200 Subject: [PATCH 08/19] Fix typo --- contrib/k2/model/entity/category.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/k2/model/entity/category.php b/contrib/k2/model/entity/category.php index d593596f4..1edbe38e9 100644 --- a/contrib/k2/model/entity/category.php +++ b/contrib/k2/model/entity/category.php @@ -7,7 +7,7 @@ * @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository */ -class ExtK2ModelEntityCategory extends ExtJoomlaModelEntityAbstract +class ExtK2ModelEntityCategory extends ExtK2ModelEntityAbstract { protected function _initialize(KObjectConfig $config) { From aa56173dff6042d3bf2367d34f006020cd68bc27 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sun, 1 Nov 2020 11:47:46 +0100 Subject: [PATCH 09/19] Return fields and attachments as entities --- contrib/k2/model/entity/article.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/contrib/k2/model/entity/article.php b/contrib/k2/model/entity/article.php index 4d0fc694b..69385cdbb 100644 --- a/contrib/k2/model/entity/article.php +++ b/contrib/k2/model/entity/article.php @@ -132,17 +132,11 @@ public function getPropertyMetadata() public function getPropertyAttachments() { - $attachments = array(); - //Get the single category - $rows = $this->getObject('ext:k2.model.attachments') + $attachments = $this->getObject('ext:k2.model.attachments') ->article($this->id) ->fetch(); - foreach($rows as $row) { - $attachments[] = $row; - } - return $attachments; } @@ -234,7 +228,7 @@ public function setPropertyFields($value) if(!empty($value)) { //Get the single field - $rows = $this->getObject('ext:k2.model.fields') + $fields = $this->getObject('ext:k2.model.fields') ->id(array_column($value, 'id')) ->fetch(); @@ -244,13 +238,11 @@ public function setPropertyFields($value) { //Set the value $field->value = $v['value']; - - //Add the field - $fields[] = $field; } } } } + else $fields = $this->getObject('ext:k2.model.fields')->create() return $fields; } From 09883be6a48f7c7cabe08178653cf8bc37a5de53 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sun, 1 Nov 2020 11:50:11 +0100 Subject: [PATCH 10/19] Ensure we always return a fields entity --- contrib/k2/model/entity/article.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/contrib/k2/model/entity/article.php b/contrib/k2/model/entity/article.php index 69385cdbb..d18b2b8f1 100644 --- a/contrib/k2/model/entity/article.php +++ b/contrib/k2/model/entity/article.php @@ -217,28 +217,23 @@ public function setPropertyArchivedDate($value) public function setPropertyFields($value) { - $fields = null; + if($value && is_string($value)) { + $value = json_decode($value, true); + } - if($value) + if($value && !empty($value)) { - if(is_string($value)) { - $value = json_decode($value, true); - } + //Get the single field + $fields = $this->getObject('ext:k2.model.fields') + ->id(array_column($value, 'id')) + ->fetch(); - if(!empty($value)) + foreach($value as $v) { - //Get the single field - $fields = $this->getObject('ext:k2.model.fields') - ->id(array_column($value, 'id')) - ->fetch(); - - foreach($value as $v) + if($field = $rows->find($v['id'])) { - if($field = $rows->find($v['id'])) - { - //Set the value - $field->value = $v['value']; - } + //Set the value + $field->value = $v['value']; } } } From 10e5ab6606ca2afabbc780fc4daf2168996e7e2e Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sun, 1 Nov 2020 23:44:50 +0100 Subject: [PATCH 11/19] Check if value is empty --- contrib/k2/model/entity/article.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/k2/model/entity/article.php b/contrib/k2/model/entity/article.php index d18b2b8f1..5ed9b9e3d 100644 --- a/contrib/k2/model/entity/article.php +++ b/contrib/k2/model/entity/article.php @@ -244,7 +244,7 @@ public function setPropertyFields($value) public function setPropertyParameters($value) { - if(is_string($value)) { + if($value && is_string($value)) { $value = json_decode($value, true); } From 685276a6a3ea822e52fce4870e76c09f0701bdb1 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sun, 1 Nov 2020 23:45:13 +0100 Subject: [PATCH 12/19] Check if value is empty --- contrib/k2/model/entity/category.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/k2/model/entity/category.php b/contrib/k2/model/entity/category.php index 1edbe38e9..c1979daac 100644 --- a/contrib/k2/model/entity/category.php +++ b/contrib/k2/model/entity/category.php @@ -92,7 +92,7 @@ public function setPropertyImage($value) public function setPropertyParameters($value) { - if(is_string($value)) { + if($value && is_string($value)) { $value = json_decode($value, true); } From b459d4a4d236413b1c3c4cacf6c7e2b26f57b4ea Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Mon, 2 Nov 2020 08:31:29 +0100 Subject: [PATCH 13/19] Rename article.php to k2_article.php --- contrib/k2/template/function/{article.php => k2_article.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/k2/template/function/{article.php => k2_article.php} (100%) diff --git a/contrib/k2/template/function/article.php b/contrib/k2/template/function/k2_article.php similarity index 100% rename from contrib/k2/template/function/article.php rename to contrib/k2/template/function/k2_article.php From 752187b8946d99fcbaf13f09d38c80d6aa658742 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Fri, 26 Feb 2021 01:49:53 +0100 Subject: [PATCH 14/19] #1364 - Move code to /contrib/extensions --- contrib/{ => extensions}/k2/model/articles.php | 0 contrib/{ => extensions}/k2/model/attachments.php | 0 contrib/{ => extensions}/k2/model/categories.php | 0 contrib/{ => extensions}/k2/model/entity/abstract.php | 0 contrib/{ => extensions}/k2/model/entity/article.php | 0 contrib/{ => extensions}/k2/model/entity/attachment.php | 0 contrib/{ => extensions}/k2/model/entity/category.php | 0 contrib/{ => extensions}/k2/model/entity/field.php | 0 contrib/{ => extensions}/k2/model/fields.php | 0 contrib/{ => extensions}/k2/template/function/k2_article.php | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename contrib/{ => extensions}/k2/model/articles.php (100%) rename contrib/{ => extensions}/k2/model/attachments.php (100%) rename contrib/{ => extensions}/k2/model/categories.php (100%) rename contrib/{ => extensions}/k2/model/entity/abstract.php (100%) rename contrib/{ => extensions}/k2/model/entity/article.php (100%) rename contrib/{ => extensions}/k2/model/entity/attachment.php (100%) rename contrib/{ => extensions}/k2/model/entity/category.php (100%) rename contrib/{ => extensions}/k2/model/entity/field.php (100%) rename contrib/{ => extensions}/k2/model/fields.php (100%) rename contrib/{ => extensions}/k2/template/function/k2_article.php (100%) diff --git a/contrib/k2/model/articles.php b/contrib/extensions/k2/model/articles.php similarity index 100% rename from contrib/k2/model/articles.php rename to contrib/extensions/k2/model/articles.php diff --git a/contrib/k2/model/attachments.php b/contrib/extensions/k2/model/attachments.php similarity index 100% rename from contrib/k2/model/attachments.php rename to contrib/extensions/k2/model/attachments.php diff --git a/contrib/k2/model/categories.php b/contrib/extensions/k2/model/categories.php similarity index 100% rename from contrib/k2/model/categories.php rename to contrib/extensions/k2/model/categories.php diff --git a/contrib/k2/model/entity/abstract.php b/contrib/extensions/k2/model/entity/abstract.php similarity index 100% rename from contrib/k2/model/entity/abstract.php rename to contrib/extensions/k2/model/entity/abstract.php diff --git a/contrib/k2/model/entity/article.php b/contrib/extensions/k2/model/entity/article.php similarity index 100% rename from contrib/k2/model/entity/article.php rename to contrib/extensions/k2/model/entity/article.php diff --git a/contrib/k2/model/entity/attachment.php b/contrib/extensions/k2/model/entity/attachment.php similarity index 100% rename from contrib/k2/model/entity/attachment.php rename to contrib/extensions/k2/model/entity/attachment.php diff --git a/contrib/k2/model/entity/category.php b/contrib/extensions/k2/model/entity/category.php similarity index 100% rename from contrib/k2/model/entity/category.php rename to contrib/extensions/k2/model/entity/category.php diff --git a/contrib/k2/model/entity/field.php b/contrib/extensions/k2/model/entity/field.php similarity index 100% rename from contrib/k2/model/entity/field.php rename to contrib/extensions/k2/model/entity/field.php diff --git a/contrib/k2/model/fields.php b/contrib/extensions/k2/model/fields.php similarity index 100% rename from contrib/k2/model/fields.php rename to contrib/extensions/k2/model/fields.php diff --git a/contrib/k2/template/function/k2_article.php b/contrib/extensions/k2/template/function/k2_article.php similarity index 100% rename from contrib/k2/template/function/k2_article.php rename to contrib/extensions/k2/template/function/k2_article.php From f9052adc41f93a42d9a07c771e42e77e6b688e05 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sun, 7 Mar 2021 19:56:12 +0100 Subject: [PATCH 15/19] #364 - Sync with changes in 0.19.7 --- contrib/extensions/k2/model/articles.php | 8 ++++---- contrib/extensions/k2/model/attachments.php | 6 +++--- contrib/extensions/k2/model/categories.php | 6 +++--- contrib/extensions/k2/model/fields.php | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/extensions/k2/model/articles.php b/contrib/extensions/k2/model/articles.php index 39d601caa..d72b4e504 100644 --- a/contrib/extensions/k2/model/articles.php +++ b/contrib/extensions/k2/model/articles.php @@ -14,8 +14,8 @@ public function __construct(KObjectConfig $config) parent::__construct($config); $this->getState() - ->insert('id' , 'cmd', null, true) - ->insert('slug' , 'cmd', null, true) + ->insertUnique('id' , 'cmd') + ->insertUnique('slug', 'cmd') ->insert('category' , 'cmd') ->insert('tags' , 'cmd') @@ -47,7 +47,7 @@ public function getAliases() return $this->getConfig()->aliases; } - public function fetchData($count = false) + public function getQuery($columns = true) { $state = $this->getState(); @@ -55,7 +55,7 @@ public function fetchData($count = false) ->table(array('tbl' => $this->getTable()->getName())); //#__content - if(!$count) + if($columns) { //#__tags $query->columns([ diff --git a/contrib/extensions/k2/model/attachments.php b/contrib/extensions/k2/model/attachments.php index 33deb7e42..2d15b4d52 100644 --- a/contrib/extensions/k2/model/attachments.php +++ b/contrib/extensions/k2/model/attachments.php @@ -14,7 +14,7 @@ public function __construct(KObjectConfig $config) parent::__construct($config); $this->getState() - ->insert('id', 'cmd', null, true) + ->insertUnique('id', 'cmd') ->insert('article', 'int'); } @@ -29,14 +29,14 @@ protected function _initialize(KObjectConfig $config) parent::_initialize($config); } - public function fetchData($count = false) + public function getQuery($columns = true) { $state = $this->getState(); $query = $this->getObject('database.query.select') ->table(array('tbl' => $this->getTable()->getName())); - if(!$count) + if($columns) { $query->columns([ 'id' => 'tbl.id', diff --git a/contrib/extensions/k2/model/categories.php b/contrib/extensions/k2/model/categories.php index b81baea0d..42bacc59e 100644 --- a/contrib/extensions/k2/model/categories.php +++ b/contrib/extensions/k2/model/categories.php @@ -14,7 +14,7 @@ public function __construct(KObjectConfig $config) parent::__construct($config); $this->getState() - ->insert('id' , 'cmd', null, true) + ->insertUnique('id' , 'cmd') ->insert('published' , 'boolean') ->insert('access' , 'cmd', array_unique($this->getObject('user')->getRoles())) ; @@ -31,7 +31,7 @@ protected function _initialize(KObjectConfig $config) parent::_initialize($config); } - public function fetchData($count = false) + public function getQuery($columns = true) { $state = $this->getState(); @@ -39,7 +39,7 @@ public function fetchData($count = false) ->table(array('tbl' => $this->getTable()->getName())); //#__k2_categories - if(!$count) + if($columns) { $query->columns([ 'id' => 'tbl.id', diff --git a/contrib/extensions/k2/model/fields.php b/contrib/extensions/k2/model/fields.php index 01ae21348..11689d77e 100644 --- a/contrib/extensions/k2/model/fields.php +++ b/contrib/extensions/k2/model/fields.php @@ -14,7 +14,7 @@ public function __construct(KObjectConfig $config) parent::__construct($config); $this->getState() - ->insert('id', 'cmd', null, true) + ->insertUnique('id', 'cmd') ->insert('group' , 'int') ->insert('published' , 'boolean'); } @@ -30,14 +30,14 @@ protected function _initialize(KObjectConfig $config) parent::_initialize($config); } - public function fetchData($count = false) + public function getQuery($columns = true) { $state = $this->getState(); $query = $this->getObject('database.query.select') ->table(array('tbl' => $this->getTable()->getName())); - if(!$count) + if($columns) { $query->columns([ 'id' => 'tbl.id', From af03e00aeb6b69ec33ae6bb9b217e07b4374789f Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sun, 7 Mar 2021 19:58:09 +0100 Subject: [PATCH 16/19] #364 - Sync with changes in 0.19.7 --- contrib/extensions/k2/model/articles.php | 1 - contrib/extensions/k2/model/attachments.php | 1 - contrib/extensions/k2/model/categories.php | 1 - contrib/extensions/k2/model/fields.php | 1 - 4 files changed, 4 deletions(-) diff --git a/contrib/extensions/k2/model/articles.php b/contrib/extensions/k2/model/articles.php index d72b4e504..50cbf40f4 100644 --- a/contrib/extensions/k2/model/articles.php +++ b/contrib/extensions/k2/model/articles.php @@ -98,7 +98,6 @@ public function getQuery($columns = true) '_image_caption' => 'tbl.image_caption', ]); } - else $query->columns('COUNT(*)'); //Joins $query diff --git a/contrib/extensions/k2/model/attachments.php b/contrib/extensions/k2/model/attachments.php index 2d15b4d52..7bfb2a58d 100644 --- a/contrib/extensions/k2/model/attachments.php +++ b/contrib/extensions/k2/model/attachments.php @@ -46,7 +46,6 @@ public function getQuery($columns = true) 'impressions' => 'tbl.hits', ]); } - else $query->columns('COUNT(*)'); if(!is_null($state->id)) { diff --git a/contrib/extensions/k2/model/categories.php b/contrib/extensions/k2/model/categories.php index 42bacc59e..88fdc02d9 100644 --- a/contrib/extensions/k2/model/categories.php +++ b/contrib/extensions/k2/model/categories.php @@ -54,7 +54,6 @@ public function getQuery($columns = true) 'parameters' => 'tbl.params', ]); } - else $query->columns('COUNT(*)'); if(!is_null($state->id)) { diff --git a/contrib/extensions/k2/model/fields.php b/contrib/extensions/k2/model/fields.php index 11689d77e..4ef717b06 100644 --- a/contrib/extensions/k2/model/fields.php +++ b/contrib/extensions/k2/model/fields.php @@ -49,7 +49,6 @@ public function getQuery($columns = true) '_value' => 'tbl.value', ]); } - else $query->columns('COUNT(*)'); if(!is_null($state->id)) { From 3089e98ac7aff1860e844a52c58e17d4387812af Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Sun, 7 Mar 2021 23:05:47 +0100 Subject: [PATCH 17/19] #364 - Sync with changes in 0.19.7 --- contrib/extensions/k2/model/entity/abstract.php | 4 ++-- contrib/extensions/k2/model/entity/article.php | 6 +++--- contrib/extensions/k2/model/entity/category.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/extensions/k2/model/entity/abstract.php b/contrib/extensions/k2/model/entity/abstract.php index 44ebe260b..a589cbf02 100644 --- a/contrib/extensions/k2/model/entity/abstract.php +++ b/contrib/extensions/k2/model/entity/abstract.php @@ -79,7 +79,7 @@ public function getPropertyMetadata() } //Remove empty values - $metadata = new KObjectConfigJson($metadata); + $metadata = new ComPagesObjectConfig($metadata); $metadata->append($this->getConfig()->data->metadata); if(!isset($metadata->description) && $this->summary) { @@ -132,7 +132,7 @@ public function setPropertyDate($value) public function setPropertyParameters($value) { - return new KObjectConfigJson($value); + return new ComPagesObjectConfig($value); } public function getBasePath() diff --git a/contrib/extensions/k2/model/entity/article.php b/contrib/extensions/k2/model/entity/article.php index 5ed9b9e3d..252a213ff 100644 --- a/contrib/extensions/k2/model/entity/article.php +++ b/contrib/extensions/k2/model/entity/article.php @@ -104,7 +104,7 @@ public function getPropertyImage() ]; } - return new KObjectConfigJson($image); + return new ComPagesObjectConfig($image); } public function getPropertyMetadata() @@ -150,7 +150,7 @@ public function setPropertyTags($value) } else $value = []; - return new KObjectConfigJson($value); + return new ComPagesObjectConfig($value); } public function setPropertyCategory($value) @@ -250,7 +250,7 @@ public function setPropertyParameters($value) //$params = JComponentHelper::getParams('com_k2')->toArray(); - $config = new KObjectConfigJson(/*$params*/); + $config = new ComPagesObjectConfig(/*$params*/); $config->merge($value); // Override global params with specific params return $config; diff --git a/contrib/extensions/k2/model/entity/category.php b/contrib/extensions/k2/model/entity/category.php index c1979daac..c5c9a005b 100644 --- a/contrib/extensions/k2/model/entity/category.php +++ b/contrib/extensions/k2/model/entity/category.php @@ -87,7 +87,7 @@ public function setPropertyImage($value) } } - return new KObjectConfigJson($image); + return new ComPagesObjectConfig($image); } public function setPropertyParameters($value) @@ -98,7 +98,7 @@ public function setPropertyParameters($value) //$params = JComponentHelper::getParams('com_k2')->toArray(); - $config = new KObjectConfigJson(/*$params*/); + $config = new ComPagesObjectConfig(/*$params*/); $config->merge($value); // Override global params with article specific params return $config; From 71328cc1fe8714384712eb4feadd6293370c03eb Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Thu, 18 Mar 2021 01:45:53 +0100 Subject: [PATCH 18/19] #364 - Fix typo --- contrib/extensions/k2/model/entity/article.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/extensions/k2/model/entity/article.php b/contrib/extensions/k2/model/entity/article.php index 252a213ff..abdfc8ffb 100644 --- a/contrib/extensions/k2/model/entity/article.php +++ b/contrib/extensions/k2/model/entity/article.php @@ -237,7 +237,7 @@ public function setPropertyFields($value) } } } - else $fields = $this->getObject('ext:k2.model.fields')->create() + else $fields = $this->getObject('ext:k2.model.fields')->create(); return $fields; } From a18dedba199e848445f703fdb272a4f461af44b9 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Thu, 18 Mar 2021 01:54:58 +0100 Subject: [PATCH 19/19] #364 - Fix typo --- contrib/extensions/k2/model/entity/article.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/extensions/k2/model/entity/article.php b/contrib/extensions/k2/model/entity/article.php index abdfc8ffb..5b75c893e 100644 --- a/contrib/extensions/k2/model/entity/article.php +++ b/contrib/extensions/k2/model/entity/article.php @@ -230,7 +230,7 @@ public function setPropertyFields($value) foreach($value as $v) { - if($field = $rows->find($v['id'])) + if($field = $fields->find($v['id'])) { //Set the value $field->value = $v['value'];