コード例 #1
0
ファイル: ProjectsRepository.php プロジェクト: vanderlin/halp
 public function delete($id)
 {
     if (is_object($id)) {
         $id = $id->id;
     }
     $project = Project::withTrashed()->whereId($id)->first();
     if ($project) {
         $project->delete();
     }
     return $this->listener->statusResponse(['project' => $project]);
 }
コード例 #2
0
ファイル: TasksRepository.php プロジェクト: vanderlin/halp
 public function store($input)
 {
     $validator = Validator::make($input, Task::$rules);
     if ($validator->fails()) {
         return $this->listener ? $this->listener->errorResponse($validator->errors()->all()) : $validator->errors()->all();
     }
     $creator_id = isset($input['creator_id']) ? $input['creator_id'] : Auth::id();
     $claimed_id = isset($input['claimed_id']) ? $input['claimed_id'] : NULL;
     $project = Project::where('title', '=', $input['project'])->first();
     // if null we need to create the new project
     if ($project == NULL) {
         $project = new Project(['title' => $input['project'], 'creator_id' => $creator_id]);
         $project->save();
     }
     // does_not_expire
     $does_not_expire = false;
     if (Input::has('does_not_expire')) {
         $does_not_expire = bool_val($input['does_not_expire']);
     }
     $task_date = NULL;
     if (Input::has('task_date')) {
         $task_date = Carbon::createFromFormat("m/d/Y", Input::get('task_date'))->startOfDay();
     }
     $data = ['title' => $input['title'], 'duration' => $input['duration'], 'claimed_id' => $claimed_id, 'project_id' => $project->id, 'creator_id' => $creator_id, 'details' => isset($input['details']) ? $input['details'] : NULL, 'task_date' => $does_not_expire ? NULL : $task_date, 'does_not_expire' => $does_not_expire];
     $task = new Task($data);
     if (isset($input['created_at'])) {
         $task->created_at = $task->updated_at = $input['created_at'];
     }
     $task->save();
     $view = NULL;
     // fire a new notification to the system
     Event::fire(Notification::NOTIFICATION_NEW_TASK, array(['object' => $task, 'name' => Notification::NOTIFICATION_NEW_TASK]));
     if (Input::has('view') && Input::get('view') == true) {
         $view = View::make('site.tasks.card', array('task' => $task, 'claimed' => false))->render();
     }
     $id = $task->id;
     $task = Task::where('id', '=', $id)->with('Creator')->first();
     return $this->listener ? $this->listener->statusResponse(['notice' => 'Task Created. Help is on the way!', 'task' => $task, 'view' => $view]) : $task;
 }
