HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/class.contentvars.php
<?php
/**
 * This file contains the iwp_content_vars class
 *
 * @version $Id$
 * 
 *
 * @package IWP
 * @subpackage IWP_API
 */

/**
 * IWP Content Vars Class
 * This class extends the iwp_engine abstract class.
 * This class handles the functions for variables in a Content Type. Its never usually intialized on its own, but rather as a member object to the iwp_contenttypes class
 *
 * @package IWP
 * @subpackage IWP_API
 */

class iwp_contentvars extends iwp_engine {
	/**
	 * primaryKey
	 * This is the name of the field that is the primary key for this table. It is a private and final variable
	 *
	 * @var primaryKey
	 **/
	protected $primaryKey = 'varid';

	/**
	 * baseTableName
	 * This is the name of the table without its prefix. This is a final private class variable and cannot be changed.
	 *
	 * @var baseTableName
	 **/
	protected $baseTableName = 'content_vars';

	/**
	 * data
	 * The data array of the current row held in the class memory. It should be the same structure as _columns.
	 *
	 * @var data
	 *
	 * @see Save
	 * @see Load
	 * @see LoadMulti
	 **/
	protected $data = array();

	/**
	 * _columns
	 * This is the final structure of the table in use. It can not be changed after this declaration.
	 *
	 * @var _columns
	 *
	 * @see ValidColumn
	 **/
	protected $_columns = array('moduleid' => 0,
							'typeid' => 0,
							'varid' => 0,
							'name' => '',
							'value' => ''
						);

	/**
	 * validation
	 * The array of validation functions to apply to the data values whenever we save to the database.
	 *
	 * @var validation
	 *
	 * @see Save
	 * @see iwp_validation
	 **/
	protected $validation = array(
							'moduleid' => 'IntGreaterThanZero',
							'typeid' => 'IntGreaterThanZero',
							'name' => array('FilterAlphaNumeric', 'FilterLimit250'),
							'value' => null
						);

	/**
	 * Instance
	 * This static variable holds the current instance of this object being loaded.
	 * So using the getInstance function anywhere will return the very same instance.
	 *
	 * @var object Instance
	 */
	public static $Instance;

	/**
	 * getInstance
	 * This is a static function that sets up the class instance and stores it to the static variable. It will then return that instantiation in the future.
	 *
	 * @return object Returns the instantiated object
	 **/
	public static function getInstance(){
		if(!isset(self::$Instance)){
			self::$Instance = new self();
		}
		return self::$Instance;
	}

	/**
	 * __construct
	 * The class contructor. Call the parent constructor then reset the data columns
	 *
	 * @return void
	**/
	function __construct(){
		parent::__construct();
	}

	/**
	 * Load
	 * Calls the LoadMulti() function instead of the Load() function
	 *
	 * @param $id integer The id number of the content-type to load
	 *
	 * @return void
	**/
	function Load($id){
		$this->LoadMulti('typeid', $id);
	}

	/**
	 * Set
	 * Overrides the parent function. Sets the variable in the database and the data array
	 *
	 * @param $name     string The name of the variable to save
	 * @param $value    string The value of the variable to save
	 * @param $typeid   string The content type ID number of the variable
	 * @param $moduleid string The module ID number it relates to
	 *
	 * @return void
	 *
	 * @see ExistsInData
	 * @see ValidColumn
	**/
	function Set($name, $value, $typeid, $moduleid=0){
			$InsertData = array();
			$InsertData['moduleid'] = $moduleid;
			$InsertData['typeid']   = $typeid;
			$InsertData['name']     = $name;
			$InsertData['value']    = $value;

			$id = $this->ExistsInData($name, $typeid, $moduleid);

			if($id !== false){
				$this->db->UpdateQuery($this->GetTableName(), $InsertData, ' varid='.$id);
			}else{
				$id = $this->db->InsertQuery($this->GetTableName(), $InsertData);
			}

			$InsertData[$this->primaryKey] = $id;
			$this->data[$id] = $InsertData;
	}

	/**
	 * Get
	 * Overrides the parent function with a different get method. It runs through the data array and returns the
	 * correct value.
	 *
	 * @param varname string description
	 *
	 * @return void
	**/
	function Get($name, $typeid, $moduleid){

		foreach($this->data as $_key=>$val) {

			if(isset($val['name']) && isset($val['moduleid']) && isset($val['typeid']) && isset($val['value']) && $name == $val['name'] && $moduleid == $val['moduleid'] && $typeid == $val['typeid']){
				return $val['value'];
			}
		}
		return false;
	}

	/**
	 * Returns all the content variables for a specific module
	 *
	 * @param integer $moduleid The ID number of the module to get the variables for
	 *
	 * @return array The array of variables for this module
	 */

	function GetVarsByModuleId($moduleid){
		$return = array();
		foreach($this->data as $_key=>$val) {
			if($moduleid == $val['moduleid']){
				$return[$val['name']] = $val['value'];
			}
		}
		return $return;
	}

	/**
	 * ExistsInData
	 * This checks to see if the particular variable already exists in the data array. If it is found, it returns
	 * the ID number, otherwise it returns false.
	 *
	 * @param $name     string The name of the variable to check for
	 * @param $typeid   string The content type id number the variable relates to
	 * @param $moduleid string The module id number the variable relates to
	 *
	 * @return void
	**/
	function ExistsInData($name, $typeid, $moduleid){
		foreach($this->data as $key=>$value){
			if($value['name'] == $name && $value['typeid'] == $typeid && $value['moduleid'] == $moduleid){
				return $key;
			}
		}
		return false;
	}

	/**
	 * Delete
	 * Deletes a row from the data array and removes it from the database as well
	 *
	 * @param varname string description
	 *
	 * @return void
	**/
	function Delete($name, $typeid, $moduleid){
		foreach($this->data as $key=>$val){
			if($name == $val['name'] && $val['typeid'] == $typeid && $moduleid == $val['moduleid']){
				$key = $val[$this->primaryKey];
				$this->db->Query("delete from " . $this->GetTableName() . ' where `'.$this->primaryKey.'`="'.$key.'" limit 1');
				unset($this->data[$key]);
				break;
			}
		}
	}

	/**
	 * This function deletes all variables associated with a content type
	 *
	 * @param integer $typeid The ID number of the content type to delete all the variables from the database for
	 *
	 * @return mixed Null if the content ID is not valid, true if successfull or false otherwise
	 */
	function DeleteAll($typeid=null){
		if($typeid == null){
			return null;
		}

		$typeid = (int)$typeid;

		if($typeid > 0){
			$q = $this->db->Query("delete from " . $this->GetTableName() . ' where `typeid`='.$typeid);
			return $q;
		}else{
			return null;
		}
	}

}