/** * Add an object to the fiedset's elements collection * * @param \ValidFormBuilder\Base $field The object to add * @throws \InvalidArgumentException if property passed to `addField()` is not an instance of Base */ public function addField($field) { if (!$field instanceof Base) { throw new \InvalidArgumentException("No valid object passed to Fieldset::addField(). " . "Object should be an instance of \\ValidFormBuilder\\Base.", E_ERROR); } $this->__fields->addObject($field); // Set parent element hard, overwrite if previously set. $field->setMeta("parent", $this, true); if ($field->isDynamic() && get_class($field) !== "ValidFormBuilder\\MultiField" && get_class($field) !== "ValidFormBuilder\\Area") { $objHidden = new Hidden($field->getId() . "_dynamic", ValidForm::VFORM_INTEGER, array("default" => 0, "dynamicCounter" => true)); $this->__fields->addObject($objHidden); $field->setDynamicCounter($objHidden); } }
/** * Retrieve an array with available records for a specific form. * * @param string $strFormId The Fulcrum form id * @return \Fulcrum\Records */ public function getRecords($strFormId, $arrParameters = array()) { $objReturn = new Collection(); $strGet = "/records"; $arrParameters["form_id"] = $strFormId; $this->objRest = new RestRequest($this->apiUrl . $strGet, "GET", $arrParameters, $this->getHeaders()); $this->objRest->execute(); $this->parseResponse(); if (is_object($this->response)) { $objReturn->setTotalCount($this->response->total_count); $objStdRecords = $this->response->records; $objForm = $this->getForm($strFormId); foreach ($objStdRecords as $objStdClass) { $objReturn->addObject(new Record($objStdClass, $objForm)); } } return $objReturn; }
/** * getFields creates a flat collection of all form fields. * * @internal * @param boolean $blnIncludeMultiFields Set this to true if you want to include MultiFields in the collection * @return Collection The collection of fields. */ public function getFields($blnIncludeMultiFields = false) { $objFields = new Collection(); foreach ($this->__elements as $objPage) { if ($objPage->hasFields()) { foreach ($objPage->getFields() as $objFieldset) { if ($objFieldset->hasFields()) { foreach ($objFieldset->getFields() as $objField) { if (is_object($objField)) { if ($objField->hasFields()) { // Also add the multifield to the resulting collection, if $blnIncludeMultiFields is true. if (get_class($objField) == "ValidFormBuilder\\MultiField" && $blnIncludeMultiFields) { $objFields->addObject($objField); } foreach ($objField->getFields() as $objSubField) { if (is_object($objSubField)) { if ($objSubField->hasFields()) { // Also add the multifield to the resulting collection, if $blnIncludeMultiFields is true. if (get_class($objField) == "ValidFormBuilder\\MultiField" && $blnIncludeMultiFields) { $objFields->addObject($objField); } foreach ($objSubField->getFields() as $objSubSubField) { if (is_object($objSubSubField)) { $objFields->addObject($objSubSubField); } } } else { $objFields->addObject($objSubField); } } } } else { $objFields->addObject($objField); } } } } else { $objFields->addObject($objFieldset); } } } else { $objFields->addObject($objPage); } } return $objFields; }
/** * Get a flat Collection of all internal elements. * * This loops through all elements and adds each element and their children to a new Collection which will be * returned. This results in a flat Collection filled with ValidForm Builder elements. * * @return \ValidFormBuilder\Collection */ public function getFields() { $objFields = new Collection(); foreach ($this->__elements as $objFieldset) { if ($objFieldset->hasFields()) { foreach ($objFieldset->getFields() as $objField) { if (is_object($objField)) { if ($objField->hasFields()) { if (get_class($objField) == "ValidFormBuilder\\Area" && $objField->isActive()) { $objFields->addObject($objField); } foreach ($objField->getFields() as $objSubField) { if (is_object($objSubField)) { if ($objSubField->hasFields()) { if (get_class($objSubField) == "ValidFormBuilder\\Area" && $objSubField->isActive()) { $objFields->addObject($objSubField); } foreach ($objSubField->getFields() as $objSubSubField) { if (is_object($objSubSubField)) { $objFields->addObject($objSubSubField); } } } else { $objFields->addObject($objSubField); } } } } else { $objFields->addObject($objField); } } } } else { $objFields->addObject($objFieldset); } } $this->__cachedfields = $objFields; return $objFields; }
/** * Get a collection of fields and look for dynamic counters recursively * @internal * @param Collection $objFields * @param Collection $objCollection * @return Collection */ protected function getCountersRecursive($objFields, $objCollection = null) { if (is_null($objCollection)) { $objCollection = new Collection(); } foreach ($objFields as $objField) { if ($objField instanceof Element && $objField->isDynamicCounter()) { $objCollection->addObject($objField); } if ($objField->hasFields()) { $this->getCountersRecursive($objField->getFields(), $objCollection); } } return $objCollection; }