Jump to content

Prevent users from submitting listings until a profile is complete


DanielH

Recommended Posts

Alejandro,

 

Been working with the solution you gave us to not allow submissions from this thread. until a profile has been submitted and approved.

 

The only thing I am able to accomplish is all listings/categories have no access even for profile submissions and users with profiles are redirected to the $profilePreview.

 

Tried various "!" and strings using the variables that are present and can get the create to load with a user that has a profile but the _loadForm never completes loading and yet the profile submission is completely inaccessible. The debug php and sql output does not show any syntax errors when reaching that point with the edits made.

 

Tried editing the noAccess function and the plgAfterFilter functions to no avail. I am understanding how the original userprofiles_listings_create.php is working to redirect to the profilePreview and prevent duplicate actions on profiles and your edited file just missing the code that differs from the listings_controller.php functions on create and _loadForm.

 

 

Also is it possible to instead query this check or not a good idea? I checked in phpMyAdmin using the following complete query from the debug output:

SELECT Listing.id AS `Listing.listing_id`, Listing.alias AS `Listing.slug`, Listing.title AS `Listing.title`, Listing.introtext AS `Listing.summary`, Listing.fulltext AS `Listing.description`, Listing.images AS `Listing.images`, Listing.hits AS `Listing.hits`, Listing.catid AS `Listing.cat_id`, Listing.created_by AS `Listing.user_id`, Listing.created_by_alias AS `Listing.author_alias`, Listing.created AS `Listing.created`, Listing.modified AS `Listing.modified`, Listing.access AS `Listing.access`, Listing.state AS `Listing.state`, Listing.publish_up AS `Listing.publish_up`, Listing.publish_down AS `Listing.publish_down`, Listing.metakey AS `Listing.metakey`, Listing.metadesc AS `Listing.metadesc`, 'com_content' AS `Listing.extension`, Field.featured AS `Listing.featured`, JreviewsCategory.criteriaid AS `Listing.listing_type_id`, Category.id AS `Category.cat_id`, Category.title AS `Category.title`, Category.alias AS `Category.slug`, Category.params AS `Category.params`, Directory.id AS `Directory.dir_id`, Directory.desc AS `Directory.title`, Directory.title AS `Directory.slug`, User.id AS `User.user_id`, User.name AS `User.name`, User.username AS `User.username`, User.email AS `User.email`, Claim.approved AS `Claim.approved`, Totals.user_rating AS `Review.user_rating`, Totals.user_rating_count AS `Review.user_rating_count`, Totals.user_criteria_rating AS `Review.user_criteria_rating`, Totals.user_criteria_rating_count AS `Review.user_criteria_rating_count`, Totals.user_comment_count AS `Review.review_count`, Totals.editor_rating AS `Review.editor_rating`, Totals.editor_rating_count AS `Review.editor_rating_count`, Totals.editor_criteria_rating AS `Review.editor_criteria_rating`, Totals.editor_criteria_rating_count AS `Review.editor_criteria_rating_count`, Totals.editor_comment_count AS `Review.editor_review_count`, Totals.media_count AS `Listing.media_count`, Totals.video_count AS `Listing.video_count`, Totals.photo_count AS `Listing.photo_count`, Totals.audio_count AS `Listing.audio_count`, Totals.attachment_count AS `Listing.attachment_count`, (Totals.media_count - Totals.media_count_user) AS `Listing.media_count_owner`, (Totals.video_count - Totals.video_count_user) AS `Listing.video_count_owner`, (Totals.photo_count - Totals.photo_count_user) AS `Listing.photo_count_owner`, (Totals.audio_count - Totals.audio_count_user) AS `Listing.audio_count_owner`, (Totals.attachment_count - Totals.attachment_count_user) AS `Listing.attachment_count_owner`, Totals.media_count_user AS `Listing.media_count_user`, Totals.video_count_user AS `Listing.video_count_user`, Totals.photo_count_user AS `Listing.photo_count_user`, Totals.audio_count_user AS `Listing.audio_count_user`, Totals.attachment_count_user AS `Listing.attachment_count_user` FROM #_content AS Listing LEFT JOIN #_jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.id AND Totals.extension = 'com_content' LEFT JOIN #_jreviews_content AS Field ON Field.contentid = Listing.id LEFT JOIN #_jreviews_categories AS JreviewsCategory ON JreviewsCategory.id = Listing.catid AND JreviewsCategory.`option` = 'com_content' LEFT JOIN #_categories AS Category ON Category.id = Listing.catid AND Category.extension = 'com_content' LEFT JOIN #_jreviews_directories AS Directory ON Directory.id = JreviewsCategory.dirid LEFT JOIN #_users AS User ON User.id = Listing.created_by LEFT JOIN #_jreviews_claims AS Claim ON Claim.listing_id = Listing.id AND Claim.user_id = Listing.created_by AND Claim.approved = 1 WHERE 1 = 1 AND ( Listing.catid IN (105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,75,71) AND Listing.created_by = {user_id} );

