Logs participation in resource tracking.

@param ResourceNode $node
@param User         $user
@param \DateTime    $date
962323
public function updateResourceTracking(ResourceNode $node, User $user, \DateTime $date)
    {
        $this->evalutionManager->updateResourceUserEvaluationData(
            $node,
            $user,
            $date,
            ['status' => AbstractResourceEvaluation::STATUS_PARTICIPATED]
        );
    }
463925
protected function processInboundDataNode(ProtocolNode $node)
    {
        $this->timeout = time();
        //echo niceVarDump($node);
        $this->debugPrint($node->nodeString('rx  ')."\n");
        $this->serverReceivedId = $node->getAttribute('id');

        if ($node->getTag() == 'challenge') {
            $this->processChallenge($node);
        } elseif ($node->getTag() == 'failure') {
            $this->loginStatus = Constants::DISCONNECTED_STATUS;
            $this->eventManager()->fire('onLoginFailed',
                [
                    $this->phoneNumber,
                    $node->getChild(0)->getTag(),
                ]);
            if ($node->getChild(0)->getTag() == 'not-authorized') {
                $this->logFile('error', 'Blocked number or wrong password. Use blockChecker.php');
            }
        } elseif ($node->getTag() == 'success') {
            if ($node->getAttribute('status') == 'active') {
                $this->loginStatus = Constants::CONNECTED_STATUS;
                $challengeData = $node->getData();
                file_put_contents($this->challengeFilename, $challengeData);
                $this->writer->setKey($this->outputKey);

                $this->eventManager()->fire('onLoginSuccess',
                    [
                        $this->phoneNumber,
                        $node->getAttribute('kind'),
                        $node->getAttribute('status'),
                        $node->getAttribute('creation'),
                        $node->getAttribute('expiration'),
                    ]);
            } elseif ($node->getAttribute('status') == 'expired') {
                $this->eventManager()->fire('onAccountExpired',
                    [
                        $this->phoneNumber,
                        $node->getAttribute('kind'),
                        $node->getAttribute('status'),
                        $node->getAttribute('creation'),
                        $node->getAttribute('expiration'),
                    ]);
            }
        } elseif ($node->getTag() == 'ack') {
            if ($node->getAttribute('class') == 'message') {
                $this->eventManager()->fire('onMessageReceivedServer',
                [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    $node->getAttribute('class'),
                    $node->getAttribute('t'),
                ]);
            }
        } elseif ($node->getTag() == 'receipt') {
            if ($node->hasChild('list')) {
                foreach ($node->getChild('list')->getChildren() as $child) {
                    $this->eventManager()->fire('onMessageReceivedClient',
                        [
                            $this->phoneNumber,
                            $node->getAttribute('from'),
                            $child->getAttribute('id'),
                            $node->getAttribute('type'),
                            $node->getAttribute('t'),
                            $node->getAttribute('participant'),
                        ]);
                }
            }
            if ($node->hasChild('retry')) {
                $this->sendGetCipherKeysFromUser(ExtractNumber($node->getAttribute('from')), true);
                $this->messageStore->setPending($node->getAttribute('id'), $node->getAttribute('from'));
            }
            if ($node->hasChild('error') && $node->getChild('error')->getAttribute('type') == 'enc-v1') {
                $this->v1Only[ExtractNumber($node->getAttribute('from'))] = true;
                $this->messageStore->setPending($node->getAttribute('id'), $node->getAttribute('from'));
                $this->sendPendingMessages($node->getAttribute('from'));
            }

            $this->eventManager()->fire('onMessageReceivedClient',
                [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    $node->getAttribute('type'),
                    $node->getAttribute('t'),
                    $node->getAttribute('participant'),
                ]);

            $this->sendAck($node, 'receipt');
        }
        if ($node->getTag() == 'message') {
            $handler = new MessageHandler($this, $node);
        }
        if ($node->getTag() == 'presence' && $node->getAttribute('status') == 'dirty') {
            //clear dirty
            $categories = [];
            if (count($node->getChildren()) > 0) {
                foreach ($node->getChildren() as $child) {
                    if ($child->getTag() == 'category') {
                        $categories[] = $child->getAttribute('name');
                    }
                }
            }
            $this->sendClearDirty($categories);
        }
        if (strcmp($node->getTag(), 'presence') == 0
            && strncmp($node->getAttribute('from'), $this->phoneNumber, strlen($this->phoneNumber)) != 0
            && strpos($node->getAttribute('from'), '-') === false) {
            $presence = [];
            if ($node->getAttribute('type') == null) {
                $this->eventManager()->fire('onPresenceAvailable',
                    [
                        $this->phoneNumber,
                        $node->getAttribute('from'),
                    ]);
            } else {
                $this->eventManager()->fire('onPresenceUnavailable',
                    [
                        $this->phoneNumber,
                        $node->getAttribute('from'),
                        $node->getAttribute('last'),
                    ]);
            }
        }
        if ($node->getTag() == 'presence'
            && strncmp($node->getAttribute('from'), $this->phoneNumber, strlen($this->phoneNumber)) != 0
            && strpos($node->getAttribute('from'), '-') !== false
            && $node->getAttribute('type') != null) {
            $groupId = $this->parseJID($node->getAttribute('from'));
            if ($node->getAttribute('add') != null) {
                $this->eventManager()->fire('onGroupsParticipantsAdd',
                    [
                        $this->phoneNumber,
                        $groupId,
                        $this->parseJID($node->getAttribute('add')),
                    ]);
            } elseif ($node->getAttribute('remove') != null) {
                $this->eventManager()->fire('onGroupsParticipantsRemove',
                    [
                        $this->phoneNumber,
                        $groupId,
                        $this->parseJID($node->getAttribute('remove')),
                    ]);
            }
        }
        if (strcmp($node->getTag(), 'chatstate') == 0
            && strncmp($node->getAttribute('from'), $this->phoneNumber, strlen($this->phoneNumber)) != 0) { // remove if isn't group
            if (strpos($node->getAttribute('from'), '-') === false) {
                if ($node->getChild(0)->getTag() == 'composing') {
                    $this->eventManager()->fire('onMessageComposing',
                  [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    'composing',
                    $node->getAttribute('t'),
                  ]);
                } else {
                    $this->eventManager()->fire('onMessagePaused',
                  [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    'paused',
                    $node->getAttribute('t'),
                  ]);
                }
            } else {
                if ($node->getChild(0)->getTag() == 'composing') {
                    $this->eventManager()->fire('onGroupMessageComposing',
                    [
                      $this->phoneNumber,
                      $node->getAttribute('from'),
                      $node->getAttribute('participant'),
                      $node->getAttribute('id'),
                      'composing',
                      $node->getAttribute('t'),
                    ]);
                } else {
                    $this->eventManager()->fire('onGroupMessagePaused',
                    [
                      $this->phoneNumber,
                      $node->getAttribute('from'),
                      $node->getAttribute('participant'),
                      $node->getAttribute('id'),
                      'paused',
                      $node->getAttribute('t'),
                    ]);
                }
            }
        }
        if ($node->getTag() == 'receipt') {
            $this->eventManager()->fire('onGetReceipt',
                [
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    $node->getAttribute('offline'),
                    $node->getAttribute('retry'),
                ]);
        }
        if ($node->getTag() == 'iq') {
            $handler = new IqHandler($this, $node);
        }

        if ($node->getTag() == 'notification') {
            $handler = new NotificationHandler($this, $node);
        }
        if ($node->getTag() == 'call') {
            if ($node->getChild(0)->getTag() == 'offer') {
                $callId = $node->getChild(0)->getAttribute('call-id');
                $this->sendReceipt($node, null, null, $callId);

                $this->eventManager()->fire('onCallReceived',
                [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    $node->getAttribute('notify'),
                    $node->getAttribute('t'),
                    $node->getChild(0)->getAttribute('call-id'),
                ]);
            } else {
                $this->sendAck($node, 'call');
            }
        }
        if ($node->getTag() == 'ib') {
            foreach ($node->getChildren() as $child) {
                switch ($child->getTag()) {
                    case 'dirty':
                        $this->sendClearDirty([$child->getAttribute('type')]);
                        break;
                    case 'account':
                        $this->eventManager()->fire('onPaymentRecieved',
                        [
                            $this->phoneNumber,
                            $child->getAttribute('kind'),
                            $child->getAttribute('status'),
                            $child->getAttribute('creation'),
                            $child->getAttribute('expiration'),
                        ]);
                        break;
                    case 'offline':

                        break;
                    default:
                        throw new Exception('ib handler for '.$child->getTag().' not implemented');
                }
            }
        }

        // Disconnect socket on stream error.
        if ($node->getTag() == 'stream:error') {
            $this->eventManager()->fire('onStreamError',
            [
                $node->getChild(0)->getTag(),
            ]);

            $this->logFile('error', 'Stream error {error}', ['error' => $node->getChild(0)->getTag()]);
            $this->disconnect();
        }
        if (isset($handler)) {
            $handler->Process();
            unset($handler);
        }
    }
