How to create custom content in Joomla! 3.0?

I need to create a user-specific content page, I have registered users, and I need to create a module / page / menu / channel or anything that displays articles that are intended for only one or more users.

For example, on my website I show the public some projects (articles edited as some architectural project), for example: news, finished projects, etc., some people register and can access other content intended for registered users, for example: new projects that only registered customers were interested in, so far I have managed to do this work, but now I have work that is designed for a specific user, and he / she can only see it in his feed, for example: the status of their project, made by us, some galleries with photos of work in progress, etc.

So, this feed should be a module / page / menu that displays articles with a specific category for registered users. But I want to publish an article intended only for a specific user or set of users, and impressions in this channel (module) or at least a completely new module that displays user-specific content without the need to create a category and access level for each user.

Is there an extension or plugin that helps me do this?

+4
source share
3 answers

you need to do two things:

  • (Users- > User group) . , .
  • (Users- > access-levels)
  • , .

, , , .

+2

, , :

(http://docs.joomla.org/J2.5:Creating_a_content_plugin). onContentPrepareForm created_by_alias, , .

function onContentPrepareForm($form, $data){
    // first check that context is right
    // Then change the type of the field. This should allow to select 
    // the user when you create the article. 
    $form->getField('created_by_alias')->__set('type', 'user'); 
}

onContentPrepareData, , created_by_alias ,

public function onContentPrepare($context, $article, $params, $page){
    // first check that context is right
    //Then fetch the user data: 

    if(is_int($article->created_by_alias)){ // ( Optionally check if the article is in a specific category )
        $db=JFactory::getDbo(); 
        $currentuser=JFactory::getUser(); 
        $allowedgroup=2; // the registered users group
        $sql="select u.id from #__users inner join #__user_usergroup_map ug (u.id=ug.user_id) where ug.group_id={$allowedgroup}";  
        $db->setQuery($sql);
        $user=$db->loadObject();  
        if($user->id==$currentuser){
            $data->user=$user; 
        }
        else{
            //Unset the article content to prevent unothorized users from seeing the content. 
            unset($article); 
        }
}

, (http://docs.joomla.org/Creating_a_simple_module), , :

$list=array(); 
$user=Jfactory::getUser(); 
if($user->id>0){
    $sql="select * from #__content where created_by_alias={$user->id}"; 
    // ( also add sql to check that the user has access, 
    // the article is published, the correct category etc)
    $db=Jfactory::getDbo(); 
    $db->setQuery($sql); 
    $list=$db->loadObjectList(); 
    if(!count($list)) return; 
}
else return; 
print_r($list); // Prints the content articles

. ( , ) . , . " " .

+2

: . UddeIM - . . UddeIM , . ..

+1

Source: https://habr.com/ru/post/1536650/


All Articles