<commit_before># Reusables
* By <NAME>






## Basic Guidelines and How-to

* write your own functions where you retrieve/deal with data in the /reusables/classes/CustomData directory with the namespace of CustomaData.
* create pages in the views directory from the root directory.
* add paths to pages in the index.php file
* add your own css to style pages in reusables/customcss. create a file with the same name as the page you want to modify ( with file extension .css ). if the page is in a directory ( or directories ) within /views then create that same directory in /customcss and place your custom css file in it

* in each page, add the following functions and add reusable views in between the two function:
	ReusableClasses::startpage( __FILE__ );
	ReusableClasses::endpage( "", __FILE__ );
* in the first parameter of the endpage function, add the directory the page is in, if its in the /views root directory then leave it as "". 
* when dealing with data in CustomData, make sure you return it to a variable in the format below (desired data format)
	* most of the time this can easily be done by first specifying the conditions (e.g. [ [ "key"=>"","value"=>"" ], [ "key"=>"","value"=>"" ] ] ). Make sure your condition keys are also in the returned dict/array. now pass both the data ( e.g. from an sql query ) and the conditions through the function \ReusableClasses::toValueAndDBInfo( $data, $conditions, "" ) where the third parameter is the default tablename
* this returns the array in a format very similar to the "desired data format". the only difference is that the array inside "value" is the same array returned previously (e.g. from the sql query). 
* when getting the above data in a page, we will save this array in the data class with this function: Data::addData( $data, $unique_identifier )
* then translate the data into the format each reusable view will understand with this function: formatForDefaultData( $dataid )
	* assign the returned value to a variable
* you can then add custom key value pairs to that variable by: $array[customkey] = customvalue
* data format for reusable view:
	```
	data:
	{
		"value": {
			key: { "data_id": "", "key": "", "index": "" },
			key: { "data_id": "", "key": "", "index": "" },
			key: { "data_id": "", "key": "", "index": "" }
		},
		"db_info": {
			"tablenames": {
				{ key: tablename }
			},
			"conditions": {
				{ "key": "", "value": ""},
				{ "key": "", "value": ""}
			}
		}
	}
	```
* echo each root reusable view
* each reusable view has a set of parameters you can define
* to add an existing reusable view to a page call the reusable view class (e.g. Header is the class for all the headers) then call the make function
	* this is different for wrappers, you call the wrapper class (Wrapper) then the function name is the same as the reusable view filename
* there are three parameters when calling the make function (filename, data, identifier)
	* two parameters for wrapper (data, identifier)
* to connect to your database change the information in the classes/CustomData/config.php and classes/CustomData/db_pdo.php files

* when dealing with data from the database, if you get from a "custom" table then use the function: Data::convertFromCustomTable( $data ) to turn it into a normal dictionary with key value pairs
* add the condition keys you'll need to change something in the data you fetched, leave the condition values as ""
* the condition values will come from this array that you fetched from the database, make sure the condition keys match the specific keys in the fetched data array. if certain keys you need for the condition aren't present in the data, add them right after the convertFromCustomTable function (if from customtable)
* convert data into default data by using the function: ReusableClasses::toValueAndDBInfo( $data, $conditions, $tablename )

* add this to include reusable assets 
	<link rel=stylesheet href='/vendor/miltonian/reusables/assets/css/reusables.css' type=text/css>
	<script src='/vendor/miltonian/reusables/assets/js/reusable.js'></script>
	<script src='/vendor/miltonian/reusables/assets/js/ReusableClasses.js'></script>
	
	<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>


### NAV 

	```
	data:
	[
		"logo|brandname"=>imagepath/text,
		"pages": {
			[ 
				"name"=>"", 
				"classname" => "", 
				"slug" => "", 
				"imagepath" => "", 
				"position" => "left/right", 
				"buttons" => array(
					[ "name" => "", "classname", "slug" => "" ]
				)
			]
		}
	]
	```

### HEADER

	```
	data:
	[
		"title" => "",
		"buttons" => array(
			[ "name"=>"", "classname"=>"", "type"=>"modal|link", "modal"=>[ "parentclass"=>"", "modalclass"=>"" ] ]
		)
	]
	```

in the above data, parentclass is for the outer most wrapper ( inside modal_background ) and modalclass is the main class inside the form in the modal


* make a form inside modal
```
echo Reusables\Structure::make(
	"modal_background",
	[
		Reusables\Wrapper::wrapper1(
			[],
			array(
				Reusables\Structure::make(
					"modalinner_1",
					[
						"title"=>"",
						"first"=>array(
							"<form class='theform' method='post' action='/edit_view.php' enctype='multipart/form-data'>",
							/* views inside form go here*/
							"/form"
						)
					],
					"editstructure"
				)
			),
			"editwrapper"
		)
	],
	"modalbackground"
);
```


