Forum

Thread tagged as: Question, Members

Thanks Drew.

Hi Drew,

Did you manage to look in to this at all? Sorry to ask but I'm getting close to a launch date for this project!

Thanks, Andy

Drew McLellan

Drew McLellan 2638 points
Perch Support

I haven't yet - I'm run off my feet currently.

Andy. Is this on a live site or local development server.

I ask because I have had some funny happenings on my local server when it comes to members app and tags. I can upload all the files to live site and all the issues go away. I am sure it's to do with my local setup but I have never been able to narrow down the issue or solution..

Andy, I have actually created a website using perch in a way that makes members admins of their own content inside of perch. The site I created is a bit of a fine line between what you describe. After a member registers, they become an 'editor' of sorts and log into perch as an admin. At this point they can upload documents, download documents and edit their own information. I have interested other perch users to take a look and see if it's the kind of solution they could also use. I am currently in v2 which I am focusing on tiding up the code and adding new features. I would love to share code with you if you find your still needing additional help with this.

Just wanted to let ya know.

Hi Robert,

It is on a local MAMP server however I just uploaded everything to a development server and unfortunately the same issues occur.

Your site sounds great - In my case I just want admin users to upload files for specific non admin users. Then the non admin users can log in and download files (based on their tags) the files assigned to them, but what you describe sounds like a great bit of functionality.

Any suggestions are much appreciated...

Thanks for your input.

Hi Drew/Robert,

Is there another way to achieve the following as I need to get something to the client asap.

  1. Member is created by admin and then given a unique tag.
  2. Admin uploads files to assets and tags them with the same unique tag as in step 1.
  3. Member logs in.
  4. Member sees a list of assets that displayed for that member only by matching member tag and asset tag.

Thanks again for your help.

Andy

Drew McLellan

Drew McLellan 2638 points
Perch Support

So another way would be to use skip-template and the return-html options. Check the tags in PHP and then only output the HTML if the tags match.

Hi Drew,

I have used skip-template and return-html options before so good with that.

How would I 'Check the tags in PHP' though?

Thanks for this Drew.

Drew McLellan

Drew McLellan 2638 points
Perch Support

if (perch_member_has_tag($tag_read_from_skip_template_output)) {
     ...
}

Hi Drew,

OK, so I have the following on the page:

<?php
  perch_content_create('Downloads', array(
    'template'   => 'downloads.html',
    'sort' => 'date',
    'sort-order' => 'ASC'
  ));
?>

<?php
  $result = perch_content_custom('Downloads', array(
        'template' => 'downloads.html',
        'skip-template' => true,
        'return-html'   => true,
        ));
?>

<?php 
    if (perch_member_has_tag($tag_read_from_skip_template_output)) {
        echo $result['html'];
    }
?>

..and this in the template downloads.html

<perch:repeater id="downloads" label="Downloads">

    <a href="<perch:content id="download" type="file" label="Download" order="1" />"><perch:content type="text" id="desc" label="Title" order="1" required="true" title="true" /></a>

</perch:repeater>

What do I replace ~~~ $tag_read_from_skip_template_output' ~~~ with? How do I get the assets tag (added in the assets app) come in to play?

Many thanks, Andy

Drew McLellan

Drew McLellan 2638 points
Perch Support

It would be $result[0]['id_of_your_tag_field']

Hi Drew,

What would the ID of the tag field be? Im trying to match the member tag to the asset tag in Assets?

Or do I need to add in ~~~ <perch:content id="tag" type="text" label="Member tag" suppress="true" /> ~~~ in to the template?

Drew McLellan

Drew McLellan 2638 points
Perch Support

To the asset tag? I'm not sure that will work.

OK, in that case back to the template method.

I have added

<perch:content id="tag" type="text" label="Member tag" suppress="true" />

in to the template.

and on the page I have

<?php
  perch_content_create('Downloads', array(
    'template'   => 'downloads.html',
    'sort' => 'date',
    'sort-order' => 'ASC'
  ));
