Пример #1
0
 /**
  * Adds restriction (a binding between a specific item and optional type and the attribute)
  *
  * $pn_table_num: the number of the table to bind to
  * 
  */
 public function addTypeRestriction($pn_table_num, $pn_type_id, $va_settings)
 {
     if (!($vn_element = $this->getPrimaryKey())) {
         return null;
     }
     // element must be loaded
     if ($this->get('parent_id')) {
         return null;
     }
     // element must be root of hierarchy
     if (!is_array($va_settings)) {
         $va_settings = array();
     }
     $t_restriction = new ca_metadata_type_restrictions();
     $t_restriction->setMode(ACCESS_WRITE);
     $t_restriction->set('table_num', $pn_table_num);
     $t_restriction->set('type_id', $pn_type_id);
     $t_restriction->set('element_id', $this->getPrimaryKey());
     foreach ($va_settings as $vs_setting => $vs_setting_value) {
         $t_restriction->setSetting($vs_setting, $vs_setting_value);
     }
     $t_restriction->insert();
     if ($t_restriction->numErrors()) {
         $this->errors = $t_restriction->errors();
         return false;
     }
     return true;
 }