Horde_LoginTasks::_createTaskList PHP Method

_createTaskList() protected method

Creates the list of login tasks that are available for this session (stored in a Horde_LoginTasks_Tasklist object).
protected _createTaskList ( )
    protected function _createTaskList()
    {
        /* Create a new Horde_LoginTasks_Tasklist object. */
        $this->_tasklist = new Horde_LoginTasks_Tasklist();
        /* Get last task run date(s). Array keys are app names, values are
         * last run timestamps. Special key '_once' contains list of
         * ONCE tasks previously run. */
        $lasttask = $this->_backend->getLastRun();
        /* Create time objects for today's date and last task run date. */
        $cur_date = getdate();
        foreach ($this->_backend->getTasks() as $classname => $app) {
            $ob = new $classname();
            /* If marked inactive, skip the task. */
            if (!$ob->active) {
                continue;
            }
            $addtask = false;
            if ($ob->interval == self::FIRST_LOGIN) {
                $addtask = empty($lasttask[$app]);
            } else {
                $lastrun = getdate(empty($lasttask[$app]) ? time() : $lasttask[$app]);
                switch ($ob->interval) {
                    case self::YEARLY:
                        $addtask = $cur_date['year'] > $lastrun['year'];
                        break;
                    case self::MONTHLY:
                        $addtask = $cur_date['year'] > $lastrun['year'] || $cur_date['mon'] > $lastrun['mon'];
                        break;
                    case self::WEEKLY:
                        $days = date('L', $lastrun[0]) ? 366 : 365;
                        $addtask = $cur_date['wday'] < $lastrun['wday'] || $cur_date['year'] == $lastrun['year'] && $cur_date['yday'] >= $lastrun['yday'] + 7 || $cur_date['year'] > $lastrun['year'] && $cur_date['yday'] >= $lastrun['yday'] + 7 - $days;
                        break;
                    case self::DAILY:
                        $addtask = $cur_date['year'] > $lastrun['year'] || $cur_date['yday'] > $lastrun['yday'];
                        break;
                    case self::EVERY:
                        $addtask = true;
                        break;
                    case self::ONCE:
                        if (empty($lasttask['_once']) || !in_array($classname, $lasttask['_once'])) {
                            $addtask = true;
                            $lasttask['_once'][] = $classname;
                            $this->_backend->setLastRun($lasttask);
                        }
                        break;
                }
            }
            if ($addtask) {
                $this->_tasklist->addTask($ob);
            }
        }
        /* If tasklist is empty, we can simply set it to true now. */
        if ($this->_tasklist->isDone()) {
            $this->_tasklist = true;
        }
    }