Пример #1
0
    function toString()
    {
        $ret = '<' . $this->name;
        $attribute_string = array();
        foreach ($this->attributes as $key => $att) {
            $attribute_string[] = $key . '="' . $att . '"';
        }
        $attribute_string = implode($attribute_string, ' ');
        $ret .= ' ' . $attribute_string;
        if (count($this->sections) && is_array($this->sections)) {
            $ret .= '>
';
            foreach ($this->sections as $sect) {
                $type = ArrayUtility::getArrayValue($sect, 'type');
                $data = ArrayUtility::getArrayValue($sect, 'data');
                if ($type == 'cdata') {
                    $ret .= $data;
                } else {
                    $ret .= $data->toString();
                }
            }
            $ret .= '</' . $this->name . '>
';
        } else {
            $ret .= ' />
';
        }
        return $ret;
    }
Пример #2
0
 function setOptions($name, $options)
 {
     if ($obj = ArrayUtility::getArrayValue($this->inputs, $name)) {
         $obj->setOptions($options);
     } else {
         throw new Exception('No object with name: ' . $name . ' exists in form: ' . $this->name);
     }
 }
 /**
  * Take an array of files from a form post and copy them to the required directory
  * @param file_vars  - the $_FILES superglobal from a form post
  * @return array     - an array of file names that were uploaded
  */
 function uploadFiles($file_vars = "")
 {
     $util = FileUtility::current();
     // Get the asset group for the file
     $disp = Display::current();
     $asset_group = $disp->getValue('asset_group') . "/";
     if (!is_dir(FileUtility::UPLOAD_DIR . $asset_group)) {
         mkdir(FileUtility::UPLOAD_DIR . $asset_group);
     }
     if (!$util->uploadDone()) {
         if (!$file_vars) {
             $file_vars = $_FILES;
         }
         $pathinfo = pathinfo($file_vars['media_url']['name']);
         $extension = '.' . $pathinfo['extension'];
         $filename = $pathinfo['filename'];
         $ret = array();
         if (!empty($file_vars) && count($file_vars)) {
             foreach ($file_vars as $label => $file) {
                 // Set the filename to an md5 #
                 //$original_name = $file['name'];
                 //$file['name'] = md5($file['name']);
                 $file['name'] = str_replace(' ', '-', $filename);
                 while (file_exists(FileUtility::UPLOAD_DIR . $asset_group . $file['name'] . $extension)) {
                     $file['name'] = md5($file['name']);
                 }
                 $file['name'] = $file['name'] . $extension;
                 $error = ArrayUtility::getArrayValue($file, "error");
                 if (!$error) {
                     if (move_uploaded_file($file['tmp_name'], FileUtility::UPLOAD_DIR . $asset_group . $file['name'])) {
                         $ret[$label] = ArrayUtility::getArrayValue($file, 'name');
                     } else {
                         throw new Exception("Error uploading file " . FileUtility::UPLOAD_DIR . $asset_group . $file['name']);
                     }
                 }
             }
         }
         $util->setUploadedFiles($ret);
     } else {
         $ret = $util->uploadedFiles();
     }
     return $ret;
 }
Пример #4
0
 /**
  * The same as {@link completeKey()} but instead of using 
  * this object's field values, it gets the values from the
  * array passed to the first argument.
  * @param arr       - an associative array of key => value pairs
  * @param use_table - (boolean) true if the field name in the array passed
  *                    has the table name in it
  * @return string   - a complete key string (see completeKey for more details)
  * @see completeKey
  */
 public function completeKeyFromArray($arr, $use_table = true)
 {
     $key_fields = $this->primaryKeys();
     $to_concat = array();
     $invalid = false;
     foreach ($key_fields as $field) {
         if ($use_table) {
             $name = $this->tableName() . '.' . $field->name();
         } else {
             $name = $field->name();
         }
         $val = ArrayUtility::getArrayValue($arr, $name);
         if (!$val && !is_numeric($val) || $val == 'NULL') {
             //throw new Exception('Value for: '.$field->name().' not present in array. Here is debug info:<br /><br />'.print_r($arr).'<br /><br />Finished');
             $invalid = true;
         }
         $to_concat[] = $val;
     }
     if (!$invalid) {
         $ret = implode('-', $to_concat);
     } else {
         $ret = false;
     }
     return $ret;
 }
Пример #5
0
 /**
  * Get the current session
  * @return Session - the current session
  * @access public
  * @static
  */
 public static function currentSession()
 {
     global $_SESSION;
     $session = ArrayUtility::getArrayValue($_SESSION, 'session');
     return $session;
 }
Пример #6
0
 /**
  * Set the value of a field
  * @param name     - The the name of the field to initialise
  * @param value    - The value to be set
  * @param required - Optional argument specifiying whether or not 
  *                   value can be empty (default is false)
  * @access public
  */
 function initialiseFieldValue($field, $value)
 {
     if ($field->date()) {
         if (is_array($value)) {
             $day = ArrayUtility::getArrayValue($value, 'day');
             $month = ArrayUtility::getArrayValue($value, 'month');
             $year = ArrayUtility::getArrayValue($value, 'year');
             //$date = new DateUtility($day,$month,$year);
             $value = $year . '-' . $month . '-' . $day;
         } else {
             $value = '';
         }
     }
     $this->setFieldValue($field->name(), $value);
 }
 function sumArrayElementsByKey($row1, $row2)
 {
     global $current_array_summing_field_name;
     $val1 = ArrayUtility::getArrayValue($row1, $current_array_summing_field_name);
     $val2 = ArrayUtility::getArrayValue($row2, $current_array_summing_field_name);
     return $val1 + $val2;
 }
 /**
  * Retrieve some display information for this object
  * @param name   - the name of the value to be retrieved
  * @access protected
  */
 protected function displayInfoValue($name)
 {
     $ret = ArrayUtility::getArrayValue($this->display_info_values, $name);
     return $ret;
 }
Пример #9
0
 /**
  * Return an associative array where the key is the value of the 
  * database field corresponding to the 'key' argument, and the
  * value of each element is the value of the field corresponding
  * to the 'element' argument
  * @param key        - the name of the field in the database query
  *                     for which the value should be used as the key
  *                     in the associative array returned
  * @param element    - the name of the field in the database query
  *                     for which the value should be used as the
  *                     value in each element of the return array
  * @return array     - an associative array of database values
  * @access public
  */
 function assocArray($key, $element)
 {
     $this->check();
     $ret = array();
     while ($row = $this->next()) {
         $ret[ArrayUtility::getArrayValue($row, $key)] = ArrayUtility::getArrayValue($row, $element);
     }
     $this->reset();
     return $ret;
 }
 /**
  * Return the value of a particular attribute for the current element
  */
 function attributeValue($att_name, $optional = '')
 {
     if (!$optional) {
         $optional = XmlUtility::REQUIRED;
     }
     $ret = '';
     if (array_key_exists($att_name, $this->cur_attributes)) {
         $ret = ArrayUtility::getArrayValue($this->cur_attributes, $att_name);
     } else {
         if ($optional == XmlUtility::REQUIRED) {
             $this->xmlErrorMessage('Tried to access non-existent attribute: ' . $att_name . ', in element: ' . $this->currentElementName());
         }
     }
     return $ret;
 }