Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
Comment Class Reference

Public Member Functions

 tableName ()
 setRequiredForAnonymous ($requiredForAnonymous)
 getRequiredForAnonymous ()
 rules ()
 relations ()
 defaultScope ()
 scopes ()
 delete ($completely=false)
 hash ()
 attributeLabels ()
 getStatusText ()
 search ()

Static Public Member Functions

static model ($className=__CLASS__)

Public Attributes

const NOT_APPROVED = 0
const APPROVED = 1
const DELETED = -1
 $verifyCode

Protected Attributes

 $requiredForAnonymous = null

Detailed Description

Definition at line 30 of file Comment.php.

Member Function Documentation

Comment::attributeLabels ( )

Get attribute labels

Returns
array

Definition at line 227 of file Comment.php.

References CommentsModule\t().

{
return array(
'content_id' => CommentsModule::t('Content id'),
'email' => CommentsModule::t('Email'),
'subject' => CommentsModule::t('Subject'),
'description' => CommentsModule::t('Description'),
'parent_id' => CommentsModule::t('Parent id'),
'user_id' => CommentsModule::t('User id'),
'notify_user' => CommentsModule::t('Notify me on new comments'),
'status' => CommentsModule::t('Status'),
'moderator_email' => CommentsModule::t('Moderator email'),
'firstname' => CommentsModule::t('First name'),
'lastname' => CommentsModule::t('Last name'),
'verifyCode' => CommentsModule::t('Verify Code'),
);
}
Comment::defaultScope ( )

Returns the default named scope that should be implicitly applied to all queries for this model.

Returns
array

Definition at line 167 of file Comment.php.

{
return array(
'condition' => 'status != ' . self::DELETED
);
}
Comment::delete (   $completely = false)

Delete comment

Parameters
bool$completelyif true delete from database
Returns
bool

Definition at line 201 of file Comment.php.

{
if ($completely) {
return parent::delete();
} else {
$this->status = self::DELETED;
return $this->update('status');
}
}
Comment::getRequiredForAnonymous ( )

Returns the array which include information about fields requirement

Returns
array if field is require

Definition at line 81 of file Comment.php.

Referenced by rules().

{
$initialValue = true;
if(isset($this->requiredForAnonymous) && $this->requiredForAnonymous == false){
$initialValue = false;
}
$Required = array(
'email' => $initialValue,
'firstname' => $initialValue,
'lastname' => $initialValue,
);
if(isset($this->requiredForAnonymous) && $this->requiredForAnonymous){
$requiredFields = explode(',', $this->requiredForAnonymous);
function trim_value(&$value){
$value = trim($value);
}
array_walk($requiredFields, 'trim_value');
foreach($Required as $fieldName=>&$isRequired){
if(in_array($fieldName,$requiredFields)){
$isRequired = true;
}else{
$isRequired = false;
}
}
}
return $Required;
}
Comment::getStatusText ( )

Comment status in readable format

Returns
string

Definition at line 250 of file Comment.php.

References CommentsModule\t().

{
$label = '';
switch ($this->status) {
case self::DELETED:
$label = CommentsModule::t('Deleted');
break;
case self::NOT_APPROVED:
$label = CommentsModule::t('Not approved');
break;
case self::APPROVED:
$label = CommentsModule::t('Approved');
break;
}
return $label;
}
Comment::hash ( )

Get comment hash

Returns
string comment hash for delete via email

Definition at line 216 of file Comment.php.

{
$str = $this->id . $this->parent_id . $this->subject . $this->description . $this->email . Yii::app()->getModule('comments')->hashSalt;
return md5($str);
}
static Comment::model (   $className = __CLASS__)
static
Comment::relations ( )

Return list of related object declarations

Returns
array

Definition at line 154 of file Comment.php.

{
return array(
'childs' => array(self::HAS_MANY, 'Comment', 'parent_id', 'alias' => 'comments_childs'),
'parent' => array(self::BELONGS_TO, 'Comment', 'parent_id')
);
}
Comment::rules ( )

Returns the validation rules for attributes.

Returns
array

Definition at line 118 of file Comment.php.

References getRequiredForAnonymous().

{
$rules = array();
$requiredForAnonymous = $this->getRequiredForAnonymous();
foreach($requiredForAnonymous as $fieldName => $isRequire){
if($isRequire){
$rules[] = array( $fieldName, 'required', 'on' => 'createAnonymous');
}
}
$rules = CMap::mergeArray($rules, array(
array('content_id, subject, description, language', 'required'),
array('email', 'required', 'except' => 'createAnonymous'),
array('parent_id, user_id, status', 'numerical', 'integerOnly' => true),
array('notify_moderator, notify_user', 'boolean'),
array('content_id, moderator_email, firstname, lastname, email, subject, createtime, language', 'length', 'max' => 255),
array('email, moderator_email', 'email'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, content_id, email, subject, description, parent_id, user_id, notify, status, moderator_email, firstname, lastname, createtime', 'safe', 'on' => 'search'),
array('firstname, lastname, description, email, subject','filter', 'filter'=>array($obj=new CHtmlPurifier(),'purify')),
));
if (Yii::app()->getController()) {
$rules[] = array('verifyCode', 'captcha', 'on' => 'createAnonymous');
$rules[] = array('verifyCode', 'captcha', 'on' => 'create');
}
return $rules;
}
Comment::scopes ( )

Returns the declaration of named scopes.

Returns
array

Definition at line 179 of file Comment.php.

{
return array(
'approved' => array(
'condition' => 'status = ' . self::APPROVED
),
'isParent' => array(
'condition' => 't.parent_id is NULL'
),
'isChild' => array(
'condition' => 't.parent_id is NOT NULL'
)
);
}
Comment::search ( )

Search

Returns
CActiveDataProvider

Definition at line 272 of file Comment.php.

{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('parent_id', $this->parent_id);
$criteria->compare('content_id', $this->content_id, true);
$criteria->compare('user_id', $this->user_id);
$criteria->compare('moderator_email', $this->moderator_email, true);
$criteria->compare('firstname', $this->firstname, true);
$criteria->compare('lastname', $this->lastname, true);
$criteria->compare('email', $this->email, true);
$criteria->compare('subject', $this->subject, true);
$criteria->compare('description', $this->description, true);
$criteria->compare('notify_moderator', $this->notify_moderator);
$criteria->compare('notify_user', $this->notify_user);
$criteria->compare('status', $this->status);
$criteria->compare('createtime', $this->createtime, true);
return new CActiveDataProvider($this, array('criteria' => $criteria,));
}
Comment::setRequiredForAnonymous (   $requiredForAnonymous)

Set the value of the protected variable $requiredForAnonymous

Definition at line 72 of file Comment.php.

{
$this->requiredForAnonymous = $requiredForAnonymous;
}
Comment::tableName ( )

Returns the name of the associated database table. By default this method returns the class name as the table name. You may override this method if the table is not named after this convention.

Returns
string the table name

Definition at line 65 of file Comment.php.

{
return '{{comments}}';
}

Member Data Documentation

const Comment::NOT_APPROVED = 0

Values for $status field

Definition at line 36 of file Comment.php.

Referenced by CommentController\actionApprove(), CommentController\actionCreate(), and CommentController\actionRemoteApprove().


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