_audit = $audit; return $this; } public function setPost($post) { $this->_post = $post; return $this; } /** * Get all the focus pages data */ public function init() { //get data from DB with the completed tasks $this->_dbtasks = json_decode(get_option(SQ_TASKS), true); //Add filters for tasks, color and value add_filter('sq_assistant_tasks', array($this, 'parseTasks')); //parse the category add_filter('sq_assistant_categories', array($this, 'parseCategory')); } /** * Set all Tasks from all Assistant Classes * Extend and add the current assistant tasks * @param $tasks * @return mixed */ public function setTasks($tasks) { return $this->_tasks = $tasks; } /** * Get all tasks * @return mixed */ public function getTasks() { return $this->_tasks; } /** * Get all saved statuses from database * @return array */ public function getDbTasks() { return $this->_dbtasks; } /** * Get the task value if exists * Set false by default * @return bool */ public function getValue() { return false; } /** * If data integrity is affected, return error * @return bool */ public function isError() { return $this->_error; } /** * Get the task color * @param $complete * @return string */ public function getColor($complete) { if ($this->_error) { return self::TASK_ERROR; } elseif (!$complete) { return self::TASK_INCOMPLETE; } elseif ($this->_pattern) { return self::TASK_PATTERN; } elseif ($complete) { return self::TASK_COMPLETE; } return self::TASK_INCOMPLETE; } public function getTitle($title) { if ($this->_error) { $title = __("We are gathering data for this category", _SQ_PLUGIN_NAME_); } return $title; } /** * Parse tasks for each category * @param $tasks * @param $category * @return mixed */ public function parseTasks($tasks, $category = null) { if (!isset($category)) { $category = $this->_category; } //$this->_error = false; $this->setTasks($tasks); if (isset($this->_tasks[$category])) { foreach ($this->_tasks[$category] as $name => &$task) { $task['completed'] = true; $task['pattern'] = $task['error'] = $task['error_message'] = false; //Set task status from DB or active $task['active'] = true; if (isset($this->_dbtasks[$category][$name]['active'])) { $task['active'] = $this->_dbtasks[$category][$name]['active']; } /// //set the current task if ($task['active']) { if (method_exists($this, 'check' . ucfirst($name))) { $task = @call_user_func_array(array($this, 'check' . ucfirst($name)), array($task)); //Check if the task has errors if ($task['error']) { $task['completed'] = false; $task['error_message'] = (isset($task['error_message']) && $task['error_message'] <> '' ? $task['error_message'] : __("Not enough data to process this task", _SQ_PLUGIN_NAME_)); } else { //If the task has value if (isset($task['value'])) { $task['description'] = '
' . (isset($task['value_title']) ? $task['value_title'] : __('Current', _SQ_PLUGIN_NAME_)) . ': ' . $task['value'] . '
' . $task['description']; } //Check if the task has patterns if ($task['pattern']) { $this->_pattern = true; } } } } else { //set complete if task inactive $task['completed'] = true; $this->_error = $task['error'] = $task['pattern'] = false; $task['error_message'] = __('You chose to ignore this task. Click to activate it.', _SQ_PLUGIN_NAME_); } if (!isset($task['status'])) { $task['status'] = ($task['active'] ? ($task['error'] ? ' error' : ($task['completed'] ? ($task['pattern'] ? 'pattern' : 'completed') : '')) : 'ignore'); } } } //Save the completed Tasks in DB $this->saveDBTasks(); //Get the DbTasks add_filter('sq_assistant_dbtasks', array($this, 'getDbTasks')); //return all tasks return $this->getTasks(); } /** * Parse all the categories for this page * Get status data for each category * @param $categories * @return mixed */ public function parseCategory($categories) { if (!isset($categories[$this->_category])) { $categories[$this->_category]['completed'] = true; $categories[$this->_category]['title'] = ''; $categories[$this->_category]['penalty'] = 0; //initialize the category penality to 0 foreach ($this->_tasks[$this->_category] as $task) { if ($task['active']) { if (!$task['completed']) { $categories[$this->_category]['completed'] = false; } if ($task['error']) { $categories[$this->_category]['error'] = true; $this->_error = true; break; } if (!$task['completed'] && !$task['error'] && isset($task['penalty'])) { $categories[$this->_category]['penalty'] += (int)$task['penalty']; } } } $categories[$this->_category]['color'] = $this->getColor($categories[$this->_category]['completed']); $categories[$this->_category]['title'] = $this->getTitle($categories[$this->_category]['title']); $categories[$this->_category]['value'] = $this->getValue(); $categories[$this->_category]['error'] = $this->isError(); if (method_exists($this, 'getHeader')) { $categories[$this->_category]['header'] = call_user_func(array($this, 'getHeader')); } } return $categories; } /** * Modify task for best practice * @param $content * @param $task * @return string */ public function getPractice($content, $task) { return '
  • ' . $task['title'] . '

  • '; } /** * Save the completed tasks in DB */ public function saveDBTasks() { update_option(SQ_TASKS, json_encode($this->_dbtasks)); } }