blob: 96bee3eb6821fdd49240215edc9ad94d1627ee13 [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2011 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wayne Beaton (Eclipse Foundation)- initial API and implementation
*******************************************************************************/
require_once($_SERVER['DOCUMENT_ROOT'] . "/projects/classes/common.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/projects/classes/debug.php");
trace_file_info(__FILE__);
function getOrganization($id) {
$organizations = getOrganizations();
return $organizations[$id];
}
function getOrganizations() {
global $_organizations;
if ($_organizations) return $_organizations;
global $App;
$_organizations = array();
$sql = "select
o.OrganizationId as id, Name1 as name, SCRM_GUID,
om.Relation as type, om.EntryDate as startDate, om.ExpiryDate as endDate
from Organizations as o
left join OrganizationMemberships as om on (o.OrganizationId = om.OrganizationId)";
$result = $App->foundation_sql($sql);
while ($row = mysql_fetch_assoc($result)) {
$id = $row['id'];
if (!isset($_organizations[$id]))
$_organizations[$id] = new Organization($row);
if (isset($row['type'])) {
$_organizations[$id]->memberships[] = new Membership($row);
}
}
return $_organizations;
}
class Organization {
var $data;
var $memberships = array();
function __construct($row) {
$this->data = $row;
}
function getId() {
return $this->data['id'];
}
function getSugarId() {
return $this->data['SCRM_GUID'];
}
function getName() {
return $this->data['name'];
}
function isMember() {
foreach($this->memberships as $membership) {
if ($membership->isActive()) return true;
}
return false;
}
}
class Membership {
var $data;
function __construct($row) {
$this->data = $row;
}
function isActive() {
// if we have an end date, we're not active. Otherwise, we are.
return $this->getEndDate() ? false : true;
}
function getEndDate() {
if (!$this->data['endDate']) return null;
$date = strtotime($this->data['endDate']);
return $date < 0 ? null : $date;
}
}
?>