class oApp const APP_TABLE_ID const APP_REPORT_TABLE_ID function __con

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class oApp{
const APP_TABLE_ID=4;
const APP_REPORT_TABLE_ID=3;
function __construct()
{
///constructor
}
public function WriteInfo()
{
//write info
$arJsonData=$_POST["data"];
$arData=self::object2array(json_decode($arJsonData));
$entity=self::IncludeHL(self::APP_REPORT_TABLE_ID);
$error=false;
foreach ($arData as $key=>$data)
{
foreach ($data["applications"] as $application)
{
$arE=array(
"UF_LOGIN"=>$data["login"],
"UF_DATE"=>self::ConvertDate($data["date"]),
"UF_HOUR"=>$data["hour"],
"UF_APP"=>self::GetAppId($application["name"]),
"UF_DURATION"=>$application["time"]
);
$entity_data_class = $entity->getDataClass();
if($id=$entity_data_class::add($arE))
{
}else{
$error=true;
}
}
}
$result=array(
"status"=>(!$error)?("success"):("error"),
"statusCode"=>(!$error)?("200"):("404")
);
$GLOBALS["APPLICATION"]->RestartBuffer();
echo json_encode($result);
die();
}
function GetAppId($code)
{
$entity=self::IncludeHL(self::APP_TABLE_ID);
$main_query = new Bitrix\Main\Entity\Query($entity);
$main_query->setSelect(array('*'));
$main_query->setFilter(array("UF_CODE"=>$code));
$main_query->setOrder(array('ID' =>'DESC'));
$result = $main_query->exec();
$result = new CDBResult($result);
if($app=$result->Fetch())
{
return $app["ID"];
}else{
$arE=array(
"UF_CODE"=>$code,
"UF_NAME"=>"",
);
$entity_data_class = $entity->getDataClass();
$id=$entity_data_class::add($arE);
return $id->GetID();
}
}
function IncludeHL($hl)
{
// hlblock info
CModule::IncludeModule("highloadblock");
$hlblock_id = $hl;
$hlblock = Bitrix\Highloadblock\HighloadBlockTable::getById($hlblock_id)->fetch();
$entity = Bitrix\Highloadblock\HighloadBlockTable::compileEntity($hlblock);
return $entity;
}
public function object2array($object)
{
$result=array();
foreach ($object as $k=>$item)
{
if(is_object($item))
{
$result[$k]=get_object_vars($item);
if($result[$k]["applications"])
{
$result[$k]["applications"]=self::object2array($result[$k]["applications"]);
}
}
}
return $result;
}
public function ConvertDate($date)
{
return implode('.', array_reverse(explode('.', $date)));
}
public function ClearData($id)
{
$entity=oApp::IncludeHL($id);
$main_query = new Bitrix\Main\Entity\Query($entity);
$main_query->setSelect(array('*'));
$main_query->setFilter(array());
$main_query->setOrder(array('ID' =>'DESC'));
$result = $main_query->exec();
$result = new CDBResult($result);
while($app=$result->Fetch())
{
$entity_data_class = $entity->getDataClass();
$id=$entity_data_class::delete($app["ID"]);
}
}
}//end oApp class