public function create($entity) { // 验证手册id是否是该用户激活的 $this->load->model('Handbook_model', 'handbook'); $handbook = current($this->handbook->get(array('is_used' => 'Y', 'unique_id' => $entity['handbook_unique_id']))); if (empty($handbook)) { $this->errors['handbook_unique_id'] = '手册id不存在.'; return false; } // 验证用户是否激活 $this->load->model('User_model', 'user'); $user = current($this->user->get(array('is_validation' => 'Y', 'id' => $handbook->user_id))); if (empty($user)) { // 验证用户是否存在 $this->errors['user_id'] = '用户不存在或未激活.'; $this->validation($entity, 'add'); return false; } else { $entity['user_id'] = $user->id; } // 验证张数是否超过限制,目前统一是3张 $tickets = $this->get(array('user_id' => $entity['user_id'], 'spot_id' => $entity['spot_id'], 'handbook_unique_id' => $entity['handbook_unique_id'])); if (count($tickets) > 2) { $this->errors['handbook_unique_id'] = '该用户购买票的次数超过了3次.'; return false; } return parent::create($entity); }
public function create($data) { $options = array('cost' => 11); $data['password'] = password_hash($data['password'], PASSWORD_BCRYPT, $options); parent::create($data); return $this->db->insert_id(); }
public function create($entity) { if (empty($entity['content'])) { return false; } return parent::create($entity); }
/** * @override override the default function in the parent class * @param array $data cannot be null since we don't have default for everything * @return return whether the database execution is successfully executed */ public function create($data) { // check the only data that do not have the default and provide a default if (empty($data["appendix"])) { $data["appendix"] = new stdClass(); } return parent::create($data); }
function create($entity) { if (count($this->db->where(array('address' => $entity['address'], 'user_id' => $entity['user_id']))->get($this->table)->result()) > 0) { // 该地址已经存在 return false; } return parent::create($entity); }
public function create($entity) { if ($this->validation($entity, 'add') === true) { $entity['password'] = md5($entity['password']); unset($entity['repassword']); } return parent::create($entity); }
public function addGidIntoExpr($expr_id, $gid = NULL) { if (!isset($gid) || !empty($gid) || parent::count(["gid" => $gid]) > 0) { $gid = $this->next_gid(); } $data = parent::readByPk($expr_id, $this->fields); if ($data) { $data["gid"] = $gid; $data["is_forked"] = TRUE; // create return parent::create($data); } else { $this->err_msg = "Invalid Experiment ID"; $this->err_code = 404; return FALSE; } }
public function create($data) { if ($this->is_login() === TRUE) { //check permission //only the root user, pid = 0, can add users if (!empty($this->pid) && $this->pid == 0) { return $this->set_err(400, "No permission"); } $insert_data = $this->_data_filter($data); if ($insert_data !== FALSE) { $insert_data['active'] = TRUE; $insert_data['create_time'] = time(); $insert_data['appendix'] = []; $insert_data['expire_time'] = 2147483647; //insert return parent::create($insert_data); } else { return FALSE; } } else { return $this->set_err(400, "No permission: haven't logged in yet~"); } }
/** * @param $rsc_type * @param $rsc_id * @param $owners (can be JSON data) * default to be only the creator of this resources * if is FALSE, will try to gain all researchers the ownership * if is a single number, will be interpreted as the id the number represent and the creator * if is a none-empty array, will try to negotiate all the researchers inside the array to be inside * * @param string $share (can be JSON data) * default is private(only the owner can access this) * if is a none-empty array, then will be put into the share_list * @return TODO */ public function register($rsc_type, $rsc_id, $owners = NULL, $share = "private") { // get the current user id, and if this user isn't logged in ,I will kick it out if ($this->identity->is_researcher()) { $uid = $this->identity->get_uid(); } else { return FALSE; } // Deal with the owner data // first check whether the input is in JSON format if (is_string($owners) && !is_numeric($owners)) { $tmp_owners = json_decode($owners); if ($tmp_owners != NULL && (is_array($tmp_owners) || is_numeric($tmp_owners) || is_bool($tmp_owners))) { $owners = $tmp_owners; } } if ($owners === FALSE) { $owners = array(0); // what is owned by zero is owned by everyone } else { if (is_numeric($owners)) { $owners = array($owners, $uid); } else { if (is_array($owners)) { // array->list if (!in_array($uid, $owners)) { array_push($owners, $uid); } } else { // default $owners = array($uid); } } } // deal with the share value if (is_array($share) && count($share) > 0) { // none empty array $share_list = $share; $share = "limited"; } else { $share_list = array(); // first check whether it is json $tmp_share = json_decode($share); if (is_string($tmp_share)) { $share = $tmp_share; } else { if (is_array($tmp_share)) { $share = "limited"; $share_list = $tmp_share; } } // check whether it is a valid share value if (!in_array($share, $this->valid_share_value)) { $this->err_code = 400; $this->err_msg = "Invalid Share Value"; return FALSE; } } // prepare all the registration data $data = array("rsc_type" => $rsc_type, "rsc_id" => $rsc_id, "share" => $share, "share_list" => $share_list, "appendix" => array()); foreach ($owners as $owner) { $data["owner"] = $owner; if (!parent::create($data)) { return FALSE; } } return TRUE; }