creecros / MetaMagik

Custom Fields for Kanboard - Plugin MetaMagik
MIT License
99 stars 16 forks source link

Referencing custom field in automatic action #73

Closed oszem closed 3 years ago

oszem commented 3 years ago

Can you please help how to reference a tasks's custom field in an automatic action? I would like to use a custom field to be involved in the task title. Thanks in advance!

creecros commented 3 years ago

you will need to be a bit more detailed. are you creating and automatic action and don't understand how to pull the data? go step by step, what are you trying to accomplish.

oszem commented 3 years ago

Thanks for the quick reply!

I would like to create an automatic action where task title is generated from metadata created via MetaMagik.

Here is my code, but it doesn't work mainly, because I don't know how to refer to metadata in getEventRequiredParameters:

`<?php

namespace Kanboard\Plugin\RenameTaskbyMetadata\Action;

use Kanboard\Model\TaskModel; use Kanboard\Model\TaskMetadataModel; use Kanboard\Action\Base;

class TaskRenameBasedOnMetadata extends Base {

public function getDescription()
{
    return t('TaskRenameBasedOnMetadata');
}

public function getCompatibleEvents()
{
    return array(
        TaskModel::EVENT_CREATE_UPDATE,
    );
}

public function getActionRequiredParameters()
{
    return array(
    );
}

public function getEventRequiredParameters()
{
    return array(
        'task_id',
        'metadata1',
    );
}

public function doAction(array $data)
{
    $title_test = $this->taskMetadataModel->get($data['task_id'], $data['metadata1']);
        $values = array(
            'id' => $data['task_id'],
            'title' => $title_test,
    );

    return $this->taskModificationModel->update($values, false);
}

public function hasRequiredCondition(array $data)
{
    return true;
}

}`

creecros commented 3 years ago

OK, so, I still am sluggishly following the idea.

if a certain custom field equals a certain value, then update title to certain value?

or

no matter what, change title to certain value of custom field?

I've never pulled metadata from an event, nor have I ever pondered this to even know if such an event exists. you would need to look through the events, and see if such an event exists, im doubtful. there are workarounds, but it seems such information would be static, unless this custom field contains an array, so not fully understanding your action yet. forget the code for a second. walk me through it, step by step.

oszem commented 3 years ago

So the idea is that I fill out the custom fields (metadata1, 2,3), and the task's title is generated from these custom fields' value (doesn't matter what the title currently is). As it is an array I would implode( ) them.

So do you think most probably a new event needs to be programmed?

Example: "Daniel 75kg 183cm" (metadata1: name, metadata2: weight, metadata3: height)

oszem commented 3 years ago

I managed to figure it out how you export the metamagik metadata fields! Thank you!