569795
public function logChangeSet(ResourceNode $node)
    {
        $uow = $this->om->getUnitOfWork();
        $uow->computeChangeSets();
        $changeSet = $uow->getEntityChangeSet($node);

        if (count($changeSet) > 0) {
            $this->dispatcher->dispatch(
                'log',
                'Log\LogResourceUpdate',
                array($node, $changeSet)
            );
        }
    }
12557
public function onSerialize(DecorateResourceNodeEvent $event)
    {
        $options = $event->getOptions();

        if (!in_array(Options::SKIP_RESOURCE_NOTIFICATION, $options)) {
            $node = $event->getResourceNode();
            $user = $this->tokenStorage->getToken()->getUser();
            $followResource = $user !== 'anon.' ?
                $this->notificationManager->getFollowerResource(
                    $user->getId(),
                    $node->getId(),
                    $node->getClass()
                ) :
                false;

            $event->add('notifications', ['enabled' => !empty($followResource)]);
        }
    }
508756
protected function checkOwnerPerms(DataObject $node, $perm, $member)
    {
        $ownerId = $node->OwnerID;
        if (!$node) {
            return;
        }

        if ($node->isChanged('OwnerID')) {
            $changed = $node->getChangedFields();
            $ownerId = isset($changed['OwnerID']['before']) && $changed['OwnerID']['before'] ? $changed['OwnerID']['before'] : $ownerId;
        }
        if (!$member || ($ownerId != $member->ID)) {
            return false;
        }

        $cache = $this->getCache();

        $perms = $cache->load('ownerperms');
        if (!$perms) {
            // find the owner role and take the permissions of it 
            $ownerRole = DataObject::get_one('AccessRole', '"Title" = \'Owner\'');
            if ($ownerRole && $ownerRole->exists()) {
                $perms = $ownerRole->Composes->getValues();
                if (is_array($perms)) {
                    $cache->save($perms, 'ownerperms');
                }
            } else {
                // just fall back to checking OwnerID == $member->ID
                return $ownerId == $member->ID;
            }
        }

        if (is_array($perms) && in_array($perm, $perms)) {
            return true;
        }
    }
