Ejemplo n.º 1
0
 /**
  * Sets the object fields from a JSON object string.
  *
  * @param string $jsonSource A JSON object string.
  * @param string $keyPrefix An optional prefix to strip from the keys.
  * @param boolean $setPrimaryKeys Indicates if primary key fields should be set.
  * @param boolean $rawValues Indicates if values should be set raw or via
  * {@link xPDOObject::set()}.
  * @param boolean $adhocValues Indicates if ad hoc fields should be added to the
  * xPDOObject from the source object.
  */
 public function fromJSON($jsonSource, $keyPrefix= '', $setPrimaryKeys= false, $rawValues= false, $adhocValues= false) {
     $array= $this->xpdo->fromJSON($jsonSource, true);
     if ($array) {
         $this->fromArray($array, $keyPrefix, $setPrimaryKeys, $rawValues, $adhocValues);
     } else {
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'xPDOObject::fromJSON() -- Could not convert jsonSource to a PHP array.');
     }
 }
Ejemplo n.º 2
0
 /**
  * Find all policies for this object
  * 
  * @param string $context
  * @return array
  */
 public function findPolicy($context = '')
 {
     $policy = array();
     $enabled = true;
     $context = 'mgr';
     if ($context === $this->xpdo->context->get('key')) {
         $enabled = (bool) $this->xpdo->getOption('access_media_source_enabled', null, true);
     } elseif ($this->xpdo->getContext($context)) {
         $enabled = (bool) $this->xpdo->contexts[$context]->getOption('access_media_source_enabled', true);
     }
     if ($enabled) {
         if (empty($this->_policies) || !isset($this->_policies[$context])) {
             $accessTable = $this->xpdo->getTableName('sources.modAccessMediaSource');
             $sourceTable = $this->xpdo->getTableName('sources.modMediaSource');
             $policyTable = $this->xpdo->getTableName('modAccessPolicy');
             $sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " . "LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " . "JOIN {$sourceTable} Source ON Acl.principal_class = 'modUserGroup' " . "AND (Acl.context_key = :context OR Acl.context_key IS NULL OR Acl.context_key = '') " . "AND Source.id = Acl.target " . "WHERE Acl.target = :source " . "GROUP BY Acl.target, Acl.principal, Acl.authority, Acl.policy";
             $bindings = array(':source' => $this->get('id'), ':context' => $context);
             $query = new xPDOCriteria($this->xpdo, $sql, $bindings);
             if ($query->stmt && $query->stmt->execute()) {
                 while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
                     $policy['sources.modAccessMediaSource'][$row['target']][] = array('principal' => $row['principal'], 'authority' => $row['authority'], 'policy' => $row['data'] ? $this->xpdo->fromJSON($row['data'], true) : array());
                 }
             }
             $this->_policies[$context] = $policy;
         } else {
             $policy = $this->_policies[$context];
         }
     }
     return $policy;
 }
Ejemplo n.º 3
0
 /**
  * Validate any dependencies for the object represented in this vehicle.
  *
  * @param xPDOTransport &$transport A reference to the xPDOTransport in
  * which this vehicle is stored.
  * @param xPDOObject &$object An object reference to access during
  * validation.
  * @param array $options Additional options for the validation process.
  * @return boolean Indicating if the validation was successful.
  */
 public function validate(&$transport, &$object, $options = array())
 {
     $validated = true;
     if (isset($this->payload['validate'])) {
         while (list($rKey, $r) = each($this->payload['validate'])) {
             $type = $r['type'];
             $body = $r['body'];
             switch ($type) {
                 case 'php':
                     if (isset($options[xPDOTransport::VALIDATE_PHP]) && !$options[xPDOTransport::VALIDATE_PHP]) {
                         continue;
                     }
                     $fileMeta = xPDO::fromJSON($body, true);
                     $fileName = $fileMeta['name'];
                     $fileSource = $transport->path . $fileMeta['source'];
                     if (!($validated = (include $fileSource))) {
                         $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error executing xPDOVehicle validator: type php ({$fileSource})");
                     }
                     break;
                 default:
                     $transport->xpdo->log(xPDO::LOG_LEVEL_WARN, "xPDOVehicle does not support validators of type {$type}.");
                     break;
             }
         }
     } else {
         $validated = true;
     }
     return $validated;
 }