public function loadCreatePermission($parameters) { $errors = array(); if (isset($_POST['permission_name'])) { //Check for length if ($_POST['permission_name'] == "") { $errors[] = "Name cannot be blank."; } //Check for whitespace in the abbreviation if (stristr($_POST['permission_name'], ' ')) { $errors[] = "Abbreviation cannot contain whitespace."; } //Check the name for uniqueness if (!DinklyPermissionCollection::isUniqueName($_POST['permission_name'])) { $errors[] = "Name already in use, please try another."; } //Make sure that the abbreviation is also alphanumeric, without funky symbols $valid_symbols = array('-', '_'); if (!ctype_alnum(str_replace($valid_symbols, '', $_POST['permission_name']))) { $errors[] = "Name must be alphanumeric. Underscores and dashes are allowed."; } if ($errors != array()) { echo implode('<br>', $errors); } else { $permission = new DinklyPermission(); $permission->setName($_POST['permission_name']); $permission->setDescription($_POST['permission_description']); $permission->save(); echo 'success'; } } return false; }
public static function isUniqueName($name, $db = null) { $user = new DinklyPermission(); if ($db == null) { $db = self::fetchDB(); } $query = $user->getSelectQuery() . " where name=" . $db->quote($name); $results = $db->query($query)->fetchAll(); if ($results != array() && $results != NULL) { return false; } else { return true; } }
public function addPermissions($permission_ids) { if ($permission_ids != array()) { foreach ($permission_ids as $id) { $permission = new DinklyPermission(); $permission->init($id); //If the permission isn't new, that means it exists, which is a good thing if (!$permission->isNew()) { //Make sure this join record doesn't already exist first $permission_join = new DinklyGroupPermission(); $permission_join->initWithGroupAndPermission($this->getId(), $id); if ($permission_join->isNew()) { $permission_join->setDinklyGroupId($this->getId()); $permission_join->setDinklyPermissionId($id); $permission_join->save(); } } } return true; } return false; }