Hi Shadow,
Thank you for your help and try, ...
here are the tables say for Videos Favorite Feature:
videos Table:
id int(11) UNSIGNED No auto_increment
user_id int(11) Yes NULL
category_id int(11) Yes NULL
name varchar(120) latin1_swedish_ci No
description text latin1_swedish_ci Yes NULL
embed_code text latin1_swedish_ci Yes NULL
video_thumb text latin1_swedish_ci Yes NULL
views int(11) No 0
comments int(11) No 0
last_comment datetime Yes NULL
featured int(1) UNSIGNED No 0
privacy int(1) UNSIGNED No 0
created datetime No 0000-00-00 00:00:00
favorites int(1) UNSIGNED No 0
spotlights int(1) UNSIGNED No 0
video_favorites Table:
id int(11) UNSIGNED No auto_increment
video_id int(11) UNSIGNED No 0
user_id int(11) No 0
video_user_id int(11) UNSIGNED No 0
created datetime No 0000-00-00 00:00:00
WHERE "video_user_id" IS ORIGINAL VIDEO POSTER to video table.
BUT THERE IS ALSO A User TABLE WHICH IS SO HUGE no need to paste in
here...
Here are Models:
video.php
<?php
class Video extends AppModel {
var $name = 'Video';
var $validate = array(
'name' => VALID_NOT_EMPTY,
'user_id' => VALID_NOT_EMPTY,
'category_id' => VALID_NOT_EMPTY,
'description' => VALID_NOT_EMPTY,
'embed_code' => VALID_NOT_EMPTY
);
var $belongsTo = array(
'VideoCategory' => array(
'className' => 'VideoCategory',
'foreignKey' => 'category_id'
),
'User'
);
var $hasMany = array(
'VideoComment' => array(
'className' => 'VideoComment',
'foreignKey' => 'video_id'
),
'VideoFavorite' => array(
'className' => 'VideoFavorite',
'foreignKey' => 'video_id'
)
);
function afterDelete()
{
$this->loadModels('VideoComment', 'VideoFavorite');
foreach($this->VideoComment->find('all', array('conditions' =>
array('VideoComment.video_id' => $this->id()))) as $video_comment)
$this->VideoComment->delete($video_comment);
foreach($this->VideoFavorite->find('all', array('conditions' =>
array('VideoFavorite.video_id' => $this->id()))) as $video_favorite)
$this->VideoFavorite->delete($video_favorite);
}
}
?>
AND video_favirite.php
<?php
class VideoFavorite extends AppModel {
var $name = 'VideoFavorite';
var $validate = array(
'video_id' => VALID_NOT_EMPTY,
'video_user_id' => VALID_NOT_EMPTY,
'user_id' => VALID_NOT_EMPTY
);
var $belongsTo = array('User' => array('foreignKey' =>
'video_user_id'), 'Video' => array('foreignKey' => 'video_id'),
'VideoCategory' => array('foreignKey' => 'video_id')
);
function afterDelete()
{
}
}
?>
AND user.php
<?php
class User extends AppModel {
var $name = 'User';
var $validate = array(
'username' => '/^[a-z0-9\_\-\.]{5,40}$/i',
'password' => VALID_NOT_EMPTY,
'firstname' => VALID_NOT_EMPTY,
'lastname' => VALID_NOT_EMPTY,
'gender' => VALID_NOT_EMPTY,
'birthday' => VALID_NOT_EMPTY,
'location' => VALID_NOT_EMPTY,
'email' => VALID_EMAIL
);
function afterDelete()
{
}
}
?>
here is the function to set favorite:
function set_favorites($id)
{
if(!($user = $this->User->findById($this->user['id'])))
{
$this->flash('error', ucfirst(i18n::translate('user not
found')));
$this->redirect('/');
}
else
{
if(!($video = $this->Video->findById($id)))
{
$this->flash('error', ucfirst(i18n::translate('video not
found')));
$this->redirect('/');
}
else
{
$favorite['VideoFavorite']['video_id'] = $video['Video']
['id'];
$favorite['VideoFavorite']['user_id'] = $user['User']['id'];
$favorite['VideoFavorite']['video_user_id'] = $video['Video']
['user_id'];
if(!$this->VideoFavorite->save($favorite))
{
$this->flash('error',
ucfirst(i18n::translate('unexpected')));
}
else
{
$this->User->query('UPDATE fociki_users' . ' SET
video_favorites = video_favorites + 1' . ' WHERE id = ' . $this-
>user['id']);
$this->flash('valid', ucfirst(i18n::translate('video
added to your favorites')));
}
$this->redirect('/videos/favorites/' . $user['User']
['username']);
}
}
}
ALL I NEED IS WHEN some User favorite that Video,... so that "Button"
= "Add To Favorite" will NOT show up since its in your Favorite
already. And can be removed from your Favorites after...
I don't know how to right the code... funny... aaa... Don't laugh at
me...
Thank You... ! All... !
Salute
Chris
On Feb 7, 11:24 pm, ShadowCross <[email protected]> wrote:
> Chris:
>
> I find it extremely difficult to make any recommendations without
> additional details, particularly:
> - the associations you defined in your User and Video models
> - the code in the controller/action that will be used to retrieve the
> information from the model(s)
> - the code (or snippet) of the view that will display the information
>
> In my previous reply, I made MAJOR assumptions, which, based on your
> reply, didn't really apply to your case.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php