public function edit_card($card_id = 0, $type_id = 1, $deck_id = 1, $repeating = 0) { if ($repeating == 1) { $this->data['error'] = "New Card Added."; } $card = new Card($card_id); $card->type_id = $type_id; $card->deck_id = $deck_id; if ($_POST) { $repeat = FALSE; if ($card_id == 0) { $repeat = TRUE; } foreach ($this->input->post() as $key => $val) { $card->{$key} = nl2br($val); } $card->save(); if ($repeat) { redirect('/admin/cards/edit_card/0/' . $type_id . '/' . $deck_id . '/1'); } } $this->data['card'] = $card; $this->data['current_function_view'] = $this->load->view('admin/cards/edit_card', $this->data, true); $this->load->view('admin/master', $this->data); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $card = new Card(); $card->fill(Input::all()); $card->save(); return Response::json(array('success' => true)); }
public function generate() { $serial = new Serial(); $serial->serial = $this->serial; $serial->duration = $this->duration; $serial->save(); for ($number = 1; $number <= $this->quantity; $number++) { $card = new Card(); $card->serial_id = $serial->id; $card->number = $number; $card->save(); } }
public function updateCard(Card $card) { $inputs = ['color' => Input::get('color'), 'content' => Input::get('content'), 'comment' => Input::get('comment'), 'worker_id' => Input::get('worker_id')]; $valid = Validator::make($inputs, Card::$rules); if ($valid->passes()) { $card->color = $inputs['color']; $card->content = $inputs['content']; $card->comment = $inputs['comment']; $card->worker_id = $inputs['worker_id']; $card->save(); return Redirect::route('card.list')->with('success', Lang::choice('messages.Cards', 1) . ' ' . trans('is updated')); } else { return Redirect::back()->withErrors($valid)->withInput(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (Yii::app()->user->checkAccess('addCard')) { $model = new Card(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $model->owner_id = Yii::app()->user->id; if (isset($_POST['Card'])) { $model->attributes = $_POST['Card']; //$model->office=$_POST['office']; //$model->department=$_POST['department']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } /*$office=new Office; $department=new Department; $model->save();*/ $this->render('create', array('model' => $model)); } else { throw new CHttpException(403, 'You are not allowed to perform this action.'); } }
$app->get('/add_player_two_cards', function () use($app) { return $app['twig']->render('add_player_two_cards.html.twig'); }); $app->post('/player_two_hand', function () use($app) { $active_game = Game::getAll(); $active_players = Player::getAll(); $cardOne = new Card(rand(1, 10), firstcard); $cardOne->save(); $cardTwo = new Card(rand(1, 10), secondcard); $cardTwo->save(); $cardThree = new Card(rand(1, 10), thirdcard); $cardThree->save(); $cardFour = new Card(rand(1, 10), fourthcard); $cardFour->save(); $cardFive = new Card(rand(1, 10), fifthcard); $cardFive->save(); $current_players = $active_players[0]->getPlayers(); $current_score = $active_players[0]->setScore2(0); $current_score = $active_players[0]->getScore2(); $current_hand = array(); $draw = array(); for ($i = 0; $i <= 4; $i++) { array_push($current_hand, rand(1, 2)); } for ($z = 0; $z <= 4; $z++) { if ($current_hand[0] == $current_hand[1] && $current_hand[0] == $current_hand[2] && $current_hand[0] == $current_hand[3]) { $active_players[0]->setScore2($current_score + 1); } } // var_dump($current_hand); for ($x = 0; $x <= 4; $x++) {
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aRoomprofile !== null) { if ($this->aRoomprofile->isModified() || $this->aRoomprofile->isNew()) { $affectedRows += $this->aRoomprofile->save($con); } $this->setRoomprofile($this->aRoomprofile); } if ($this->aActivity !== null) { if ($this->aActivity->isModified() || $this->aActivity->isNew()) { $affectedRows += $this->aActivity->save($con); } $this->setActivity($this->aActivity); } if ($this->aReservationreason !== null) { if ($this->aReservationreason->isModified() || $this->aReservationreason->isNew()) { $affectedRows += $this->aReservationreason->save($con); } $this->setReservationreason($this->aReservationreason); } if ($this->aUsergroup !== null) { if ($this->aUsergroup->isModified() || $this->aUsergroup->isNew()) { $affectedRows += $this->aUsergroup->save($con); } $this->setUsergroup($this->aUsergroup); } if ($this->aCard !== null) { if ($this->aCard->isModified() || $this->aCard->isNew()) { $affectedRows += $this->aCard->save($con); } $this->setCard($this->aCard); } if ($this->aUser !== null) { if ($this->aUser->isModified() || $this->aUser->isNew()) { $affectedRows += $this->aUser->save($con); } $this->setUser($this->aUser); } if ($this->aReservationRelatedByReservationparentId !== null) { if ($this->aReservationRelatedByReservationparentId->isModified() || $this->aReservationRelatedByReservationparentId->isNew()) { $affectedRows += $this->aReservationRelatedByReservationparentId->save($con); } $this->setReservationRelatedByReservationparentId($this->aReservationRelatedByReservationparentId); } if ($this->isNew()) { $this->modifiedColumns[] = ReservationPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = ReservationPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += ReservationPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collReservationsRelatedByReservationparentId !== null) { foreach ($this->collReservationsRelatedByReservationparentId as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collReservationOtherMemberss !== null) { foreach ($this->collReservationOtherMemberss as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function addAction() { //var_dump(Input::all()); if (Input::server("REQUEST_METHOD") == "POST") { try { $action = "insert"; $id = Input::get('id'); //$school = Input::get('school'); $course = Input::get('course'); $name = Input::get('name'); $description = Input::get('description'); $fluency = Input::get('fluency'); $publish = Input::get('publish'); $cards_id = Input::get('card_ids'); $f_text = Input::get('f_text'); $f_cardtype = Input::get('cardtype'); $f_text_option = Input::get('f_text_option'); $f_sound = Input::get('f_sound'); $f_image = Input::get('f_image'); if (isset($id) && !empty($id)) { $sprint = Sprint::find($id); $action = "update"; $cards = DB::table('cards')->where('sprint', $id)->get(); foreach ($cards as $card) { $flag = false; for ($i = 0; $i < sizeof($cards_id); $i++) { if ($card->id == $cards_id[$i]) { $flag = true; } } if (!$flag) { DB::table('cards')->where('id', $card->id)->delete(); } } } else { $sprint = new Sprint(); } //$sprint->school = $school; $sprint->course = $course; $sprint->name = $name; $sprint->description = $description; $sprint->fluency_rate = $fluency; $sprint->published = $publish; $sprint->save(); if ($action == "insert") { $sprint_id = DB::getPdo()->lastInsertId(); } else { $sprint_id = $id; } $cards = ""; for ($i = 0; $i < count($f_text); $i++) { $idx = $i + 1; $card_type = $f_cardtype[$i]; $cardid = $cards_id[$i]; if ($action == "update" && $cardid > 0) { $card = Card::find($cardid); } else { $card = new Card(); } $card->sprint = $sprint_id; $card->card_type = $card_type; $card->f_text = $f_text[$i]; if (!empty($f_text_option[$i])) { $card->f_text_option = $f_text_option[$i]; } else { $card->f_text_option = 0; } if (!empty($f_sound[$i])) { $f_sound_path = ""; $f_sound_file = ""; if ($f_sound[$i] == "none") { $card->f_sound_option = 0; } else { $card->f_sound_option = 1; $f_sound_pos = strripos($f_sound[$i], "/"); $f_sound_path = substr($f_sound[$i], 0, $f_sound_pos + 1); $f_sound_file = substr($f_sound[$i], $f_sound_pos + 1); } $card->f_sound = $f_sound_file; $card->f_sound_path = $f_sound_path; } else { if ($f_sound[$i] == "none") { $card->f_sound_option = 0; } else { $card->f_sound_option = 1; } $card->f_sound = ""; $card->f_sound_path = ""; } if (!empty($f_image[$i])) { $f_image_file = ""; $f_image_path = ""; if ($f_image[$i] == "none") { $card->f_image_option = 0; } else { $card->f_image_option = 0; $f_image_pos = strripos($f_image[$i], "/"); $f_image_path = substr($f_image[$i], 0, $f_image_pos + 1); $f_image_file = substr($f_image[$i], $f_image_pos + 1); } $card->f_image = $f_image_file; $card->f_image_path = $f_image_path; } else { if ($f_image[$i] == "none") { $card->f_image_option = 0; } else { $card->f_image_option = 1; } $card->f_image = ""; $card->f_image_path = ""; } if (is_array(Input::get('b_text-' . $idx))) { $b_value = Input::get('b_text-' . $idx); $b_text_options = Input::get('b_text_option-' . $idx); $b_sounds = Input::get('b_sound-' . $idx); $b_images = Input::get('b_image-' . $idx); $subcard_id = Input::get('subcard_id-' . $idx); if ($card_type == 'singlecard') { $card->b_text = $b_value[0]; if (!empty($b_text_options[0])) { $card->b_text_option = $b_text_options[0]; } else { $card->b_text_option = 0; } if (!empty($b_sounds[0])) { $b_sound_file = ""; $b_sound_path = ""; if ($b_sounds[0] == "none") { $card->b_sound_option = 0; } else { $card->b_sound_option = 1; $b_sound_pos = strripos($b_sounds[0], "/"); $b_sound_path = substr($b_sounds[0], 0, $b_sound_pos + 1); $b_sound_file = substr($b_sounds[0], $b_sound_pos + 1); } $card->b_sound = $b_sound_file; $card->b_sound_path = $b_sound_path; } else { if ($b_sounds[0] == "none") { $card->b_sound_option = 0; } else { $card->b_sound_option = 1; } $card->b_sound = ""; $card->b_sound_path = ""; } if (!empty($b_images[0])) { $b_image_file = ""; $b_image_path = ""; if ($b_images[0] == "none") { $card->b_image_option = 0; } else { $card->b_image_option = 1; $b_image_pos = strripos($b_images[0], "/"); $b_image_path = substr($b_images[0], 0, $b_image_pos + 1); $b_image_file = substr($b_images[0], $b_image_pos + 1); } $card->b_image = $b_image_file; $card->b_image_path = $b_image_path; } else { if ($b_images[0] == "none") { $card->b_image_option = 0; } else { $card->b_image_option = 1; } $card->b_image = ""; $card->b_image_path = ""; } $card->save(); if ($action == "update" && $cardid > 0) { $card_id = $cardid; } else { $card_id = DB::getPdo()->lastInsertId(); } $cards .= $card_id; $cards .= ","; } else { $card->b_text = ""; $card->b_sound = ""; $card->b_sound_path = ""; $card->b_image = ""; $card->b_image_path = ""; $card->save(); if ($action == "update" && $cardid > 0) { $card_id = $cardid; } else { $card_id = DB::getPdo()->lastInsertId(); } $cards .= $card_id; $cards .= ","; for ($j = 0; $j < count($b_value); $j++) { $subcardid = $subcard_id[$j]; $answer = 0; $key = $j + 1; if ($card_type == 'radiocard') { $b_radios = Input::get('option-' . $idx); if ($key == $b_radios[0]) { $answer = 1; } } else { if ($card_type == 'checkcard') { $b_checks = Input::get('check-' . $idx); for ($k = 0; $k < count($b_checks); $k++) { if ($key == $b_checks[$k]) { $answer = 1; break; } } } } if ($action == "update" && $subcardid > 0) { $subcard = SubCard::find($subcardid); } else { $subcard = new SubCard(); } $subcard->cards = $card_id; $subcard->answer = $b_value[$j]; if (!empty($b_text_options[$j])) { $subcard->b_text_option = $b_text_options[$j]; } else { $subcard->b_text_option = 0; } if (!empty($b_sounds[$j])) { $b_sound_file = ""; $b_sound_path = ""; if ($b_sounds[$j] == "none") { $subcard->b_sound_option = 0; } else { $subcard->b_sound_option = 1; $b_sound_pos = strripos($b_sounds[$j], "/"); $b_sound_path = substr($b_sounds[$j], 0, $b_sound_pos + 1); $b_sound_file = substr($b_sounds[$j], $b_sound_pos + 1); } $subcard->b_sound = $b_sound_file; $subcard->b_sound_path = $b_sound_path; } else { if ($b_sounds[$j] == "none") { $subcard->b_sound_option = 0; } else { $subcard->b_sound_option = 1; } $subcard->b_sound = ""; $subcard->b_sound_path = ""; } if (!empty($b_images[$j])) { $b_image_file = ""; $b_image_path = ""; if ($b_images[$j] == "none") { $subcard->b_image_option = 0; } else { $subcard->b_image_option = 1; $b_image_pos = strripos($b_images[$j], "/"); $b_image_path = substr($b_images[$j], 0, $b_image_pos + 1); $b_image_file = substr($b_images[$j], $b_image_pos + 1); } $subcard->b_image = $b_image_file; $subcard->b_image_path = $b_image_path; } else { if ($b_images[$j] == "none") { $subcard->b_image_option = 0; } else { $subcard->b_image_option = 1; } $subcard->b_image = ""; $subcard->b_image_path = ""; } $subcard->correctanswer = $answer; $subcard->save(); } } } } $cards = substr($cards, 0, strlen($cards) - 1); $sprint = Sprint::find($sprint_id); if ($cards == "") { $sprint->cards = ""; } else { $sprint->cards = $cards; } $sprint->save(); if (strcmp(strtolower(Auth::user()->permission), "teacher") == 0) { return Redirect::route('teacher/sprints'); } else { if (strcmp(strtolower(Auth::user()->permission), "administrator") == 0) { return Redirect::route('admin/sprints'); } } } catch (Exception $ex) { echo $ex; Session::flash('status_error', ''); } } }
} if (!move_uploaded_file($_FILES['NewLogo']['tmp_name'], DIR_LOGOS . $filename)) { $errors[] = $Lang['Errors']['move_upload_error']; } else { //Sets logo filename in card data $card->logo = $filename; } break; #TODO : more explicit error messages #TODO : more explicit error messages default: $errors[] = $Lang['Errors']['other_upload_error']; } } //3. Saves the card $card->save(); $id = $card->id; //4. Keywords //TODO : more clever code Keywords::Truncate('C', $card->id); $keywords = explode(', ', $_POST['keywords']); foreach ($keywords as $keyword) { Keywords::Add('C', $card->id, $keyword); } //Yes, it's absolutely not optimized and very stupid to all delete and add again ! $action = 'view'; } elseif ($_GET['action'] == 'clone') { //User's cloning a card, so erase base card info unset($id, $card->id); } if ($action == 'view') {
public function actionCreateCard() { //$orderNo = substr(md5(time()), 0, 12); if ($num = intval($_POST['num'])) { $card_arr = $_POST['Card']; $type_id = $card_arr['type_id']; if ($type_id >= 1000) { $typeid = $type_id; } else { if ($type_id < 1000 && $type_id >= 100) { $typeid = '0' . $type_id; } else { if ($type_id < 100 && $type_id >= 10) { $typeid = '00' . $type_id; } else { if ($type_id < 10 && $type_id > 0) { $typeid = '000' . $type_id; } } } } $i = 1; while ($num >= $i) { $card_num = 'U' . $typeid . date('ymd') . mt_rand(1000, 9999); $card_arr['card_num'] = $card_num; $model = new Card(); $model->attributes = $card_arr; if ($model->validate() && $model->save()) { // var_dump($card_num); $i++; } else { var_dump($model->getErrors()); } } Yii::app()->user->setFlash('Card', '创建成功'); $this->redirect(array('card/card')); } else { Yii::app()->user->setFlash('card', '请输入创建数量'); } $model = new Card(); $getTypes = CardType::model()->getType(); $this->render('create', ['model' => $model, 'getTypes' => $getTypes]); }