Exemplo n.º 1
0
 /**
  * Goes into the contents of the 'changes' part of the Notification body
  * (from internal variable _lastHistory) and checks for contents that have to be translated
  * if the $translate option is true, then returns the final array.
  *
  * @param Zend_Locale $lang Locale for use in translations.
  * @param boolean     $translate Translate the fields or not.
  *
  * @return array Array with changes.
  */
 public function getBodyChanges($lang = null, $translate = true)
 {
     // The following algorithm loops inside $this->_lastHistory and prepares $bodyChanges while:
     // * Searches Integer values that should be converted into Strings and converts them
     $order = Phprojekt_ModelInformation_Default::ORDERING_FORM;
     $fieldDefinition = $this->_model->getInformation()->getFieldDefinition($order);
     $bodyChanges = $this->_lastHistory;
     // Iterate in every change done
     for ($i = 0; $i < count($bodyChanges); $i++) {
         foreach ($fieldDefinition as $field) {
             // Find the field definition for the field that has been modified
             if ($field['key'] == $bodyChanges[$i]['field']) {
                 $bodyChanges[$i]['field'] = $field['key'];
                 $bodyChanges[$i]['label'] = Phprojekt::getInstance()->translate($field['originalLabel'], $lang);
                 $bodyChanges[$i]['type'] = $field['type'];
                 if ($translate && in_array($field['type'], array('selectbox', 'display', 'multipleselectbox'))) {
                     // Is the field of a type that should be translated from an Id into a descriptive String?
                     $convertToString = true;
                     if ($field['type'] == 'display') {
                         if (!is_array($field['range'])) {
                             $convertToString = false;
                         } else {
                             foreach ($field['range'] as $range) {
                                 if (!is_array($range)) {
                                     $convertToString = false;
                                     break;
                                 }
                             }
                         }
                     }
                     if ($convertToString) {
                         // Yes, so translate it into the appropriate meaning
                         foreach ($field['range'] as $range) {
                             // Try to replace oldValue Integer with the String
                             if ($range['id'] == $bodyChanges[$i]['oldValue']) {
                                 $bodyChanges[$i]['oldValue'] = isset($range['originalName']) ? Phprojekt::getInstance()->translate($range['originalName'], $lang) : $range['name'];
                             }
                             // Try to replace oldValue Integer with the String
                             if ($range['id'] == $bodyChanges[$i]['newValue']) {
                                 $bodyChanges[$i]['newValue'] = isset($range['originalName']) ? Phprojekt::getInstance()->translate($range['originalName'], $lang) : $range['name'];
                             }
                         }
                     }
                 }
                 $bodyChanges[$i]['oldValue'] = $this->_convert($field, $bodyChanges[$i]['oldValue'], $lang);
             }
         }
     }
     return $bodyChanges;
 }
Exemplo n.º 2
0
 /**
  * Checks that the 'field' parameter for download and delete file actions is valid.
  * If not, terminates script execution printing an error.
  *
  * @param Phprojekt_Model_Interface $model Current module.
  * @param string                    $field Name of the field in the module.
  *
  * @return void
  */
 private static function _checkParamField($model, $field)
 {
     $valid = false;
     $info = $model->info();
     if (in_array($field, $info['cols'])) {
         $dbManager = $model->getInformation();
         $fieldType = $dbManager->getType($field);
         if ($fieldType == 'upload') {
             $valid = true;
         }
     }
     if (!$valid) {
         $error = Phprojekt::getInstance()->translate('Error in received parameter, consult the admin. Parameter:');
         $error .= ' field';
         self::_logError("Error: wrong 'field' parameter trying to Download or Delete a file.", array(get_class($model), $field));
         throw new InvalidArgumentException($error);
     }
 }
Exemplo n.º 3
0
 /**
  * Checks that the 'field' parameter for download and delete file actions is valid.
  * If not, terminates script execution.
  *
  * @param Phprojekt_Model_Interface $model Current module.
  * @param string                    $field Name of the field in the module.
  *
  * @return void
  */
 private function _fileCheckParamField($model, $field)
 {
     $valid = false;
     $info = $model->info();
     if (in_array($field, $info['cols'])) {
         $dbManager = $model->getInformation();
         $dbField = $dbManager->find($field);
         if (!empty($dbField)) {
             $fieldType = $dbManager->getType($field);
             if ($fieldType == 'upload') {
                 $valid = true;
             }
         }
     }
     if (!$valid) {
         $error = Phprojekt::getInstance()->translate('Error in received parameter, consult the admin. Parameter:');
         $error .= ' field';
         // Log error
         Phprojekt::getInstance()->getLog()->err("Error: wrong 'field' parameter trying to Download or Delete a file" . ". User Id: " . Phprojekt_Auth::getUserId() . " - Module: " . $this->getRequest()->getModuleName());
         // Show error to user and stop script execution
         die($error);
     }
 }