コード例 #3
0
ファイル: SetupSite.php プロジェクト: vanderlin/halp
 public function seedTasks()
 {
     foreach (Task::all() as $task) {
         $task->delete();
     }
     Task::truncate();
     Notification::truncate();
     $options = $this->option();
     $task_repo = App::make('TasksRepository');
     $task_titles = ["Draw me a picture", "Proof-read a email", "Using the espresso machine", "Render a building", "Take a picture", "Make a latte", "Sing a song", "Giving a hug", "Use the 3D printer", "Setup a wordpress site", "Make a ios prototype", "Finding a place to eat", "Move a couch", "Chop veggies", "Talk about life..."];
     $durs = ['a min', 'couple of hours', 'a day', 'few mins', "2 minutes", "an hour", "1/2 hour", "5 minutes", "20 minutes", "10 minutes"];
     $n = isset($options['count']) ? min($options['count'], 1500) : 250;
     $faker = Faker\Factory::create();
     for ($i = 0; $i < $n; $i++) {
         $created_at = $faker->dateTimeBetween('-3 days', '3 days');
         if ($faker->boolean(80)) {
             $created_at = $faker->dateTimeBetween('-3 months', '3 months');
         }
         $data = ['title' => array_random_item($task_titles), 'project' => Project::getRandom()->title, 'creator_id' => User::getRandomID(), 'duration' => array_random_item($durs), 'created_at' => $created_at];
         // dd($data);
         if ($faker->boolean(80)) {
             $data['details'] = implode("\n", $faker->sentences(4));
         }
         if ($faker->boolean(10)) {
             $data['does_not_expire'] = true;
             $data['task_date'] = NULL;
         }
         $task = $task_repo->store($data);
         $this->info("{$task->id} Creating Task:{$task->title}");
     }
     $this->comment("----- Seed Claiming -----");
     // Get a bunch for a few users
     for ($i = 0; $i <= User::count() / 2; $i++) {
         $user_id = User::getRandomID();
         for ($j = 0; $j <= $faker->numberBetween(5, 120); $j++) {
             $task = Task::orderByRaw("RAND()")->where('creator_id', '<>', $user_id)->take(1)->first();
             $task->claimed_id = $user_id;
             $task->claimed_at = $task->date->subDays($faker->randomDigit);
             $task->save();
             $this->info("{$task->title} Claimed at: " . $task->claimed_at->diffForHumans($task->created_at));
             Notification::fire($task, Notification::NOTIFICATION_TASK_CLAIMED);
         }
     }
     // now claime some randomly
     foreach (Task::orderByRaw("RAND()")->take(Task::count() / 2)->get() as $task) {
         $task->claimed_id = User::getRandomID([$task->creator_id]);
         $task->claimed_at = $task->date->subDays($faker->randomDigit);
         $task->save();
         $this->info("{$task->title} Claimed at: " . $task->claimed_at->diffForHumans($task->created_at));
         Notification::fire($task, Notification::NOTIFICATION_TASK_CLAIMED);
     }
     $this->call('halp:awards', array('--full' => 'true'));
 }
コード例 #4
0
     $em = Project::srvc('EntityManager');
     $repo = $em->getRepository('OrderedItem\\ExampleEntities\\OrderedItemWithParentRelation');
     $f1 = $repo->find($fixtureIds[0]);
     $f2 = $repo->find($fixtureIds[1]);
     $f3 = $repo->find($fixtureIds[2]);
     $repo->addBefore($f3, $f1);
     $em->flush();
     $em->clear();
     $parent = $repo->find($f1->getParent()->getId());
     $all = $repo->findAllByParent($parent);
     expect($all[0]->getid())->should('be equals', $f3->getId());
     expect($all[1]->getid())->should('be equals', $f1->getId());
     expect($all[2]->getid())->should('be equals', $f2->getId());
 });
 it('should move to another parent', function () use(&$fixtureIds) {
     $em = Project::srvc('EntityManager');
     $repo = $em->getRepository('OrderedItem\\ExampleEntities\\OrderedItemWithParentRelation');
     $parent2 = OrderedItemWithParentRelation::build('parent2', null);
     $repo->addLast($parent2);
     $em->flush();
     $fixture2Ids = OrderedItemWithParentRelationFixtures::threeItems($em, $parent2);
     $f_1 = $repo->find($fixtureIds[1]);
     $f2_1 = $repo->find($fixture2Ids[1]);
     $em->flush();
     $em->clear();
     $parent = $repo->find($parent2->getId());
     $f_1->setParent($parent);
     // needs to clear the repo before calling add last to test the query to find the max position.
     $repo->addLast($f_1);
     $children = $repo->findAllByParent($parent);
     expect(count($children))->should('be equals', 4);
コード例 #5
0
ファイル: index.php プロジェクト: brunoreis/DoctrineLearning
<?php

use PSpec\PSpecSuite, Project\Project;
require_once __DIR__ . "/../../../class_loaders.php";
Project::init('test');
PSpecSuite::instance('../../../vendor_lib/pspec/')->addParameters($_GET)->addListener(Project::srvc('DoctrineSqlLogger'))->setSpec(__DIR__ . '/specs/OrderedItem.spec.php')->runAndReport();