Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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
    
    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, 4 months ago by acedesign123. Reason: Specify the question
    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.

Viewing 3 replies - 1 through 3 (of 3 total)