public function check() { global $AppUI; $errorArray = array(); $baseErrorMsg = get_class($this) . '::store-check failed - '; $this->task_id = (int) $this->task_id; if (is_null($this->task_priority) || !is_numeric((int) $this->task_priority)) { $errorArray['task_priority'] = $baseErrorMsg . 'task priority is NULL'; } if ($this->task_name == '') { $errorArray['task_name'] = $baseErrorMsg . 'task name is NULL'; } if (is_null($this->task_project) || 0 == (int) $this->task_project) { $errorArray['task_project'] = $baseErrorMsg . 'task project is not set'; } //Only check the task dates if the config option "check_task_dates" is on if (w2PgetConfig('check_task_dates')) { if ($this->task_start_date == '' || $this->task_start_date == '0000-00-00 00:00:00') { $errorArray['task_start_date'] = $baseErrorMsg . 'task start date is NULL'; } if ($this->task_end_date == '' || $this->task_end_date == '0000-00-00 00:00:00') { $errorArray['task_end_date'] = $baseErrorMsg . 'task end date is NULL'; } if (!isset($errorArray['task_start_date']) && !isset($errorArray['task_end_date'])) { $startTimestamp = strtotime($this->task_start_date); $endTimestamp = strtotime($this->task_end_date); if (60 > abs($endTimestamp - $startTimestamp)) { $endTimestamp = $startTimestamp; } if ($startTimestamp > $endTimestamp) { $errorArray['bad_date_selection'] = $baseErrorMsg . 'task start date is after task end date'; } } } // ensure changes to checkboxes are honoured $this->task_milestone = (int) $this->task_milestone; $this->task_dynamic = (int) $this->task_dynamic; $this->task_percent_complete = (int) $this->task_percent_complete; $this->task_target_budget = $this->task_target_budget ? $this->task_target_budget : 0.0; if (!$this->task_duration || $this->task_milestone) { $this->task_duration = '0'; } if ($this->task_milestone) { if ($this->task_start_date && $this->task_start_date != '0000-00-00 00:00:00') { $this->task_end_date = $this->task_start_date; } else { $this->task_start_date = $this->task_end_date; } } if (!$this->task_creator) { $this->task_creator = $AppUI->user_id; } if (!$this->task_duration_type) { $this->task_duration_type = 1; } if (!$this->task_related_url) { $this->task_related_url = ''; } if (!$this->task_notify) { $this->task_notify = 0; } if ('' != $this->task_related_url && !w2p_check_url($this->task_related_url)) { $errorArray['task_related_url'] = $baseErrorMsg . 'task related url is not formatted properly'; } /* * Check for bad or circular task relationships (dep or child-parent). * These checks are definately not exhaustive it is still quite possible * to get things in a knot. * Note: some of these checks may be problematic and might have to be removed */ static $addedit; if (!isset($addedit)) { $addedit = w2PgetParam($_POST, 'dosql', '') == 'do_task_aed' ? true : false; } $this_dependencies = array(); /* * If we are called from addedit then we want to use the incoming * list of dependencies and attempt to stop bad deps from being created */ if ($addedit) { $hdependencies = w2PgetParam($_POST, 'hdependencies', '0'); if ($hdependencies) { $this_dependencies = explode(',', $hdependencies); } } else { $this_dependencies = explode(',', $this->getDependencies()); } // Set to false for recursive updateDynamic calls etc. $addedit = false; // Have deps if (array_sum($this_dependencies)) { if ($this->task_dynamic == 1) { return array('BadDep_DynNoDep'); } $this_dependents = $this->task_id ? explode(',', $this->dependentTasks()) : array(); $more_dependents = array(); // If the dependents' have parents add them to list of dependents foreach ($this_dependents as $dependent) { $dependent_task = new CTask(); $dependent_task->load($dependent); if ($dependent_task->task_id != $dependent_task->task_parent) { $more_dependents = explode(',', $this->dependentTasks($dependent_task->task_parent)); } } $this_dependents = array_merge($this_dependents, $more_dependents); // Task dependencies can not be dependent on this task $intersect = array_intersect($this_dependencies, $this_dependents); if (array_sum($intersect)) { $ids = '(' . implode(',', $intersect) . ')'; return array('BadDep_CircularDep', $ids); } } // Has a parent if ($this->task_id && $this->task_parent && $this->task_id != $this->task_parent) { $this_children = $this->getChildren(); $this_parent = new CTask(); $this_parent->load($this->task_parent); $parents_dependents = explode(',', $this_parent->dependentTasks()); if (in_array($this_parent->task_id, $this_dependencies)) { return array('BadDep_CannotDependOnParent'); } // Task parent cannot be child of this task if (in_array($this_parent->task_id, $this_children)) { return array('BadParent_CircularParent'); } if ($this_parent->task_parent != $this_parent->task_id) { // ... or parent's parent, cannot be child of this task. Could go on ... if (in_array($this_parent->task_parent, $this_children)) { return array('BadParent_CircularGrandParent', '(' . $this_parent->task_parent . ')'); } // parent's parent cannot be one of this task's dependencies if (in_array($this_parent->task_parent, $this_dependencies)) { return array('BadDep_CircularGrandParent', '(' . $this_parent->task_parent . ')'); } } // grand parent if ($this_parent->task_dynamic == 1) { $intersect = array_intersect($this_dependencies, $parents_dependents); if (array_sum($intersect)) { $ids = '(' . implode(',', $intersect) . ')'; return array('BadDep_CircularDepOnParentDependent', $ids); } } if ($this->task_dynamic == 1) { // then task's children can not be dependent on parent $intersect = array_intersect($this_children, $parents_dependents); if (array_sum($intersect)) { return array('BadParent_ChildDepOnParent'); } } } // parent return $errorArray; }
public function isValid() { $baseErrorMsg = get_class($this) . '::store-check failed - '; if ($this->task_name == '') { $this->_error['task_name'] = $baseErrorMsg . 'task name is NULL'; } if (is_null($this->task_project) || 0 == (int) $this->task_project) { $this->_error['task_project'] = $baseErrorMsg . 'task project is not set'; } //Only check the task dates if the config option "check_task_dates" is on if (w2PgetConfig('check_task_dates')) { if ($this->task_start_date == '' || $this->task_start_date == '0000-00-00 00:00:00') { $this->_error['task_start_date'] = $baseErrorMsg . 'task start date is NULL'; } if ($this->task_end_date == '' || $this->task_end_date == '0000-00-00 00:00:00') { $this->_error['task_end_date'] = $baseErrorMsg . 'task end date is NULL'; } if (!isset($errorArray['task_start_date']) && !isset($errorArray['task_end_date'])) { $startTimestamp = strtotime($this->task_start_date); $endTimestamp = strtotime($this->task_end_date); if (60 > abs($endTimestamp - $startTimestamp)) { $endTimestamp = $startTimestamp; } if ($startTimestamp > $endTimestamp) { $this->_error['bad_date_selection'] = $baseErrorMsg . 'task start date is after task end date'; } } } if ($this->task_milestone) { if ($this->task_start_date && $this->task_start_date != '0000-00-00 00:00:00') { $this->task_end_date = $this->task_start_date; } else { $this->task_start_date = $this->task_end_date; } } /* * Check for bad or circular task relationships (dep or child-parent). * These checks are definately not exhaustive it is still quite possible * to get things in a knot. * Note: some of these checks may be problematic and might have to be removed */ static $addedit; if (!isset($addedit)) { $addedit = w2PgetParam($_POST, 'dosql', '') == 'do_task_aed' ? true : false; } $this_dependencies = array(); /* * If we are called from addedit then we want to use the incoming * list of dependencies and attempt to stop bad deps from being created */ if ($addedit) { $hdependencies = w2PgetParam($_POST, 'hdependencies', '0'); if ($hdependencies) { $this_dependencies = explode(',', $hdependencies); } } else { $this_dependencies = explode(',', $this->getDependencies()); } // Have deps if (array_sum($this_dependencies)) { if ($this->task_dynamic == 1) { $this->_error['BadDep_DynNoDep'] = 'BadDep_DynNoDep'; return false; } $this_dependents = $this->task_id ? explode(',', $this->dependentTasks()) : array(); $more_dependents = array(); // If the dependents' have parents add them to list of dependents foreach ($this_dependents as $dependent) { $dependent_task = new CTask(); $dependent_task->overrideDatabase($this->_query); $dependent_task->load($dependent); if ($dependent_task->task_id != $dependent_task->task_parent) { $more_dependents = explode(',', $this->dependentTasks($dependent_task->task_parent)); } } $this_dependents = array_merge($this_dependents, $more_dependents); // Task dependencies can not be dependent on this task $intersect = array_intersect($this_dependencies, $this_dependents); if (array_sum($intersect)) { $ids = '(' . implode(',', $intersect) . ')'; $this->_error['BadDep_CircularDep'] = 'BadDep_CircularDep'; return false; } } // Has a parent if ($this->task_id && $this->task_parent && $this->task_id != $this->task_parent) { $this_children = $this->getChildren(); $this_parent = new CTask(); $this_parent->overrideDatabase($this->_query); $this_parent->load($this->task_parent); $parents_dependents = explode(',', $this_parent->dependentTasks()); // Task parent cannot be child of this task if (in_array($this_parent->task_id, $this_children)) { $this->_error['BadParent_CircularParent'] = 'BadParent_CircularParent'; return false; } if ($this_parent->task_parent != $this_parent->task_id) { // ... or parent's parent, cannot be child of this task. Could go on ... if (in_array($this_parent->task_parent, $this_children)) { $this->_error['BadParent_CircularGrandParent'] = 'BadParent_CircularGrandParent'; return false; } // parent's parent cannot be one of this task's dependencies if (in_array($this_parent->task_parent, $this_dependencies)) { $this->_error['BadParent_CircularGrandParent'] = 'BadParent_CircularGrandParent'; return false; } } // grand parent if ($this_parent->task_dynamic == 1) { $intersect = array_intersect($this_dependencies, $parents_dependents); if (array_sum($intersect)) { $ids = '(' . implode(',', $intersect) . ')'; $this->_error['BadDep_CircularDepOnParentDependent'] = 'BadDep_CircularDepOnParentDependent'; return false; } } if ($this->task_dynamic == 1) { // then task's children can not be dependent on parent $intersect = array_intersect($this_children, $parents_dependents); if (array_sum($intersect)) { $this->_error['BadParent_ChildDepOnParent'] = 'BadParent_ChildDepOnParent'; return false; } } } // parent return count($this->_error) ? false : true; }
function check() { global $AppUI; if ($this->task_id === NULL) { return 'task id is NULL'; } // ensure changes to checkboxes are honoured $this->task_milestone = intval($this->task_milestone); $this->task_dynamic = intval($this->task_dynamic); $this->task_percent_complete = intval($this->task_percent_complete); if ($this->task_milestone) { $this->task_duration = '0'; } else { if (!$this->task_duration) { $this->task_duration = '1'; } } if (!$this->task_creator) { $this->task_creator = $AppUI->user_id; } if (!$this->task_duration_type) { $this->task_duration_type = 1; } if (!$this->task_related_url) { $this->task_related_url = ''; } if (!$this->task_notify) { $this->task_notify = 0; } /* * Check for bad or circular task relationships (dep or child-parent). * These checks are definately not exhaustive it is still quite possible * to get things in a knot. * Note: some of these checks may be problematic and might have to be removed */ static $addedit; if (!isset($addedit)) { $addedit = dPgetParam($_POST, 'dosql', '') == 'do_task_aed' ? true : false; } $this_dependencies = array(); /* * If we are called from addedit then we want to use the incoming * list of dependencies and attempt to stop bad deps from being created */ if ($addedit) { $hdependencies = dPgetParam($_POST, 'hdependencies', '0'); if ($hdependencies) { $this_dependencies = explode(',', $hdependencies); } } else { $this_dependencies = explode(',', $this->getDependencies()); } // Set to false for recursive updateDynamic calls etc. $addedit = false; // Has a parent if ($this->task_id && $this->task_id != $this->task_parent) { $this_children = $this->getChildren(); $this_child_deps = array(); foreach ($this_children as $child) { $child_dep_str = $this->staticGetDependencies($child); $this_child_deps = array_unique(array_merge($this_child_deps, explode(',', $child_dep_str))); } $current_task = $this; $parents_children = array(); //itrative walk through parent tasks while ($current_task->task_id != $current_task->task_parent) { $current_parent = new CTask(); $current_parent->load($current_task->task_parent); $parents_children = array_unique(array_merge($parents_children, $current_parent->getChildren())); // Task parent (of any level) cannot be a child of task or its children // extra precaution against any UI bugs allowing otherwise if (in_array($current_parent->task_id, $parents_children)) { return $this->task_id == $current_parent->task_parent ? 'BadParent_CircularParent' : array('BadParent_CircularGrandParent', '(' . $current_parent->task_id . ')'); } //Task's children cannot have a parent (of any level) as a dependency if (in_array($current_parent->task_id, $this_child_deps)) { return 'BadParent_ChildDepOnParent'; } //Task cannot have a parent (of any level) as a dependency if (in_array($current_parent->task_id, $this_dependencies)) { return $current_task == $this ? 'BadDep_CannotDependOnParent' : array('BadDep_CircularGrandParent', '(' . $current_parent->task_id . ')'); } $parents_dependents = explode(',', $current_parent->dependentTasks()); $this_intersect = array_intersect($this_dependencies, $parents_dependents); //Any tasks dependent on a dynamic parent task cannot be dependencies of task if (array_sum($this_intersect)) { $ids = '(' . implode(',', $intersect) . ')'; return array('BadDep_CircularDepOnParentDependent', $ids); } $current_task = $current_parent; } } // parent // Have deps if (array_sum($this_dependencies)) { if ($this->task_dynamic == 1) { return 'BadDep_DynNoDep'; } $this_dependents = $this->task_id ? explode(',', $this->dependentTasks()) : array(); // Treat parent task, like a dependent if ($this->task_id != $this->task_parent) { array_push($this_dependents, $this->task_parent); $dep_string = $this->dependentTasks($this->task_parent); $this_dependents = array_unique(array_merge($this_dependents, explode(',', $dep_string))); } $more_dependents = array(); // Treat dependents' parents them like dependents too and pull parent dependents foreach ($this_dependents as $dependent) { $dependent_task = new CTask(); $dependent_task->load($dependent); if ($dependent_task->task_id != $dependent_task->task_parent) { $current_task = $dependent_task; while ($current_task->task_id != $current_task->task_parent) { $current_parent_id = $current_task->task_parent; array_push($more_dependents, $current_parent_id); $dep_string = $this->dependentTasks($dependent_task->task_parent); $more_dependents = array_unique(array_merge($more_dependents, explode(',', $dep_string))); $current_task = new CTask(); $current_task->load($current_parent_id); } } } $this_dependents = array_unique(array_merge($this_dependents, $more_dependents)); // Task dependencies can not be dependent on this task $intersect = array_intersect($this_dependencies, $this_dependents); if (array_sum($intersect)) { $ids = '(' . implode(',', $intersect) . ')'; return array('BadDep_CircularDep', $ids); } } //Is dynamic and no child if (dPgetConfig('check_task_empty_dynamic') && $this->task_dynamic == 1) { $children_of_dynamic = $this->getChildren(); if (empty($children_of_dynamic)) { return 'BadDyn_NoChild'; } } return NULL; }
function check() { global $AppUI; if ($this->task_id === NULL) { return 'task id is NULL'; } // ensure changes to checkboxes are honoured $this->task_milestone = intval($this->task_milestone); $this->task_dynamic = intval($this->task_dynamic); $this->task_percent_complete = intval($this->task_percent_complete); if (!$this->task_duration) { $this->task_duration = '1'; } if (!$this->task_creator) { $this->task_creator = $AppUI->user_id; } if (!$this->task_duration_type) { $this->task_duration_type = 1; } if (!$this->task_related_url) { $this->task_related_url = ''; } if (!$this->task_notify) { $this->task_notify = 0; } /* * Check for bad or circular task relationships (dep or child-parent). * These checks are definately not exhaustive it is still quite possible * to get things in a knot. * Note: some of these checks may be problematic and might have to be removed */ static $addedit; if (!isset($addedit)) { $addedit = dPgetParam($_POST, 'dosql', '') == 'do_task_aed' ? true : false; } $this_dependencies = array(); /* * If we are called from addedit then we want to use the incoming * list of dependencies and attempt to stop bad deps from being created */ if ($addedit) { $hdependencies = dPgetParam($_POST, 'hdependencies', '0'); if ($hdependencies) { $this_dependencies = explode(',', $hdependencies); } } else { $this_dependencies = explode(',', $this->getDependencies()); } // Set to false for recursive updateDynamic calls etc. $addedit = false; // Have deps if (array_sum($this_dependencies)) { if ($this->task_dynamic == '1') { return 'BadDep_DynNoDep'; } $this_dependents = $this->task_id ? explode(',', $this->dependentTasks()) : array(); // If the dependents' have parents add them to list of dependents foreach ($this_dependents as $dependent) { $dependent_task = new CTask(); $dependent_task->load($dependent); if ($dependent_task->task_id != $dependent_task->task_parent) { $more_dependents = explode(',', $this->dependentTasks($dependent_task->task_parent)); } } $this_dependents = array_merge($this_dependents, $more_dependents); // Task dependencies can not be dependent on this task $intersect = array_intersect($this_dependencies, $this_dependents); if (array_sum($intersect)) { $ids = "(" . implode(',', $intersect) . ")"; return array('BadDep_CircularDep', $ids); } } // Has a parent if ($this->task_id && $this->task_id != $this->task_parent) { $this_children = $this->getChildren(); $this_parent = new CTask(); $this_parent->load($this->task_parent); $parents_dependents = explode(',', $this_parent->dependentTasks()); if (in_array($this_parent->task_id, $this_dependencies)) { return 'BadDep_CannotDependOnParent'; } // Task parent cannot be child of this task if (in_array($this_parent->task_id, $this_children)) { return 'BadParent_CircularParent'; } if ($this_parent->task_parent != $this_parent->task_id) { // ... or parent's parent, cannot be child of this task. Could go on ... if (in_array($this_parent->task_parent, $this_children)) { return array('BadParent_CircularGrandParent', '(' . $this_parent->task_parent . ')'); } // parent's parent cannot be one of this task's dependencies if (in_array($this_parent->task_parent, $this_dependencies)) { return array('BadDep_CircularGrandParent', '(' . $this_parent->task_parent . ')'); } } // grand parent if ($this_parent->task_dynamic == '1') { $intersect = array_intersect($this_dependencies, $parents_dependents); if (array_sum($intersect)) { $ids = "(" . implode(',', $intersect) . ")"; return array('BadDep_CircularDepOnParentDependent', $ids); } } if ($this->task_dynamic == '1') { // then task's children can not be dependent on parent $intersect = array_intersect($this_children, $parents_dependents); if (array_sum($intersect)) { return 'BadParent_ChildDepOnParent'; } } } // parent return NULL; }