示例#1
0
 /**
  * Convert an Action from a single association to multiassociation
  */
 public function convertToMultiassociation()
 {
     $success = true;
     if ($this->associationId) {
         $joinModel = ActionToRecord::model()->findByAttributes(array('actionId' => $this->id, 'recordId' => $this->associationId, 'recordType' => $this->associationType));
         if (!$joinModel) {
             $joinModel = new ActionToRecord();
             $joinModel->setAttributes(array('actionId' => $this->id, 'recordId' => $this->associationId, 'recordType' => $this->associationType), false);
             $success &= $joinModel->save();
         }
         $this->associationId = null;
     }
     $this->associationType = self::ASSOCIATION_TYPE_MULTI;
     $success &= $this->save();
     return $success;
 }
示例#2
0
文件: Actions.php 项目: xl602/X2CRM
 /**
  * Associate this action with a record (using join table)
  * @param X2Model $model 
  * @return mixed false if model couldn't be saved, -1 if association already exists, true
  *  if successful
  * @throws CException if this action has an invalid association type
  */
 public function multiAssociateWith(X2Model $model)
 {
     if ($this->associationType !== self::ASSOCIATION_TYPE_MULTI) {
         throw new CException('Attempting to multi-associate action with single association type');
     }
     $joinModel = ActionToRecord::model()->findByAttributes(array('actionId' => $this->id, 'recordId' => $model->id, 'recordType' => get_class($model)));
     if ($joinModel) {
         return -1;
     }
     $joinModel = new ActionToRecord();
     $joinModel->setAttributes(array('actionId' => $this->id, 'recordId' => $model->id, 'recordType' => get_class($model)), false);
     return $joinModel->save();
 }