CODE STYLE class.pmDashlet.php

This commit is contained in:
Fernando Ontiveros
2012-10-09 12:55:53 -04:00
parent 7f1d0fad9c
commit 16b4ea4e2a

View File

@@ -4,7 +4,8 @@ require_once 'classes/interfaces/dashletInterface.php';
require_once 'classes/model/Dashlet.php'; require_once 'classes/model/Dashlet.php';
require_once 'classes/model/DashletInstance.php'; require_once 'classes/model/DashletInstance.php';
class PMDashlet extends DashletInstance implements DashletInterface { class PMDashlet extends DashletInstance implements DashletInterface
{
// Own properties // Own properties
private $dashletInstance; private $dashletInstance;
@@ -12,7 +13,9 @@ class PMDashlet extends DashletInstance implements DashletInterface {
// Interface functions // Interface functions
public static function getAdditionalFields($className) {
public static function getAdditionalFields ($className)
{
try { try {
if (! class_exists( $className )) { if (! class_exists( $className )) {
self::setIncludePath(); self::setIncludePath();
@@ -21,15 +24,13 @@ class PMDashlet extends DashletInstance implements DashletInterface {
G::LoadClass( $className ); G::LoadClass( $className );
eval( "\$additionalFields = $className::getAdditionalFields(\$className);" ); eval( "\$additionalFields = $className::getAdditionalFields(\$className);" );
return $additionalFields; return $additionalFields;
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
public function setup ($dasInsUid)
{
public function setup($dasInsUid) {
try { try {
$this->dashletInstance = $this->loadDashletInstance( $dasInsUid ); $this->dashletInstance = $this->loadDashletInstance( $dasInsUid );
if (! isset( $this->dashletInstance['DAS_CLASS'] )) { if (! isset( $this->dashletInstance['DAS_CLASS'] )) {
@@ -43,37 +44,41 @@ class PMDashlet extends DashletInstance implements DashletInterface {
} }
$this->dashletObject = new $className(); $this->dashletObject = new $className();
$this->dashletObject->setup( $this->dashletInstance ); $this->dashletObject->setup( $this->dashletInstance );
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
public function render($width = 300) { public function render ($width = 300)
{
try { try {
if (is_null( $this->dashletObject )) { if (is_null( $this->dashletObject )) {
throw new Exception( 'Please call to the function "setup" before call the function "render".' ); throw new Exception( 'Please call to the function "setup" before call the function "render".' );
} }
$this->dashletObject->render( $width ); $this->dashletObject->render( $width );
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
// Getter and Setters // Getter and Setters
public function getDashletInstance() {
public function getDashletInstance ()
{
return $this->dashletInstance; return $this->dashletInstance;
} }
public function getDashletObject() { public function getDashletObject ()
{
return $this->dashletObject; return $this->dashletObject;
} }
// Own functions // Own functions
public function getDashletsInstances($start = null, $limit = null) {
public function getDashletsInstances ($start = null, $limit = null)
{
try { try {
$dashletsInstances = array (); $dashletsInstances = array ();
$criteria = new Criteria( 'workflow' ); $criteria = new Criteria( 'workflow' );
@@ -109,8 +114,7 @@ class PMDashlet extends DashletInstance implements DashletInterface {
try { try {
$user = $userInstance->load( $row['DAS_INS_OWNER_UID'] ); $user = $userInstance->load( $row['DAS_INS_OWNER_UID'] );
$row['DAS_INS_OWNER_TITLE'] = $user['USR_FIRSTNAME'] . ' ' . $user['USR_LASTNAME']; $row['DAS_INS_OWNER_TITLE'] = $user['USR_FIRSTNAME'] . ' ' . $user['USR_LASTNAME'];
} } catch (Exception $error) {
catch (Exception $error) {
$this->remove( $row['DAS_INS_UID'] ); $this->remove( $row['DAS_INS_UID'] );
$row['DAS_INS_UID'] = ''; $row['DAS_INS_UID'] = '';
} }
@@ -121,8 +125,7 @@ class PMDashlet extends DashletInstance implements DashletInterface {
try { try {
$department = $departmentInstance->load( $row['DAS_INS_OWNER_UID'] ); $department = $departmentInstance->load( $row['DAS_INS_OWNER_UID'] );
$row['DAS_INS_OWNER_TITLE'] = $department['DEPO_TITLE']; $row['DAS_INS_OWNER_TITLE'] = $department['DEPO_TITLE'];
} } catch (Exception $error) {
catch (Exception $error) {
$this->remove( $row['DAS_INS_UID'] ); $this->remove( $row['DAS_INS_UID'] );
$row['DAS_INS_UID'] = ''; $row['DAS_INS_UID'] = '';
} }
@@ -133,8 +136,7 @@ class PMDashlet extends DashletInstance implements DashletInterface {
try { try {
$group = $groupInstance->load( $row['DAS_INS_OWNER_UID'] ); $group = $groupInstance->load( $row['DAS_INS_OWNER_UID'] );
$row['DAS_INS_OWNER_TITLE'] = $group['GRP_TITLE']; $row['DAS_INS_OWNER_TITLE'] = $group['GRP_TITLE'];
} } catch (Exception $error) {
catch (Exception $error) {
$this->remove( $row['DAS_INS_UID'] ); $this->remove( $row['DAS_INS_UID'] );
$row['DAS_INS_UID'] = ''; $row['DAS_INS_UID'] = '';
} }
@@ -149,25 +151,25 @@ class PMDashlet extends DashletInstance implements DashletInterface {
$dataset->next(); $dataset->next();
} }
return $dashletsInstances; return $dashletsInstances;
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
public function getDashletsInstancesQuantity() { public function getDashletsInstancesQuantity ()
{
try { try {
$criteria = new Criteria( 'workflow' ); $criteria = new Criteria( 'workflow' );
$criteria->addSelectColumn( '*' ); $criteria->addSelectColumn( '*' );
$criteria->addJoin( DashletInstancePeer::DAS_UID, DashletPeer::DAS_UID, Criteria::INNER_JOIN ); $criteria->addJoin( DashletInstancePeer::DAS_UID, DashletPeer::DAS_UID, Criteria::INNER_JOIN );
return DashletInstancePeer::doCount( $criteria ); return DashletInstancePeer::doCount( $criteria );
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
public function loadDashletInstance($dasInsUid) { public function loadDashletInstance ($dasInsUid)
{
try { try {
$dashletInstance = $this->load( $dasInsUid ); $dashletInstance = $this->load( $dasInsUid );
//Load data from the serialized field //Load data from the serialized field
@@ -177,31 +179,31 @@ class PMDashlet extends DashletInstance implements DashletInterface {
$dashletFields = array (); $dashletFields = array ();
} }
return array_merge( $dashletFields, $dashletInstance ); return array_merge( $dashletFields, $dashletInstance );
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
public function saveDashletInstance($data) { public function saveDashletInstance ($data)
{
try { try {
$this->createOrUpdate( $data ); $this->createOrUpdate( $data );
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
public function deleteDashletInstance($dasInsUid) { public function deleteDashletInstance ($dasInsUid)
{
try { try {
$this->remove( $dasInsUid ); $this->remove( $dasInsUid );
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
public function getDashletsInstancesForUser($userUid) { public function getDashletsInstancesForUser ($userUid)
{
try { try {
$dashletsInstances = array (); $dashletsInstances = array ();
// Include required classes // Include required classes
@@ -317,13 +319,13 @@ class PMDashlet extends DashletInstance implements DashletInterface {
// Check for permission assigments // Check for permission assigments
// ToDo: Next release // ToDo: Next release
return array_values( $dashletsInstances ); return array_values( $dashletsInstances );
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
public static function getXTemplate($className) { public static function getXTemplate ($className)
{
try { try {
if (! class_exists( $className )) { if (! class_exists( $className )) {
self::setIncludePath(); self::setIncludePath();
@@ -332,13 +334,13 @@ class PMDashlet extends DashletInstance implements DashletInterface {
G::LoadClass( $className ); G::LoadClass( $className );
eval( "\$additionalFields = $className::getXTemplate(\$className);" ); eval( "\$additionalFields = $className::getXTemplate(\$className);" );
return $additionalFields; return $additionalFields;
} } catch (Exception $error) {
catch (Exception $error) {
throw $error; throw $error;
} }
} }
private static function setIncludePath() { private static function setIncludePath ()
{
$oPluginRegistry = &PMPluginRegistry::getSingleton(); $oPluginRegistry = &PMPluginRegistry::getSingleton();
$pluginsDashlets = $oPluginRegistry->getDashlets(); $pluginsDashlets = $oPluginRegistry->getDashlets();
foreach ($pluginsDashlets as $pluginDashlet) { foreach ($pluginsDashlets as $pluginDashlet) {