### FORM 

	* for now, you have to create your own form. but its easy
	* create the php script for you form in the /views/CustomView directory
	* put this at the top of the file:
			namespace Reusables\CustomView;
			extract( \Reusables\CustomView::makeFormVars( $customviewdict ) );
	* now you have these already defined vars to work with: $data_id, $default_tablename, $customviewdict
	* put this right after "?>"
		```
		<div class="<?php echo $identifier ?> form_simple_2 main">
			<div class='container' style='text-align: left; margin-top: 10px; margin-bottom: 30px; text-align: center;'>
				<input type="hidden" name="goto" value="userprofile">

				// put your code here<commit_msg>and again<commit_after># Reusables
* By <NAME>






## Basic Guidelines and How-to

* write your own functions where you retrieve/deal with data in the /reusables/classes/CustomData directory with the namespace of CustomaData.
* create pages in the views directory from the root directory.
* add paths to pages in the index.php file
* add your own css to style pages in reusables/customcss. create a file with the same name as the page you want to modify ( with file extension .css ). if the page is in a directory ( or directories ) within /views then create that same directory in /customcss and place your custom css file in it

* in each page, add the following functions and add reusable views in between the two function:
	```
	ReusableClasses::startpage( __FILE__ );
	ReusableClasses::endpage( "", __FILE__ );
	```
* in the first parameter of the endpage function, add the directory the page is in, if its in the /views root directory then leave it as "". 
* when dealing with data in CustomData, make sure you return it to a variable in the format below (desired data format)
	* most of the time this can easily be done by first specifying the conditions (e.g. [ [ "key"=>"","value"=>"" ], [ "key"=>"","value"=>"" ] ] ). Make sure your condition keys are also in the returned dict/array. now pass both the data ( e.g. from an sql query ) and the conditions through the function \ReusableClasses::toValueAndDBInfo( $data, $conditions, "" ) where the third parameter is the default tablename
* this returns the array in a format very similar to the "desired data format". the only difference is that the array inside "value" is the same array returned previously (e.g. from the sql query). 
* when getting the above data in a page, we will save this array in the data class with this function: Data::addData( $data, $unique_identifier )
* then translate the data into the format each reusable view will understand with this function: formatForDefaultData( $dataid )
	* assign the returned value to a variable
* you can then add custom key value pairs to that variable by: $array[customkey] = customvalue
* data format for reusable view:
	```
	data:
	{
		"value": {
			key: { "data_id": "", "key": "", "index": "" },
			key: { "data_id": "", "key": "", "index": "" },
			key: { "data_id": "", "key": "", "index": "" }
		},
		"db_info": {
			"tablenames": {
				{ key: tablename }
			},
			"conditions": {
				{ "key": "", "value": ""},
				{ "key": "", "value": ""}
			}
		}
	}
	```
* echo each root reusable view
* each reusable view has a set of parameters you can define
* to add an existing reusable view to a page call the reusable view class (e.g. Header is the class for all the headers) then call the make function
	* this is different for wrappers, you call the wrapper class (Wrapper) then the function name is the same as the reusable view filename
* there are three parameters when calling the make function (filename, data, identifier)
	* two parameters for wrapper (data, identifier)
* to connect to your database change the information in the classes/CustomData/config.php and classes/CustomData/db_pdo.php files

* when dealing with data from the database, if you get from a "custom" table then use the function: Data::convertFromCustomTable( $data ) to turn it into a normal dictionary with key value pairs
* add the condition keys you'll need to change something in the data you fetched, leave the condition values as ""
* the condition values will come from this array that you fetched from the database, make sure the condition keys match the specific keys in the fetched data array. if certain keys you need for the condition aren't present in the data, add them right after the convertFromCustomTable function (if from customtable)
* convert data into default data by using the function: ReusableClasses::toValueAndDBInfo( $data, $conditions, $tablename )

* add this to include reusable assets 
	```
	<link rel=stylesheet href='/vendor/miltonian/reusables/assets/css/reusables.css' type=text/css>
	<script src='/vendor/miltonian/reusables/assets/js/reusable.js'></script>
	<script src='/vendor/miltonian/reusables/assets/js/ReusableClasses.js'></script>
	
	<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>
	```

### NAV 
	* example
	```
	data:
	[
		"logo|brandname"=>imagepath/text,
		"pages": {
			[ 
				"name"=>"", 
				"classname" => "", 
				"slug" => "", 
				"imagepath" => "", 
				"position" => "left/right", 
				"buttons" => array(
					[ "name" => "", "classname", "slug" => "" ]
				)
			]
		}
	]
	```

### HEADER
	* example
	```
	data:
	[
		"title" => "",
		"buttons" => array(
			[ "name"=>"", "classname"=>"", "type"=>"modal|link", "modal"=>[ "parentclass"=>"", "modalclass"=>"" ] ]
		)
	]
	```

in the above data, parentclass is for the outer most wrapper ( inside modal_background ) and modalclass is the main class inside the form in the modal


* make a form inside modal
```
echo Reusables\Structure::make(
	"modal_background",
	[
		Reusables\Wrapper::wrapper1(
			[],
			array(
				Reusables\Structure::make(
					"modalinner_1",
					[
						"title"=>"",
						"first"=>array(
							"<form class='theform' method='post' action='/edit_view.php' enctype='multipart/form-data'>",
							/* views inside form go here*/
							"/form"
						)
					],
					"editstructure"
				)
			),
			"editwrapper"
		)
	],
	"modalbackground"
);
```


### FORM 
	* for now, you have to create your own form. but its easy
	* create the php script for you form in the /views/CustomView directory
	* put this at the top of the file:
		```
		namespace Reusables\CustomView;
		extract( \Reusables\CustomView::makeFormVars( $customviewdict ) );
		```
	* now you have these already defined vars to work with: $data_id, $default_tablename, $customviewdict
	* put this right after "?>"
		```
		<div class="<?php echo $identifier ?> form_simple_2 main">
			<div class='container' style='text-align: left; margin-top: 10px; margin-bottom: 30px; text-align: center;'>
				<input type="hidden" name="goto" value="userprofile">

				// put your code here
{'fraction_non_alphanumeric': 0.12081418253447143, 'fraction_numerical': 0.0018056467498358503, 'mean_word_length': 3.8584529505582137, 'pattern_counts': {'":': 36, '<': 29, '<?xml version=': 0, '>': 77, 'https://': 2, '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': '5228083', 'n_tokens_mistral': 3970, 'n_tokens_neox': 3579, 'n_words': 1458}