Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: PHP Notice: Trying to access array offset on value of type null #14

Closed
aljawaid opened this issue Jan 14, 2023 · 16 comments
Closed
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@aljawaid
Copy link
Owner

For Project Name / Project Identifier, getting the following error:

PHP Notice:  Trying to access array offset on value of type null in /var/www/mydomain.com/public_html/plugins/KanboardEmailHistory/Action/EmailTaskHistory.php on line 72

$subject = $this->getParam('subject') . ": " . $project['name'] . " " . $data['task']['title'] . " (#" . $data['task']['id'] . ")";

Relates to: #7 Use Project Name & Identifier in Email Subject

@aljawaid aljawaid added bug Something isn't working help wanted Extra attention is needed labels Jan 14, 2023
@aljawaid
Copy link
Owner Author

@creecros I think $project['name'] is called wrong?

Should it be:
$project = $this->projectModel->getById($data['task']['project_id']); (worked for email so I moved it for subject too)

  • $project_id['name'] (because of line 62)
  • $data['task']['project_id']['name']
  • $data['project']['name'])

@aljawaid
Copy link
Owner Author

oh wait... it could be the language strings

@creecros
Copy link
Collaborator

creecros commented Jan 15, 2023

I am still on my phone, but would say none are correct.

the only event parameter you have is task.

with what you have. you would need to use the project model to grab the project before calling name.

like you did here

$project = $this->projectModel->getById($project_id);

and this is confusing, don't call this project_id, it's project.

$project_id = $this->projectModel->getById($data['task']['project_id']);

actually, now I think I see your issue.

the last one is correct, I just don't like the confusing variable name, and then you used that confusion the second time on line 71. that's where your array to string issue is, because $project_id is not a string, that's an array.

aljawaid added a commit that referenced this issue Jan 15, 2023
@aljawaid
Copy link
Owner Author

Does 8b9b031 fix it?

aljawaid added a commit that referenced this issue Jan 15, 2023
@aljawaid
Copy link
Owner Author

aljawaid commented Jan 15, 2023

@creecros I think 29f15a9 is what you meant?

But now, is $subject = $this->getParam('subject') . ": " . $project['name'] . " " . $project['identifier']; called correctly?

or should it be...
$data['task']['project_name'] to display/call it?

@aljawaid
Copy link
Owner Author

@creecros any advice how to call the project name based on the last comment?

@creecros
Copy link
Collaborator

$project = $this->projectModel->getById($data['task']['project_id']); is correct.

and $project['name'] should now work.

@aljawaid
Copy link
Owner Author

aljawaid commented Jan 15, 2023

It still doesnt work, I think my elseif might be wrong.... I will look into them again

// SUBJECT OPTIONS
        if ($this->getParam('check_box_include_title') == true ) {
            // TASK TITLE // Subject becomes: `subject` `task title` `task id`
            $subject = $this->getParam('subject') . ": " . $data['task']['title'] . " (#" . $data['task']['id'] . ")";

        } elseif ($this->getParam('check_box_include_project') == true ) {
            // PROJECT NAME // Subject becomes: `subject` `project name` `task title` `task id`
            $project = $this->projectModel->getById($data['task']['project_id']);
            $subject = $this->getParam('subject') . ": " . $project['name'] . " " . $data['task']['title'] . " (#" . $data['task']['id'] . ")";

        } elseif ($this->getParam('check_box_include_title') == true && $this->getParam('check_box_include_project_identifier')) {
            // PROJECT IDENTIFIER // Subject becomes: `subject` `project identifier`
            $project = $this->projectModel->getById($data['task']['project_id']);
            $subject = $this->getParam('subject') . ": " . $project['identifier'];

        } elseif ($this->getParam('check_box_include_title') == true && $this->getParam('check_box_include_project_identifier')) {
            // PROJECT IDENTIFIER + TITLE // Subject becomes: `subject` `project identifier` `task title` `task id`
            $project = $this->projectModel->getById($data['task']['project_id']);
            $subject = $this->getParam('subject') . ": " . $project['identifier'] . " " . $data['task']['title'] . " (#" . $data['task']['id'] . ")";

        } elseif ($this->getParam('check_box_include_project') == true && $this->getParam('check_box_include_project_identifier')) {
            // PROJECT NAME + PROJECT IDENTIFIER // Subject becomes: `subject` `project identifier`
            $project = $this->projectModel->getById($data['task']['project_id']);
            $subject = $this->getParam('subject') . ": " . $project['name'] . " " . $project['identifier'];

        } elseif ($this->getParam('check_box_include_title') == true && $this->getParam('check_box_include_project')) {
            // PROJECT NAME + TITLE // Subject becomes: `subject` `project name` `task title` `task id`
            $project = $this->projectModel->getById($data['task']['project_id']);
            $subject = $this->getParam('subject') . ": " . $project['name'] . " " . $data['task']['title'] . " (#" . $data['task']['id'] . ")";

        } elseif ($this->getParam('check_box_include_title') == true && $this->getParam('check_box_include_project_identifier') && $this->getParam('check_box_include_project')) {
            // PROJECT NAME + PROJECT IDENTIFIER + TITLE // Subject becomes: `subject` `project name` `project identifier` `task title` `task id`
            $project = $this->projectModel->getById($data['task']['project_id']);
            $subject = $this->getParam('subject') . ": " . $project['name'] . " " .$project['identifier'] . " " . $data['task']['title'] . " (#" . $data['task']['id'] . ")";

        } else {
            // NO SELECTION // Subject becomes: `subject`
            $subject = $this->getParam('subject');
        }

