コード例 #1
0
 protected function updatePersonFormFields()
 {
     ini_set('max_execution_time', 6000);
     ini_set('memory_limit', "64M");
     $db = MDB2::singleton();
     $factory = I2CE_FormFactory::instance();
     if ($db->supports('transactions')) {
         $db->beginTransaction();
     }
     $personFormId = I2CE_Form::getFormId("person", true);
     if ($personFormId == 0) {
         I2CE::raiseError("Unable to get person form id.  Assuming that no person forms have ever been created.");
         if ($db->in_transaction) {
             $db->rollback();
         }
         return true;
     }
     $adminUser = I2CE_User::findUser('role', 'admin', false);
     if (!$adminUser instanceof I2CE_User) {
         I2CE::raiseError("Cannot find an administrative user");
         if ($db->in_transaction) {
             $db->rollback();
         }
         return false;
     }
     $details = array();
     $changes = array('country' => 'residence_country', 'district' => 'residence_district', 'county' => 'county_district');
     foreach (array_keys($changes) as $location) {
         die("deprecated badness in managemodule");
         $details[$location] = I2CE_FormField::getFormFieldIdAndType("person", $location);
         if ($details[$location] === null) {
             I2CE::raiseError("Unable to get details for person:{$location}.  Assuming that is has never beens used so skipping.");
             if ($db->in_transaction) {
                 $db->rollback();
             }
             unset($changes[$location]);
             continue;
         }
         $details[$location]['qry'] = $db->prepare("SELECT " . $details[$location]['type'] . "_value as val FROM last_entry where record = ? and form_field = ? LIMIT 1", array("integer", "integer"), MDB2_PREPARE_RESULT);
         if (I2CE::pearError($details[$location]['qry'], "Error preping statement:")) {
             if ($db->in_transaction) {
                 $db->rollback();
             }
             return false;
         }
     }
     $qry = $db->prepare('SELECT id from record where form = ?', array('integer'), MDB2_PREPARE_RESULT);
     if (I2CE::pearError($qry, "Error preping select records")) {
         if ($db->in_transaction) {
             $db->rollback();
         }
         return false;
     }
     $results = $qry->execute($personFormId);
     if (I2CE::pearError($results, "Error getting records")) {
         if ($db->in_transaction) {
             $db->rollback();
         }
         return false;
     }
     while ($row = $results->fetchRow()) {
         $person = $factory->createContainer('person' . '|' . $row->id);
         if (!$person instanceof iHRIS_Person) {
             I2CE::raiseError("Unable to create person with id " . $row->id);
             if ($db->in_transaction) {
                 $db->rollback();
             }
             return false;
         }
         $person->populate();
         foreach ($changes as $old => $new) {
             $t_results = $details[$old]['qry']->execute(array($row->id, $details[$old]['id']));
             if (I2CE::pearError($t_results, "Error selecting data for {$old} for id " . $row->id)) {
                 if ($db->in_transaction) {
                     $db->rollback();
                 }
                 return false;
             }
             $t_row = $t_results->fetchRow();
             if (!$t_row) {
                 continue;
                 //we did not get anything
             }
             if (I2CE::pearError($t_row, "Error getting data for {$old} for id " . $row->id)) {
                 if ($db->in_transaction) {
                     $db->rollback();
                 }
                 return false;
             }
             $person->{$new} = $t_row->val;
         }
         if (!$person->save($adminUser)) {
             I2CE::raiseError("Unable to save record " . $row->id);
             if ($db->in_transaction) {
                 $db->rollback();
             }
             return false;
         }
         $person->cleanup();
     }
     if ($db->in_transaction) {
         return $db->commit() == MDB2_OK;
     } else {
         return true;
     }
 }
