Beispiel #1
0
 public function afterSave()
 {
     parent::afterSave();
     $event = new Events();
     $event->visibility = 1;
     $event->associationType = 'TopicRepies';
     $event->associationId = $this->id;
     $event->user = Yii::app()->user->getName();
     $event->type = 'topic_reply';
     $event->save();
 }
Beispiel #2
0
 /**
  * Runs when a model is saved.
  * Scans attributes for phone numbers and index them in <tt>x2_phone_numbers</tt>.
  * Updates <tt>x2_relationships</tt> table based on link type fields.
  * Fires onAfterSave event.
  */
 public function afterSave()
 {
     if ($this->_runAfterCreate) {
         $this->afterCreate();
     } else {
         $this->afterUpdate();
     }
     $phoneFields = array();
     $linkFields = array();
     // look through fields for phone numbers and relationships
     foreach (self::$_fields[$this->tableName()] as &$_field) {
         if ($_field->type === 'phone') {
             $phoneFields[$_field->fieldName] = $this->getAttribute($_field->fieldName);
         } elseif ($_field->type === 'link') {
             $nameAndId = Fields::nameAndId($this->getAttribute($_field->fieldName));
             $linkFields[$_field->fieldName] = array('id' => $nameAndId[1], 'type' => $_field->linkType);
         }
     }
     // deal with phone numbers
     if (count($phoneFields)) {
         // clear out old phone numbers
         X2Model::model('PhoneNumber')->deleteAllByAttributes(array('modelId' => $this->id, 'modelType' => get_class($this)));
     }
     // create new entries in x2_phone_numbers
     foreach ($phoneFields as $field => &$number) {
         if (!empty($number)) {
             $num = new PhoneNumber();
             // eliminate everything other than digits
             $num->number = preg_replace('/\\D/', '', $number);
             $num->modelId = $this->id;
             $num->modelType = get_class($this);
             $num->fieldName = $field;
             $num->save();
         }
     }
     parent::afterSave();
     // raise onAfterSave event for behaviors, such as X2ChangeLogBehavior
 }
Beispiel #3
0
 public function afterSave()
 {
     $flow = CJSON::decode($this->flow);
     $triggerClass = $flow['trigger']['type'];
     if ($triggerClass === 'PeriodicTrigger') {
         $trigger = X2FlowTrigger::create($flow['trigger']);
         $trigger->afterFlowSave($this);
     }
     parent::afterSave();
 }
Beispiel #4
0
 /**
  * Save default layouts 
  */
 public function afterSave()
 {
     parent::afterSave();
     foreach ($this->_widgetLayouts as $name => $settings) {
         if ($settings) {
             $settings->save();
         }
     }
 }
Beispiel #5
0
 /**
  * Runs when a model is saved.
  * Scans attributes for phone numbers and index them in <tt>x2_phone_numbers</tt>.
  * Updates <tt>x2_relationships</tt> table based on link type fields.
  * Fires onAfterSave event.
  */
 public function afterSave()
 {
     if ($this->_runAfterCreate) {
         $this->afterCreate();
     } else {
         $this->afterUpdate();
     }
     $phoneFields = array();
     $linkFields = array();
     // look through fields for phone numbers and relationships
     foreach (self::$_fields[$this->tableName()] as &$_field) {
         if ($_field->type === 'phone') {
             $phoneFields[$_field->fieldName] = $this->getAttribute($_field->fieldName);
         } elseif ($_field->type === 'link') {
             $nameAndId = Fields::nameAndId($this->getAttribute($_field->fieldName));
             $linkFields[$_field->fieldName] = array('id' => $nameAndId[1], 'type' => $_field->linkType);
         }
     }
     // deal with phone numbers
     if (count($phoneFields)) {
         // clear out old phone numbers
         X2Model::model('PhoneNumber')->deleteAllByAttributes(array('modelId' => $this->id, 'modelType' => get_class($this)));
     }
     // create new entries in x2_phone_numbers
     foreach ($phoneFields as $field => &$number) {
         if (!empty($number)) {
             $num = new PhoneNumber();
             // eliminate everything other than digits
             $num->number = preg_replace('/\\D/', '', $number);
             $num->modelId = $this->id;
             $num->modelType = get_class($this);
             $num->fieldName = $field;
             $num->save();
         }
     }
     /////////////// deal with relationships ///////////////
     $oldAttributes = $this->getOldAttributes();
     $relationSql = '(firstType=:type1 AND firstId=:id1 AND secondType=:type2 AND secondId=:id2) OR
          (firstType=:type2 AND firstId=:id2 AND secondType=:type1 AND secondId=:id1)';
     foreach ($linkFields as $fieldName => &$relation) {
         list($oldLinkName, $oldLinkId) = Fields::nameAndId(isset($oldAttributes[$fieldName]) ? $oldAttributes[$fieldName] : '');
         if ($relation['id'] == $oldLinkId) {
             // skip field if it hasn't changed
             continue;
         }
         // forget old relationship (wouldn't it be nice...)
         if (!empty($oldLinkId)) {
             CActiveRecord::model('Relationships')->deleteAll($relationSql, array(':type1' => get_class($this), ':id1' => $this->id, ':type2' => $relation['type'], ':id2' => $oldLinkId));
         }
         // save new relationship
         if (!empty($relation['id']) && ctype_digit((string) $relation['id'])) {
             // check if there's already a relationship between these here thingies
             if (!CActiveRecord::model('Relationships')->exists($relationSql, array(':type1' => get_class($this), ':id1' => $this->id, ':type2' => $relation['type'], ':id2' => $relation['id']))) {
                 $rel = new Relationships();
                 $rel->firstType = get_class($this);
                 $rel->secondType = $relation['type'];
                 $rel->firstId = $this->id;
                 $rel->secondId = $relation['id'];
                 $rel->save();
             }
         }
     }
     parent::afterSave();
     // raise onAfterSave event for behaviors, such as X2ChangeLogBehavior
 }