Exemple #1
0
 /**
  * Recalculate activity contacts on add new activity to the target
  *
  * @param ActivityEvent $event
  */
 public function onAddActivity(ActivityEvent $event)
 {
     $activity = $event->getActivity();
     $target = $event->getTarget();
     $direction = $this->activityContactProvider->getActivityDirection($activity, $target);
     if ($direction !== DirectionProviderInterface::DIRECTION_UNKNOWN) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $contactDate = $this->activityContactProvider->getActivityDate($activity);
         $accessor->setValue($target, ActivityScope::CONTACT_COUNT, (int) $accessor->getValue($target, ActivityScope::CONTACT_COUNT) + 1);
         $lastContactDate = $accessor->getValue($target, ActivityScope::LAST_CONTACT_DATE);
         if ($lastContactDate < $contactDate) {
             $accessor->setValue($target, ActivityScope::LAST_CONTACT_DATE, $contactDate);
         }
         if ($direction === DirectionProviderInterface::DIRECTION_INCOMING) {
             $directionCountPath = ActivityScope::CONTACT_COUNT_IN;
             $contactDatePath = ActivityScope::LAST_CONTACT_DATE_IN;
         } else {
             $directionCountPath = ActivityScope::CONTACT_COUNT_OUT;
             $contactDatePath = ActivityScope::LAST_CONTACT_DATE_OUT;
         }
         $accessor->setValue($target, $directionCountPath, (int) $accessor->getValue($target, $directionCountPath) + 1);
         $lastContactDate = $accessor->getValue($target, $contactDatePath);
         if ($lastContactDate < $contactDate) {
             $accessor->setValue($target, $contactDatePath, $contactDate);
         }
     }
 }
 public function testEvent()
 {
     $target = new \stdClass();
     $activity = new \stdClass();
     $event = new ActivityEvent($activity, $target);
     $this->assertSame($target, $event->getTarget());
     $this->assertSame($activity, $event->getActivity());
 }
Exemple #3
0
 /**
  * @param ActivityEvent $event
  */
 public function onRemoveActivity(ActivityEvent $event)
 {
     $activity = $event->getActivity();
     $target = $event->getTarget();
     if (TargetExcludeList::isExcluded(ClassUtils::getClass($target))) {
         return;
     }
     $accessor = PropertyAccess::createPropertyAccessor();
     $accessor->setValue($target, ActivityScope::CONTACT_COUNT, (int) $accessor->getValue($target, ActivityScope::CONTACT_COUNT) - 1);
     $direction = $this->activityContactProvider->getActivityDirection($activity, $target);
     list($directionProperty) = $this->getDirectionProperties($direction);
     $accessor->setValue($target, $directionProperty, (int) $accessor->getValue($target, $directionProperty) - 1);
 }