<commit_before><?php
namespace Wiki\Domain;

use Wiki\Domain\Manager\PageManager;
use Wiki\Domain\Manager\CategoryManager;
use Wiki\Domain\Manager\CategoryPageManager;
use Wiki\Domain\Manager\PageLinkManager;
use Wiki\Domain\Manager\PageMetaManager;
use Wiki\Exception\AuthorizationMissingException;
use Wiki\Exception\PagenameAlreadyTakenException;
use Wiki\Exception\CannotDeleteHomepageException;
use Wiki\Tools\StringTools;

/**
 * @table pagemeta
 * @author <NAME> <<EMAIL>>
 * @version 0.1
 * @since 0.1
 */
class PageMeta extends Domain
{
	//
	// CONSTRUCTOR
	//

	/**
	 * @author <NAME> <<EMAIL>>
	 * @version 0.1
	 * @since 0.1
	 */
	public function __construct() {
			
	}

	//
	// METHODS
	//

	public function jsonSerialize() {
			
		return [
			"data" => $this->data
		];
	}

	public function Save() {

		$this->data = json_encode($this->data);
		$success = parent::Save();
		$this->data = json_decode($this->data);

		return $success;
	}

	public function Delete() {
		return parent::Delete();
	}

	protected function CalculateChecksum() {
		return md5($this->Status.$this->page->ID.$this->user->ID.$this->data);
	}

	public function __tostring() {
		return (string) $this->data;
	}

	//
	// ATTRIBUTES
	//

	/**
	 * @field page_id
	 */
	protected $page;

	/**
	 * @field user_id
	 */
	protected $user;

	/**
	 * @field data
	 */
	protected $data;

	  //
	 // GETTERS / SETTERS
	//

	# Page

	/**
	 * @author <NAME> <<EMAIL>>
	* @version 0.1
	* @since 0.1
	*/
	protected function GetPage() {
		return $this->page;
	}

	/**
	 * @author <NAME> <<EMAIL>>
	 * @version 0.1
	 * @since 0.1
	 */
	protected function SetPage(Page $value) {
		$this->page = $value;
	}

	# User

	/**
	 * @author <NAME> <<EMAIL>>
	* @version 0.1
	* @since 0.1
	*/
	protected function GetUser() {
		return $this->user;
	}

	/**
	 * @author <NAME> <<EMAIL>>
	 * @version 0.1
	 * @since 0.1
	 */
	protected function SetUser(User $value) {
		$this->user = $value;
	}

	# Data

	/**
	 * @author <NAME> <<EMAIL>>
	* @version 0.1
	* @since 0.1
	*/
	protected function GetData() {
		return $this->data;
	}

	/**
	 * @author <NAME> <<EMAIL>>
	 * @version 0.1
	 * @since 0.1
	 */
	protected function SetData($value) {
		$this->data = $value;
	}

	  //
	 // FUNCTIONS
	//

	public static function LoadMetaData(Page $page, User $user)
	{
		$metaManager = PageMetaManager::GetInstance();

		if(!self::$currentGlobalPageMeta) {
			self::$currentGlobalPageMeta = $metaManager->GetGlobalByPage($page);
		}

		if(!self::$currentUserPageMeta) {
			self::$currentUserPageMeta = $metaManager->GetByPageAndUser($page, $user);
		}

		$globalMeta = self::$currentGlobalPageMeta;
		$userMeta = self::$currentUserPageMeta;

		if($globalMeta) {
			$globalMeta = json_decode($globalMeta->Data);
		} else {
			$globalMeta = [];
		}

		if($userMeta)
		{
			$userMeta = json_decode($userMeta->Data);
		}
		else
		{
			$userMeta = [];
		}

		$meta = array_merge_recursive($globalMeta, $userMeta);

		return $meta;
	}