@aljawaid
Copy link
Owner Author

aljawaid commented Jan 15, 2023

@creecros am I right, the above code should be edited as:

  1. Remove == true
  2. Add == true to the second part of the elseif
  3. Change && to ||
  4. Move the first if to the last one, so the if checks all the others before 'task title+id' only

@creecros
Copy link
Collaborator

I'll have to play with it. too much for me to comprehend on my phone. I just haven't had the motivation as of yet. it's tough to get away from wife and kids on the weekends to sit down on a computer.

@aljawaid
Copy link
Owner Author

I understand, based on what you previously once told me, the if statement will stop when it matches what its looking for, which is why Im thinking it wont show an error becuase it never gets past the 'task title+id' if statement... which makes the subject codeblock wrong...

Currently, I think it stops at the first if

@creecros
Copy link
Collaborator

I would say, you are correct, if it hits the first if and is true, then the corresponding else ifs are ignored.

@aljawaid
Copy link
Owner Author

I would say, you are correct, if it hits the first if and is true, then the corresponding else ifs are ignored.

great, so I need to code it backwards with the most restrictive (less likely option used) first, and the free option (task title+id) as the last... I will work on this tonight, I think I have a solution in my head

@creecros
Copy link
Collaborator

creecros commented Jan 15, 2023

well, that could work, but the correct way to fix would be to make it bullet proof.

couple ways to do that, but basically, the easiest would be very specific in the statement.

example:
3 checkboxes, a, b, c
instead of, if (a)
use if (a && !b && !c)

see the difference?

also, == true is redundant.
if (a ==true) is the same as if (a)
and if (a ==false) is the same as if (!a)

another method would be to nest the if statements.

example:
3 checkboxes, a, b, c

if (a) {
   if (b) {
     if (c) {
    }
  }
}

and yet another method would be just make them all ifs, no else ifs.

@aljawaid
Copy link
Owner Author

well, that could work, but the correct way to fix would be to make it bullet proof.

couple ways to do that, but basically, the easiest would be very specific in the statement.

example:
3 checkboxes, a, b, c
instead of, if (a)
use if (a && !b && !c)

see the difference?

also, == true is redundant.
if (a ==true) is the same as if (a)
and if (a ==false) is the same as if (!a)

another method would be to nest the if statements.

example:
3 checkboxes, a, b, c

if (a) {
   if (b) {
     if (c) {
    }
  }
}

example:
3 checkboxes, a, b, c
instead of, if (a)
use if (a && !b && !c)

if (a && !b && !c)

To get a on its own, it would be the else right?

@creecros
Copy link
Collaborator

creecros commented Jan 15, 2023

no, this is a on its own

if (a && !b && !c)

in English, its:
if a and not b and not c

if you are specific and account for all possibilities, there is no need for an else, just the else ifs.

so your next else if would be:
else if (a && b && !c)

followed by
else if (a && b && c)

then
else if (!a && b && !c)

and so forth....until all possible outcomes have been covered.

aljawaid added a commit that referenced this issue Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants