Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | List of all members
LikeController Class Reference
Inheritance diagram for LikeController:
Controller BaseController

Public Member Functions

 actionIndex ()
 actionLogin ($return_url)

Additional Inherited Members

- Public Attributes inherited from Controller
 $menu = array()
 $breadcrumbs = array()
- Protected Member Functions inherited from BaseController
 beforeAction ($action)

Detailed Description

Gentics Portal.Node PHP Author & Copyright (c) by Gentics Software GmbH sales.nosp@m.@gen.nosp@m.tics..nosp@m.com http://www.gentics.com Licenses can be found in the LICENSE.txt file in the root-folder of this installation You must not use this software without a valid license agreement.

Comment controller class file.

Author
Vitalii Kovalchuk vital.nosp@m.y.ko.nosp@m.valch.nosp@m.uk@o.nosp@m.berig.nosp@m..com Comment controller class
Vitalii Kovalchuk vital.nosp@m.y.ko.nosp@m.valch.nosp@m.uk@o.nosp@m.berig.nosp@m..com

Definition at line 21 of file LikeController.php.

Member Function Documentation

LikeController::actionIndex ( )

default action used to like or unlike content

Returns
bool

Definition at line 28 of file LikeController.php.

References Like\model(), and LikeModule\t().

{
$contentId = Yii::app()->request->getPost('contentId', 0);
if (Yii::app()->user->isGuest || $contentId<=0) {
return false;
}
$model = Like::model()->findByAttributes(array('content_id'=>$contentId, 'user_id'=>Yii::app()->user->id));
if ($model) {
$model->delete();
$result['caption'] = '<span>' . LikeModule::t('Like') . '</span>';
} else {
/* user have not liked this content so make him like it */
$model = new Like();
$model->content_id = $contentId;
$model->user_id = Yii::app()->user->id;
$model->createdate = date('Y-m-d H:i:s');
$model->save();
$result['caption'] = '<span>' . LikeModule::t('Unlike') . '</span>';
}
/* formatting result array */
$result = array(
'contentId' => $model->content_id,
'likesQty' => $model->getLikesQty(),
'caption' => $result['caption'],
);
/* set likes qty limitations */
$model->lastLikesQty = Yii::app()->getModule('like')->lastLikesQty;
$model->topLikesQty = Yii::app()->getModule('like')->topLikesQty;
/* get top and last likes depending on config set above */
$likes = $model->getLikes();
$result['topLikes'] = array();
if ($model->topLikesQty > 0 && count($likes) > 0) {
for ($i = 0; $i < $model->topLikesQty && $i < count($likes); $i++) {
if ($likes[$i]->profile->user_id==Yii::app()->user->id) {
$result['topLikes'][] = LikeModule::t('You');
} else {
if (trim($likes[$i]->profile->firstname)!='' || trim($likes[$i]->profile->lastname)!='') {
$result['topLikes'][] = $likes[$i]->profile->firstname.' '.$likes[$i]->profile->lastname;
} else {
$result['topLikes'][] = LikeModule::t('Noname');
}
}
}
if (count($likes) > $model->topLikesQty) {
$result['andOthers'] = LikeModule::t('and').' '.($result['likesQty'] - $model->topLikesQty).' '.LikeModule::t('others like this');
}
}
$result['lastLikes'] = array();
if ($model->lastLikesQty > 0 && (count($likes) - $model->topLikesQty) > 0) {
for ($i = $model->topLikesQty; $i < ($model->topLikesQty + $model->lastLikesQty) && $i < count($likes); $i++) {
if (isset($likes[$i]->profile)) {
if ($likes[$i]->profile->user_id==Yii::app()->user->id) {
$result['lastLikes'][] = LikeModule::t('You');
} else {
if (trim($likes[$i]->profile->firstname) != '' || trim($likes[$i]->profile->lastname) != '') {
$result['lastLikes'][] = $likes[$i]->profile->firstname.' '.$likes[$i]->profile->lastname;
} else {
$result['lastLikes'][] = LikeModule::t('Noname');
}
}
}
}
if ($result['likesQty'] > count($likes)) {
$result['lastLikes'][] = LikeModule::t('And others...');
}
}
echo json_encode($result);
}
LikeController::actionLogin (   $return_url)

Intermidiate action. Used for saving $return_url in session to return back after log in.

Parameters
string$return_url- return url
Returns
void

Definition at line 120 of file LikeController.php.

{
Yii::app()->user->setReturnUrl($return_url);
$this->redirect(Yii::app()->getModule('like')->loginUrl);
}

The documentation for this class was generated from the following file: