Skip to content

Commit

Permalink
Dev: ported #11415 to other models
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 22, 2016
1 parent a463a2d commit 0e51fd1
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion application/models/Participant.php
Expand Up @@ -114,7 +114,7 @@ public function search()

$criteria = new CDbCriteria;

$criteria->compare('participant_id', $this->participant_id, true);
$criteria->compare('participant_id', $this->participant_id, false);
$criteria->compare('firstname', $this->firstname, true);
$criteria->compare('lastname', $this->lastname, true);
$criteria->compare('email', $this->email, true);
Expand Down
174 changes: 87 additions & 87 deletions application/models/ParticipantShare.php
Expand Up @@ -22,100 +22,100 @@
*/
class ParticipantShare extends LSActiveRecord
{
/**
* Returns the static model of Settings table
*
* @static
* @access public
/**
* Returns the static model of Settings table
*
* @static
* @access public
* @param string $class
* @return CActiveRecord
*/
public static function model($class = __CLASS__)
{
return parent::model($class);
}
* @return CActiveRecord
*/
public static function model($class = __CLASS__)
{
return parent::model($class);
}

/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{participant_shares}}';
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{participant_shares}}';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('participant_id, share_uid, date_added, can_edit', 'required'),
array('share_uid', 'numerical', 'integerOnly'=>true),
array('participant_id', 'length', 'max'=>50),
array('can_edit', 'length', 'max'=>5),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('participant_id, share_uid, date_added, can_edit', 'safe', 'on'=>'search'),
);
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('participant_id, share_uid, date_added, can_edit', 'required'),
array('share_uid', 'numerical', 'integerOnly'=>true),
array('participant_id', 'length', 'max'=>50),
array('can_edit', 'length', 'max'=>5),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('participant_id, share_uid, date_added, can_edit', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'participant_id' => 'Participant',
'share_uid' => 'Share Uid',
'date_added' => 'Date Added',
'can_edit' => 'Can Edit',
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'participant_id' => 'Participant',
'share_uid' => 'Share Uid',
'date_added' => 'Date Added',
'can_edit' => 'Can Edit',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;
$criteria=new CDbCriteria;

$criteria->compare('participant_id',$this->participant_id,true);
$criteria->compare('share_uid',$this->share_uid);
$criteria->compare('date_added',$this->date_added,true);
$criteria->compare('can_edit',$this->can_edit,true);
$criteria->compare('participant_id',$this->participant_id, false);
$criteria->compare('share_uid',$this->share_uid);
$criteria->compare('date_added',$this->date_added,true);
$criteria->compare('can_edit',$this->can_edit,true);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

public function storeParticipantShare($data)
public function storeParticipantShare($data)
{
$ownerid = Yii::app()->db->createCommand()->select('*')->from('{{participants}}')->where('participant_id = :participant_id')->bindParam(":participant_id", $data['participant_id'], PDO::PARAM_STR)->queryRow();
$ownerid = Yii::app()->db->createCommand()->select('*')->from('{{participants}}')->where('participant_id = :participant_id')->bindParam(":participant_id", $data['participant_id'], PDO::PARAM_STR)->queryRow();
// CHeck if share already exists
$arShare=self::findByPk(array('participant_id'=>$data['participant_id'],'share_uid'=>$data['share_uid']));
if ($ownerid['owner_uid'] == $data['share_uid']) return;
if(is_null($arShare ))// A check to ensure that the participant is not added to it's owner
{
Yii::app()->db->createCommand()->insert('{{participant_shares}}',$data);
}
if(is_null($arShare ))// A check to ensure that the participant is not added to it's owner
{
Yii::app()->db->createCommand()->insert('{{participant_shares}}',$data);
}
else
{
self::updateShare($data);
Expand All @@ -131,20 +131,20 @@ function updateShare($data)
}
$criteria = new CDbCriteria;
$criteria->addCondition("participant_id = '{$data['participant_id']}'");
$criteria->addCondition("share_uid = '{$data['share_uid']}' ");
$criteria->addCondition("share_uid = '{$data['share_uid']}' ");
ParticipantShare::model()->updateAll($data,$criteria);
}

function deleteRow($rows)
{
// Converting the comma separated id's to an array to delete multiple rows
$rowid=explode(",",$rows);
// Converting the comma separated id's to an array to delete multiple rows
$rowid=explode(",",$rows);
foreach($rowid as $row)
{
{
list($participantId, $uId)=explode("--", $row);
Yii::app()->db
Yii::app()->db
->createCommand()
->delete('{{participant_shares}}',"participant_id = '$participantId' AND share_uid = $uId");
}
}
}
}
}
2 changes: 1 addition & 1 deletion application/models/SurveyDynamic.php
Expand Up @@ -605,7 +605,7 @@ public function search()
}

// Basic filters
$criteria->compare('t.id',$this->id, true);
$criteria->compare('t.id',$this->id, false);
$criteria->compare('t.lastpage',$this->lastpage, true);
$criteria->compare('t.submitdate',$this->submitdate, true);
$criteria->compare('t.startlanguage',$this->startlanguage, true);
Expand Down

0 comments on commit 0e51fd1

Please sign in to comment.