?>

<?php
  $result = perch_content_custom('Downloads', array(
        'template' => 'downloads.html',
        'skip-template' => true,
        'return-html'   => true,
    ));
?>

<?php 
    if (perch_member_has_tag($result[0]['tag'])) {
        echo $result['html'];
    }
?>

Displays nothing on screen and gives this debug output:

Debug Message
SELECT * FROM perch2_members_sessions WHERE sessionID='25f28b6b730d926521dc74ea492b17e0f9418775' AND sessionHttpFootprint='cd20cbb671f1fc73c65abcdf3ddda185545866b3' AND sessionExpires>'2015-01-15 16:24:42' LIMIT 1
User is logged in
SELECT * FROM perch2_pages WHERE pagePath='/members/index.php' LIMIT 1
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/members/index.php' OR regionPage='*' ORDER BY regionPage DESC
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Downloads' AND (regionPage='/members/index.php' OR regionPage='*')
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=5 AND idx.itemRev=63)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
Using template: /templates/content/downloads.html
Array
(
    [type] => 8
    [message] => Undefined index: tag
    [file] => /Users/rifle-ak/Documents/Dev/contour-capital.com/members/index.php
    [line] => 84
)

Andy, you need to have ~~~ on a line by itself if you want it to format as code...

Hi Robert - thanks realised that after I posted! I have updated the post.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's not going to work with Asset tags in any way shape or form.

Hi Drew,

OK - I had abandoned the Asset tag idea.

So any ideas why this code is not working? For reference:

Page code:

<?php
    if (perch_member_logged_in()) {
?>  

    <!-- This content can be viewed by logged in users -->

    <div class="row">
        <div class="col-sm-6">
            <h3>User details:</h3>
            <h2><?php echo perch_member_get('first_name');?> <?php echo perch_member_get('last_name');?></h2>
            <h3><?php echo perch_member_get('email');?></h3>
            <a href="logout.php" class="btn btn-default">Log out</a>
        </div>
        <div class="col-sm-6">


            <?php
        perch_content_create('Downloads', array(
          'template'   => 'downloads.html',
          'sort' => 'date',
          'sort-order' => 'ASC'
        ));
      ?>

            <?php
        $result = perch_content_custom('Downloads', array(
                    'template' => 'downloads.html',
                    'skip-template' => true,
                    'return-html'   => true,
                    ));
            ?>

            <?php 
                if (perch_member_has_tag($result[0]['tag'])) {
                    echo $result['html'];
                }
            ?>

        </div>
    </div>

<?php
    } else {
        perch_members_login_form();
    }
?>

Template code:

<perch:repeater id="downloads" label="Downloads">

    <perch:content id="tag" type="text" label="Member tag" suppress="true" />
    <a href="<perch:content id="download" type="file" label="Download" order="1" />"><perch:content type="text" id="desc" label="Title" order="1" required="true" title="true" /></a>

</perch:repeater>

Debug output from the page:

Debug Message
SELECT * FROM perch2_members_sessions WHERE sessionID='00b52fd032df5cc397b67b88aa12f7a9b6e82052' AND sessionHttpFootprint='cd20cbb671f1fc73c65abcdf3ddda185545866b3' AND sessionExpires>'2015-01-19 09:18:26' LIMIT 1
User is logged in
SELECT * FROM perch2_pages WHERE pagePath='/members/index.php' LIMIT 1
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/members/index.php' OR regionPage='*' ORDER BY regionPage DESC
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Downloads' AND (regionPage='/members/index.php' OR regionPage='*')
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=6 AND idx.itemRev=2)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
Using template: /templates/content/downloads.html
Array
(
    [type] => 8
    [message] => Undefined index: tag
    [file] => /Users/rifle-ak/Documents/Dev/contour-capital.com/members/index.php
    [line] => 84
)

Thanks Drew...

Drew McLellan

Drew McLellan 2638 points
Perch Support

In what way is it not working? How does it fail?