/** * Creates a new Tenant object based on the given values from the database. * @param array $values * @return \PhoenixSNS\Objects\Tenant based on the values of the fields in the given associative array */ public static function GetByAssoc($values) { $item = new Tenant(); $item->ID = $values["tenant_ID"]; $item->URL = $values["tenant_URL"]; $item->Description = $values["tenant_Description"]; switch ($values["tenant_Status"]) { case 1: $item->Status = TenantStatus::Enabled; break; case 0: $item->Status = TenantStatus::Disabled; break; } $item->Type = TenantType::GetByID($values["tenant_TypeID"]); $item->PaymentPlan = PaymentPlan::GetByID($values["tenant_PaymentPlanID"]); $item->BeginTimestamp = $values["tenant_BeginTimestamp"]; $item->EndTimestamp = $values["tenant_EndTimestamp"]; // get the data centers associated with this tenant global $MySQL; $query = "SELECT " . System::$Configuration["Database.TablePrefix"] . "DataCenters.* FROM " . System::$Configuration["Database.TablePrefix"] . "DataCenters, " . System::$Configuration["Database.TablePrefix"] . "TenantDataCenters WHERE " . System::$Configuration["Database.TablePrefix"] . "TenantDataCenters.tdc_TenantID = " . $item->ID . " AND " . System::$Configuration["Database.TablePrefix"] . "TenantDataCenters.tdc_DataCenterID = " . System::$Configuration["Database.TablePrefix"] . "DataCenters.datacenter_ID"; $result = $MySQL->query($query); $count = $result->num_rows; $retval = array(); for ($i = 0; $i < $count; $i++) { $values = $result->fetch_assoc(); $retval[] = DataCenter::GetByAssoc($values); } $item->DataCenters->Items = $retval; return $item; }
/** * Retrieves a single DataCenter with the given ID. * @param int $id The ID of the DataCenter to return * @return NULL|\PhoenixSNS\Objects\DataCenter The DataCenter with the given ID, or null if no DataCenter with the given ID was found or the given ID was invalid */ public static function GetByID($id) { if (!is_numeric($id)) { return null; } global $MySQL; $query = "SELECT * FROM " . System::$Configuration["Database.TablePrefix"] . "DataCenters WHERE datacenter_ID = " . $id; $result = $MySQL->query($query); $count = $result->num_rows; if ($count == 0) { return null; } $values = $result->fetch_assoc(); return DataCenter::GetByAssoc($values); }