Example #1
0
 /**
  * Responsible for sending the actual email
  */
 public static function send_email($data_context, $address, $subject_tmpl_file, $message_tmpl_file, $attachment)
 {
     // Load the subject and message templates
     $message_tmpl = file_get_contents(dirname(dirname(dirname(__FILE__))) . '/email_templates/' . $message_tmpl_file);
     $subject_tmpl = file_get_contents(dirname(dirname(dirname(__FILE__))) . '/email_templates/' . $subject_tmpl_file);
     // Fill the templates
     $message_tmpl = EntityStringUtils::parse($message_tmpl, $data_context);
     $subject_tmpl = EntityStringUtils::parse($subject_tmpl, $data_context);
     LogUtils::shadow_log($data_context);
     LogUtils::shadow_log('Sending mail to ' . $address . ' with subject ' . $subject_tmpl);
     // Send the email
     wp_mail($address, $subject_tmpl, $message_tmpl, '', $attachment);
 }
 /**
  *
  */
 public static function init_entity_data($artifact_name)
 {
     $entity_data = array();
     $entity_data['has_errors'] = false;
     // Get the requested artifact name
     if (EntityStringUtils::is_invalid_string($artifact_name)) {
         $entity_data['has_errors'] = true;
         $entity_data['error_message'] = 'Artifact name must be specified';
         return $entity_data;
     }
     // Check if artifact to entity name mapping exists
     if (!isset(ArtifactUtils::$artifacts[$artifact_name])) {
         $entity_data['has_errors'] = true;
         $entity_data['error_message'] = 'Artifact not found';
         return $entity_data;
     }
     // Check the type of the artifact
     $entity_data['entity_artifact_name'] = $artifact_name;
     $entity_data['entity_name'] = ArtifactUtils::$artifacts[$artifact_name]['name'];
     $entity_data['artifact_type'] = ArtifactUtils::$artifacts[$artifact_name]['artifact_type'];
     $entity_data['entity_description'] = ArtifactUtils::$artifacts[$artifact_name]['description'];
     if ($entity_data['artifact_type'] != 'entity') {
         return $entity_data;
     }
     // Use reflection to get the post name and entity fields from
     // the model class
     $entity_name = ArtifactUtils::$artifacts[$artifact_name]['name'] . 'CPT';
     $entity_class = new ReflectionClass($entity_name);
     $post_name = $entity_class->getStaticPropertyValue('post_name');
     // Check the ajax request
     $entity_data['entity_post_name'] = $post_name;
     $entity_data['entity_fields'] = $entity_class->getStaticPropertyValue('entity_fields');
     $entity_data['related_child_entities'] = $entity_class->getStaticPropertyValue('related_child_entities');
     $entity_data['is_global_entity'] = $entity_class->getStaticPropertyValue('is_global_entity');
     return $entity_data;
 }
 /**
  *
  */
 public static function build_criteria_from_form_data($entity_data)
 {
     $criteria_data = array();
     /*if(isset($_POST['bcat'])) {
           $category_data = EntityAPI::get_by_code(
               'businesscategory', array('entity_code' => strtoupper(sanitize_text_field($_POST['cat']))));
           if(isset($category_data['id']))
               $criteria_data['type.category'] = $category_data['id'];
       }*/
     // Process global search
     if (!EntityStringUtils::is_invalid_string($_POST['search']['value'])) {
         $criteria_data['is_global'] = true;
         $criteria_data['search'] = sanitize_text_field($_POST['search']['value']);
     } else {
         if (isset($_POST['columns'])) {
             $columns_data = $_POST['columns'];
             foreach ($columns_data as $column_data) {
                 $column_name = sanitize_text_field($column_data['data']);
                 if (EntityStringUtils::ends_with($column_name, '_txt')) {
                     $column_name = str_replace('_txt', '', $column_name);
                 }
                 if (array_key_exists($column_name, $entity_data['entity_fields'])) {
                     if (isset($column_data['search'])) {
                         if (!EntityStringUtils::is_invalid_string($column_data['search']['value'])) {
                             $field_value = sanitize_text_field($column_data['search']['value']);
                             $criteria_data[$column_name] = $field_value;
                         }
                     }
                 }
             }
             LogUtils::shadow_log('Doing global');
             foreach ($entity_data['entity_fields'] as $field_name => $field_data) {
                 if (isset($_POST[$field_data['name']])) {
                     LogUtils::shadow_log('Doing global1');
                     $criteria_data[$field_data['name']] = sanitize_text_field($_POST[$field_data['name']]);
                 }
             }
         } else {
             if (isset($_POST['form'])) {
                 if (isset($_POST['form'][3])) {
                     $criteria_data[$_POST['form'][3]['name']] = $_POST['form'][3]['value'];
                 }
             }
         }
     }
     return $criteria_data;
 }