Skip to content

Commit

Permalink
Set vv_cur_co for cos (CFM-18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jan 28, 2022
1 parent 7037c3b commit 677f3be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/src/Controller/CosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ class CosController extends StandardController {
]
];

/**
* Callback run prior to the view rendering.
*
* @since COmanage Registry v5.0.0
* @param EventInterface $event Cake Event
*/

public function beforeRender(\Cake\Event\EventInterface $event) {
// In order to get the sidebar to render we need to set the current CO,
// which for cos is the COmanage CO.
$this->set('vv_cur_co', $this->Cos->find('COmanageCO')->firstOrFail());

return parent::beforeRender($event);
}

/*
* XXX implement, also REST API
*
Expand Down
20 changes: 16 additions & 4 deletions app/src/Model/Table/CosTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ public function duplicate($id) {
// XXX document AR-CO-4, use TableMetaTrait to determine which tables are configuration
}*/

/**
* Find the COmanage CO.
*
* @since COmanage Registry v5.0.0
* @param \Cake\ORM\Query $query Query
* @return \Cake\ORM\Query Query
*/

public function findCOmanageCO(Query $query): Query {
return $query->where(['lower(name)' => 'comanage']);
}

/**
* Determine if this is a Read Only record.
*
Expand All @@ -172,7 +184,7 @@ public function duplicate($id) {
* @return boolean true if the entity is read only, false otherwise
*/

public function isReadOnly($entity) {
public function isReadOnly($entity): bool {
// The COmanage CO is read only

return $entity->isCOmanageCO();
Expand All @@ -187,7 +199,7 @@ public function isReadOnly($entity) {
* @return boolean true if the Rule check passes, false otherwise
*/

public function ruleIsCOmanageCO($entity, $options) {
public function ruleIsCOmanageCO($entity, $options): bool {
// We want negative logic since we want to fail if we're editing the COmanage CO
if($entity->isCOmanageCO()) {
return __d('error', 'edit.comanage');
Expand All @@ -205,7 +217,7 @@ public function ruleIsCOmanageCO($entity, $options) {
* @return boolean true if the Rule check passes, false otherwise
*/

public function ruleIsActive($entity, $options) {
public function ruleIsActive($entity, $options): bool {
// We want negative logic since we want to fail if the record is Active
if($entity->status == TemplateableStatusEnum::Active) {
return __d('error', 'delete.active');
Expand All @@ -222,7 +234,7 @@ public function ruleIsActive($entity, $options) {
* @return bool True on success
*/

public function setup(int $id) {
public function setup(int $id): bool {
$Types = TableRegistry::getTableLocator()->get('Types');

// AR-Type-1 Set up the default values for extended types
Expand Down

0 comments on commit 677f3be

Please sign in to comment.