本文整理汇总了PHP中app\Project::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Project::firstOrNew方法的具体用法?PHP Project::firstOrNew怎么用?PHP Project::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Project
的用法示例。
在下文中一共展示了Project::firstOrNew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUpdateAll
public function getUpdateAll()
{
// Fetch all projects in Egypt
$ch = curl_init();
$projectsUrl = "https://api.betterplace.org/en/api_v4/projects.json?around=Egypt&scope=location&per_page=100";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $projectsUrl);
$projects = json_decode(curl_exec($ch), true);
curl_close($ch);
foreach ($projects['data'] as $project) {
if ($project['country'] == 'Egypt') {
$projectData = array('external_id' => $project['id'], 'city' => $project['city'], 'country' => $project['country'], 'title' => $project['title'], 'description' => $project['description'], 'tax_deductible' => $project['tax_deductible'], 'donations_prohibited' => $project['donations_prohibited'], 'completed_at' => $project['completed_at'], 'open_amount_in_cents' => $project['open_amount_in_cents'], 'positive_opinions_count' => $project['positive_opinions_count'], 'negative_opinions_count' => $project['negative_opinions_count'], 'donor_count' => $project['donor_count'], 'progress_percentage' => $project['progress_percentage'], 'incomplete_need_count' => $project['incomplete_need_count'], 'completed_need_count' => $project['completed_need_count']);
// Insert new or update existing project
$newProject = Project::firstOrNew(array('external_id' => $project['id']));
$newProject->fill($projectData);
$newProject->save();
}
}
// Fetch all opinions for the given project
$mh = curl_multi_init();
$curl_arr = array();
$projects = Project::all();
$totalProjects = $projects->count();
for ($i = 0; $i < $totalProjects; $i++) {
$opinionsUrl = "https://api.betterplace.org/de/api_v4/projects/" . $projects[$i]['external_id'] . "/opinions.json?per_page=" . $projects[$i]['donor_count'];
// Executing requests in parallel
$curl_arr[$i] = curl_init($opinionsUrl);
curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($mh, $curl_arr[$i]);
}
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
for ($i = 0; $i < $totalProjects; $i++) {
$opinions = json_decode(curl_multi_getcontent($curl_arr[$i]), true);
foreach ($opinions['data'] as $opinion) {
// Excluding opinions witothout a donation
if (isset($opinion['donated_amount_in_cents'])) {
$opinionData = array('external_id' => $opinion['id'], 'project_id' => $project['id'], 'donated_amount_in_cents' => $opinion['donated_amount_in_cents'], 'score' => $opinion['score'], 'author' => $opinion['author']['name'], 'message' => $opinion['message'], 'donated_at' => $opinion['created_at']);
// Insert new or update existing opinion
$newOpinion = Opinion::firstOrNew(array('external_id' => $opinion['id']));
$newOpinion->fill($opinionData);
$newOpinion->save();
}
}
}
curl_multi_close($mh);
return view('projects.update');
}
示例2: createProjectStub
/**
* @param $input
* @return mixed
*/
private function createProjectStub($input, $org_id)
{
$project = Project::firstOrNew(['name' => $input['name'], 'org_id' => $org_id]);
$project->name = $input['name'];
$project->desc = $input['desc'];
$project->type = $input['type'];
$project->validate = $input['validate'];
$project->submit = $input['submit'];
$project->sections = $input['sections'];
$project->reporting = $input['reporting'];
return $project;
}