Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
class MyModule extends Module {
...
	public function validateService($package, array $vars=null) {
		// Set any input rules to validate against
		$rules = array(
			'mymodule_field' => array(
				'formatempty' => array(
					'rule' => "isEmpty",
					'negate' => true,
					'message' => Language::_("MyModule.!error.mymodule_field.formatempty", true)
				);
			)
		);

		$this->Input->setRules($rules);

		// Determine whether the input validates
		return $this->Input->validates($vars);
	}
...
}

...

addPackage(array $vars=null)

 

editPackage($package, array $vars=null)

 

...

This method attempts to save any meta data related to a package, and may perform a remote request to add a package. It also performs any input validation against the input vars, and sets any input errors. This method returns meta fields as an array containing an array of key=>value fields for each meta field and its value, as well as whether the value should be encrypted.

Code Block
languagephp
class MyModule extends Module {
...
	public function addPackage(array $vars=null) {
		// Set any package meta field rules
		$rules = array(
			'meta[field]' => array(
				'empty' => array(
					'rule' => "isEmpty",
					'negate' => true,
					'message' => Language::_("MyModule.!error.meta[field].empty", true)
				)
			)
		);

		// Determine whether the input validates
		$meta = array();
		if ($this->Input->validates($vars)) {
			// Set meta fields to save
			foreach ($vars['meta'] as $key => $value) {
				$meta[] = array(
					'key' => $key,
					'value' => $value,
					'encrypted' => 0
				);
			}
		}

		return $meta;
	}
...
}

 

editPackage($package, array $vars=null)

This method attempts to update any meta data related to a package, and may perform a remote request to add a package. It also performs any input validation against the input vars, and sets any input errors. This method returns meta fields as an array containing an array of key=>value fields for each meta field and its value, as well as whether the value should be encrypted.

This method is very similar to addPackage().

deletePackage($package)

This method attempts to delete a package from a remote server. It may set Input errors on failure.

Code Block
languagephp
class MyModule extends Module {
...
	public function deletePackage($package) {
		// Attempt to delete a package remotely (this is dependent on the module's API, omitted here)
		$response = $this->apiCall($package);
		
		if (isset($response->status) && !$response->status)
			$this->Input->setErrors(array('api' => array('response' => "The request could not be performed.")));
	}

	private function apiCall($params) {
		// Make the API call to the module (this is dependent on the module's API, omitted here)
		return (object)array('status' => false);
	}
...
}

 

manageModule($module, array &$vars)

...