Duffer Derek
<?php
namespace App\Repository\Phases;
use App\Repository\Copy\AppCopyRepo;
use App\Repository\General\DB;
use App\Repository\General\Log;
use App\Repository\Utils\CustomPodioAPI;
class PhasesCopyRepo
{
private $customPodioAPI;
/**
* AppRepo constructor.
*/
public function __construct()
{
$this->customPodioAPI = new CustomPodioAPI();
}
public function saveAppDetails($identifier, $app)
{
$appCopy = new AppCopyRepo();
//save app config
$podioApp = $this->customPodioAPI->podioGet("/app/" . $app['app_id']);
if ($podioApp) {
$sql = "INSERT IGNORE INTO apps (identifier,src_space_id,src_app_id,src_name,src_config,
copy_next_step,create_next_step) VALUES
(:identifier,:src_space_id,:src_app_id,:src_name,:src_config,:copy_next_step,:create_next_step)";
$STH = DB::prepare($sql);
$data = array("identifier" => $identifier,
"copy_next_step" => "save_app_details", "create_next_step" => "clone_or_create_app");
// foreach ($podioApp as $app) {
$data['src_space_id'] = 7855409;
$data["src_app_id"] = $podioApp['app_id'];
$data["src_name"] = $podioApp['config']['name'];
$appData = $this->customPodioAPI->podioGet("/app/" . $podioApp['app_id'] . "/");
$data["src_config"] = json_encode($appData['config']);
$STH->execute($data);
// }
$appCopy->saveAppViews($app['src_app_id']);
$srcFields = $podioApp['fields'];
$this->saveAppFields($identifier, $app, $srcFields);
$srcFields = json_encode($srcFields);
$voting = $appCopy->getVoting($app);
$flows = $appCopy->getAppFlows($app);
$widgets = $appCopy->getWidget($app);
$sql = "UPDATE apps SET voting=:voting ,src_fields =:src_fields,src_app_type=:src_app_type,src_app_url=:src_app_url,
copy_next_step=:copy_next_step,copy_completed_steps=:copy_completed_steps,src_app_url_label=:src_app_url_label,
flows=:flows,widgets=:widgets
WHERE id=:id";
$data = array("copy_next_step" => "save_items_in_app", "id" => $app['id'], "src_fields" => $srcFields, 'voting' => $voting,
'src_app_url' => $podioApp['url'], "src_app_type" => $podioApp['config']['type'],
"copy_completed_steps" => "save_app", 'src_app_url_label' => $podioApp['url_label'], 'flows' => $flows, 'widgets' => $widgets);
$STH = DB::prepare($sql);
$STH->execute($data);
$app['copy_next_step'] = "save_items_in_app";
$app['copy_completed_steps'] = "save_app";
$STH = NULL;
}
}
private function saveAppFields($identifier, $app, $srcFields)
{
try {
if ($srcFields && is_array($srcFields) && count($srcFields) > 0) {
$sql = "INSERT INTO `app_fields` ( `identifier`, `src_app_id`, `src_field_id`,`status`, `field_type`,
`src_field_config`, `src_field_external_id`, `label`,`src_delta`) VALUES (:identifier, :src_app_id,
:src_field_id,:status, :field_type,:src_field_config, :src_field_external_id, :label,:src_delta) ON DUPLICATE KEY
UPDATE src_delta=:src_delta ";
$STH = DB::prepare($sql);
foreach ($srcFields as $field) {
$config = $field['config'];
$src_delta = $config['delta'];
$config = json_encode($config);
$data = array("identifier" => $identifier, "src_app_id" => $app['src_app_id'], "src_field_id" => $field['field_id'],
'status' => $field['status'], 'field_type' => $field['type'], 'src_field_config' => $config,
'src_field_external_id' => $field['external_id'], 'label' => $field['label'], 'src_delta' => $src_delta);
$STH->execute($data);
}
$STH = NULL;
}
} catch (\Exception $e) {
Log::logError($e . "", $srcFields, "saveAppFields");
}
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists