function fetchParticipantMap($itemID, $sortBy, $offset, $limit, $field) { $itemParameters = array('item_id' => $itemID, 'offset' => $offset, 'limit' => $limit, 'sort_by' => $sortBy); if ($field !== false) { $itemParameters['sort_field'] = $field; } $children = eZCollaborationItemParticipantLink::fetchParticipantMap($itemParameters); if ($children === null) { $resultArray = array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND)); } else { $resultArray = array('result' => $children); } return $resultArray; }
function setLastRead($userID = false, $timestamp = false) { if ($userID === false) { $userID = eZUser::currentUserID(); } if ($timestamp === false) { $timestamp = time(); } $collaborationID = $this->attribute('id'); eZCollaborationItemStatus::setLastRead($collaborationID, $userID, $timestamp); eZCollaborationItemParticipantLink::setLastRead($collaborationID, $userID, $timestamp); }
static function handleCollaborationEvent($event, $item, &$parameters) { $participantList = eZCollaborationItemParticipantLink::fetchParticipantList(array('item_id' => $item->attribute('id'), 'participant_type' => eZCollaborationItemParticipantLink::TYPE_USER, 'as_object' => false)); $userIDList = array(); $participantMap = array(); foreach ($participantList as $participant) { $userIDList[] = $participant['participant_id']; $participantMap[$participant['participant_id']] = $participant; } // $collaborationIdentifier = $event->attribute( 'collaboration_identifier' ); $collaborationIdentifier = $event->attribute('data_text1'); $ruleList = eZCollaborationNotificationRule::fetchItemTypeList($collaborationIdentifier, $userIDList, false); $userIDList = array(); foreach ($ruleList as $rule) { $userIDList[] = $rule['user_id']; } $userList = array(); if (count($userIDList) > 0) { $db = eZDB::instance(); $userIDListText = $db->generateSQLINStatement($userIDList, 'contentobject_id', false, false, 'int'); $userList = $db->arrayQuery("SELECT contentobject_id, email FROM ezuser WHERE {$userIDListText}"); } else { return eZNotificationEventHandler::EVENT_SKIPPED; } $itemHandler = $item->attribute('handler'); $collectionHandling = $itemHandler->notificationCollectionHandling(); $db = eZDB::instance(); $db->begin(); if ($collectionHandling == self::NOTIFICATION_COLLECTION_ONE_FOR_ALL) { $tpl = eZTemplate::factory(); $tpl->resetVariables(); $tpl->setVariable('collaboration_item', $item); $result = $tpl->fetch('design:notification/handler/ezcollaboration/view/plain.tpl'); $subject = $tpl->variable('subject'); if ($tpl->hasVariable('message_id')) { $parameters['message_id'] = $tpl->variable('message_id'); } if ($tpl->hasVariable('references')) { $parameters['references'] = $tpl->variable('references'); } if ($tpl->hasVariable('reply_to')) { $parameters['reply_to'] = $tpl->variable('reply_to'); } if ($tpl->hasVariable('from')) { $parameters['from'] = $tpl->variable('from'); } if ($tpl->hasVariable('content_type')) { $parameters['content_type'] = $tpl->variable('content_type'); } $collection = eZNotificationCollection::create($event->attribute('id'), eZCollaborationNotificationHandler::NOTIFICATION_HANDLER_ID, eZCollaborationNotificationHandler::TRANSPORT); $collection->setAttribute('data_subject', $subject); $collection->setAttribute('data_text', $result); $collection->store(); foreach ($userList as $subscriber) { $collection->addItem($subscriber['email']); } } else { if ($collectionHandling == self::NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE) { $userCollection = array(); foreach ($userList as $subscriber) { $contentObjectID = $subscriber['contentobject_id']; $participant = $participantMap[$contentObjectID]; $participantRole = $participant['participant_role']; $userItem = array('participant' => $participant, 'email' => $subscriber['email']); if (!isset($userCollection[$participantRole])) { $userCollection[$participantRole] = array(); } $userCollection[$participantRole][] = $userItem; } $tpl = eZTemplate::factory(); $tpl->resetVariables(); foreach ($userCollection as $participantRole => $collectionItems) { $templateName = $itemHandler->notificationParticipantTemplate($participantRole); if (!$templateName) { $templateName = eZCollaborationItemHandler::notificationParticipantTemplate($participantRole); } $itemInfo = $itemHandler->attribute('info'); $typeIdentifier = $itemInfo['type-identifier']; $tpl->setVariable('collaboration_item', $item); $tpl->setVariable('collaboration_participant_role', $participantRole); $result = $tpl->fetch('design:notification/handler/ezcollaboration/view/' . $typeIdentifier . '/' . $templateName); $subject = $tpl->variable('subject'); if ($tpl->hasVariable('message_id')) { $parameters['message_id'] = $tpl->variable('message_id'); } if ($tpl->hasVariable('references')) { $parameters['references'] = $tpl->variable('references'); } if ($tpl->hasVariable('reply_to')) { $parameters['reply_to'] = $tpl->variable('reply_to'); } if ($tpl->hasVariable('from')) { $parameters['from'] = $tpl->variable('from'); } if ($tpl->hasVariable('content_type')) { $parameters['content_type'] = $tpl->variable('content_type'); } $collection = eZNotificationCollection::create($event->attribute('id'), eZCollaborationNotificationHandler::NOTIFICATION_HANDLER_ID, eZCollaborationNotificationHandler::TRANSPORT); $collection->setAttribute('data_subject', $subject); $collection->setAttribute('data_text', $result); $collection->store(); foreach ($collectionItems as $collectionItem) { $collection->addItem($collectionItem['email']); } } } else { if ($collectionHandling == self::NOTIFICATION_COLLECTION_PER_USER) { } else { eZDebug::writeError("Unknown collaboration notification collection handling type '{$collectionHandling}', skipping notification", __METHOD__); } } } $db->commit(); return eZNotificationEventHandler::EVENT_HANDLED; }
function participantRoleString() { if ($this->ParticipantRole < self::ROLE_CUSTOM) { return eZCollaborationItemParticipantLink::roleString($this->ParticipantRole); } $item = eZCollaborationItem::fetch($this->CollaborationID); return $item->attribute('type_identifier') . '_' . $item->handler()->participantRoleString($this->ParticipantRole); }
function participant() { return eZCollaborationItemParticipantLink::fetch( $this->CollaborationID, $this->ParticipantID ); }
function handleCustomAction($module, $collaborationItem) { $redirectView = 'item'; $redirectParameters = array('full', $collaborationItem->attribute('id')); $addComment = false; if ($this->isCustomAction('Comment')) { $addComment = true; } else { if ($this->isCustomAction('Accept') or $this->isCustomAction('Deny') or $this->isCustomAction('Defer')) { // check user's rights to approve $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); $participantList = eZCollaborationItemParticipantLink::fetchParticipantList(array('item_id' => $collaborationItem->attribute('id'))); $approveAllowed = false; foreach ($participantList as $participant) { if ($participant->ParticipantID == $userID && $participant->ParticipantRole == eZCollaborationItemParticipantLink::ROLE_APPROVER) { $approveAllowed = true; break; } } if (!$approveAllowed) { return $module->redirectToView($redirectView, $redirectParameters); } $contentObjectVersion = $this->contentObjectVersion($collaborationItem); $status = self::STATUS_DENIED; if ($this->isCustomAction('Accept')) { $status = self::STATUS_ACCEPTED; } else { if ($this->isCustomAction('Defer') or $this->isCustomAction('Deny')) { $status = self::STATUS_DENIED; } } $collaborationItem->setAttribute('data_int3', $status); $collaborationItem->setAttribute('status', eZCollaborationItem::STATUS_INACTIVE); $timestamp = time(); $collaborationItem->setAttribute('modified', $timestamp); $collaborationItem->setIsActive(false); $redirectView = 'view'; $redirectParameters = array('summary'); $addComment = true; } } if ($addComment) { $messageText = $this->customInput('ApproveComment'); if (trim($messageText) != '') { $message = eZCollaborationSimpleMessage::create('ezapprove_comment', $messageText); $message->store(); eZCollaborationItemMessageLink::addMessage($collaborationItem, $message, self::MESSAGE_TYPE_APPROVE); } } $collaborationItem->sync(); return $module->redirectToView($redirectView, $redirectParameters); }
static function createApproval($contentObjectID, $contentObjectVersion, $authorID, $approverIDList, $collaborationID = false) { $createNotification = false; $collaborationItem = false; $participantList = array(); if ($collaborationID === false) { $collaborationItem = eZCollaborationItem::create('ezapprove2', $authorID); $collaborationItem->setAttribute('data_int1', $contentObjectID); $collaborationItem->setAttribute('data_int2', $contentObjectVersion); $collaborationItem->setAttribute('data_int3', false); $collaborationItem->store(); $createNotification = true; $collaborationID = $collaborationItem->attribute('id'); $participantList[] = array('id' => $authorID, 'role' => eZCollaborationItemParticipantLink::ROLE_AUTHOR); } foreach ($approverIDList as $approverID) { $participantList[] = array('id' => $approverID, 'role' => eZCollaborationItemParticipantLink::ROLE_APPROVER); } // #HACK# ??? foreach ($participantList as $participantItem) { $participantID = $participantItem['id']; $participantRole = $participantItem['role']; $link = eZCollaborationItemParticipantLink::create($collaborationID, $participantID, $participantRole, eZCollaborationItemParticipantLink::TYPE_USER); $link->store(); $profile = eZCollaborationProfile::instance($participantID); $groupID = $profile->attribute('main_group'); eZCollaborationItemGroupLink::addItem($groupID, $collaborationID, $participantID); } // Create the notification if ($createNotification) { $collaborationItem->createNotificationEvent(); } return $collaborationItem; }