Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
CommentsModule.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  * Comments module class file.
11  */
12 class CommentsModule extends CWebModule
13 {
14  /**
15  * @var string salt which is used for every hash operation in this module
16  */
17  public $hashSalt = 'h1ads29ds1a91hgj29jl451';
18 
19  public $notificationsEmail = 'comments@example.com';
20 
21  private $_assetsUrl;
22 
23  /**
24  * page contained UserLoginWidget
25  *
26  * @return mixed
27  */
28  public function getLoginUrl()
29  {
30  return is_array(Yii::app()->getModule('user')->loginUrl) ? Yii::app()->getModule('user')->loginUrl[0] : Yii::app()->getModule('user')->loginUrl;
31  }
32 
33  /**
34  * @var int the number of seconds in which the cached value will expire. 0 means never expire.
35  */
36  public $cacheTime = 60;
37 
38  /**
39  * Import dependent classes
40  *
41  * @return void
42  */
43  public function init()
44  {
45  // import the module-level models and components
46  $this->setImport(
47  array(
48  'comments.models.*',
49  'comments.widgets.*',
50  )
51  );
52  }
53 
54 
55  /**
56  * Check if current user have delete permission on comment
57  *
58  * @param Comment $comment comment for operation
59  *
60  * @return bool
61  */
62  public static function canDelete(Comment $comment)
63  {
64  return
65  ($comment->user_id != null && $comment->user_id == Yii::app()->user->id) ||
66  $comment->moderator_email == Yii::app()->user->email ||
67  Yii::app()->user->checkAccess('manageComments');
68  }
69 
70  /**
71  * Check if current user have approve permission on comment
72  *
73  * @param Comment $comment comment model
74  *
75  * @return bool
76  */
77  public static function canApprove($comment)
78  {
79  return $comment->moderator_email == Yii::app()->user->email || Yii::app()->user->checkAccess('manageComments');
80  }
81 
82  /**
83  * Check if exists comments with such moderator email
84  *
85  * @param string $email email
86  *
87  * @return bool
88  */
89  public static function isEmailModerator($email)
90  {
91  return !empty($email) ? Comment::model()->countByAttributes(array('moderator_email' => $email)) > 0 : false;
92  }
93 
94  /**
95  * Publish module assets and return url
96  *
97  * @return string
98  */
99  public function getAssetsUrl()
100  {
101  if (!$this->_assetsUrl) {
102  $this->_assetsUrl = Yii::app()->assetManager->publish(Yii::getPathOfAlias('comments.assets'), true);
103  }
104  return $this->_assetsUrl;
105  }
106 
107  /**
108  * Translates a message to the specified language.
109  *
110  * @param string $str message
111  * @param array $params params
112  * @param string $dic dictionary
113  *
114  * @return string
115  */
116  public static function t($str = '', $params = array(), $dic = 'core')
117  {
118  return Yii::t("CommentsModule." . $dic, $str, $params);
119  }
120 }