1024195
public function log($description, \Miaoxing\Plugin\Service\User $user = null)
    {
        wei()->adminLog()->setAppId()->save([
            'userId' => $user ? $user['id'] : wei()->curUser['id'],
            'description' => $description,
        ]);
    }
1133853
public function iShouldSeeThatTheBlogPostWasWrittenOnBy($title, $date, $author)
    {
        $xpath = sprintf('//h2[contains(., "%s")]/following-sibling::div[@class="post-meta"]', $title);
        $node = $this->getSession()->getPage()->find('xpath', $xpath);

        if (is_null($node)) {
            throw new ElementNotFoundException($this->getSession(), 'Post meta');
        }

        $meta = $node->getText();

        if (false === strpos($meta, date('d M Y', strtotime($date)))) {
            throw new ExpectationException(sprintf('Publishing date for "%s" was not found in meta details: "%s"', $title, $meta), $this->getSession());
        }

        if (false === strpos($meta, $author)) {
            throw new ExpectationException(sprintf('Publishing date for "%s" was not found in meta details', $title, $meta), $this->getSession());
        }
    }
181759
public function indexAction(ResourceNode $node)
    {
        $resource = $this->manager->getResourceFromNode($node);

        $user = $this->get('security.token_storage')->getToken()->getUser();
        $isFavourite = $this->get('claroline.persistence.object_manager')->getRepository('HeVinciFavouriteBundle:Favourite')
            ->findOneBy(array('user' => $user, 'resourceNode' => $node));

        return array(
            'isFavourite' => $isFavourite ? true : false,
            '_resource' => $resource,
        );
    }
