/** * Create a new job based on the PUT parameters given and content-type. * * @param $uri string The identifier of the job * * @return void */ public function createJob($uri) { list($collection_uri, $name) = $this->getParts($uri); // Retrieve the parameters of the PUT requests (either a JSON document or a key=value string) $params = \Request::getContent(); // Is the body passed as JSON, if not try getting the request parameters from the uri if (!empty($params)) { $params = json_decode($params, true); } else { $params = \Input::all(); } // If we get empty params, then something went wrong if (empty($params)) { \App::abort(400, "The parameters could not be parsed from the body or request URI, make sure parameters are provided and if they are correct (e.g. correct JSON)."); } // Validate the job properties $job_params = $this->validateParameters('Job', 'job', $params); // Check which parts are set for validation purposes $extract = @$params['extract']; $load = @$params['load']; // Check for every emlp part if the type is supported $extractor = $this->getClassOfType(@$extract, 'Extract'); $loader = $this->getClassOfType(@$load, 'Load'); // Save the emlp models $extractor->save(); $loader->save(); // Create the job associated with emlp relations $job = new \Job(); $job->collection_uri = $collection_uri; $job->name = $name; // Add the validated job params foreach ($job_params as $key => $value) { $job->{$key} = $value; } $job->extractor_id = $extractor->id; $job->extractor_type = $this->getClass($extractor); $job->loader_id = $loader->id; $job->loader_type = $this->getClass($loader); $job->save(); // Execute the job for a first time $job->date_executed = time(); $job->save(); $job_name = $job->collection_uri . '/' . $job->name; \Queue::push(function ($queued_job) use($job_name) { \Artisan::call('input:execute', ['jobname' => $job_name]); $queued_job->delete(); }); return \Response::make([], 200); }
public function postAddJob() { $job = new Job(); $job->job = $_POST['name']; $job->category_id = $_POST['cat_id']; $job->save(); }
public function apply() { $id = (int) $_POST['id']; //find the offer $market = new JobMarket(); $offer = $market->get($id); if (empty($offer)) { throw new Exception('offer not found'); } //check if matches the requirements $skill = new Skill(); $skill = $skill->get($this->user->id); if ($skill->economic < $offer->skill) { throw new Exception("you don't meet the requirements"); } //give him the job $data = array('uid' => $this->user->id, 'company' => $offer->company, 'salary' => $offer->salary); $job = new Job($data); $saved = $job->save(); // update the offer if (!empty($saved)) { $offer->quantity--; if ($offer->quantity == 0) { $offer->delete(); } else { $offer->save(); } return true; } else { return false; } }
/** * Serialize the form into the database. * */ public function save($con = null) { if ($this->getObject()) { $j = $this->getObject(); } else { $j = new Job(); } $j->setPublicationId($this->getValue("publication_id")); $j->setStatusId($this->getValue("status_id")); $j->setEvent($this->getValue("event")); $j->setDate($this->getValue("date")); $j->setStartTime($this->getValue("start_time")); $j->setEndTime($this->getValue("end_time")); $j->setDueDate($this->getValue("due_date")); $j->setContactName($this->getValue("contact_name")); $j->setContactPhone($this->getValue("contact_phone")); $j->setContactEmail($this->getValue("contact_email")); $j->setAcctNum($this->getValue("acct_num")); $j->save(); $logEntry = new Log(); $logEntry->setWhen(time()); $logEntry->setPropelClass("Job"); $logEntry->setSfGuardUserProfileId(sfContext::getInstance()->getUser()->getUserId()); $logEntry->setMessage("Basic info updated."); $logEntry->setLogMessageTypeId(sfConfig::get("app_log_type_update")); $logEntry->setPropelId($j->getId()); $logEntry->save(); }
/** * @before _secure, _vendor */ public function index() { $this->seo(array("title" => "Schedule Your Appointments", "view" => $this->getLayoutView())); $this->getLayoutView()->set("cal", true); $view = $this->getActionView(); if (RequestMethods::post("appointment_id")) { if (RequestMethods::post("job_id", "")) { $job = Job::first(array("appointment_id = ?" => RequestMethods::post("appointment_id"))); $job->user_id = RequestMethods::post("user_id"); } else { $job = new Job(array("user_id" => RequestMethods::post("user_id"), "muser_id" => RequestMethods::post("muser_id"), "puser_id" => RequestMethods::post("puser_id"), "appointment_id" => RequestMethods::post("appointment_id"), "location_id" => RequestMethods::post("location_id"), "centre_id" => RequestMethods::post("centre_id"), "organization_id" => RequestMethods::post("organization_id"))); } $job->save(); $view->set("message", "Runner Assigned Successfully"); } if (RequestMethods::post("action") == "capacity") { foreach (RequestMethods::post("slot") as $key => $value) { $slot = Slot::first(array("organization_id = ?" => $this->member->organization_id, "day = ?" => $key)); if (isset($slot)) { $slot->start = $value["start"]; $slot->day = $key; $slot->end = $value["end"]; $slot->capacity = $value["hlimit"]; } else { $slot = new Slot(array("user_id" => $this->user->id, "organization_id" => $this->member->organization_id, "day" => $key, "start" => $value["start"], "end" => $value["end"], "capacity" => $value["hlimit"])); } $slot->save(); } $view->set("message", "Slots Saved Successfully"); } $runners = Member::all(array("organization_id = ?" => $this->member->organization_id, "designation = ?" => "runner"), array("user_id", "id")); $view->set("runners", $runners); $view->set("day", array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")); $view->set("slots", Slot::all(array("organization_id = ?" => $this->member->organization_id), array("start", "end", "capacity", "day"))); }
public function run($arg) { try { $arg = unserialize(base64_decode($arg)); if (!isset($arg['class']) || !isset($arg['function'])) { return array('result' => array('done' => false, 'job_id' => -1), 'WorkerJobSetIdentifier' => isset($arg['WorkerJobSetIdentifier']) ? $arg['WorkerJobSetIdentifier'] : -1, 'background' => isset($arg['background']) ? $arg['background'] : -1); } $log = $arg["class"] . '::' . $arg["function"]; if (defined('THREAD') && defined('THREAD_TYPE')) { print date('d.m.Y H:i:s') . ' :: ' . THREAD_TYPE . ' Thread :: ' . str_pad(THREAD, 3, '0', STR_PAD_LEFT) . ' :: ' . $log . "\n"; } $task_id = $arg['task_id']; $Job = Job::model()->find('id=:id', array(':id' => $task_id)); if ($Job == null) { $Job = new Job(); return null; } $Job->started = 1; $Job->starttime = date('Y-m-d H:i:s'); $Job->save(); $tmp = $this->runClassFunction($arg["class"], $arg["function"], $arg["params"]); $done = false; if ($tmp != null) { $Job->parameters = null; $Job->result = base64_encode(serialize($tmp)); $Job->finishtime = date('Y-m-d H:i:s'); $Job->save(); $Job->finished = 1; $Job->save(); $done = true; } } catch (CDbException $e) { if (function_exists('thread_shutdown')) { thread_shutdown(); } die; } $log = $arg["class"] . '::' . $arg["function"] . ' :: DONE'; if (defined('THREAD') && defined('THREAD_TYPE')) { print date('d.m.Y H:i:s') . ' :: ' . THREAD_TYPE . ' Thread :: ' . str_pad(THREAD, 3, '0', STR_PAD_LEFT) . ' :: ' . $log . "\n"; } return array('result' => array('done' => $done, 'job_id' => $Job->id), 'WorkerJobSetIdentifier' => $arg['WorkerJobSetIdentifier'], 'background' => $arg['background']); }
public function createJob($type, $chart, $user, $params) { $job = new Job(); $job->setChartId($chart->getId()); $job->setUserId($user->getId()); $job->setCreatedAt(time()); $job->setType($type); $job->setParameter(json_encode($params)); $job->save(); return $job; }
public function executeAction() { Assert::found($id = (int) $this->dispatcher->getParam('0', 'uint')); Assert::found($task = Task::findFirst($id), "Task not found"); $job = Job::findFirst(['task_id = ?0 and executed_at is null', 'bind' => [$task->task_id]]); if (!$job) { $job = new Job(); $job->save(['task_id' => $task->task_id]); Assert::noMessages($job); } return $this->response->redirect('/task/run/' . $job->job_id, true); }
public function run() { $replace = \Config::get('laravel-jobs::seed.replace'); if ($replace) { \DB::table('fbf_jobs')->delete(); } $faker = \Faker\Factory::create(); $statuses = array(Job::DRAFT, Job::APPROVED); $types = array(Job::PERMANENT, Job::TEMPORARY); $times = array(Job::FULL_TIME, Job::PART_TIME); for ($i = 0; $i < 100; $i++) { $job = new Job(); $job->title = $faker->sentence(rand(1, 4)); if (\Config::get('laravel-jobs::use_reference_field')) { $job->reference = 'JOB/' . rand(1000, 9999); } if (\Config::get('laravel-jobs::use_location_field')) { $job->location = $faker->city(); } if (\Config::get('laravel-jobs::use_type_field')) { $job->type = $faker->randomElement($types); } if (\Config::get('laravel-jobs::use_time_field')) { $job->time = $faker->randomElement($times); } if (\Config::get('laravel-jobs::use_closing_date_field')) { $job->closing_date = $faker->dateTimeBetween('-1 week', '+3 months'); } switch (\Config::get('laravel-jobs::salary_field')) { case 'text': $job->salary_text = $this->salaryText(); break; case 'number': $job->salary_from = rand(20000, 200000); break; case 'range': $number1 = rand(20000, 200000); $number2 = rand(20000, 200000); $job->salary_from = min($number1, $number2); $job->salary_to = max($number1, $number2); break; } $job->description = '<p>' . implode('</p><p>', $faker->paragraphs(rand(1, 10))) . '</p>'; $job->meta_description = $faker->paragraph(rand(1, 4)); $keywords = $faker->words(10, true); $job->search_extra = $keywords; $job->meta_keywords = $keywords; $job->status = $faker->randomElement($statuses); $job->published_date = $faker->dateTimeBetween('-6 weeks', '+1 week'); $job->save(); } echo 'Database seeded' . PHP_EOL; }
function schedule_recurring_event($event) { global $wpdb; $schedules = wp_get_schedules(); $schedule = $event->schedule; $job = new Job(); $job->hook = $event->hook; $job->site = get_current_blog_id(); $job->start = $job->nextrun = $event->timestamp; $job->interval = $event->interval; $job->args = $event->args; $job->save(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Job(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Job'])) { $model->attributes = $_POST['Job']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Job(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Job'])) { $model->attributes = $_POST['Job']; if ($model->save()) { EQuickDlgs::checkDialogJsScript(); $this->redirect(array('index')); } } EQuickDlgs::render('create', array('model' => $model)); }
public function store() { $job = new Job(); $job->heading = Input::get('heading'); $job->description = Input::get('description'); $job->user_id = userId(); $job->salary_max = Input::get('salary_max'); $job->salary_min = Input::get('salary_min'); $job->start_date = Input::get('start_date'); $job->end_date = Input::get('end_date'); $job->state = Input::get('state'); $job->suburb = Input::get('suburb'); $update = $job->save(); return Response::json(['data' => $job], 200); }
public function run() { $client = new Net_Gearman_Client(array('localhost:4730')); $this->JobSet->starttime = date('Y-m-d H:i:s'); $this->JobSet->save(); $client->runSet($this->taskList); if (!$this->background) { if ($this->taskList->finished()) { global $WorkerJobSetResults; $handles = $this->taskList->handles; $key_handles = array_keys($handles); for ($i = 0; $i < count($WorkerJobSetResults[$this->randomHash]); $i++) { if (array_key_exists($key_handles[$i], $WorkerJobSetResults[$this->randomHash])) { if ($WorkerJobSetResults[$this->randomHash][$key_handles[$i]]['done']) { $job = Job::model()->find('id=:id', array(':id' => $WorkerJobSetResults[$this->randomHash][$key_handles[$i]]['job_id'])); if ($job != null) { if ($job == null) { $job = new Job(); } $this->results[] = unserialize(base64_decode($job->result)); // echo "Done"; $job->needed = 0; $job->save(); } else { die("Some results didn't come...\n"); } } } else { die("Some results didn't come...\n"); } } $this->JobSet->finishtime = date('Y-m-d H:i:s'); if ($this->auto_destroy_results) { $this->JobSet->needed = 0; $this->JobSet->delete(); $this->JobSet = null; } else { $this->JobSet->save(); } return $this->results; } echo "Task set could not be finished!<br />\n"; return false; } else { // background work return true; } }
public function createJob($data, $jobgroup = null) { $data['queue'] = $this->_queue; $data['jail'] = $this->_jail; $job = new Job(); if ($job->setJobData($data) !== true) { return false; } if ($job->save() !== true) { return false; } if ($jobgroup == null) { return true; } return $jobgroup->addJob($job->getJobId()); }
/** * 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->aPhotographer !== null) { if ($this->aPhotographer->isModified() || $this->aPhotographer->isNew()) { $affectedRows += $this->aPhotographer->save($con); } $this->setPhotographer($this->aPhotographer); } if ($this->aJob !== null) { if ($this->aJob->isModified() || $this->aJob->isNew()) { $affectedRows += $this->aJob->save($con); } $this->setJob($this->aJob); } if ($this->isNew()) { $this->modifiedColumns[] = JobPhotographerPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = JobPhotographerPeer::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 += JobPhotographerPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
public function addGCodeFile($file, $qty = 1) { $jobs = array(); for ($i = 0; $i < $qty; $i++) { $sort = db()->getValue("SELECT max(id)+1 FROM jobs"); $job = new Job(); $job->set('user_id', User::$me->id); $job->set('queue_id', $this->id); $job->set('file_id', $file->id); $job->set('name', $file->get('path')); $job->set('status', 'available'); $job->set('created_time', date("Y-m-d H:i:s")); $job->set('user_sort', $sort); $job->save(); $jobs[] = $job; } return $jobs; }
/** * Serialize the form into the database. * */ public function save($con = null) { $j = new Job(); $j->setEvent($this->getValue("event")); $j->setStartTime($this->getValue("start_time")); $j->setEndTime($this->getValue("end_time")); $j->setDueDate($this->getValue("due_date")); $j->setPublicationId($this->getValue("publication_id")); $j->setStreet($this->getValue("street")); $j->setCity($this->getValue("city")); $j->setState($this->getValue("state")); $j->setZip($this->getValue("zip")); $j->setContactName($this->getValue("contact_name")); $j->setContactPhone($this->getValue("contact_phone")); $j->setContactEmail($this->getValue("contact_email")); $j->setStatusId(sfConfig::get("app_job_status_pending", 1)); $j->setProjectId($this->getValue("project_id")); $j->save(); }
/** * Serialize the form into the database. * */ public function save($con = null) { if ($this->getObject()) { $j = $this->getObject(); } else { $j = new Job(); } $j->setEstimate($this->getValue("estimate")); $j->setProcessing($this->getValue("processing")); $j->save(); $logEntry = new Log(); $logEntry->setWhen(time()); $logEntry->setPropelClass("Job"); $logEntry->setSfGuardUserProfileId(sfContext::getInstance()->getUser()->getUserId()); $logEntry->setMessage("Billing info updated."); $logEntry->setLogMessageTypeId(sfConfig::get("app_log_type_update")); $logEntry->setPropelId($j->getId()); $logEntry->save(); }
public function createJob() { if (!Request::isMethod('post')) { return View::make('job_form'); } else { $job = new Job(); $job->job_status = Input::get('job_status'); $job->job_date = Input::get('date'); $job->job_number = Input::get('job_number'); $job->customer_reference = Input::get('customer_reference'); $job->order_details = Input::get('order_details'); $job->boards = Input::get('boards'); $job->accessories = Input::get('accessories'); $job->boards_ordered = Input::get('boards_ordered'); $job->sales_order_complete = Input::get('sales_order_complete') == 'no' ? 0 : 1; $job->notes = Input::get('notes'); $job->save(); return Redirect::to('/')->with('message', 'Your job has been created.'); } }
/** * Serialize the form into the database. * */ public function save($con = null) { if ($this->getObject()) { $j = $this->getObject(); } else { $j = new Job(); } $j->setState($this->getValue("state")); $j->setCity($this->getValue("city")); $j->setZip($this->getValue("zip")); $j->setStreet($this->getValue("street")); $j->save(); $logEntry = new Log(); $logEntry->setWhen(time()); $logEntry->setPropelClass("Job"); $logEntry->setSfGuardUserProfileId(sfContext::getInstance()->getUser()->getUserId()); $logEntry->setMessage("Shoot info updated."); $logEntry->setLogMessageTypeId(sfConfig::get("app_log_type_update")); $logEntry->setPropelId($j->getId()); $logEntry->save(); }
/** * Serialize the form into the database. * */ public function save($con = null) { if ($this->getObject()) { $j = $this->getObject(); } else { $j = new Job(); } $j->setPhotoType(implode(", ", $this->getValue("photo_type"))); $j->setQues1($this->getValue("ques1")); $j->setQues2($this->getValue("ques2")); $j->setQues3($this->getValue("ques3")); $j->setOther($this->getValue("other")); $j->save(); $logEntry = new Log(); $logEntry->setWhen(time()); $logEntry->setPropelClass("Job"); $logEntry->setSfGuardUserProfileId(sfContext::getInstance()->getUser()->getUserId()); $logEntry->setMessage("Photography info updated."); $logEntry->setLogMessageTypeId(sfConfig::get("app_log_type_update")); $logEntry->setPropelId($j->getId()); $logEntry->save(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), Job::$rules); if ($validator->fails()) { Session::flash('errorMessage', 'Job failed'); return Redirect::back()->withInput()->withErrors($validator); } else { $job = new Job(); $job->category = Input::get('category'); $job->description = Input::get('description'); $job->price = Input::get('price'); $job->is_complete = Input::has('is_complete'); $job->price = Input::get('price'); $job->required_date = Input::get('required_date'); $job->required_time = Input::get('required_time'); $job->creator()->associate(Auth::user()); $job->save(); Session::flash('successMessage', 'Post successfully created'); return Redirect::action('UsersController@dashboard_creator', Auth::id()); } //end of else }
/** * Adds a Job */ public function add() { $this->load->model("Job"); $this->load->helper("url"); $this->load->library("table"); $this->load->library("form_validation"); $jobs = $this->Job->get(); $job_form_options = array(); foreach ($jobs as $id => $job) { $job_form_options[$id] = $job->job_title; } $this->form_validation->set_rules(array(array('field' => 'job_title', 'label' => 'Job Title', 'rules' => 'required'))); $this->form_validation->set_error_delimiters("<div class='alert alert-error'>", "</div>"); if (!$this->form_validation->run()) { $this->load->view('job_form', array("job_form_options" => $job_form_options)); } else { $this->load->model("Job"); $job = new Job(); $job->job_title = $this->input->post("job_title"); $job->save(); $this->load->view('job_form_success', array('job' => $job)); } }
<?php include "../../extensions/global.php"; include "../patches.php"; $patchNumber = 12; start_patch(); if (!patch_exists($patchNumber)) { // Fix the temperature fields: $rs = db()->query("SELECT * from jobs"); while ($row = $rs->fetch(PDO::FETCH_ASSOC)) { $job = new Job($row['id']); $fixed_data = fix_temp_data($job->get('temperature_data')); $job->set('temperature_data', $fixed_data); $job->save(); } $rs = db()->query("SELECT * from bots"); while ($row = $rs->fetch(PDO::FETCH_ASSOC)) { $bot = new Bot($row['id']); $fixed_data = fix_temp_data($bot->get('temperature_data')); $bot->set('temperature_data', $fixed_data); $bot->save(); } $expandTemperatureData = "\n\t\tALTER TABLE jobs\n \t\tMODIFY COLUMN temperature_data longtext NOT NULL"; db()->execute($expandTemperatureData); $expandTemperatureData = "\n\t\tALTER TABLE bots\n \t\tMODIFY COLUMN temperature_data longtext NOT NULL"; finish_patch($patchNumber, "Expanded temperature data fields"); } function fix_temp_data($data) { if (strlen($data) == 0) { return "";
public function update_sort() { $this->assertLoggedIn(); if (!$this->args('jobs')) { die("Error: You didn't pass any jobs in."); } $jobs = explode(",", $this->args('jobs')); if (count($jobs) < 1) { die("Error: You need to pass in at least 2 jobs."); } //load up our ids. $jids = array(); foreach ($jobs as $job) { $jarray = explode("_", $job); $jid = (int) $jarray[1]; if (!$jid) { die("Error: format must be a csv of job_### where ### is the job id."); } $jids[] = $jid; } //find our our current max $sql = "SELECT min(user_sort) FROM jobs WHERE id IN (" . implode($jids, ",") . ")"; $min = (int) db()->getValue($sql); //now actually update. foreach ($jids as $jid) { $job = new Job($jid); if ($job->get('user_id') == User::$me->id) { $job->set('user_sort', $min); $job->save(); $min++; } else { die("Error: Job {$jid} is not your job."); } } die("OK"); }
public function transformJobs() { $statusHash = array(); $statusObjects = StatusPeer::doSelect(new Criteria()); foreach ($statusObjects as $s) { $statusHash[$s->getState()] = $s->getId(); } $this->jobKeys = array(); $dom = DOMDocument::load("tuftsph_jm2db.xml"); $jobs = $dom->getElementsByTagName("jobs"); $total = $jobs->length; $count = 1; $jobList = array(); foreach ($jobs as $job) { $jid = 0; $childNodes = $job->childNodes; $j = new Job(); $del = new Delivery(); $jid = 1; $startTime = null; $shootStart = null; $shootEnd = null; $endTime = null; $notes = ""; $photog = 0; $slug = ""; $childNodes = $job->childNodes; foreach ($childNodes as $child) { switch ($child->nodeName) { case "id": $jid = $child->textContent; break; case "shoot_name": $j->setEvent($child->textContent); break; case "shoot_date": $j->setDate($child->textContent); break; case "shoot_startT": $startTime = $child->textContent; break; case "shoot_start": $shootStart = $child->textContent; break; case "shoot_endT": $endTime = $child->textContent; break; case "shoot_end": $shootEnd = $child->textContent; break; case "shoot_duedate": $j->setDueDate($child->textContent); break; case "submitted_at": $j->setCreatedAt($child->textContent); break; case "requester_address": $j->setStreet($child->textContent); break; case "requester_campus": $j->setCity($child->textContent); break; case "requester_name": $j->setContactName($child->textContent); break; case "requester_email": $j->setContactEmail($child->textContent); break; case "requester_phone": $j->setContactPhone($child->textContent); break; case "internal_notes": $notes .= $child->textContent . "<br/>"; break; case "billing_notes": $notes .= $child->textContent . "<br/>"; break; case "estimate": $j->setEstimate($child->textContent); break; case "billing_acctnum": $j->setAcctNum($child->textContent); break; case "billing_deptid": $j->setDeptId($child->textContent); break; case "billing_grantid": $j->setGrantId($child->textContent); break; case "shoot_directions": $j->setOther($child->textContent); break; case "status": $j->setStatusId($statusHash[$child->textContent]); break; case "photog_id": $photog = $child->textContent; break; case "delivery_pubname": $del->setPubName($child->textContent); break; case "delivery_pubtype": $del->setPubType($child->textContent); break; case "delivery_other": $del->setOther($child->textContent); break; case "delivery_format": break; case "delivery_color": $del->setColor($child->textContent); break; case "delivery_format": $del->setFormat($child->textContent); break; case "delivery_size": $del->setSize($child->textContent); break; case "delivery_method": $del->setMethod($child->textContent); break; case "delivery_special": $del->setInstructions($child->textContent); break; case "slug": $slug = $child->textContent; break; case "#text": default: break; } } if (is_null($endTime)) { $endTime = $shootEnd; } if (is_null($startTime)) { $startTime = $shootStart; } if ($j->getCity() == "Boston") { $j->setZip("02101"); } else { $j->setZip("02155"); } $j->setNotes($notes); $j->setState("Massachusetts"); list($hour, $min, $sec) = explode(":", $endTime); list($shour, $smin, $ssec) = explode(":", $startTime); $t = new DateTime(); $t->setTime($hour, $min, $sec); $j->setEndTime($t); $t = new DateTime(); $t->setTime($shour, $smin, $ssec); $j->setStartTime($t); $j->addTag($slug); if (isset($this->jobProjectKeys[$jid])) { $j->setProjectId($this->projectKeys[$this->jobProjectKeys[$jid]]); } while (count($jobList) - 1 != $jid) { $jobList[] = false; } $jobList[intval($jid)] = array("job" => $j, "del" => $del, "photog" => $photog); } for ($i = 1; $i < count($jobList); $i++) { sleep(1); $obj = $jobList[$i]; $c = new Criteria(); $c->add(JobPeer::ID, $i); if (JobPeer::doCount($c) > 0) { continue; } echo $i . "/" . $total . "\n"; // keep the ids lined up if ($obj == false) { $myJob = new Job(); try { $myJob->save(); } catch (Exception $ex) { echo $ex->getMessage(); } $myJob->delete(); } else { $j = $obj["job"]; $del = $obj["del"]; $photog = $obj["photog"]; try { $j->save(); } catch (Exception $ex) { echo $ex->getMessage(); echo $ex->getTraceAsString(); } $del->setJobId($j->getId()); $del->save(); $this->jobKeys[$jid] = $j->getId(); if ($photog) { $jp = new JobPhotographer(); $jp->setPhotographerId($this->photogKeys[$photog]); $jp->setJobId($j->getId()); try { $jp->save(); } catch (Exception $ex) { echo $ex->getMessage(); } } // add the requester as a client $c = new Criteria(); $c->add(sfGuardUserPeer::USERNAME, $j->getContactEmail()); if (ClientPeer::doCount($c) == 0 && trim(strlen($j->getContactEmail())) != 0) { $user = new sfGuardUser(); $user->setUsername($j->getContactEmail()); $user->setPassword("admin"); $user->save(); $userProfile = new sfGuardUserProfile(); $userProfile->setUserId($user->getId()); $userProfile->setUserTypeId(sfConfig::get("app_user_type_client")); $userProfile->save(); $clientProfile = new Client(); $clientProfile->setUserId($userProfile->getId()); $clientProfile->setName($j->getContactName()); $clientProfile->setEmail($j->getContactEmail()); $clientProfile->setPhone($j->getContactPhone()); $clientProfile->save(); $jobClient = new JobClient(); $jobClient->setClientId($clientProfile->getId()); $jobClient->setJobId($j->getId()); $jobClient->save(); } } $count += 1; } }
public function save($con = null) { sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url', 'Object', 'Tag', 'Text', 'PMRender', 'Asset', 'Helper')); $j = new Job(); $j->setEvent($this->getValue("event")); $j->setStartTime($this->getValue("start_time")); $j->setEndTime($this->getValue("end_time")); $j->setDate($this->getValue("date")); $j->setDueDate($this->getValue("due_date")); $j->setAcctNum($this->getValue("acct_num")); $j->setDeptId($this->getValue("dept_id")); $j->setPublicationId($this->getValue("publication_id")); $j->setStreet($this->getValue("street")); $j->setCity($this->getValue("city")); $j->setState($this->getValue("state")); $j->setZip($this->getValue("zip")); if (is_array($this->getValue("photo_type"))) { $j->setPhotoType(implode(", ", $this->getValue("photo_type"))); } else { $j->setPhotoType($this->getValue("photo_type")); } $j->setOther($this->getValue("other")); $j->setQues1($this->getValue("ques1")); $j->setQues2($this->getValue("ques2")); $j->setQues3($this->getValue("ques3")); $j->setContactName($this->getValue("contact_name")); $j->setContactPhone($this->getValue("contact_phone")); $j->setContactEmail($this->getValue("contact_email")); $j->setStatusId(sfConfig::get("app_job_status_pending", 1)); $j->setProjectId($this->getValue("project_id")); $j->save(); $body = "Dear {$this->getValue("name")},\r\n\r\nYour job, {$this->getValue("event")}, has been entered into our system. \r\nIf you wish to track the progress of your job, you may do so at http://jobs.tuftsphoto.com \r\n\r\nThanks for using University Photography; we look forward to working with you! \r\n\r\nThe Tufts Photo Team \r\nUniversity Photography\r\n80 George St., First Floor\r\nMedford, MA 02155\r\nTel: 617.627.4282\r\nFax: 617.627.3549\r\nphoto@tufts.edu\r\n\r\n\r\n" . getJobDetails($j); mail($this->getValue("email") . ", photo@tufts.edu", "University Photography Job #" . $j->getId() . " - " . $j->getEvent(), $body, "From: photo@tufts.edu"); $user = sfContext::getInstance()->getUser(); if ($this->getValue("clientId") > 0 && ($user->hasCredential("client") || $user->hasCredential("admin"))) { $client = ClientPeer::retrieveByPK($this->getValue("clientId")); $j->addClient($client); } // if they are a user lets make them a client if ($user->getProfile()->getUserType()->getId() == sfConfig::get("app_user_type_user")) { $clientProfile = new Client(); $clientProfile->setUserId($user->getProfile()->getId()); $clientProfile->setName($this->getValue("name")); $clientProfile->setDepartment($this->getValue("department")); $clientProfile->setAddress($this->getValue("address")); $clientProfile->setEmail($this->getValue("email")); $clientProfile->setPhone($this->getValue("phone")); $clientProfile->save(); $user->getProfile()->setUserTypeId(sfConfig::get("app_user_type_client")); $user->getProfile()->save(); $user->clearCredentials(); $user->addCredential("client"); } else { if ($user->getProfile()->getUserType()->getId() == sfConfig::get("app_user_type_client")) { $c = new Criteria(); $c->add(ClientPeer::USER_ID, $user->getProfile()->getId()); $clientProfile = ClientPeer::doSelectOne($c); if (is_null($clientProfile)) { $clientProfile = new Client(); } $clientProfile->setUserId($user->getProfile()->getId()); $clientProfile->setName($this->getValue("name")); $clientProfile->setDepartment($this->getValue("department")); $clientProfile->setAddress($this->getValue("address")); $clientProfile->setEmail($this->getValue("email")); $clientProfile->setPhone($this->getValue("phone")); $clientProfile->save(); } } if (isset($clientProfile) && !is_null($clientProfile)) { $j->addClient($clientProfile); } return $j->getId(); }
/** * @param $job Job * @param $can_slice bool * @return Job * @throws Exception */ public function grabJob($job, $can_slice = true) { $grabAttemptSQL = "\n UPDATE jobs\n SET bot_id =\n CASE\n WHEN bot_id=0\n THEN\n ?\n ELSE\n bot_id\n END\n WHERE id = ?\n "; // Attempt to grab the job unless another bot already has db()->execute($grabAttemptSQL, array($this->id, $job->id)); $job = new Job($job->id); // Reload the job if ($job->get('bot_id') != $this->id) { // We didn't grab it in time. throw new Exception("Unable to lock job #{$job->id}"); } $job->setStatus('taken'); $job->set('taken_time', date('Y-m-d H:i:s')); $job->save(); //do we need to slice this job? if (!$job->getFile()->isHydrated() && $can_slice) { //pull in our config and make sure it's legit. $config = $this->getSliceConfig(); if (!$config->isHydrated()) { $job->setStatus('available'); $job->set('bot_id', 0); $job->set('taken_time', 0); $job->save(); throw new Exception("This bot does not have a slice engine + configuration set."); } //is there an existing slice job w/ this exact file and config? $sj = SliceJob::byConfigAndSource($config->id, $job->get('source_file_id')); if ($sj->isHydrated()) { //update our job status. $job->set('slice_job_id', $sj->id); $job->set('slice_complete_time', $job->get('taken_time')); $job->set('file_id', $sj->get('output_id')); $job->save(); } else { //nope, create our slice job for processing. $sj->set('user_id', User::$me->id); $sj->set('job_id', $job->id); $sj->set('input_id', $job->get('source_file_id')); $sj->set('slice_config_id', $config->id); $sj->set('slice_config_snapshot', $config->getSnapshot()); $sj->set('add_date', date("Y-m-d H:i:s")); $sj->setStatus('available'); $sj->save(); //update our job status. $job->setStatus('slicing'); $job->set('slice_job_id', $sj->id); $job->save(); } } $log = new JobClockEntry(); $log->set('job_id', $job->id); $log->set('user_id', User::$me->id); $log->set('bot_id', $this->id); $log->set('queue_id', $job->get('queue_id')); $log->set('start_date', date("Y-m-d H:i:s")); $log->setStatus('working'); $log->save(); $this->set('job_id', $job->id); $this->setStatus(BotState::Working); $this->set('last_seen', date("Y-m-d H:i:s")); $this->save(); return $job; }
public function getConvertcsv() { if (($handle = fopen(storage_path() . '/jobs.csv', 'r')) === false) { die('Error opening file'); } /* foreach (\QuestionTemplate::get() as $q) $q->forceDelete(); foreach (\JobConfiguration::get() as $q) $q->forceDelete(); foreach (\Job::get() as $q) $q->forceDelete(); */ Activity::truncate(); $activity = new Activity(); $activity->label = "Imported jobs from CSV file."; //$activity->used = $job->_id; $activity->softwareAgent_id = 'importer'; $activity->save(); $headers = fgetcsv($handle, 1024, ','); $count = 0; $complete = array(); while ($row = fgetcsv($handle, 1024, ',')) { $c = array_combine($headers, $row); $c['platform'] = array($c['platform']); $j = new JobConfiguration(); //$j->_id = "entity/text/medical/jobconf/$count"; $j->type = isset($row['type']) ? $row['type'] : 'todo'; $j->content = $c; $j->hash = md5(serialize($j->content)); $j->activity_id = $activity->_id; $j->user_id = 'CrowdWatson'; $j->save(); $job = new Job(); $job->jobConf_id = $j->_id; $job->activity_id = $activity->_id; $job->batch_id = "entity/text/medical/batch/{$count}"; $job->type = isset($row['type']) ? $row['type'] : 'todo'; $job->user_id = 'CrowdWatson'; $job->status = 'finished'; $job->save(); $count++; } //new MongoDate(strtotime( fclose($handle); echo json_encode($complete, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); }