	public static function AddMetaData($key, $value, Page $page, User $user = null)
	{
		$metaManager = PageMetaManager::GetInstance();

		if(!self::$currentGlobalPageMeta) {
			self::$currentGlobalPageMeta = $metaManager->GetGlobalByPage($page);
		}

		if(!self::$currentUserPageMeta) {
			self::$currentUserPageMeta = $metaManager->GetByPageAndUser($page, $user);<commit_msg>Removed json_decode in meta loader<commit_after><?php
namespace Wiki\Domain;

use Wiki\Domain\Manager\PageManager;
use Wiki\Domain\Manager\CategoryManager;
use Wiki\Domain\Manager\CategoryPageManager;
use Wiki\Domain\Manager\PageLinkManager;
use Wiki\Domain\Manager\PageMetaManager;
use Wiki\Exception\AuthorizationMissingException;
use Wiki\Exception\PagenameAlreadyTakenException;
use Wiki\Exception\CannotDeleteHomepageException;
use Wiki\Tools\StringTools;

/**
 * @table pagemeta
 * @author <NAME> <<EMAIL>>
 * @version 0.1
 * @since 0.1
 */
class PageMeta extends Domain
{
	//
	// CONSTRUCTOR
	//

	/**
	 * @author <NAME> <<EMAIL>>
	 * @version 0.1
	 * @since 0.1
	 */
	public function __construct() {
			
	}

	//
	// METHODS
	//

	public function jsonSerialize() {
			
		return [
			"data" => $this->data
		];
	}

	public function Save() {

		$this->data = json_encode($this->data);
		$success = parent::Save();
		$this->data = json_decode($this->data);

		return $success;
	}

	public function Delete() {
		return parent::Delete();
	}

	protected function CalculateChecksum() {
		return md5($this->Status.$this->page->ID.$this->user->ID.$this->data);
	}

	public function __tostring() {
		return (string) $this->data;
	}

	//
	// ATTRIBUTES
	//

	/**
	 * @field page_id
	 */
	protected $page;

	/**
	 * @field user_id
	 */
	protected $user;

	/**
	 * @field data
	 */
	protected $data;

	  //
	 // GETTERS / SETTERS
	//

	# Page

	/**
	 * @author <NAME> <<EMAIL>>
	* @version 0.1
	* @since 0.1
	*/
	protected function GetPage() {
		return $this->page;
	}

	/**
	 * @author <NAME> <<EMAIL>>
	 * @version 0.1
	 * @since 0.1
	 */
	protected function SetPage(Page $value) {
		$this->page = $value;
	}

	# User

	/**
	 * @author <NAME> <<EMAIL>>
	* @version 0.1
	* @since 0.1
	*/
	protected function GetUser() {
		return $this->user;
	}

	/**
	 * @author <NAME> <<EMAIL>>
	 * @version 0.1
	 * @since 0.1
	 */
	protected function SetUser(User $value) {
		$this->user = $value;
	}

	# Data

	/**
	 * @author <NAME> <<EMAIL>>
	* @version 0.1
	* @since 0.1
	*/
	protected function GetData() {
		return $this->data;
	}

	/**
	 * @author <NAME> <<EMAIL>>
	 * @version 0.1
	 * @since 0.1
	 */
	protected function SetData($value) {
		$this->data = $value;
	}

	  //
	 // FUNCTIONS
	//

	public static function LoadMetaData(Page $page, User $user)
	{
		$metaManager = PageMetaManager::GetInstance();

		if(!self::$currentGlobalPageMeta) {
			self::$currentGlobalPageMeta = $metaManager->GetGlobalByPage($page);
		}

		if(!self::$currentUserPageMeta) {
			self::$currentUserPageMeta = $metaManager->GetByPageAndUser($page, $user);
		}

		$globalMeta = self::$currentGlobalPageMeta;
		$userMeta = self::$currentUserPageMeta;

		if($globalMeta) {
			$globalMeta = $globalMeta->Data;
		} else {
			$globalMeta = [];
		}

		if($userMeta)
		{
			$userMeta = $userMeta->Data;
		}
		else
		{
			$userMeta = [];
		}

		$meta = array_merge_recursive($globalMeta, $userMeta);

		return $meta;
	}

	public static function AddMetaData($key, $value, Page $page, User $user = null)
	{
		$metaManager = PageMetaManager::GetInstance();

		if(!self::$currentGlobalPageMeta) {
			self::$currentGlobalPageMeta = $metaManager->GetGlobalByPage($page);
		}

		if(!self::$currentUserPageMeta) {
			self::$currentUserPageMeta = $metaManager->GetByPageAndUser($page, $user);
{'fraction_non_alphanumeric': 0.1731200478397369, 'fraction_numerical': 0.009866945731798474, 'mean_word_length': 3.398422090729783, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7294780', 'n_tokens_mistral': 2646, 'n_tokens_neox': 2361, 'n_words': 455}