Exemplo n.º 1
0
 public function setRules(array $rules = array())
 {
     if (count($rules) == 0) {
         $rules = (array) ObjectModel::getRules($this);
     }
     // attach each rule to the relevant property
     foreach ($rules as $trigger => $rulesArray) {
         $parts = explode('/', $trigger);
         foreach ($rulesArray as $key => $rule) {
             // rules on properties
             if (isset($parts[2]) && ($property = $this->_dataObject->getProperty($parts[2])) !== false) {
                 $property->attach($rule, $parts[0] . '/' . $parts[1]);
                 unset($rules[$trigger][$key]);
                 /*
                  * @todo find  a way to also pass rules to whatever property is concerned
                  * ex: if the rules allows to compute data from a collection, any change to the collection
                  * members should trigger the rule.
                  */
             } else {
                 $this->attach($rule, $parts[0] . '/' . $parts[1]);
             }
         }
     }
     $this->_rules = $rules;
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Return the number of distinct objects matching the given property
  * @param string $string
  * @param unknown_type $backend
  * @throws Backend\Exception
  * @return array
  */
 public function returnsDistinct($string, $backend = null)
 {
     $prop = $this->_do->getProperty($string);
     if (!$prop instanceof Property\AbstractProperty) {
         throw new Backend\Exception(array("CONDITION_UNKNOWN_PROPERTY", $string));
     }
     if (is_null($backend)) {
         $backend = ObjectModel::getObjectBackend($this->_do->getClass());
     }
     return (array) Backend::returnsDistinct($this, $prop, $backend);
 }