<commit_before><?php
/**
 * This file contains class Model, the base class for all Models including Account
 */


namespace Jeff\Api\Models;
use Jeff\Api as Api;


/**
 *	This is the base class for all models.
 *	Includes getters and setters as far as they can be generalized
 *	This class shall be extended by consuming app to define the app-specific models.
 *	Many of the parameters and methods shall be overridden.
 *	
 *	@author <NAME>
 *	@copyright Copyright (c) 2015-2016
 *	@license   private
 *	@version   1.8.1
 */
Class Model 
{

	/**
	* The name of the model. e.g. "Post", "Comment"
	*
	*  a modelName __MUST NOT__ include a '2', because otherwise it'll be treated as a relational-model.
	*  Shall be overridden
	* @var string The name of the model. e.g. "Post", "Comment"
	*/
	protected $modelName = null;
	
	/** @var string the plural version of $modelName */
	protected $modelNamePlural = null;
	
	/**
	*
	* Name of parent Model.
	* __Not used til now (2018)__
	* this will be needed to make a bubbleUp method, 
	* to determine all the mother-models of a grand-child model such as a track, 
	* that belongsTo an artistgroup, an production, a workgroup
	* will be needed to figure out if a user may edit/delete an item or not
	*
	* @var string Name of parent model
	*/
	protected $motherModel = null; 


	/**
	*
	* Database-Table definition to be used by {@see DBHelper} class to create the corresponding table
	* usually to be overriden in class that extends model-class.
	* an array with this specification:
	* 
	* ```
	* public $dbDefinition = Array(
	*		string $fieldName, 			// 'id', 'email', 'label',..
	*		string $fieldType, 			//	'int', 'varchar', 'timestamp',..
	*		string|NULL $fieldLength, 	// '11', '250', NULL
	*		boolean $canBeNull, 		// true, false
	*		mixed $defaultValue, 		// '', NULL, 
	*		string $special  			// 'auto_increment', 'on update CURRENT_TIMESTAMP'
	* );
	* ```
	* 
	* so a typical dbDefinition could look like this:
	* 
	* ```
	* public $dbDefinition = Array(
	* 		array ('id', 'int', '11', false, NULL, 'auto_increment'),
	* 		array ('email', 'varchar', '80', false),
	* 		array ('password', 'varchar', '<PASSWORD>', true),
	* 		array ('rights', 'tinyint', '4', false, '0'),
	* 		array ('authToken', 'varchar', '250', true),
	* 		array ('refreshToken', 'varchar', '250', true),
	* 		array ('fullName', 'varchar', '80', false, ''),
	* 		array ('firstName', 'varchar', '20', false, ''),
	* 		array ('middleName', 'varchar', '20', false, ''),
	* 		array ('prefixName', 'varchar', '20', false, ''),
	* 		array ('lastName', 'varchar', '30', false, ''),
	* 		array ('profilePic', 'varchar', '100', false, ''),
	* 		array ('lastOnline', 'timestamp', null, true),
	* 		array ('lastLogin', 'timestamp', null, true),
	* 		array ('invitationToken', 'varchar', '250', true),
	* 		array ('invitedBy', 'int', '11', true),
	* 		array ('modDate', 'timestamp', NULL, false, 'CURRENT_TIMESTAMP', 'on update CURRENT_TIMESTAMP'),
	* 		array ('modBy', 'int', '11', true),
	* 	);
	* ```
	*
	* @var array $dbDefinition Database-Table definition
	* @see DBHelper
	* 
	*/
	protected $dbDefinition = array();


	/** @var string field-name in which api will store the last account-id that changed/created an item. Can be NULL */
	public $modifiedByField = 'modBy';
	/** @var boolean Models with isSortable=true MUST have a field 'sort' in dbTable */
	public $isSortable = false;
	/** @var string If a model is sortable it usually has a parent-model as group 
	*               For example if you want comments to be sortable, then this would be 'post' - the reference to the parent
	*/
	public $sortBy = 'referenceField';


	/** 
	* @var string typically 'role' or 'rights'
	* many2many-references often have a value that describe that relationship
	*/
	public $many2manyParam = 'role';


	// DB-vars & Object
	/** @var \MySqliDb Instance of Database class */
	protected $db = null;

	/**
	* @var string $dbTable The name of the corresponding database table
	*/
	protected $dbTable = 'undefined';

	/**
	* @var string $dbIdField Database-Fieldname in which the id is stored. Usually (and by default) 'id'
	*/
	protected $dbIdField = 'id';

	/**
	*	@var string primary database id/key.
	*	usually/per default 'id'
	*/	
	public $dbPrimaryKey = 'id';

	/**
	*	@var array the database keys/indexes definition
	*	           shall look like that:
	*	           
	*	           array(
	*	               "name" => "firstIndex",
	*	               "collation" => "A",
	*	               "cardinality" => 5,
	*	               "type" => "BTREE",
	*	               "comment" => "This is a database index foo bar, whatsoever",
	*	               "columns" => ["fieldName1", "anotherField"]
	*	           )
	*	
	*/	
	public $dbKeys = [];

	/** @var array An array of all database-columns. Set in `__constructor` via `_makeAssociativeFieldsArray()` */
	public $cols = null;
	/** @var int When a new item of model is added, this param will have it's newly created id */
	public $lastInsertedID = -1;
	/** @var object When adding sideload to the request load, they will live here 
	* 
	* ```
	* $sideload->otherModelName->data[]
	* ```
	* 
	*/
	public $sideload = null;

	/** 
	* Array of field-names that shall be masked with *** when sent to client according to it's properties 
	* 
	* ```
	* Array(
	*    'email' => Jeff\Api\DataMasker::MASK_TYPE_EMAIL,
	*    'tel' => Jeff\Api\DataMasker::MASK_TYPE_TEL,
	* );
	* ```<commit_msg>implemented database-keys<commit_after><?php
/**
 * This file contains class Model, the base class for all Models including Account
 */


namespace Jeff\Api\Models;
use Jeff\Api as Api;


/**
 *	This is the base class for all models.
 *	Includes getters and setters as far as they can be generalized
 *	This class shall be extended by consuming app to define the app-specific models.
 *	Many of the parameters and methods shall be overridden.
 *	
 *	@author <NAME>
 *	@copyright Copyright (c) 2015-2016
 *	@license   private
 *	@version   1.8.1
 */
Class Model 
{

	/**
	* The name of the model. e.g. "Post", "Comment"
	*
	*  a modelName __MUST NOT__ include a '2', because otherwise it'll be treated as a relational-model.
	*  Shall be overridden
	* @var string The name of the model. e.g. "Post", "Comment"
	*/
	protected $modelName = null;
	
	/** @var string the plural version of $modelName */
	protected $modelNamePlural = null;
	
	/**
	*
	* Name of parent Model.
	* __Not used til now (2018)__
	* this will be needed to make a bubbleUp method, 
	* to determine all the mother-models of a grand-child model such as a track, 
	* that belongsTo an artistgroup, an production, a workgroup
	* will be needed to figure out if a user may edit/delete an item or not
	*
	* @var string Name of parent model
	*/
	protected $motherModel = null; 


	/**
	*
	* Database-Table definition to be used by {@see DBHelper} class to create the corresponding table
	* usually to be overriden in class that extends model-class.
	* an array with this specification:
	* 
	* ```
	* public $dbDefinition = Array(
	*		string $fieldName, 			// 'id', 'email', 'label',..
	*		string $fieldType, 			//	'int', 'varchar', 'timestamp',..
	*		string|NULL $fieldLength, 	// '11', '250', NULL
	*		boolean $canBeNull, 		// true, false
	*		mixed $defaultValue, 		// '', NULL, 
	*		string $special  			// 'auto_increment', 'on update CURRENT_TIMESTAMP'
	* );
	* ```
	* 
	* so a typical dbDefinition could look like this:
	* 
	* ```
	* public $dbDefinition = Array(
	* 		array ('id', 'int', '11', false, NULL, 'auto_increment'),
	* 		array ('email', 'varchar', '80', false),
	* 		array ('password', 'varchar', '250', true),
	* 		array ('rights', 'tinyint', '4', false, '0'),
	* 		array ('authToken', 'varchar', '250', true),
	* 		array ('refreshToken', 'varchar', '250', true),
	* 		array ('fullName', 'varchar', '80', false, ''),
	* 		array ('firstName', 'varchar', '20', false, ''),
	* 		array ('middleName', 'varchar', '20', false, ''),
	* 		array ('prefixName', 'varchar', '20', false, ''),
	* 		array ('lastName', 'varchar', '30', false, ''),
	* 		array ('profilePic', 'varchar', '100', false, ''),
	* 		array ('lastOnline', 'timestamp', null, true),
	* 		array ('lastLogin', 'timestamp', null, true),
	* 		array ('invitationToken', 'varchar', '250', true),
	* 		array ('invitedBy', 'int', '11', true),
	* 		array ('modDate', 'timestamp', NULL, false, 'CURRENT_TIMESTAMP', 'on update CURRENT_TIMESTAMP'),
	* 		array ('modBy', 'int', '11', true),
	* 	);
	* ```
	*
	* @var array $dbDefinition Database-Table definition
	* @see DBHelper
	* 
	*/
	protected $dbDefinition = array();


	/** @var string field-name in which api will store the last account-id that changed/created an item. Can be NULL */
	public $modifiedByField = 'modBy';
	/** @var boolean Models with isSortable=true MUST have a field 'sort' in dbTable */
	public $isSortable = false;
	/** @var string If a model is sortable it usually has a parent-model as group 
	*               For example if you want comments to be sortable, then this would be 'post' - the reference to the parent
	*/
	public $sortBy = 'referenceField';


	/** 
	* @var string typically 'role' or 'rights'
	* many2many-references often have a value that describe that relationship
	*/
	public $many2manyParam = 'role';


	// DB-vars & Object
	/** @var \MySqliDb Instance of Database class */
	protected $db = null;

	/**
	* @var string $dbTable The name of the corresponding database table
	*/
	protected $dbTable = 'undefined';

	/**
	* @var string $dbIdField Database-Fieldname in which the id is stored. Usually (and by default) 'id'
	*/
	protected $dbIdField = 'id';

	/**
	*	@var string primary database id/key.
	*	usually/per default 'id'
	*/	
	public $dbPrimaryKey = 'id';

	/**
	 * the database keys/indexes definition which shall look like that:
	*	           
	*	           ```
	*	           array(
	*	               "name" => "firstIndex",
	*	               "collation" => "A",
	*	               "cardinality" => 5,
	*	               "type" => "BTREE",
	*	               "comment" => "This is a database index foo bar, whatsoever",
	*	               "columns" => ["fieldName1", "anotherField"]
	*	           )
	*	           ```
	*	
	* @var array   the database keys/indexes definition, 
	*/	
	public $dbKeys = [];

	/** @var array An array of all database-columns. Set in `__constructor` via `_makeAssociativeFieldsArray()` */
	public $cols = null;
	/** @var int When a new item of model is added, this param will have it's newly created id */
	public $lastInsertedID = -1;
	/** @var object When adding sideload to the request load, they will live here 
	* 
	* ```
	* $sideload->otherModelName->data[]
	* ```
	* 
	*/
	public $sideload = null;

	/** 
	* Array of field-names that shall be masked with *** when sent to client according to it's properties 
	* 
	* ```
	* Array(
	*    'email' => Jeff\Api\DataMasker::MASK_TYPE_EMAIL,
	*    'tel' => Jeff\Api\DataMasker::MASK_TYPE_TEL,
	* );
	* ```
{'fraction_non_alphanumeric': 0.14929603218138598, 'fraction_numerical': 0.010879502651307368, 'mean_word_length': 3.097003745318352, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 26, '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': '1490431', 'n_tokens_mistral': 3840, 'n_tokens_neox': 3646, 'n_words': 1230}