コード例 #2
0
 /**
  * Return the list of scheduled course for the given course id.
  * @param integer $course_id.  Defaults to zero meaning we get all courses
  * @param boolean $flat.  defaults to false
  * @return array the keys are the id of the scheduled course, the values are the string "$start_date -- $end_date"
  */
 public static function getScheduledCourses($course_id = 0, $flat = false)
 {
     if ($course_id > 0) {
         $flat = true;
     }
     $values = array();
     foreach (array('start_date', 'end_date') as $field) {
         $data = I2CE_FormField::getFormFieldIdAndType('scheduled_training_course', $field);
         if (!is_array($data)) {
             I2CE::raiseError("Could not available courses b/c could not find field {$field} in form scheduled_training_course");
             return array();
         }
         $values[] = $data['id'];
     }
     $query = "SELECT le_start_date.record AS id, le_start_date.date_value AS start_date, le_end_date.date_value AS end_date,  r.parent AS parent ";
     $query .= "FROM last_entry le_start_date ";
     $query .= "JOIN last_entry le_end_date ON le_start_date.record = le_end_date.record ";
     $query .= "JOIN record r ON le_start_date.record = r.id ";
     $query .= "WHERE le_start_date.form_field = ? ";
     $query .= "AND le_end_date.form_field = ? ";
     if ($course_id > 0) {
         $query .= "AND r.parent = ? ";
         $values[] = $course_id;
     }
     $query .= "ORDER BY le_start_date.date_value DESC, le_end_date.date_value ASC";
     $db = MDB2::singleton();
     $sth = $db->prepare($query, array('integer', 'integer'), MDB2_PREPARE_RESULT);
     if (I2CE::pearError($sth, "Could not setup statement to get available courses")) {
         return array();
     }
     $results = $sth->execute($values);
     if (I2CE::pearError($results, "Could not get available courses")) {
         return array();
     }
     $scheduled_courses = array();
     while ($result =& $results->fetchRow()) {
         $start_date = I2CE_Date::fromDB($result->start_date);
         $end_date = I2CE_Date::fromDB($result->end_date);
         if ($flat) {
             $scheduled_courses[$result->id] = $start_date->displayDate() . " - " . $end_date->displayDate();
         } else {
             $scheduled_courses[$result->parent][$result->id] = $start_date->displayDate() . " - " . $end_date->displayDate();
         }
     }
     return $scheduled_courses;
 }
コード例 #3
0
 /**
  * Shows details the underlying database information and class information of a  form field.
  * Intend to be called when there is no form instance we are going to set (i.e. no id for a record is
  * expected to be give)
  * @param string $form
  * @param I2CE_MagicDataNode $fieldConfig.  The magic data node /modules/forms/formClasses/$form/fields/$fieldName
  * where $fieldName is the name of the field we are adding
  * @param boolean $even (Defaults to false). If true, will add the class 'even' to the created form field nodes.
  */
 protected function showFieldDetails($detailNode, $form, $fieldConfig, $even = 'I2CE_FormField')
 {
     $field = $fieldConfig->getName();
     die("deprecated bbaddness in i2ceformbrowser");
     $details = I2CE_FormField::getFormFieldIdAndType($form, $field);
     $fieldNode = $this->template->appendFileById("formBrowser_form_details_no_record.html", "tr", "particular_record", false, $detailNode);
     if (!$fieldNode instanceof DOMNode) {
         return;
     }
     if ($even) {
         $fieldNode->setAttribute('class', 'even');
     }
     $fieldType = "";
     $fieldClass = "";
     $fieldConfig->setIfIsSet($fieldType, "formfield");
     I2CE::getConfig()->setIfIsSet($fieldClass, "/modules/forms/FORMFIELD/{$fieldType}");
     $this->template->setDisplayDataImmediate('field_class', $fieldClass, $fieldNode);
     $this->template->setDisplayDataImmediate('field_type', $fieldType, $fieldNode);
     $this->template->setDisplayDataImmediate('field_name', $field, $fieldNode);
     $this->template->setDisplayDataImmediate('field_id', $details['id'], $fieldNode);
 }