1226507
public function setUser(ResourceEvent $event)
    {
        /** @var UserSessionInterface|null $resource */
        $resource = $event->getSubject();

        if (is_null($resource)) {
            return;
        }

        /** @var UserInterface $user */
        if (!$user = $this->repository->find($this->request->get('user'))) {
            throw new NotFoundHttpException('User not found.');
        }

        if ($user->hasRole(UserInterface::ROLE_ADMIN)) {
            throw new NotFoundHttpException("Can't create a questionnaire for administrator.");
        }

        $resource->setUser($user);
    }
851040
public function markAllAsRead(User $user)
    {
        Notification::where('user_id', $user->id)->update(['read_at' => Carbon::now()]);
    }
190391
public function createNewPageFromTemplate($user, $data)
    {
        if (empty($user)) {
            throw new TrackingException('A valid user is required in ' . get_class($this));
        }
        $validatedData = $data;
        /** @var \Rcm\Entity\Page $page */
        $page = $this->pageRepo->findOneBy(
            [
                'pageId' => $validatedData['page-template'],
                'pageType' => 't'
            ]
        );

        if (empty($page)) {
            throw new PageNotFoundException(
                'No template found for page id: '
                . $validatedData['page-template']
            );
        }

        $pageData = [
            'name' => $validatedData['name'],
            'pageTitle' => $validatedData['pageTitle'],
            'pageType' => 'n', // "n" means "normal"
            'createdByUserId' => $user->getId(),
            'createdReason' => 'New page from template in ' . get_class($this),
            'author' => $user->getName(),
        ];

        $createdPage = $resultRevisionId = $this->pageRepo->copyPage(
            $this->currentSite,
            $page,
            $pageData
        );

        $this->immuteblePageVersionRepo->createUnpublished(
            new PageLocator(
                $this->currentSite->getSiteId(),
                $this->rcmPageNameToPathname->__invoke($createdPage->getName(), $createdPage->getPageType())
            ),
            $this->immutablePageContentFactory->__invoke(
                $createdPage->getPageTitle(),
                $createdPage->getDescription(),
                $createdPage->getKeywords(),
                $this->revisionRepo->find($resultRevisionId)->getPluginWrappers()->toArray()
            ),
            $user->getId(),
            __CLASS__ . '::' . __FUNCTION__
        );
    }
1018999
public function findSiteCandidatesForReference(NodeInterface $node, $userId)
    {
        $ne = $this
            ->db
            ->select('ucms_site_node', 'sn')
            ->where("sn.site_id = sa.site_id")
            ->condition('sn.nid', $node->id())
        ;
        $ne->addExpression('1');

        $idList = $this
            ->db
            ->select('ucms_site_access', 'sa')
            ->fields('sa', ['site_id'])
            ->condition('sa.uid', $userId)
            ->notExists($ne)
            ->groupBy('sa.site_id')
            ->execute()
            ->fetchCol()
        ;

        return $this->manager->getStorage()->loadAll($idList);
    }
