• Resolved acedesign123

    (@acedesign123)


    Hi Guys.

    I was reading the documentation over at https://torro-forms.com/api/ but I could not find topics to address the following questions.

    1.) How to get current active forms that are not expired to display in my template without using <?php echo do_shortcode('[form id="512"]') ?>

    2.) Is there a global variable that I can hook into and display on my theme sidebar to tell logged in users that they have a form to fill out?

    3.) Can I expire the whole form like we once did for https://www.ads-software.com/plugins/questions/ I do not see the options on the right hand side?

    ###My Template file

    <?php
    /**
     * Template Name: .....
     */
    
    get_header(); 
    $current_user = wp_get_current_user();
    ?>
    
    <div class="content">
        <div class="left">
           <?php echo do_shortcode('[form id="512"]') ?>
           <?php
             // Pseudocode
             // What I want to do. Get Active forms without using a shortcode and editing code
             // Because, we will add another form in three weeks.
             get_active_forms_that_are_not_expired();
           ?>
        </div>
    
        <div class="right">
            <?php get_sidebar(); ?>
        </div>
    
    </div><!-- Content -->
     <?php get_footer(); ?>
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Sven Wagener

    (@mahype)

    Hello,

    I am very sorry, but at the moment this is not possible by the API. I have to change the way we are saving the date. We are saving the date as string and we need it as timestamp to do the query. I have added a ticket for that and will change this in the next beta.

    Here is the Issue on Github on that topic:
    https://github.com/awsmug/torro-forms/issues/298

    At the moment there is only the possibility to use the function get_posts to get all from post_type “torro_form” and to check the dates manually.

    Greetings,

    Sven

    • This reply was modified 8 years, 1 month ago by Sven Wagener.
    Plugin Author Sven Wagener

    (@mahype)

    I have written you the function for the actual version of Torro Forms:

    
    function get_active_forms_that_are_not_expired() {
    	global $wpdb;
    	$results = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'torro_form'" );
    	$active_forms = array();
    
    	foreach( $results AS $result ) {
    		$start_date = get_post_meta( $result->ID, 'start_date', true );
    		$end_date = get_post_meta( $result->ID, 'end_date', true );
    
    		if( empty( $start_date ) && empty( $end_date ) ) {
    			continue;
    		}
    
    		if( strtotime( $start_date ) > time() ) {
    			continue;
    		}
    
    		if( strtotime( $end_date ) < time() ) {
    			continue;
    		}
    
    		$active_forms[] = $result;
    	}
    
    	return $active_forms;
    }
    

    I hope that helps you! ??

    Thread Starter acedesign123

    (@acedesign123)

    Hi Sven Wagener
    Thank you for your time.

    I will keep an eye on the github repo. And in the meantime I wil use your code as you suggesting.

    Thread Starter acedesign123

    (@acedesign123)

    Sorry to open This Thread again. I am carry on from the last question.
    I am trying to make a shortcode to show if there is a survey and if you are part of the people selected in that specific survey.
    But I want to get all participants of these open form. In the other plugin you did something like this :

    <?php
        $results = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'torro_form'" );
        $form_id = $result->ID;
    
        foreach( $results AS $result ) {
            $sql = $wpdb->prepare (  "SELECT user_id FROM participats_table WHERE survey_id = %s", $form_id );
            $user_ids       = $wpdb->get_col( $sql );
            $current_user   = wp_get_current_user();
    
            if ( in_array($current_user->ID, $user_ids) && count( $user_ids ) > 0 ) {
                //Rest of my code
            }
        }
    ?>

    1.) What is the name of the participants table?
    2.) Does it have user id’s ?

    Regards

    • This reply was modified 8 years ago by acedesign123. Reason: Specify the question
    Thread Starter acedesign123

    (@acedesign123)

    Sorry, I answered my Own Question

    Here is the answer.

    <?php
    function scop_due_date_function($atts) {
      
      global $wpdb;
      $goto     =  get_page_link(522);
      $results  = $wpdb->get_results( " SELECT * FROM $wpdb->posts WHERE post_type = 'torro_form' AND post_status = 'publish' ORDER BY ID DESC LIMIT 1 " );
    
      //https://github.com/awsmug/torro-forms/blob/3da63aa1716192073c94e95dda467a0b3219ce9a/torro-forms.php#L436
    
      foreach( $results AS $result ) {
        $form_id = $result->ID;
        $current_user   = wp_get_current_user();
        $sql            = $wpdb->prepare (  "SELECT user_id FROM $wpdb->torro_participants WHERE form_id = %s", $form_id );
        $participants   = $wpdb->get_col( $sql );
    
        if ( is_array( $participants ) && count( $participants ) > 0  && in_array($current_user->ID, $participants) ) {
          $a = shortcode_atts( array(
            'name' => $result->post_title,
            'date' => get_post_meta( $result->ID, 'end_date', true ),
          ), $atts );
    
          return "<p>   <a href='{$goto}'> {$a['name']}  </a>" . "<span style='float:right;'>{$a['date']}</span> </p>";
        } 
        elseif (!in_array($current_user->ID, $participants)) {
          return "<p> There are no Scop's currently running. </p>";
        } 
        else {
          return "<p> Something went wrong. </p>";
        }
      }
      
    }
    
    add_shortcode('scopdue', 'scop_due_date_function');
    ?>

    I tried to use

    $participants = torro()->participants()->query( array(
          'number'  => -1,
          'form_id' => $form_id,
        ) );

    But I was getting Protected

    Array
    (
        [0] => Torro_Participant Object
            (
                [user_id:protected] => 3
                [user:protected] => WP_User Object
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Gloabally Available Variables’ is closed to new replies.