public function delete()
 {
     $db = Database::connection();
     $db->Execute('delete from AttributeFormsAttributeValues where afID = ? and akID = ? and avID = ?', array($this->item->getID(), $this->attributeKey->getAttributeKeyID(), $this->getAttributeValueID()));
     // Before we run delete() on the parent object, we make sure that attribute value isn't being referenced in the table anywhere else
     $num = $db->GetOne('select count(avID) from AttributeFormsAttributeValues where avID = ?', array($this->getAttributeValueID()));
     if ($num < 1) {
         parent::delete();
     }
 }
 public function action_submit()
 {
     // check CSRF token
     $token = new Token();
     if (!$token->validate('attribute_form_' . $this->bID, $this->post('_token'))) {
         throw new \Exception('Invalid token');
     }
     // get objects
     $aftID = $this->post('aftID');
     $aft = AttributeFormType::getByID($aftID);
     // create new form entry
     $af = AttributeForm::add(['aftID' => $aftID]);
     // get all attributes of type and save values from form to the database
     $attributes = $aft->getAttributeObjects();
     foreach ($attributes as $akID => $ak) {
         $af->setAttribute($ak, false);
     }
     // check SPAM
     $submittedData = $af->getAttributeDataString();
     $antispam = Core::make('helper/validation/antispam');
     if (!$antispam->check($submittedData, 'attribute_form')) {
         if ($aft->getDeleteSpam()) {
             $af->delete();
         } else {
             $af->markAsSpam();
         }
     }
 }
 public function detail($afID)
 {
     $af = AttributeForm::getByID($afID);
     $aft = AttributeFormType::getByID($af->getTypeID());
     $attributes = $aft->getAttributeObjects();
     $this->set('af', $af);
     $this->set('afID', $afID);
     $this->set('attributes', $attributes);
 }