wCMF Wiki : DashboardExample

HomePage :: Categories :: PageIndex :: RecentChanges :: Login/Register

Introduction

This is an advanced example of a Dashboard coming from the EuroCom model.
In the model a user has a Worker and a worker has tasks, records and customers assigned.
We want to load all the customers, the Tasks that have a status different from 'completed' and the reports of the last 3 months.
Finally we will pass them to a view.

HOW TO

the code uses the ObjectQuery class to load only a part of all the objects.


<?php

require_once(BASE."wcmf/lib/presentation/class.Controller.php");
require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
require_once(BASE."wcmf/lib/persistence/class.ObjectQuery.php");
require_once(BASE."wcmf/lib/model/class.Node.php");
require_once(BASE."wcmf/lib/security/class.RightsManager.php");

/**
 * @class DashboardController
 * @ingroup Controller
 *
 * @author  ingo herwig <ingo@wemove.com>
 */

class DashboardController extends Controller
{
  /**
   * @see Controller::hasView()
   */

  function hasView()
  {
    return true;
  }
  /**
   * Load some nodes attached to the current worker an assign them to the
   * dashboad view.
   * @return False
   * @see Controller::executeKernel()
   */

  function executeKernel()
  {
    // load the model

    // get the authenticated user
    $rightsManager = &RightsManager::getInstance();
    $authUser = &$rightsManager->getAuthUser();
   
    // get the worker from authuser
    $authUser->loadChildren('Worker');
    $worker = &$authUser->getFirstChild('Worker', null, null);
   
    // load nodes attached to the worker
    $taskList = array();
    $customerList = array();
    $reportList = array();
    if ($worker != null)
    {
      // customers attached to worker (no need for an ObjectQuery here)
      $worker->loadChildren('Customer');
      $customerList = &$worker->getChildrenEx(null, 'Customer', null, null);
     

        // tasks attached to worker with status != "completed"
      $taskQuery = &PersistenceFacade::createObjectQuery('Task');
      $taskTpl = &$taskQuery->getObjectTemplate('Task');
      $taskTpl->setValue("status", "!= 'completed'", DATATYPE_ATTRIBUTE);
      $taskWorkerTpl = &$worker->duplicate();
      $taskQuery->registerObjectTemplate($taskWorkerTpl);
      $taskWorkerTpl->addChild($taskTpl);
      $taskList = $taskQuery->execute(BUILDDEPTH_SINGLE);
   
   
   
      // reports attached to worker with created >= 3 months ago
      $date = date("Y-m-d", mktime(0, 0, 0, date("m")-3, date("d"), date("Y")));
      $reportQuery = &PersistenceFacade::createObjectQuery('Report');
      $reporTpl = &$reportQuery->getObjectTemplate('Report');
      $reporTpl->setValue("created", ">= '".$date."'", DATATYPE_ATTRIBUTE);
      $reportWorkerTpl = &$worker->duplicate();
      $reportQuery->registerObjectTemplate($reportWorkerTpl);
      $reportWorkerTpl->addChild($reporTpl);
      $reportList = $reportQuery->execute(BUILDDEPTH_SINGLE);
    }
   
    // assign the values to the view
    $this->_view->assign_by_ref('worker', $worker);
    $this->_view->assign_by_ref('tasks', $taskList);
    $this->_view->assign_by_ref('customers', $customerList);
    $this->_view->assign_by_ref('reports', $reportList);

    // success
    return false;
  }
}
?>
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.2462 seconds