/** * Retrieves a single TenantObjectInstance with the given ID. * @param int $id The ID of the TenantObjectInstance to return * @return NULL|\PhoenixSNS\Objects\TenantObjectInstance The TenantObjectInstance with the given ID, or NULL if no TenantObjectInstance with the given ID was found */ public static function GetByID($id) { if (!is_numeric($id)) { return null; } global $MySQL; $query = "SELECT * FROM " . System::$Configuration["Database.TablePrefix"] . "TenantObjectInstances WHERE instance_ID = " . $id; $result = $MySQL->query($query); if ($result === false) { return null; } $values = $result->fetch_assoc(); return TenantObjectInstance::GetByAssoc($values); }
/** * Retrieves an array of all TenantObjectInstances associated with this Tenant. * @param string $conditions The conditions that must be satisfied to retrieve an instance. * @param string $validObjects The objects that are considered valid for retrieval. * @param string $max The maximum number of objects that may be retrieved by this function (or NULL to not specify a limit). * @return TenantObjectInstance[] array of all TenantObjectInstances associated with this Tenant. */ public function GetObjectInstances($conditions = null, $validObjects = null, $max = null) { global $MySQL; $query = "SELECT * FROM " . System::$Configuration["Database.TablePrefix"] . "TenantObjectInstances, " . System::$Configuration["Database.TablePrefix"] . "TenantObjects" . " WHERE " . System::$Configuration["Database.TablePrefix"] . "TenantObjects.object_TenantID = " . $this->ID . " AND " . System::$Configuration["Database.TablePrefix"] . "TenantObjects.object_ID = " . System::$Configuration["Database.TablePrefix"] . "TenantObjectInstances.instance_ObjectID"; if (is_array($validObjects)) { $count = count($validObjects); if ($count > 0) { $query .= " AND ("; for ($i = 0; $i < $count; $i++) { $query .= System::$Configuration["Database.TablePrefix"] . "TenantObjectInstances.instance_ObjectID = " . $validObjects[$i]->ID; if ($i < $count - 1) { $query .= " OR "; } } $query .= ")"; } } $retval = array(); $result = $MySQL->query($query); $count = $result->num_rows; for ($i = 0; $i < $count; $i++) { $values = $result->fetch_assoc(); $item = TenantObjectInstance::GetByAssoc($values); if ($conditions != null) { if (!$conditions->Evaluate(array($item))) { continue; } } $retval[] = $item; } return $retval; }
/** * Gets the instances of this TenantObject. * @param string $max The maximum number of objects that may be retrieved by this function (or NULL to not specify a limit). * @return TenantObjectInstance[] array of instances of this TenantObject */ public function GetInstances($max = null) { global $MySQL; $query = "SELECT * FROM " . System::$Configuration["Database.TablePrefix"] . "TenantObjectInstances WHERE instance_ObjectID = " . $this->ID; $result = $MySQL->query($query); $retval = array(); if ($result === false) { return $retval; } $count = $result->num_rows; for ($i = 0; $i < $count; $i++) { $values = $result->fetch_assoc(); $retval[] = TenantObjectInstance::GetByAssoc($values); } return $retval; }