/**
  * Adds the specified namespace reference to this TenantObjectMethod.
  * @param string $value The PHP namespace to reference.
  * @return boolean True if the operation completed successfully; false if the operation failed.
  */
 public function AddNamespaceReference($value)
 {
     global $MySQL;
     $query = "INSERT INTO " . System::$Configuration["Database.TablePrefix"] . "TenantObjectMethodNamespaceReferences (ns_MethodID, ns_Value) VALUES (";
     $query .= $this->ID . ", ";
     $query .= "'" . $MySQL->real_escape_string($value) . "'";
     $query .= ")";
     $result = $MySQL->query($query);
     if ($result === false) {
         PhoenixSNS::Log("Database error when trying to add a namespace reference to the specified object method.", array("DatabaseError" => $MySQL->error . " (" . $MySQL->errno . ")", "Query" => $query, "Method" => $this->Name, "Object" => $this->ParentObject == null ? "(null)" : $this->ParentObject->Name));
         return false;
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Sets the value of the given property.
  * @param string|TenantProperty $property The name of the TenantProperty to set, or the instance of the TenantProperty. 
  * @param mixed $value The desired value with which to update the TenantProperty.
  * @return boolean True if the operation completed successfully; false if the operation failed.
  */
 public function SetPropertyValue($property, $value)
 {
     global $MySQL;
     // if we passed in a string to this property (because it's easier) then let's get a reference to that property
     if (is_string($property)) {
         $propname = $property;
         $property = $this->GetProperty($property);
     }
     $query = "INSERT INTO " . System::$Configuration["Database.TablePrefix"] . "TenantPropertyValues (propval_PropertyID, propval_Value) VALUES (" . $property->ID . ", '" . $MySQL->real_escape_string($property->Encode($value)) . "') ON DUPLICATE KEY UPDATE propval_Value = '" . $MySQL->real_escape_string($property->Encode($value)) . "'";
     $result = $MySQL->query($query);
     if ($result === false) {
         PhoenixSNS::Log("Database error when trying to update the value of a property on the tenant.", array("DatabaseError" => $MySQL->error . " (" . $MySQL->errno . ")", "Query" => $query, "Property" => $property == null ? $propname == null ? "(null)" : $propname : (is_string($property) ? $property : $property->Name)));
     }
     if ($MySQL->errno != 0) {
         return false;
     }
     if ($this->mvarJournalID != null) {
         $query = "INSERT INTO " . System::$Configuration["Database.TablePrefix"] . "TenantPropertyJournalEntries (entry_JournalID, entry_PropertyID, entry_Value) VALUES (" . $this->mvarJournalID . ", " . $property->ID . ", " . $MySQL->real_escape_string($property->Encode($value)) . ")";
         $result = $MySQL->query($query);
         if ($result === false) {
             return false;
         }
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Retrieves a single DataType with the given name
  * @param string $name The name used in code to identify this DataType
  * @return NULL|\PhoenixSNS\Objects\DataType The DataType with the given name, or null if no DataType with the given name was found
  */
 public static function GetByName($name)
 {
     global $MySQL;
     $query = "SELECT * FROM " . System::$Configuration["Database.TablePrefix"] . "DataTypes WHERE datatype_Name = '" . $MySQL->real_escape_string($name) . "'";
     $result = $MySQL->query($query);
     if ($result === false) {
         return null;
     }
     $count = $result->num_rows;
     if ($count == 0) {
         PhoenixSNS::Log("No data type with the specified name was found.", array("DataType" => $name));
         return null;
     }
     $values = $result->fetch_assoc();
     return DataType::GetByAssoc($values);
 }
Esempio n. 4
0
 public static function Create($property, $tenant = null)
 {
     global $MySQL;
     $query = "INSERT INTO " . System::$Configuration["Database.TablePrefix"] . "TenantProperties (property_TenantID, property_Name, property_Description, property_DataTypeID, property_DefaultValue) VALUES (";
     $query .= ($tenant == null ? "NULL" : $tenant->ID) . ", ";
     $query .= "'" . $MySQL->real_escape_string($property->Name) . "', ";
     $query .= "'" . $MySQL->real_escape_string($property->Description) . "', ";
     $query .= ($property->DataType == null ? "NULL" : $property->DataType->ID) . ", ";
     $query .= $property->DefaultValue == null ? "NULL" : "'" . $MySQL->real_escape_string($property->DataType->Encode($property->DefaultValue)) . "'";
     $query .= ")";
     $result = $MySQL->query($query);
     if ($result === false) {
         PhoenixSNS::Log("Database error when trying to create a property on the tenant.", array("DatabaseError" => $MySQL->error . " (" . $MySQL->errno . ")", "Query" => $query, "Property" => $property == null ? $propname == null ? "(null)" : $propname : (is_string($property) ? $property : "#" . $property->ID)));
         return false;
     }
     return true;
 }
Esempio n. 5
0
 /**
  * Gets a specific instance of this TenantObject based on the given parameters.
  * @param TenantQueryParameter[] $parameters
  * @return NULL|TenantObjectInstance The instance of this TenantObject, or NULL if no TenantObject matching the specified criteria could be found.
  */
 public function GetInstance($parameters)
 {
     if (!is_array($parameters)) {
         PhoenixSNS::Log("No parameters were specified by which to extract a single instance of the object.", array("Object" => $this->Name, "Property" => $propertyName));
         return null;
     }
     global $MySQL;
     $query = "SELECT " . System::$Configuration["Database.TablePrefix"] . "TenantObjectInstances.* FROM " . System::$Configuration["Database.TablePrefix"] . "TenantObjectInstances, " . System::$Configuration["Database.TablePrefix"] . "TenantObjectInstanceProperties, " . System::$Configuration["Database.TablePrefix"] . "TenantObjectInstancePropertyValues";
     $result = $MySQL->query($query);
     if ($result === false) {
         PhoenixSNS::Log("Database error when trying to obtain an instance of an object on the tenant.", array("DatabaseError" => $MySQL->error . " (" . $MySQL->errno . ")", "Query" => $query));
         return null;
     }
     $count = $result->num_rows;
     if ($count == 0) {
         PhoenixSNS::Log("Could not obtain an instance of the object with the specified parameters.", array("Object" => $this->Name, "Query" => $query));
         return null;
     }
     for ($i = 0; $i < $count; $i++) {
         $values = $result->fetch_assoc();
         $inst = TenantObjectInstance::GetByAssoc($values);
         $found = true;
         foreach ($parameters as $parameter) {
             if ($inst->GetPropertyValue($this->GetInstanceProperty($parameter->Name)) != $parameter->Value) {
                 $found = false;
                 break;
             }
         }
         if ($found) {
             return $inst;
         }
     }
     return null;
 }