Ajuda Com Sistema de Rede Social

Bom dia,

Eu preciso da ajuda de você (e creio que vá ajudar mais pessoas), porque estou desenvolvendo um sistema aonde tem usuário e posts basicamente, e usuário podem adicionar outros como amigos. Agora onde estou enrolado, estou tendo problemas para fazer o seguinte: se tem o usuário A e ele é amigo de B e C ele tem que receber o que B e C postaram ordenados por data_time decrescente.

Eu pensei em fazer uma relação no model Usuario, a relação é a seguinte:


public function relations(

{

        return array(

                'posts'=>array(self::HAS_MANY, 'Post', 'usuario_id'),

		'amigos'=>array(self::HAS_MANY, 'Amizade', 'de'),

	);

}



A tabela amizades é simples é id, de, para, data_tempo.

E no model Amizade teria outra relação do tipo BELONGS_TO que buscaria o usuário na tabela e traria esses posts.

Depois eu faria algo assim:


$usuario=Usuario::model()->findByPk($tal_id);

Depois percorreria um por um… bom… acho que não precisa mais continuar pra perceber a complicação da coisa, então, preciso da ajuda de vocês, eu já uso há algum tempinho o Yii uso ele pra tudo praticamente que eu faço, e nisso eu simplesmente empaquei ausheueshuhsese talvez a solução seja até bem simples,

Obrigado desde já.

try this (easy way):




// this is an example SQL query, use your own that feet your needs.

$usuarios = Usuario::model()->findAllBySql("select * from usuario order by date desc"); 

then, use the "usuarios" array(), you can use directly or convert it to a dataprovider using the CArrayDataProvider

First thanks for the reply, but that was not what I wanted. It would build a system like this: the User has friends and a page will receive updates of the network of his friends, for example, "Anderson posted a new message: Test message" or, "Anderson added new photos to the album Test Album ", I just need a basic example of how to do this. Thank you.

this will be done easy using Yii actions/views/controllers and models, so if you dont know Yii at all, it will be nice for you and for your application to explore more deeply on Yii,

what you need is:

when a friend submit a new message, via actionPostMessage (as an example), then inside this action you must create a new Notification record (a new instance of your Notification model, have you a "Notification" Model ? each one stored with date, time, creator_user, dest_user, content etc… ?). So, when the welcome screen of any user is shown then you list all "Notification" models associated with it. It seems to be your "Notification" is called "Post" in your own model, so use this model when users logs on or when it welcome screen is shown.

is very large to explain how to do that in this area, because involves many pieces,

Ok… mas eu consegui fazer, logo assim que terminar vou postar o código aqui.