示例#1
0
 /**
  * Add one or more owners
  *
  * @param   string  $what  Owner type to add
  * @param   mixed   $data  integer|string|array
  * @return  object
  */
 public function add($what, $data)
 {
     $data = $this->_toArray($data);
     $what = strtolower($what);
     switch ($what) {
         case 'advisory':
             if ($this->config('allow_advisory', 0)) {
                 $tbl = new Tables\Owner($this->_db);
                 if (!$tbl->save_owners($this->get('id'), $this->config(), $data, 2)) {
                     $this->setError($tbl->getError());
                 }
             }
             break;
         case 'individuals':
             $tbl = new Tables\Owner($this->_db);
             if (!$tbl->save_owners($this->get('id'), $this->config(), $data)) {
                 $this->setError($tbl->getError());
             }
             break;
         case 'groups':
             $tbl = new Tables\OwnerGroup($this->_db);
             if (!$tbl->save_owner_groups($this->get('id'), $this->config(), $data)) {
                 $this->setError($tbl->getError());
             }
             break;
         default:
             //throw new \InvalidArgumentException(Lang::txt('Owner type not supported.'));
             throw new \RuntimeException("Lang::txt('Owner type not supported.')", 404);
             break;
     }
     // Reset the owners lists
     $this->_cache['owners.list0'] = null;
     $this->_cache['owners.list1'] = null;
     return $this;
 }