Esempio n. 1
0
 public function delete()
 {
     $db = Database::get();
     if (method_exists($this->controller, 'deleteType')) {
         $this->controller->deleteType();
     }
     $db->Execute("delete from AttributeTypes where atID = ?", array($this->atID));
     $db->Execute("delete from AttributeTypeCategories where atID = ?", array($this->atID));
 }
Esempio n. 2
0
 public function validateKey($data = false)
 {
     if ($data == false) {
         $data = $this->post();
     }
     $e = parent::validateKey($data);
     if (!$data['akTopicParentNodeID'] || !$data['akTopicTreeID']) {
         $e->add(t('You must specify a valid topic tree parent node ID and topic tree ID.'));
     }
     return $e;
 }
 protected function validate(CategoryInterface $category, Controller $controller, Request $request, Key $key = null)
 {
     /** @var \Concrete\Core\Form\Service\Validation $val */
     $val = $this->application->make('helper/validation/form');
     /** @var \Concrete\Core\Validation\CSRF\Token $valt */
     $valt = $this->application->make('helper/validation/token');
     $val->setData($request->request->all());
     $val->addRequired("akHandle", t("Handle required."));
     $val->addRequired("akName", t('Name required.'));
     $val->addRequired("atID", t('Type required.'));
     $val->test();
     $error = $val->getError();
     if (!$valt->validate('add_or_update_attribute')) {
         $error->add($valt->getErrorMessage());
     }
     /** @var \Concrete\Core\Utility\Service\Validation\Strings $stringValidator */
     $stringValidator = $this->application->make('helper/validation/strings');
     if (!$stringValidator->handle($request->request->get('akHandle'))) {
         $error->add(t('Attribute handles may only contain letters, numbers and underscore "_" characters'));
     }
     $existing = $category->getAttributeKeyByHandle($request->request->get('akHandle'));
     if (is_object($existing)) {
         if (is_object($key)) {
             if ($key->getAttributeKeyID() != $existing->getAttributeKeyID()) {
                 $error->add(t("An attribute with the handle %s already exists.", $request->request->get('akHandle')));
             }
         } else {
             $error->add(t("An attribute with the handle %s already exists.", $request->request->get('akHandle')));
         }
     }
     $controllerResponse = $controller->validateKey($request->request->all());
     if ($controllerResponse instanceof ErrorList) {
         $error->add($controllerResponse);
     }
     $response = new Response();
     if ($error->has()) {
         $response->setIsValid(false);
         $response->setErrorObject($error);
     }
     return $response;
 }
 public function validateKey($data)
 {
     $e = parent::validateKey($data);
     // additional validation for select type
     $akCustomCountries = $data['akCustomCountries'];
     $akHasCustomCountries = $data['akHasCustomCountries'];
     if ($data['akHasCustomCountries'] != 1) {
         $akHasCustomCountries = 0;
     }
     if (!is_array($data['akCustomCountries'])) {
         $akCustomCountries = array();
     }
     if ($akHasCustomCountries && count($akCustomCountries) == 0) {
         $e->add(t('You must specify at least one country.'));
     } else {
         if ($akHasCustomCountries && $data['akDefaultCountry'] != '' && !in_array($data['akDefaultCountry'], $akCustomCountries)) {
             $e->add(t('The default country must be in the list of custom countries.'));
         }
     }
     return $e;
 }