+ function fillData() {
+ $count = 1;
+ if (isset($this->_id)) {
+ /** Updating existing progress bar*/
+ $query = "SELECT * FROM civicrm_wci_progress_bar where id=" . $this->_id;
+ $params = array();
+
+ $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBar');
+
+ while ($dao->fetch()) {
+ $con_page[$dao->id] = array();
+ CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]);
+ $this->setDefaults(array(
+ 'progressbar_name' => $con_page[$dao->id]['name']));
+ $this->setDefaults(array(
+ 'starting_amount' => $con_page[$dao->id]['starting_amount']));
+ $this->setDefaults(array(
+ 'goal_amount' => $con_page[$dao->id]['goal_amount']));
+ }
+
+ $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $this->_id;
+ $params = array();
+
+ $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBarFormula');
+
+ while ($dao->fetch()) {
+ $for_page[$dao->id] = array();
+ CRM_Core_DAO::storeValues($dao, $for_page[$dao->id]);
+
+ $this->add(
+ 'select', // field type
+ 'contribution_page_'.$count, // field name
+ 'Contribution page', // field label
+ getContributionPageOptions(), // list of options
+ true // is required
+ );
+ $this->add(
+ 'text', // field type
+ 'percentage_'.$count, // field name
+ 'Percentage', // field label
+ true // is required
+ );
+ //save formula id
+ $this->addElement('hidden', 'contrib_elem_'.$count , $for_page[$dao->id]['id']);
+
+ $this->setDefaults(array(
+ 'contribution_page_'.$count => $for_page[$dao->id]['contribution_page_id']));
+ $this->setDefaults(array(
+ 'percentage_'.$count => $for_page[$dao->id]['percentage']));
+
+ $count++;
+ }
+ $count--; // because last iteration increments it to the next
+ }
+ else {
+ /** New progress bar*/
+ $this->add(
+ 'select', // field type
+ 'contribution_page_1', // field name
+ 'Contribution page', // field label
+ getContributionPageOptions(), // list of options
+ true // is required
+ );
+ $this->add(
+ 'text', // field type
+ 'percentage_1', // field name
+ 'Percentage', // field label
+ true // is required
+ );
+ }
+
+ $this->addElement('hidden', 'contrib_count', $count);
+ }
+