<?php
abstract class BaseVariablesModel extends WatchDogAppModel {

# ~ Get the environment	 - - - - - - - - - - - - - - - - - - - - - - - - - - - #
	public function get() {


		# Get the array of methods and their groups
		$variables = $this->find('all', array(
			'recursive' => -1,
			'order' => array(
				'ordering ASC'),
			'fields' =>	 array(
				'name', 'value')
		));

		# Repack
		foreach($variables as $i => $variable) {
			$variables[$i] = reset($variable);
		}

		return $variables;
	}

# ~ Update the environment - - - - - - - - - - - - - - - - - - - - - - - - - - #
	public function update($post) {

		# Remove previous
		$this->truncate();

		# Set the ordering
		$data = array();
		foreach($post as $i => $item) {
			if(!empty($item['name'])) {
				$data[$item['name']] = $item;
				$data[$item['name']]['ordering'] = $i + 1;
			}
		}
		$data = array_values($data);

		# Save the new one
		return (bool)$this->saveAll($data);
	}

}
