/** * Sets all attached links via an array of IDs * e.g. * <code> * $topic->set_attached('Post', array(1, 8, 32) ); * $topic->set_attached('Post', $_POST['id_list']); * </code> * NB: set_attached will destroy any existing attachments for the class strClass * BEFORE creating new attachments * * @param string strClass class of objects to be set as attached * @param array arrID array of object IDs * @return boolean True on success. False on failure. */ public function set_attached($strClass, $arrID) { if (is_array($arrID)) { MyActiveRecord::Begin(); $pass = true; foreach ($this->find_linked($strClass) as $fObject) { $this->detach($fObject) or $pass = false; } foreach (MyActiveRecord::FindById($strClass, $arrID) as $fObject) { $this->attach($fObject) or $pass = false; } $pass ? MyActiveRecord::Commit() : MyActiveRecord::RollBack(); return $pass; } else { trigger_error('MyActiveRecord::set_attached() - Second argument not an array', E_USER_NOTICE); return false; } }