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

Public Member Functions

 filters ()
 accessRules ()
 actionAdd ($return_url)
 actionApprove ($return_url= '')
 actionCancel ($return_url= '')
- Public Member Functions inherited from BaseController
 getClient ()
 getAssetsPath ()
 getViewFile ($viewName)
 getJs ($path)
 renderMail ($view, $title=null, $data)
 redirect ($url, $terminate=true, $statusCode=302)

Additional Inherited Members

- Public Attributes inherited from BaseController
 $layout = '//layouts/gportal'
 $mailLayout = '//layouts/mail'
- 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.

Definition at line 11 of file FriendsController.php.

Member Function Documentation

FriendsController::actionAdd (   $return_url)

Initialise friendship between two users

Parameters
string$return_urlreturn url
Exceptions
CHttpException

Definition at line 39 of file FriendsController.php.

References FriendsModule\encrypting(), Friendship\model(), and FriendsModule\t().

{
if (!isset($_GET['key'], $_GET['user_id']) || FriendsModule::encrypting($_GET['user_id']) != $_GET['key']) {
throw new CHttpException(400);
}
$friendship = Friendship::model()->findByPk(array('user1_id' => Yii::app()->user->id, 'user2_id' => $_GET['user_id']));
if ($friendship) {
$message = FriendsModule::t('You have already sent request.');
if ($friendship->status == Friendship::STATUS_NOT_APPROVED) {
$message .= FriendsModule::t('Not approved yet.');
} elseif ($friendship->status == Friendship::STATUS_APPROVED) {
$message .= FriendsModule::t('Approved yet.');
} elseif ($friendship->status == Friendship::STATUS_CANCELED) {
$message .= FriendsModule::t('Canceled by user.');
}
Yii::app()->user->setFlash('friends-error', $message);
$this->redirect($return_url);
}
$friendship = new Friendship();
$friendship->user1_id = Yii::app()->user->id;
$friendship->user2_id = $_GET['user_id'];
$friendship->status = Friendship::STATUS_NOT_APPROVED;
$friendship->save();
Yii::app()->user->setFlash('friends-success', FriendsModule::t("Your friend request was sent"));
$title = FriendsModule::t('Friendship request');
$notification = new Notification(
$title,
$this->renderMail('/mail_templates/add', $title, array('friendship' => $friendship)),
array(new EmailRecipient($friendship->friend(Yii::app()->user->id)->email, $this->module->notificationsEmail))
);
Yii::app()->notificationManager->notifyAbout($notification);
$this->redirect($return_url);
}
FriendsController::actionApprove (   $return_url = '')

Approve friendship between two users

Parameters
string$return_urlreturn url
Exceptions
CHttpException

Definition at line 85 of file FriendsController.php.

References FriendsModule\encrypting(), Friendship\model(), and FriendsModule\t().

{
if (!isset($_GET['key'], $_GET['user_id']) || FriendsModule::encrypting($_GET['user_id']) != $_GET['key']) {
throw new CHttpException(400);
}
$friendship = Friendship::model()->findByPk(array('user1_id' => $_GET['user_id'], 'user2_id' => Yii::app()->user->id));
if (!$friendship) {
Yii::app()->user->setFlash('friends-error', FriendsModule::t("Bad request"));
$this->redirect(Yii::app()->getModule('user')->friendListUrl);
}
if ($friendship->status != Friendship::STATUS_APPROVED) {
$friendship->status = Friendship::STATUS_APPROVED;
$friendship->save();
Yii::app()->user->setFlash('friends-success', FriendsModule::t("Friend request was approved"));
$title = FriendsModule::t('Friendship approved');
$notification = new Notification(
$title,
$this->renderMail('/mail_templates/approve', $title, array('friendship' => $friendship)),
array(new EmailRecipient($friendship->friend(Yii::app()->user->id)->email, $this->module->notificationsEmail))
);
Yii::app()->notificationManager->notifyAbout($notification);
} else {
Yii::app()->user->setFlash('friends-error', FriendsModule::t("Friend request already approved"));
}
if ($return_url) {
$this->redirect($return_url);
} else {
$this->redirect(Yii::app()->getModule('user')->friendListUrl);
}
}
FriendsController::actionCancel (   $return_url = '')

Cancel friendship between two users

Parameters
string$return_urlreturn url
Exceptions
CHttpException

Definition at line 126 of file FriendsController.php.

References FriendsModule\encrypting(), Friendship\model(), and FriendsModule\t().

{
if (!isset($_GET['key'], $_GET['user_id']) || FriendsModule::encrypting($_GET['user_id']) != $_GET['key']) {
throw new CHttpException(400);
}
$friendship = Friendship::model()->findByPk(array('user1_id' => $_GET['user_id'], 'user2_id' => Yii::app()->user->id));
if(!isset($friendship)){
$friendship = Friendship::model()->findByPk(array('user2_id' => $_GET['user_id'], 'user1_id' => Yii::app()->user->id));
}
if ($friendship->status != Friendship::STATUS_CANCELED) {
$friendship->status = Friendship::STATUS_CANCELED;
$friendship->save();
Yii::app()->user->setFlash('friends-success', FriendsModule::t("Friend request was canceled"));
$title = FriendsModule::t('Friendship canceled');
$notification = new Notification(
$title,
$this->renderMail('/mail_templates/cancel', $title, array('friendship' => $friendship)),
array(new EmailRecipient($friendship->friend(Yii::app()->user->id)->email, $this->module->notificationsEmail))
);
Yii::app()->notificationManager->notifyAbout($notification);
} else {
Yii::app()->user->setFlash('friends-error', FriendsModule::t("Friend request already canceled"));
}
if ($return_url) {
$this->redirect($return_url);
} else {
$this->redirect(Yii::app()->getModule('user')->friendListUrl);
}
}

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