Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Provide a mapping between our 'logical group and the $_POST array.
- // This will allow simplified 'group' processing
- // As there are various functions why not use a class?
- class GroupFieldMap
- {
- protected $post = null;
- protected $fieldNames = array();
- protected $fieldGroup = array();
- public function __construct($post, $fieldGroup) {
- $this->post = $post;
- $this->fieldGroup = $fieldGroup;
- foreach($fieldGroup as $fieldList) {
- foreach ($fieldList as $fieldName) {
- $this->fieldNames[] = $fieldName;
- }
- }
- }
- public function groupCount() {
- return count($this->post);
- }
- public function groupExists($groupIdx) {
- $found = false;
- foreach ($this->fieldNames as $fieldName) {
- if (isset($this->post[$fieldName][$groupIdx])) {
- return true;
- }
- }
- return false;
- }
- public function groupFieldExists($groupIdx, $fieldName) {
- return isset($this->post[$fieldName][$groupIdx]);
- }
- public function groupFieldHasValue($groupIdx, $fieldName, $fieldIdx) {
- return !empty($this->post[$fieldName][$groupIdx][$fieldIdx]);
- }
- public function groupFieldValue($groupIdx, $fieldName, $fieldIdx) {
- if (isset($this->post[$fieldName][$groupIdx][$fieldIdx])) {
- return $this->post[$fieldName][$groupIdx][$fieldIdx];
- }
- return null;
- }
- public function groupFieldCount($groupIdx, $fieldName) {
- if (isset($this->post[$fieldName][$groupIdx])) {
- return count($this->post[$fieldName][$groupIdx]);
- }
- return 0;
- }
- public function fields() {
- return $this->fieldNames;
- }
- public function fieldGroup() {
- return $this->fieldGroup;
- }
- } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement