public static function create_for_page($page, $author = null, $approvers = null, $notify = true) { if (!$author && $author !== FALSE) { $author = Member::currentUser(); } // take all members from the PublisherGroups relation on this record as a default if (!$approvers) { $approvers = $page->whoCanApprove(); } // if no publishers are set, the request will end up nowhere if (!$approvers->Count()) { user_error("No publishers selected", E_USER_ERROR); return null; } if (!self::can_create($author, $page)) { user_error("No create permnission for {$author->ID} on {$page->ID}", E_USER_ERROR); return null; } // get or create a publication request $request = $page->OpenWorkflowRequest(); if (!$request || !$request->ID) { $request = new WorkflowPublicationRequest(); $request->PageID = $page->ID; } // @todo Check for correct workflow class (a "publication" request might be overwritten with a "deletion" request) // @todo reassign original author as a reviewer if present $request->AuthorID = $author->ID; $request->write(); // assign publishers to this specific request foreach ($approvers as $approver) { $request->Approvers()->add($approver); } // open the request and notify interested parties $request->Status = 'AwaitingApproval'; $request->write(); return $request; }