public function add() { if (isset($_POST)) { $this->form_validation->set_rules('portfolio_name', 'Porfolio Name', 'required|is_unique[portfolios.portfolio_name]'); $this->form_validation->set_rules('beginning_cap', 'Starting Capital', 'required|numeric|greater_than[0]'); if ($this->form_validation->run()) { $portfolio = new Portfolio(); $portfolio->portfolio_name = $this->input->post('portfolio_name'); $portfolio->portfolio_description = $this->input->post('portfolio_description'); $portfolio->beginning_cap = $this->input->post('beginning_cap'); $portfolio->current_cap = $portfolio->beginning_cap; $portfolio->starting_date = date("Y-m-d H:i:s"); $portfolio->user_id = $this->input->post('user_id') + 1; $checked = $this->input->post('commision_bool'); if ((int) $checked == 1) { $portfolio->commision_bool = 1; } else { $portfolio->commision_bool = 0; } $portfolio->commision = $this->input->post('commision'); $portfolio->save(); redirect('portfolios'); } else { $this->data['message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message'); $this->data['charts'] = 0; $this->load->view('dressings/header'); $this->load->view('dressings/navbar'); $this->load->view('add_portfolio', $this->data); $this->load->view('dressings/footer'); } } }
/** * Creates a new portfolio */ public function createAction() { if (!$this->request->isPost()) { return $this->dispatcher->forward(array("controller" => "portfolio", "action" => "index")); } $portfolio = new Portfolio(); $portfolio->title = $this->request->getPost("title"); $portfolio->short_description = $this->request->getPost("short_description"); $portfolio->body = $this->request->getPost("body"); $portfolio->image = $this->request->getPost("image"); $portfolio->status = $this->request->getPost("status"); if (!$portfolio->save()) { foreach ($portfolio->getMessages() as $message) { $this->flash->error($message); } return $this->dispatcher->forward(array("controller" => "portfolio", "action" => "new")); } $this->flash->success("portfolio was created successfully"); return $this->dispatcher->forward(array("controller" => "portfolio", "action" => "index")); }
protected function envPortfolio() { $portfolio = new Portfolio(); $portfolio->picture = 'img/uploaded/2.jpg'; $portfolio->title = 'My Project'; $portfolio->description = 'This is my cute dog.'; $portfolio->template_id = 1; $portfolio->save(); $portfolio = new Portfolio(); $portfolio->picture = 'img/uploaded/park.jpeg'; $portfolio->title = 'My Project'; $portfolio->description = 'This is my favorite park'; $portfolio->template_id = 1; $portfolio->save(); $portfolio2 = new Portfolio(); $portfolio2->picture = 'img/uploaded/2.jpg'; $portfolio2->title = 'My dog'; $portfolio2->description = 'He is a cutie'; $portfolio2->template_id = 2; $portfolio2->save(); $portfolio21 = new Portfolio(); $portfolio21->picture = 'img/uploaded/park.jpeg'; $portfolio21->title = 'Best Park'; $portfolio21->description = 'This is my favorite park'; $portfolio21->template_id = 2; $portfolio21->save(); $portfolio3 = new Portfolio(); $portfolio3->picture = 'img/uploaded/2.jpg'; $portfolio3->title = 'My Project'; $portfolio3->description = 'Its pretty awesome'; $portfolio3->template_id = 3; $portfolio3->save(); $portfolio31 = new Portfolio(); $portfolio31->picture = 'img/uploaded/park.jpeg'; $portfolio31->title = 'My Project'; $portfolio31->description = 'This is my favorite park'; $portfolio31->template_id = 3; $portfolio31->save(); }
public function add_portfolio() { if (!$this->securitypolicy->validateAccessRight(4, 'add')) { $this->load->view('access_denied'); } $this->load->library('form_validation'); $this->load->helper('form'); $portfolio = new Portfolio(); $data['showmsg'] = true; if ($this->form_validation->run() == false) { $data['status'] = 'error'; $this->load->view('hotel_mngt_add_hotel_portfolio', $data); } else { $portfolio->save(); if (!empty($portfolio->errors)) { $data['msg'] = $portfolio->errors; $data['status'] = 'error'; $this->load->view('hotel_mngt_add_hotel_portfolio', $data); } else { $this->session->set_userdata(array("status" => "success")); redirect(site_url('Admin/add_portfolio')); } } }
/** * testSaveHabtmNoPrimaryData method * * @return void */ public function testSaveHabtmNoPrimaryData() { $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); $TestModel = new Article(); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')), false); $result = $TestModel->findById(2); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'Tag' => array(array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))); $this->assertEquals($expected, $result); $TestModel->id = 2; $data = array('Tag' => array('Tag' => array(2))); $result = $TestModel->save($data); $this->assertEquals($data['Tag'], $result['Tag']); $result = $TestModel->findById(2); $expected = array('Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => self::date()), 'Tag' => array(array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'))); $this->assertEquals($expected, $result); $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio'); $TestModel = new Portfolio(); $result = $TestModel->findById(2); $expected = array('Portfolio' => array('id' => 2, 'seller_id' => 1, 'name' => 'Portfolio 2'), 'Item' => array(array('id' => 2, 'syfile_id' => 2, 'published' => '', 'name' => 'Item 2', 'ItemsPortfolio' => array('id' => 2, 'item_id' => 2, 'portfolio_id' => 2)), array('id' => 6, 'syfile_id' => 6, 'published' => '', 'name' => 'Item 6', 'ItemsPortfolio' => array('id' => 6, 'item_id' => 6, 'portfolio_id' => 2)))); $this->assertEquals($expected, $result); $data = array('Item' => array('Item' => array(1, 2))); $TestModel->id = 2; $TestModel->save($data); $result = $TestModel->findById(2); $result['Item'] = Hash::sort($result['Item'], '{n}.id', 'asc'); $expected = array('Portfolio' => array('id' => 2, 'seller_id' => 1, 'name' => 'Portfolio 2'), 'Item' => array(array('id' => 1, 'syfile_id' => 1, 'published' => '', 'name' => 'Item 1', 'ItemsPortfolio' => array('id' => 7, 'item_id' => 1, 'portfolio_id' => 2)), array('id' => 2, 'syfile_id' => 2, 'published' => '', 'name' => 'Item 2', 'ItemsPortfolio' => array('id' => 8, 'item_id' => 2, 'portfolio_id' => 2)))); $this->assertEquals($expected, $result); }
/** * Store a newly created template in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Template::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { $template = new Template(); $template->color = Input::get('color'); $template->layout = Input::get('templateID'); $template->user_id = Auth::id(); $template->save(); //Storing header info if (Input::has('headerJobTitle')) { $header = new Header1(); $header->job_title = Input::get('headerJobTitle'); $header->template_id = $template->id; if (Input::has('headerResumeTitle')) { $header->description = Input::get('headerResumeTitle'); } if (Input::hasFile('headerImage')) { $header->picture = Input::file('headerImage')->move("images/uploaded/"); } if (Input::has('headerJobTitle')) { $header->description = Input::get('headerJobTitle'); } $header->save(); } //Storing adjectives for template 2 if (Input::has('adjectives1')) { $header1 = new Header1(); $header1->template_id = $template->id; $header1->adjective = Input::get('adjectives1'); $header1->save(); } if (Input::has('adjectives2')) { $header2 = new Header1(); $header2->template_id = $template->id; $header2->adjective = Input::get('adjectives2'); $header2->save(); } if (Input::has('adjectives3')) { $header3 = new Header1(); $header3->template_id = $template->id; $header3->adjective = Input::get('adjectives3'); $header3->save(); } //Checking for up to 6 skill inputs to be accpeted if (Input::has('skillPercent1') && Input::has('skillTitle1')) { $skill1 = new Skill(); $skill1->template_id = $template->id; $skill1->percent = Input::get('skillPercent1'); $skill1->skill_title = Input::get('skillTitle1'); if (Input::has('skillDescription1')) { $skill1->description = Input::get('skillDescription1'); } if (Input::has('skillDescriptionTitle1')) { $skill1->description_title = Input::get('skillDescriptionTitle1'); } if (Input::has('hobbies1')) { $skill1->description_title = Input::get('hobbies1'); } $skill1->save(); } if (Input::has('skillPercent2') && Input::has('skillTitle2')) { $skill2 = new Skill(); $skill2->template_id = $template->id; $skill2->percent = Input::get('skillPercent2'); $skill2->skill_title = Input::get('skillTitle2'); if (Input::has('skillDescription2')) { $skill2->description = Input::get('skillDescription2'); } if (Input::has('skillDescriptionTitle2')) { $skill2->description_title = Input::get('skillDescriptionTitle2'); } if (Input::has('hobbies2')) { $skill2->description_title = Input::get('hobbies2'); } $skill2->save(); } if (Input::has('skillPercent3') && Input::has('skillTitle3')) { $skill3 = new Skill(); $skill3->template_id = $template->id; $skill3->percent = Input::get('skillPercent3'); $skill3->skill_title = Input::get('skillTitle3'); if (Input::has('skillDescription3')) { $skill3->description = Input::get('skillDescription3'); } if (Input::has('skillDescriptionTitle3')) { $skill3->description_title = Input::get('skillDescriptionTitle3'); } if (Input::has('hobbies3')) { $skill3->description_title = Input::get('hobbies3'); } $skill3->save(); } if (Input::has('skillPercent4') && Input::has('skillTitle4')) { $skill4 = new Skill(); $skill4->template_id = $template->id; $skill4->percent = Input::get('skillPercent4'); $skill4->skill_title = Input::get('skillTitle4'); if (Input::has('skillDescription4') && Input::has('descriptionTitle4')) { $skill4->description = Input::get('skillDescription4'); } if (Input::has('skillDescriptionTitle4')) { $skill4->description_title = Input::get('skillDescriptionTitle4'); } $skill4->save(); } if (Input::has('skillPercent5') && Input::has('skillTitle5')) { $skill5 = new Skill(); $skill5->template_id = $template->id; $skill5->percent = Input::get('skillPercent5'); $skill5->skill_title = Input::get('skillTitle5'); if (Input::has('skillDescription5')) { $skill5->description = Input::get('skillDescription5'); } if (Input::has('skillDescriptionTitle5')) { $skill5->description_title = Input::get('skillDescriptionTitle5'); } $skill5->save(); } //Knowledge storage starts here for template 2 if (Input::has('knowledge1') && Input::has('miscHead1') && Input::has('miscFoot1') && Input::has('miscPercent1')) { $knowledge1 = new Knowledge(); $knowledge1->template_id = $template->id; $knowledge1->knowledge_item = Input::get('knowledge1'); $knowledge1->sub_percent = Input::get('miscPercent1'); $knowledge1->sub_head = Input::get('miscHead1'); $knowledge1->sub_foot = Input::get('miscFoot1'); if (Input::has('miscTitle1')) { $knowledge1->sub_title = Input::get('miscTitle1'); } $knowledge1->save(); } if (Input::has('knowledge2') && Input::has('miscHead2') && Input::has('miscFoot2') && Input::has('miscPercent2')) { $knowledge2 = new Knowledge(); $knowledge2->template_id = $template->id; $knowledge2->knowledge_item = Input::get('knowledge2'); $knowledge2->sub_percent = Input::get('miscPercent2'); $knowledge2->sub_head = Input::get('miscHead2'); $knowledge2->sub_foot = Input::get('miscFoot2'); $knowledge2->save(); } if (Input::has('knowledge3') && Input::has('miscHead3') && Input::has('miscFoot3') && Input::has('miscPercent3')) { $knowledge3 = new Knowledge(); $knowledge3->template_id = $template->id; $knowledge3->knowledge_item = Input::get('knowledge3'); $knowledge3->sub_percent = Input::get('miscPercent3'); $knowledge3->sub_head = Input::get('miscHead3'); $knowledge3->sub_foot = Input::get('miscFoot3'); $knowledge3->save(); } if (Input::has('knowledge4') && Input::has('miscHead4') && Input::has('miscFoot4') && Input::has('miscPercent4')) { $knowledge4 = new Knowledge(); $knowledge4->template_id = $template->id; $knowledge4->knowledge_item = Input::get('knowledge4'); $knowledge4->sub_percent = Input::get('miscPercent4'); $knowledge4->sub_head = Input::get('miscHead4'); $knowledge4->sub_foot = Input::get('miscFoot4'); $knowledge4->save(); } if (Input::has('aboutDescription1')) { $abouts1 = new About(); $abouts1->template_id = $template->id; $abouts1->description = Input::get('aboutDescription1'); if (Input::has('aboutTitle')) { $abouts1->title = Input::get('aboutTitle'); } if (Input::hasFile('aboutBackgroundImage1')) { $abouts1->picture = Input::file('aboutBackgroundImage1')->move("images/uploaded/"); } $abouts1->save(); } if (Input::has('aboutDescription2')) { $abouts2 = new About(); $abouts2->template_id = $template->id; $abouts2->description = Input::get('aboutDescription2'); if (Input::has('aboutTitle')) { $abouts2->title = Input::get('aboutTitle'); } if (Input::hasFile('aboutBackgroundImage2')) { $abouts2->picture = Input::file('aboutBackgroundImage2')->move("images/uploaded/"); } $abouts2->save(); } if (Input::has('aboutDescription3')) { $abouts3 = new About(); $abouts3->template_id = $template->id; $abouts3->description = Input::get('aboutDescription3'); if (Input::has('aboutTitle')) { $abouts3->title = Input::get('aboutTitle'); } if (Input::hasFile('aboutBackgroundImage3')) { $abouts3->picture = Input::file('aboutBackgroundImage3')->move("images/uploaded/"); } $abouts3->save(); } if (Input::has('contactDescription')) { $contacts = new Contact(); $contacts->template_id = $template->id; $contacts->description = Input::get('contactDescription'); $contacts->save(); } //Storing services currently for template 2 if (Input::has('serviceTitle1') || Input::has('serviceTitle2') || Input::has('serviceTitle3') || Input::has('serviceTitle4') || Input::has('serviceTitle5') || Input::has('serviceTitle6')) { if (Input::has('serviceTitle1') && Input::has('serviceDescription1')) { $service1 = new Service(); $service1->template_id = $template->id; $service1->title = Input::get('serviceTitle1'); $service1->description = Input::get('serviceDescription1'); $service1->save(); } if (Input::has('serviceTitle2') && Input::has('serviceDescription2')) { $service2 = new Service(); $service2->template_id = $template->id; $service2->title = Input::get('serviceTitle2'); $service2->description = Input::get('serviceDescription2'); $service2->save(); } if (Input::has('serviceTitle3') && Input::has('serviceDescription3')) { $service3 = new Service(); $service3->template_id = $template->id; $service3->title = Input::get('serviceTitle3'); $service3->description = Input::get('serviceDescription3'); $service3->save(); } if (Input::has('serviceTitle4') && Input::has('serviceDescription4')) { $service4 = new Service(); $service4->template_id = $template->id; $service4->title = Input::get('serviceTitle4'); $service4->description = Input::get('serviceDescription4'); $service4->save(); } if (Input::has('serviceTitle5') && Input::has('serviceDescription5')) { $service5 = new Service(); $service5->template_id = $template->id; $service5->title = Input::get('serviceTitle5'); $service5->description = Input::get('serviceDescription5'); $service5->save(); } if (Input::has('serviceTitle6') && Input::has('serviceDescription6')) { $service6 = new Service(); $service6->template_id = $template->id; $service6->title = Input::get('serviceTitle6'); $service6->description = Input::get('serviceDescription6'); $service6->save(); } } //There are the inputs for the portfolio storeTemplate1Images if (Input::has('portfolioDescription1')) { $portfolio1 = new Portfolio(); if (Input::has('portfolioTitle1')) { $portfolio1->title = Input::get('portfolioTitle1'); } $portfolio1->template_id = $template->id; $portfolio1->description = Input::get('portfolioDescription1'); if (Input::hasFile('portfolioPicture1')) { $portfolio1->picture = Input::file('portfolioPicture1')->move("img/uploaded/"); } if (Input::has('portfolioLink1')) { $portfolio1->link = Input::get('portfolioLink1'); } if (Input::has('portfolioCategory1')) { $portfolio1->category = Input::get('portfolioCategory1'); } $portfolio1->save(); } if (Input::has('portfolioDescription2')) { $portfolio2 = new Portfolio(); if (Input::has('portfolioTitle2')) { $portfolio2->title = Input::get('portfolioTitle2'); } $portfolio2->template_id = $template->id; $portfolio2->description = Input::get('portfolioDescription2'); if (Input::hasFile('portfolioPicture2')) { $portfolio2->picture = Input::file('portfolioPicture2')->move("img/uploaded/"); } if (Input::has('portfolioLink2')) { $portfolio2->link = Input::get('portfolioLink2'); } if (Input::has('portfolioCategory2')) { $portfolio2->category = Input::get('portfolioCategory2'); } $portfolio2->save(); } if (Input::has('portfolioDescription3')) { $portfolio3 = new Portfolio(); if (Input::has('portfolioTitle3')) { $portfolio3->title = Input::get('portfolioTitle3'); } $portfolio3->template_id = $template->id; $portfolio3->description = Input::get('portfolioDescription3'); if (Input::hasFile('portfolioPicture3')) { $portfolio3->picture = Input::file('portfolioPicture3')->move("img/uploaded/"); } if (Input::has('portfolioLink3')) { $portfolio3->link = Input::get('portfolioLink3'); } if (Input::has('portfolioCategory3')) { $portfolio3->category = Input::get('portfolioCategory3'); } $portfolio3->save(); } if (Input::has('portfolioDescription4')) { $portfolio4 = new Portfolio(); if (Input::has('portfolioTitle4')) { $portfolio4->title = Input::get('portfolioTitle4'); } $portfolio4->template_id = $template->id; $portfolio4->description = Input::get('portfolioDescription4'); if (Input::hasFile('portfolioPicture4')) { $portfolio4->picture = Input::file('portfolioPicture4')->move("img/uploaded/"); } if (Input::has('portfolioLink4')) { $portfolio4->link = Input::get('portfolioLink4'); } if (Input::has('portfolioCategory4')) { $portfolio4->category = Input::get('portfolioCategory4'); } $portfolio4->save(); } if (Input::has('portfolioDescription5')) { $portfolio5 = new Portfolio(); if (Input::has('portfolioTitle5')) { $portfolio5->title = Input::get('portfolioTitle5'); } $portfolio5->template_id = $template->id; $portfolio5->description = Input::get('portfolioDescription5'); if (Input::hasFile('portfolioPicture5')) { $portfolio5->picture = Input::file('portfolioPicture5')->move("img/uploaded/"); } if (Input::has('portfolioLink5')) { $portfolio5->link = Input::get('portfolioLink5'); } if (Input::has('portfolioCategory5')) { $portfolio5->category = Input::get('portfolioCategory5'); } $portfolio5->save(); } if (Input::has('portfolioDescription6')) { $portfolio6 = new Portfolio(); if (Input::has('portfolioTitle6')) { $portfolio6->title = Input::get('portfolioTitle6'); } $portfolio6->template_id = $template->id; $portfolio6->description = Input::get('portfolioDescription6'); if (Input::hasFile('portfolioPicture6')) { $portfolio6->picture = Input::file('portfolioPicture6')->move("img/uploaded/"); } if (Input::hasFile('portfolioLink6')) { $portfolio6->link = Input::get('portfolioLink6'); } if (Input::hasFile('portfolioCategory6')) { $portfolio6->category = Input::get('portfolioCategory6'); } $portfolio6->save(); } //Awards if (Input::has('awardTitle1') && Input::has('awardNumber1')) { $award1 = new Award(); $award1->template_id = $template->id; $award1->award_number = Input::get('awardTitle1'); $award1->award_title = Input::get('awardNumber1'); $award1->save(); } if (Input::has('awardTitle2') && Input::has('awardNumber2')) { $award2 = new Award(); $award2->template_id = $template->id; $award2->award_number = Input::get('awardTitle2'); $award2->award_title = Input::get('awardNumber2'); $award2->save(); } if (Input::has('awardTitle3') && Input::has('awardNumber3')) { $award3 = new Award(); $award3->template_id = $template->id; $award3->award_number = Input::get('awardTitle3'); $award3->award_title = Input::get('awardNumber3'); $award3->save(); } //Storing up to 6 work experience sections if (Input::has('workExperienceStart1') && Input::has('workExperienceDescription1') && Input::has('workExperienceTitle1')) { $experience1 = new workExperience(); if (Input::has('workExperienceExtraText1')) { $experience1->description = Input::get('workExperienceExtraText1'); } $experience1->template_id = $template->id; $experience1->start_date = Input::get('workExperienceStart1'); $experience1->title = Input::get('workExperienceTitle1'); $experience1->description = Input::get('workExperienceDescription1'); if (Input::has('workExperienceEnd1')) { $experience1->end_date = Input::get('workExperienceEnd1'); } $experience1->save(); } if (Input::has('workExperienceStart2') && Input::has('workExperienceDescription2') && Input::has('workExperienceTitle2')) { $experience2 = new workExperience(); $experience2->template_id = $template->id; $experience2->start_date = Input::get('workExperienceStart2'); $experience2->title = Input::get('workExperienceTitle2'); $experience2->description = Input::get('workExperienceDescription2'); if (Input::has('workExperienceEnd2')) { $experience2->end_date = Input::get('workExperienceEnd2'); } $experience2->save(); } if (Input::has('workExperienceStart3') && Input::has('workExperienceDescription3') && Input::has('workExperienceTitle3')) { $experience3 = new workExperience(); $experience3->template_id = $template->id; $experience3->start_date = Input::get('workExperienceStart3'); $experience3->title = Input::get('workExperienceTitle3'); $experience3->description = Input::get('workExperienceDescription3'); if (Input::has('workExperienceEnd3')) { $experience3->end_date = Input::get('workExperienceEnd3'); } $experience3->save(); } if (Input::has('workExperienceStart4') && Input::has('workExperienceDescription4') && Input::has('workExperienceTitle4')) { $experience4 = new workExperience(); $experience4->template_id = $template->id; $experience4->start_date = Input::get('workExperienceStart4'); $experience4->title = Input::get('workExperienceTitle4'); $experience4->description = Input::get('workExperienceDescription4'); if (Input::has('workExperienceEnd4')) { $experience4->end_date = Input::get('workExperienceEnd4'); } $experience4->save(); } if (Input::has('workExperienceStart5') && Input::has('workExperienceDescription5') && Input::has('workExperienceTitle5')) { $experience5 = new workExperience(); $experience5->template_id = $template->id; $experience5->start_date = Input::get('workExperienceStart5'); $experience5->title = Input::get('workExperienceTitle5'); $experience5->description = Input::get('workExperienceDescription5'); if (Input::has('workExperienceEnd5')) { $experience5->end_date = Input::get('workExperienceEnd5'); } $experience5->save(); } if (Input::has('workExperienceStart6') && Input::has('workExperienceDescription6') && Input::has('workExperienceTitle6')) { $experience6 = new workExperience(); $experience6->template_id = $template->id; $experience6->start_date = Input::get('workExperienceStart6'); $experience6->title = Input::get('workExperienceTitle6'); $experience6->description = Input::get('workExperienceDescription6'); if (Input::has('workExperienceEnd6')) { $experience6->end_date = Input::get('workExperienceEnd6'); } $experience6->save(); } if (Input::has('educationStart1') && Input::has('educationDescription1') && Input::has('educationTitle1')) { $education1 = new Education(); $education1->template_id = $template->id; $education1->start_date = Input::get('educationStart1'); if (Input::has('educationEnd1')) { $education1->end_date = Input::get('educationEnd1'); } $education1->title = Input::get('educationTitle1'); $education1->description = Input::get('educationDescription1'); $education1->save(); } if (Input::has('educationStart2') && Input::has('educationDescription2') && Input::has('educationTitle2')) { $education2 = new Education(); $education2->template_id = $template->id; $education2->start_date = Input::get('educationStart2'); if (Input::has('educationEnd2')) { $education2->end_date = Input::get('educationEnd2'); } $education2->title = Input::get('educationTitle2'); $education2->description = Input::get('educationDescription2'); $education2->save(); } if (Input::has('educationStart3') && Input::has('educationDescription3') && Input::has('educationTitle3')) { $education3 = new Education(); $education3->template_id = $template->id; $education3->start_date = Input::get('educationStart3'); if (Input::has('educationEnd3')) { $education3->end_date = Input::get('educationEnd3'); } $education3->title = Input::get('educationTitle3'); $education3->description = Input::get('educationDescription3'); $education3->save(); } if (Input::has('educationStart4') && Input::has('educationDescription4') && Input::has('educationTitle4')) { $education4 = new Education(); $education4->template_id = $template->id; $education4->start_date = Input::get('educationStart4'); if (Input::has('educationEnd4')) { $education4->end_date = Input::get('educationEnd4'); } $education4->title = Input::get('educationTitle4'); $education4->description = Input::get('educationDescription4'); $education4->save(); } } return Redirect::action('UsersController@getProfile'); }
public function actionUpdate($id) { $model = $this->loadModel($id); if ($model->occupation->templ == 'members') { $model->scenario = 'genre'; } // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Users'])) { if ($_POST['member'] == 0) { $model->name = $_POST['Users']['name']; Yii::app()->user->name = $model->name; $model->gender = $_POST['Users']['gender']; $model->date_birth = $_POST['year_b'] . '-' . $_POST['month_b'] . '-' . $_POST['day_b']; $model->birth_public = $_POST['Users']['birth_public']; $model->city_id = $_POST['Users']['city_id']; $model->email = $_POST['Users']['email']; $model->about = $_POST['Users']['about']; $model->phone = $_POST['Users']['phone']; $model->phone2 = $_POST['Users']['phone2']; $model->phone3 = $_POST['Users']['phone3']; if ($model->validate() && $model->save()) { Yii::app()->user->setFlash('success_save', '1'); $this->redirect(array('index')); } /*else { echo CHtml::errorSummary($model); //exit(); }*/ } if ($_POST['member'] == 1) { //$model->attributes=$_POST['Users']; if (isset($_POST['Users']['name_studio'])) { $_POST['Users']['name'] = $_POST['Users']['name_studio']; //unset($_POST['Users']['name_studio']); $model->setScenario('studio_update'); } foreach ($_POST['Users'] as $k => $v) { if ($k == 'photo') { if ($v != '') { $model->photo = CUploadedFile::getInstance($model, 'photo'); } } elseif ($k == 'url') { $v = str_replace('http://', '', $v); $model->{$k} = $v; } else { $model->{$k} = $v; } } if (!isset($_POST['Users']['phone2'])) { $model->phone2 = ''; } if (!isset($_POST['Users']['phone3'])) { $model->phone3 = ''; } if (isset($_POST['year_b'])) { $model->date_birth = $_POST['year_b'] . '-' . $_POST['month_b'] . '-' . $_POST['day_b']; } Yii::app()->user->name = $model->name; //echo '<pre>'; //print_r($_POST); //echo '</pre>'; //exit(); if (isset($_POST['Users']['genre_id'])) { $model->genre_id = serialize($_POST['Users']['genre_id']); } if ($model->save()) { if (isset($_POST['Users']['genre_id'])) { Yii::import('application.modules.my.models.Portfolio'); Yii::import('application.modules.my.models.Video'); Yii::import('application.modules.my.models.Genre'); $keys = array(); $data = ''; $data = Portfolio::model()->findAllByAttributes(array('uid' => Yii::app()->user->id)); //print_r($data); exit(); if (is_array($data) && !empty($data)) { //Portfolio::model()->deleteAllByAttributes(array('uid'=>Yii::app()->user->id)); //exit(); foreach ($_POST['Users']['genre_id'] as $genre) { $item = Portfolio::model()->findByAttributes(array('uid' => Yii::app()->user->id, 'title' => Genre::getName($genre))); if (count($item) > 0) { $keys[] = $item->id; } else { $mod = new Portfolio(); $mod->title = Genre::getName($genre); $mod->uid = Yii::app()->user->id; $mod->save(); $keys[] = $mod->id; } } $del = new Portfolio(); $criteria = new CDbCriteria(); $criteria->condition = 'uid=' . Yii::app()->user->id; $criteria->addNotInCondition('id', $keys); $del->deleteAll($criteria); } else { foreach ($_POST['Users']['genre_id'] as $genre) { $mod = new Portfolio(); $mod->title = Genre::getName($genre); $mod->uid = Yii::app()->user->id; $mod->save(); //print_r($mod); } //exit(); } //////////VIDEO///////////////////////// $keys = array(); $data = ''; $data = Video::model()->findAllByAttributes(array('uid' => Yii::app()->user->id)); //print_r($data); exit(); if (is_array($data) && !empty($data)) { //Portfolio::model()->deleteAllByAttributes(array('uid'=>Yii::app()->user->id)); //exit(); foreach ($_POST['Users']['genre_id'] as $genre) { $item = Video::model()->findByAttributes(array('uid' => Yii::app()->user->id, 'title' => Genre::getName($genre))); if (count($item) > 0) { $keys[] = $item->id; } else { $mod = new Video(); $mod->title = Genre::getName($genre); $mod->uid = Yii::app()->user->id; $mod->save(); $keys[] = $mod->id; } } $del = new Video(); $criteria = new CDbCriteria(); $criteria->condition = 'uid=' . Yii::app()->user->id; $criteria->addNotInCondition('id', $keys); $del->deleteAll($criteria); } else { foreach ($_POST['Users']['genre_id'] as $genre) { $mod = new Video(); $mod->title = Genre::getName($genre); $mod->uid = Yii::app()->user->id; $mod->save(); //print_r($mod); } //exit(); } } elseif (isset($_POST['Users']['hals'])) { StudioHals::model()->deleteAllByAttributes(array('uid' => Yii::app()->user->id)); $h = 1; while ($h <= $_POST['Users']['hals']) { $mod = new StudioHals(); $mod->title = 'Зал ' . $h; $mod->uid = Yii::app()->user->id; $mod->save(); $h++; } } Yii::app()->user->setFlash('success_save', '1'); $this->redirect(array('index')); } /*else { $this->render('index',array('model'=>$model)); //echo CHtml::errorSummary($model); //exit(); } */ } } //if(empty($_POST['Users']['genre_id'])) // $model->addError('genre_id','Необходимо указать жанр, в котром Вы работаете.'); $this->render('index', array('model' => $model)); }
public function add() { $path = "uploads/images/{$this->name}/"; if (Request::isMethod('post')) { if (Request::ajax()) { $file = Input::file('image'); $input = array('image' => $file); $rules = array('image' => 'image|max:3000'); $validator = Validator::make($input, $rules); if ($validator->fails()) { return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]); } else { $file = Input::file('image'); $input = array('image' => $file); $rules = array('image' => 'image|max:3000'); $validator = Validator::make($input, $rules); if ($validator->fails()) { return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]); } else { $hash = md5(time()); $filename = "{$hash}.jpg"; $filenameThumb = "{$hash}_small.jpg"; Input::file('image')->move($path, $filename); $img = Image::make($path . $filename); $img->fit(100, 100); $thumb = $path . $filenameThumb; $img->save($thumb); return Response::json(['success' => true, 'thumb' => asset($thumb), 'tmp' => $hash]); } } } $rules = array('title' => 'required|min:4', 'link' => "required|unique:{$this->table}", 'description' => 'required|min:20|max:500', 'meta_keywords' => 'required', 'images' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $images = Input::get('images'); return Redirect::to("admin/{$this->name}/add")->with('images', $images)->withErrors($validator)->withInput(Input::except('')); } else { $table = new Portfolio(); $table->title = Input::get('title'); $table->link = Input::get('link'); $table->user_id = Auth::user()->id; $table->description = Input::get('description'); $table->meta_title = Input::get('meta_title') ? Input::get('meta_title') : $table->title; $table->meta_description = Input::get('meta_description') ? Input::get('meta_description') : $table->description; $table->meta_keywords = Input::get('meta_keywords'); $table->active = Input::get('active', 0); $table->images = Input::get('images'); if ($table->save()) { $id = $table->id; $images = explode(',', $table->images); $imagesStr = ''; for ($i = 1; $i <= count($images); $i++) { $num = $i - 1; File::move($path . $images[$num] . '.jpg', "{$path}{$id}_{$i}.jpg"); File::move($path . $images[$num] . '_small.jpg', "{$path}{$id}_{$i}_small.jpg"); if ($i == count($images)) { $imagesStr .= "{$id}_{$i}"; } else { $imagesStr .= "{$id}_{$i},"; } } $table->images = $imagesStr; if ($table->save()) { $name = trans("name.{$this->name}"); return Redirect::to("admin/{$this->name}")->with('success', trans("message.{$this->action}", ['name' => $name])); } return Redirect::to("admin/{$this->name}")->with('error', trans('message.error')); } return Redirect::to("admin/{$this->name}")->with('error', trans('message.error')); } } return View::make("admin.{$this->name}.{$this->action}", ['name' => $this->name, 'action' => $this->action]); }