which does return the current users profile if having one. Tried to shorten the sql up by removing the totals queries but did not have success getting the shorter version to work yet.

 

Would you be willing to offer more suggestions to get this working for one last stab at it before I have someone code it for me? I'm close using your example just missing something.

 

Thanks

Daniel

 

Edit: forgot to attach your edited file.

class UserprofilesListingsCreateComponent extends S2Component {

    var $c;

    var $published = true;

    function startup(& $controller)
    {
        $this->c = & $controller;

        $this->c->__initComponents(array('userprofiles_profile'));
    }

    function plgAfterListingSaveValidation(& $model)
    {
        // If the submission is for a user profile category, check if the user already submitted a profile
        // to prevent duplicate

        $profileDirId = Sanitize::getInt($this->c->Config, 'userprofiles-directory');

        $profileCatIds = $this->c->Category->getReviewCategoryIds(array('dir' => $profileDirId));

        if(Sanitize::getInt($this->c->data['Listing'],'id')) return;

        $selectedCatid = Sanitize::getInt($this->c->data['Listing'],'catid');

        if(in_array($selectedCatid, $profileCatIds))
        {
            if($this->c->UserprofilesProfile->getProfileListing($this->c->_user->id, array('count' => true)))
            {
                $model->validateClearErrors();

                $model->validateSetError('userprofiles', JreviewsLocale::getPHP('USERPROFILES_PROFILE_EXISTS'), $priority = 1);
            }
        }
    }

    function plgAfterFilter()
    {
        $output = & $this->c->output;

        // If already submitted a profile then the profile preview is shown

        $createPage = $this->c->name == 'listings' && $this->c->action == 'create';

        $loadForm = $this->c->name == 'listings' && $this->c->action == '_loadForm';

        $profilePreviewRender = null;

        if($createPage || $loadForm)
        {
            $profileDirId = Sanitize::getInt($this->c->Config, 'userprofiles-directory');

            $profileCatIds = $this->c->Category->getReviewCategoryIds(array('dir' => $profileDirId));

            $passedCatId = Sanitize::getInt($this->c->params, 'cat');

            $passedDataCatId = Sanitize::getInt($this->c->data, 'catid');

            if($profilePreview = $this->c->UserprofilesProfile->renderProfilePreview($this->c->_user->id))
            {
                $this->c->set('profilePreview', $profilePreview);

                $profilePreviewRender = $this->c->partialRender('profiles', 'create_profile_exists');
            }

            if($passedCatId && !in_array($passedCatId, $profileCatIds)) $this->noAccess($output, $profilePreview);

            if($passedDataCatId && !in_array($passedDataCatId, $profileCatIds)) $this->noAccess($output, $profilePreview);

            if($createPage && $passedCatId && $profilePreviewRender)
            {
                $output = $profilePreviewRender;
            }
            elseif($loadForm && $passedDataCatId && $profilePreviewRender) {

                $output = json_encode(array('action' => 'show_form', 'html' => $profilePreviewRender));
            }

            $this->noAccess($output, $profilePreview);
        }
    }

    protected function noAccess(& $output, $hasProfile)
    {
        if(!$hasProfile) {
            $output = 'You need to submit your public profile to submit a listing';
        }
    }
}
Link to comment
  • 2 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...