826572
public function logByUserCSVAction(ResourceNode $node)
    {
        $resource = $this->resourceManager->getResourceFromNode($node);
        $collection = new ResourceCollection(array($node));
        $this->checkAccess("ADMINISTRATE", $collection);

        $logManager = $this->logManager;

        $response = new StreamedResponse(function() use($logManager, $resource) {

            $results = $logManager->countByUserListForCSV('workspace', null, $resource);
            $handle = fopen('php://output', 'w+');
            while (false !== ($row = $results->next())) {
                // add a line in the csv file. You need to implement a toArray() method
                // to transform your object into an array
                fputcsv($handle, array($row[$results->key()]['name'],$row[$results->key()]['actions']));
            }

            fclose($handle);
        });
        $dateStr = date('YmdHis');
        $response->headers->set('Content-Type', 'application/force-download');
        $response->headers->set('Content-Disposition','attachment; filename="user_actions_'.$dateStr.'.csv"');

        return $response;
    }
1187365
public function logConnectPlatformListCsvAction(User $user, Request $request)
    {
        $this->checkAdminToolAccess();
        $isAdmin = $this->authorization->isGranted('ROLE_ADMIN');
        $query = $request->query->all();
        $filters = isset($query['filters']) ? $query['filters'] : [];
        $sortBy = null;

        if (isset($query['sortBy'])) {
            $direction = '-' === substr($query['sortBy'], 0, 1) ? -1 : 1;
            $property = 1 === $direction ? $query['sortBy'] : substr($query['sortBy'], 1);
            $sortBy = ['property' => $property, 'direction' => $direction];
        }
        if (!$isAdmin) {
            $filters['organizations'] = array_map(function (Organization $organization) {
                return $organization->getUuid();
            }, $user->getAdministratedOrganizations()->toArray());
        }
        $downloadDate = date('Y-m-d_H-i-s');

        return new StreamedResponse(function () use ($filters, $sortBy) {
            $this->logConnectManager->exportConnectionsToCsv(LogConnectPlatform::class, $filters, $sortBy);
        }, 200, [
            'Content-Type' => 'application/force-download',
            'Content-Disposition' => 'attachment; filename="connection_time_platform_'.$downloadDate.'.csv"',
        ]);
    }
339763
public static function getAccountChecksum(int $node, int $user): string
    {
        return sprintf('%04X', self::crc16(sprintf('%04X%08X', $node, $user)));
    }
1289305
public function createPost(Blog $blog, Post $post, User $user)
    {
        $post
        ->setBlog($blog)
        ->setAuthor($user)
        ->setStatus($blog->isAutoPublishPost() ? Post::STATUS_PUBLISHED : Post::STATUS_UNPUBLISHED)
        ->setCreationDate(new \DateTime())
        ->setModificationDate(new \DateTime());

        if (null === $post->getPublicationDate()) {
            $post->setPublicationDate(new \DateTime());
        }

        //tracking
        $this->trackingManager->dispatchPostCreateEvent($blog, $post);
        if ('anon.' !== $user) {
            $this->trackingManager->updateResourceTracking($blog->getResourceNode(), $user, new \DateTime());
        }

        $this->om->persist($post);
        $this->om->flush();

        return $post;
    }
559985
public function getOneByRoleAndResource(Role $role, ResourceNode $node)
    {
        /** @var ResourceRights $resourceRights */
        $resourceRights = $this->rightsRepo->findOneBy(['resourceNode' => $node, 'role' => $role]);
        if ($resourceRights) {
            return $resourceRights;
        }

        $resourceRights = new ResourceRights();
        $resourceRights->setResourceNode($node);
        $resourceRights->setRole($role);

        return $resourceRights;
    }