-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert Workflow_SubmissionModel into element type
- Loading branch information
1 parent
abfc32a
commit 00ecab7
Showing
15 changed files
with
360 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
workflow/elementactions/Workflow_SubmissionsStatusElementAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
namespace Craft; | ||
|
||
class Workflow_SubmissionsStatusElementAction extends BaseElementAction | ||
{ | ||
// Public Methods | ||
// ========================================================================= | ||
|
||
public function getTriggerHtml() | ||
{ | ||
return craft()->templates->render('workflow/_elementactions/status'); | ||
} | ||
|
||
public function performAction(ElementCriteriaModel $criteria) | ||
{ | ||
$status = $this->getParams()->status; | ||
|
||
// Figure out which element IDs we need to update | ||
$elementIds = $criteria->ids(); | ||
|
||
// Update their statuses | ||
craft()->db->createCommand()->update( | ||
'workflow_submissions', | ||
array('status' => $status), | ||
array('in', 'id', $elementIds) | ||
); | ||
|
||
// Clear their template caches | ||
craft()->templateCache->deleteCachesByElementId($elementIds); | ||
|
||
// Fire an 'onSetStatus' event | ||
$this->onSetStatus(new Event($this, array( | ||
'criteria' => $criteria, | ||
'elementIds' => $elementIds, | ||
'status' => $status, | ||
))); | ||
|
||
$this->setMessage(Craft::t('Statuses updated.')); | ||
|
||
return true; | ||
} | ||
|
||
public function onSetStatus(Event $event) | ||
{ | ||
$this->raiseEvent('onSetStatus', $event); | ||
} | ||
|
||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
protected function defineParams() | ||
{ | ||
return array( | ||
'status' => array(AttributeType::Enum, 'values' => array( | ||
Workflow_SubmissionsModel::APPROVED, | ||
Workflow_SubmissionsModel::PENDING, | ||
), 'required' => true) | ||
); | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
workflow/elementtypes/Workflow_SubmissionElementType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
namespace Craft; | ||
|
||
class Workflow_SubmissionElementType extends BaseElementType | ||
{ | ||
// Public Methods | ||
// ========================================================================= | ||
|
||
public function getName() | ||
{ | ||
return Craft::t('Workflow Submission'); | ||
} | ||
|
||
public function hasContent() | ||
{ | ||
return false; | ||
} | ||
|
||
public function hasTitles() | ||
{ | ||
return false; | ||
} | ||
|
||
public function hasStatuses() | ||
{ | ||
return true; | ||
} | ||
|
||
public function getStatuses() | ||
{ | ||
return array( | ||
Workflow_SubmissionModel::APPROVED => Craft::t('Approved'), | ||
Workflow_SubmissionModel::PENDING => Craft::t('Pending'), | ||
); | ||
} | ||
|
||
public function getSources($context = null) | ||
{ | ||
$settings = craft()->workflow->getSettings(); | ||
|
||
$sources = array( | ||
'*' => array( | ||
'label' => Craft::t('All Submissions'), | ||
), | ||
); | ||
|
||
$submissions = craft()->workflow_submissions->getAll(); | ||
|
||
foreach ($submissions as $submission) { | ||
$elementType = craft()->elements->getElementType($submission->owner->elementType); | ||
$key = 'elements:'.$elementType->classHandle; | ||
|
||
$sources[$key] = array('heading' => $elementType->name); | ||
|
||
$sources[$key.':all'] = array( | ||
'label' => Craft::t('All ' . $elementType->name), | ||
'criteria' => array('elementType' => $submission->owner->elementType), | ||
); | ||
} | ||
|
||
return $sources; | ||
} | ||
|
||
public function populateElementModel($row) | ||
{ | ||
return Workflow_SubmissionModel::populateModel($row); | ||
} | ||
|
||
public function defineTableAttributes($source = null) | ||
{ | ||
return array( | ||
'id' => Craft::t('Entry'), | ||
'editor' => Craft::t('Editor'), | ||
'dateCreated' => Craft::t('Date Submitted'), | ||
'publisher' => Craft::t('Publisher'), | ||
'dateApproved' => Craft::t('Date Approved'), | ||
); | ||
} | ||
|
||
public function defineSortableAttributes() | ||
{ | ||
return array( | ||
'id' => Craft::t('Entry'), | ||
'editor' => Craft::t('Editor'), | ||
'dateCreated' => Craft::t('Date Submitted'), | ||
'publisher' => Craft::t('Publisher'), | ||
'dateApproved' => Craft::t('Date Approved'), | ||
); | ||
} | ||
|
||
public function getTableAttributeHtml(BaseElementModel $element, $attribute) | ||
{ | ||
switch ($attribute) { | ||
case 'publisher': | ||
case 'editor': { | ||
if ($element->$attribute) { | ||
return "<a href='" . $element->$attribute->cpEditUrl . "'>" . $element->$attribute . "</a>"; | ||
} | ||
} | ||
default: { | ||
return parent::getTableAttributeHtml($element, $attribute); | ||
} | ||
} | ||
} | ||
|
||
public function defineCriteriaAttributes() | ||
{ | ||
return array( | ||
'ownerId' => array(AttributeType::Number), | ||
'draftId' => array(AttributeType::Number), | ||
'editorId' => array(AttributeType::Number), | ||
'publisherId' => array(AttributeType::Number), | ||
'status' => array(AttributeType::String, 'default' => Workflow_SubmissionModel::PENDING), | ||
'order' => array(AttributeType::String, 'default' => 'dateCreated asc'), | ||
); | ||
} | ||
|
||
public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) | ||
{ | ||
$query | ||
->addSelect(' | ||
workflow_submissions.ownerId, | ||
workflow_submissions.draftId, | ||
workflow_submissions.editorId, | ||
workflow_submissions.publisherId, | ||
workflow_submissions.status | ||
') | ||
->join('workflow_submissions workflow_submissions', 'workflow_submissions.id = elements.id'); | ||
|
||
if ($criteria->ownerId) { | ||
$query->andWhere(DbHelper::parseParam('workflow_submissions.ownerId', $criteria->ownerId, $query->params)); | ||
} | ||
|
||
if ($criteria->draftId) { | ||
$query->andWhere(DbHelper::parseParam('workflow_submissions.draftId', $criteria->draftId, $query->params)); | ||
} | ||
|
||
if ($criteria->editorId) { | ||
$query->andWhere(DbHelper::parseParam('workflow_submissions.editorId', $criteria->editorId, $query->params)); | ||
} | ||
|
||
if ($criteria->publisherId) { | ||
$query->andWhere(DbHelper::parseParam('workflow_submissions.publisherId', $criteria->publisherId, $query->params)); | ||
} | ||
|
||
if ($criteria->status) { | ||
$query->andWhere(DbHelper::parseParam('workflow_submissions.status', $criteria->status, $query->params)); | ||
} | ||
|
||
if ($criteria->dateCreated) { | ||
$query->andWhere(DbHelper::parseDateParam('workflow_submissions.dateCreated', $criteria->dateCreated, $query->params)); | ||
} | ||
} | ||
|
||
public function getAvailableActions($source = null) | ||
{ | ||
return array('Workflow_SubmissionsStatus'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.