public function upload($name = '') { if (!$name) { throw new CException(Yii::t('no file name')); } $file = CUploadedFile::getInstanceByName($name); if (!$file->hasError) { //生成目录 $filename = md5(time()) . '.' . $file->extensionName; $filepath = $this->getDirByTime() . DIRECTORY_SEPARATOR; $allFilePath = $this->_dirPath . DIRECTORY_SEPARATOR . $filepath . $filename; if (!$this->createDir($this->_dirPath . DIRECTORY_SEPARATOR . $filepath) || !is_writable($this->_dirPath . DIRECTORY_SEPARATOR . $filepath)) { throw new CException(Yii::t('yii', 'dir can not create or can not writeable')); } if ($file->saveAs($allFilePath)) { //获取图片宽和高 $picSize = getimagesize($allFilePath); $imgInfo = array('name' => $file->name, 'filepath' => $filepath, 'filename' => $filename, 'filesize' => $file->size, 'type' => $file->extensionName, 'mark' => 'img', 'imgwidth' => $picSize[0], 'imgheight' => $picSize[1], 'create_time' => time()); //素材数据入库 $model = new Material(); $model->attributes = $imgInfo; $model->save(); $imgInfo['id'] = $model->id; return $imgInfo; } else { throw new CException(Yii::t('yii', 'file save error')); } } else { throw new CException(Yii::t('yii', 'there is an error for upload ,error:{error}', array('{error}' => $file->error))); } }
/** * 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->aMaterial !== null) { if ($this->aMaterial->isModified() || $this->aMaterial->isNew()) { $affectedRows += $this->aMaterial->save($con); } $this->setMaterial($this->aMaterial); } if ($this->aEspais !== null) { if ($this->aEspais->isModified() || $this->aEspais->isNew()) { $affectedRows += $this->aEspais->save($con); } $this->setEspais($this->aEspais); } if ($this->aEspaisExterns !== null) { if ($this->aEspaisExterns->isModified() || $this->aEspaisExterns->isNew()) { $affectedRows += $this->aEspaisExterns->save($con); } $this->setEspaisExterns($this->aEspaisExterns); } if ($this->aHoraris !== null) { if ($this->aHoraris->isModified() || $this->aHoraris->isNew()) { $affectedRows += $this->aHoraris->save($con); } $this->setHoraris($this->aHoraris); } if ($this->isNew()) { $this->modifiedColumns[] = HorarisespaisPeer::IDHORARISESPAIS; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = HorarisespaisPeer::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->setIdhorarisespais($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += HorarisespaisPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Material(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Material'])) { $model->attributes = $_POST['Material']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function store() { $data = Input::all(); //return json_encode($data); $material = new Material(); $material->fill($data['material']); $material->save(); if (isset($data['vinculaciones'])) { foreach ($data['vinculaciones'] as $index => $v_data) { $vinculacion = new MaterialVinculacion(); $vinculacion->fill($v_data); $vinculacion->save(); $material->vinculaciones()->save($vinculacion); } } return Redirect::route('materiales.index'); }
public function store() { $validator = Validator::make(Input::all(), Material::$rules, Material::$messages); if ($validator->passes()) { $material = new Material(); $material->name = Input::get('name'); $material->value = Input::get('value'); $material->code = Input::get('code'); $material->dimensions = Input::get('dimensions'); $material->weight = Input::get('weight'); $material->observation = Input::get('observation'); //$material->projectid = Input::get('projectid'); $material->organizationid = Input::get('organizationid'); $material->save(); $organization = app('organization'); return Redirect::to('/materials/')->with('message', "Material ingresado con exito"); } else { return Redirect::to('materials/create')->with('error', 'Ocurrieron los siguientes errores')->withErrors($validator)->withInput(); } }
public function post_create() { $rules = array('clave' => 'required|max:10|alpha_dash', 'nombre' => 'required|max:30', 'stock_min' => 'numeric', 'cat_mat_id' => 'required|integer|exists:categoriamaterial,id', 'uni_mat_id' => 'required|integer|exists:unidadmaterial,id'); $validation = Validator::make(Input::all(), $rules); if ($validation->fails()) { Messages::add('error', $validation->errors->all()); return Redirect::to('admin/' . $this->views . '/create')->with_input(); } else { $mat = new Material(); $mat->clave = strtoupper(Input::get('clave')); $mat->nombre = strtoupper(Input::get('nombre')); $mat->stock_min = Input::get('stock_min'); $mat->cat_mat_id = Input::get('cat_mat_id'); $mat->uni_mat_id = Input::get('uni_mat_id'); $mat->observaciones = Input::get('observaciones'); $mat->estatus = 'A'; $mat->save(); Messages::add('success', 'Material Creado'); return Redirect::to('admin/' . $this->views . ''); } }
function geMaterial() { $this->autoRender = false; $sql = "SELECT DISTINCT material FROM inventory;"; $datas = $this->Cabinet->query($sql); App::uses("Material", "Inventory.Model"); foreach ($datas as $data) { $material = new Material(); if (!empty($data['inventory']['material'])) { $m['Material']['name'] = $data['inventory']['material']; $m['Material']['code'] = $data['inventory']['material']; $m['Material']['material_group_id'] = 9; $material->save($m); } } }
if (count($materials) > 20) { return $response->write('{"msg":"çok fazla malzeme bilgisi var"}'); } foreach ($materials as $material) { $oldMaterial = Material::where('name', $material)->get(); if (!$oldMaterial->isEmpty()) { $oldMaterial = $oldMaterial->first(); $oldMaterial->count += 1; $oldMaterial->last_update_date = date("YmdHi"); $oldMaterial->save(); } else { $newMaterial = new Material(); $newMaterial->name = $material; $newMaterial->create_date = date("YmdHi"); $newMaterial->last_update_date = date("YmdHi"); $newMaterial->save(); } } $sqlStr = "*" . implode("* *", $materials) . "*"; // giri *domates* *tavuk* *malzeme* şeklindedir // saklı yordam kullanılmıştır $foods = Food::hydrateRaw("CALL searchRecipe(?)", array($sqlStr)); return $response->write(json_encode($foods) . " "); })->setName('search_foods'); // sayfalı son yemekler $this->get('/all/{page:[0-9]+}', function ($request, $response, $args) { $food = Food::select('food_id', 'name', 'description')->where('deleted', 0)->take(6)->offset($args['page'] * 6)->orderBy('food_id', 'DESC')->get(); if ($food) { return $response->write(json_encode($food) . ' '); } return $response->write('{"msg": "ERR"}');
public function createReceipt() { $input = Input::all(); $api_key = Request::header('Authorization'); $id = $input['id']; $check = DB::select(DB::raw("select * from user where api_key='" . $api_key . "'" . ' and id=' . $id)); if (count($check) > 0) { try { // Insert new Post $post = new Post(); $title = $input['title']; $description = $input['description']; $totle_time_finish = $input['total_time_finish']; $total_kcal = $input['total_kcal']; $post->User_id = $id; $post->name = $title; $post->description = $description; $post->created_at = $this->getCurrentTime(); $post->total_view = 0; $post->total_time_finish = $totle_time_finish; $post->total_kcal = $total_kcal; $post->save(); // update img_cover of Post $post_id = $this->getIdPostMax(); $user = User::find($id); $img_cover = base64_decode($input['img_cover']); $destinationPath = public_path() . '\\assets\\img-data\\receipt'; $file_name = md5($user['email'] . $post_id); file_put_contents($destinationPath . '/' . $file_name . '.jpg', $img_cover); $path = 'assets/img-data/receipt/' . $file_name . '.jpg'; $postt = Post::find($post_id); $postt->img_cover_url = $path; $postt->save(); $name_continent = $input['name_continent']; $name_area = $input['name_area']; // insert Post_continent $post_continent = new PostContinent(); $post_continent->Post_id = $post_id; $post_continent->Cate_contilent_id = (new Continent())->getIdContinentByName($name_continent); $post_continent->save(); // insert Post_area $post_area = new PostArea(); $post_area->Post_id = $post_id; $post_area->Cate_area_id = (new Area())->getIdAreaByName($name_area); $post_area->save(); // Insert Material $mix_material = $input['mix_material']; $split = explode("||", $mix_material); for ($i = 0; $i < count($split) - 1; $i++) { $material = new Material(); $material->name = $split[$i]; $material->Post_id = $post_id; $material->save(); } return array('error' => false, 'message' => 'success'); } catch (Exception $ex) { return array('error' => true, 'message' => 'Some Error: ' . $ex->getMessage()); } } else { return array('error' => true, 'message' => 'Not Authorization'); } }
/** 1.3. Add a new product */ $product = new Product(); $product->belongs_to($company); $product->name = 'Kanapa trzydrzwiowa'; $product->save(); /** 1.4. Check if successfully created */ debug($product->load()); /** 1.5. Create two new materials */ $mat_1 = new Material(); $mat_1->belongs_to($company); $mat_1->name = 'Skóra'; $mat_1->save(); $mat_2 = new Material(); $mat_2->belongs_to($company); $mat_2->name = 'Drewno brzozowe'; $mat_2->save(); /** 1.6. Check if materials successfully created */ debug($mat_1->load()); debug($mat_2->load()); /** 1.7. Create a new material combination */ $comb = new Combination(); $comb->belongs_to($product); $comb->has_multiple($mat_1, $mat_2); $comb->price = '12.34'; $comb->save(); /** 1.8. Check if combination successfully created */ debug($comb->load()); /* CREATE TABLE `product` ( `id` int(10) unsigned NOT NULL auto_increment, `company_id` int(10) unsigned NOT NULL,