protected function setUp()
 {
     parent::setUp();
     $this->_contactIds = array($this->individualCreate(array('first_name' => 'Antonia', 'last_name' => 'D`souza')), $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')));
     $this->_docTypes = CRM_Core_SelectValues::documentApplicationType();
 }
 /**
  * Global form rule.
  *
  * @param array $params
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param array $self
  *
  * @return array
  *   array of errors
  */
 public static function formRule($params, $files, $self)
 {
     $errors = array();
     // If user uploads non-document file other than odt/docx
     if (!empty($files['file_id']['tmp_name']) && array_search($files['file_id']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL) {
         $error['file_id'] = ts('Invalid document file format');
     } elseif (empty($files['file_id']['tmp_name']) && !empty($params['file_type']) && !$self->_is_document) {
         //On edit page of docx/odt message template if user changes file type but forgot to upload document
         $errors['file_id'] = ts('Please upload document');
     }
     return $errors;
 }
Example #3
0
 /**
  * @param array $path  docx/odt file path
  * @param string $type  File type
  *
  * @return array
  *    Return extracted content of document in HTML and document type
  */
 public static function docReader($path, $type)
 {
     $type = array_search($type, CRM_Core_SelectValues::documentApplicationType());
     $fileType = $type == 'docx' ? 'Word2007' : 'ODText';
     $phpWord = \PhpOffice\PhpWord\IOFactory::load($path, $fileType);
     $phpWordHTML = new \PhpOffice\PhpWord\Writer\HTML($phpWord);
     // return the html content for tokenreplacment and eventually used for document download
     return array($phpWordHTML->getWriterPart('Body')->write(), $type);
 }
 /**
  * Form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  * @param array $self
  *   Additional values form 'this'.
  *
  * @return bool
  *   TRUE if no errors, else array of errors.
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     $template = CRM_Core_Smarty::singleton();
     // If user uploads non-document file other than odt/docx
     if (empty($fields['template']) && !empty($files['document_file']['tmp_name']) && array_search($files['document_file']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL) {
         $errors['document_file'] = ts('Invalid document file format');
     }
     //Added for CRM-1393
     if (!empty($fields['saveTemplate']) && empty($fields['saveTemplateName'])) {
         $errors['saveTemplateName'] = ts("Enter name to save message template");
     }
     if (!is_numeric($fields['margin_left'])) {
         $errors['margin_left'] = 'Margin must be numeric';
     }
     if (!is_numeric($fields['margin_right'])) {
         $errors['margin_right'] = 'Margin must be numeric';
     }
     if (!is_numeric($fields['margin_top'])) {
         $errors['margin_top'] = 'Margin must be numeric';
     }
     if (!is_numeric($fields['margin_bottom'])) {
         $errors['margin_bottom'] = 'Margin must be numeric';
     }
     return empty($errors) ? TRUE : $errors;
 }