bool b = connection.isConnected() == true ? true : false;
My first internship presented me with this.
public boolean logout(String token)
{
LogedUser user = logedUsers.remove(token);
return (user != null) ? true : false;
}
someslice := []*string{
&"fuck",
&"pointers",
}
for i, value := range someSlice {
someSlice[i] = &*value
}
$gallery = \common\models\UtVideogallery::find()->select(['ut_videogallery.VideogalleryID',
'ut_videogallery.Name_rus','ut_videogallery.TournamentID','ut_videogallery.MatchID', 'Slug',
'ut_videogallery.Date','COUNT(ut_video_to_gallery.VideoToGalleryID) count','ut_matches_videos.Data',
'm1.Data DataP'])
->leftJoin('ut_video_to_gallery','ut_video_to_gallery.VideogalleryID=ut_videogallery.VideogalleryID')
->leftJoin('ut_matches_videos','ut_matches_videos.VideoID=ut_video_to_gallery.VideoID')
->leftJoin('ut_matches_videos m1','m1.VideoID=ut_videogallery.PreviewID')
->where(['ut_videogallery.Active'=>1])
//->andWhere(['TournamentID'=>$list['selected']])
->groupBy('ut_videogallery.VideogalleryID')
->orderBy('ut_videogallery.Date DESC')
->limit(self::$countPerPage)
->asArray()->all();
foreach ($gallery as $key => $value) {
if($value['count']==0) unset($gallery[$key]);
}
foreach($gallery as $k=>$v){
if(isset($v['Data']))
$v['Data'] = str_replace('http:','https:',$v['Data']);
if(isset($v['DataP']))
$v['DataP'] = str_replace('http:','https:',$v['DataP']);
$gallery[$k]=$v;
}
$galleryCount = \common\models\UtVideogallery::find()->select(['ut_videogallery.VideogalleryID',
'ut_videogallery.Name_rus','ut_videogallery.TournamentID','ut_videogallery.MatchID',
'ut_videogallery.Date','COUNT(ut_video_to_gallery.VideoToGalleryID) count','ut_matches_videos.Data'])
->leftJoin('ut_video_to_gallery','ut_video_to_gallery.VideogalleryID=ut_videogallery.VideogalleryID')
->leftJoin('ut_matches_videos','ut_matches_videos.VideoID=ut_video_to_gallery.VideoID')
->leftJoin('ut_matches_videos m1','m1.VideoID=ut_videogallery.PreviewID')
->where(['ut_videogallery.Active'=>1])
//->andWhere(['TournamentID'=>$list['selected']])
->groupBy('ut_videogallery.VideogalleryID')
->orderBy('ut_videogallery.Date DESC')
->asArray()->all();
foreach ($galleryCount as $key => $value) {
if($value['count']==0) unset($galleryCount[$key]);
}
$pagination = new \yii\data\Pagination(
[
'totalCount' => count($galleryCount),
'pageSize' => self::$countPerPage,
]);
Picasso of PHP
// Is this valid?
function validateStockInItems() {
if (stockInItemsToUpdate.length === 0)
return true;
return true;
}
Found in a legacy code base for a stock management system. I will be rewriting said system soon.
zipped_file.extractall(f'{file_path}')
zipped_file.close()
for x,x1 in enumerate(hack):
if hack[x] in letters:
exception +=1
ffs why
o.isInsured = function ()
{ return !!this.insured; }
Why don't be like normal people and use bool() cast?
@RequestMapping(value = "user/getOnlineApplicationsList", produces = "XML/Text; charset=utf-8", method = RequestMethod.POST)
public @ResponseBody String getOnlineApplicationsList(HttpSession session, HttpServletRequest request,
@RequestParam("status") int status, @RequestParam("fullname") String fullname,
@RequestParam("privateNumber") String privateNumber, @RequestParam("phoneNumber") String phoneNumber,
@RequestParam("applicationIdFrom") String applicationIdFrom,
@RequestParam("applicationIdTo") String applicationIdTo,
// @RequestParam("dateFrom") String timeFrom,
// @RequestParam("dateTo") String timeTo,
@RequestParam("order") int order, @RequestParam("companyId") int companyId) {
try {
TimeFunctions tf = new TimeFunctions();
StringBuilder ret = new StringBuilder();
List<OnlineApplication> onlineAppList = new ArrayList<OnlineApplication>();
List<OnlineApplicationForConsumerLoan> onlineAppListCL = new ArrayList<OnlineApplicationForConsumerLoan>();
if (companyId == 3) {
onlineAppList = onlineAppService.getOnlineApps(fullname, privateNumber,
tf.dateStrToMilliseconds("11-11-1111"), tf.dateStrToMilliseconds("11-11-9999"), 0, 250, order,
status, phoneNumber, applicationIdFrom, applicationIdTo);
}
else if (companyId == 2) {
onlineAppListCL = onlineAppService.getConsumerOnlineApps(fullname, privateNumber,
tf.dateStrToMilliseconds("11-11-1111"), tf.dateStrToMilliseconds("11-11-9999"), 0, 250, order,
status, phoneNumber, applicationIdFrom, applicationIdTo);
}
else {
onlineAppList = onlineAppService.getOnlineApps(fullname, privateNumber,
tf.dateStrToMilliseconds("11-11-1111"), tf.dateStrToMilliseconds("11-11-9999"), 0, 250, order,
status, phoneNumber, applicationIdFrom, applicationIdTo);
onlineAppListCL = onlineAppService.getConsumerOnlineApps(fullname, privateNumber,
tf.dateStrToMilliseconds("11-11-1111"), tf.dateStrToMilliseconds("11-11-9999"), 0, 250, order,
status, phoneNumber, applicationIdFrom, applicationIdTo);
}
for (OnlineApplication onlineApp : onlineAppList) {
if (onlineApp.getStatus() == 0) {
ret.append("<br>"
+ "<table style=\"width:100%; height: 180px; border: 1px solid black; text-align:center; border-collapse: collapse; spacing: 5px;\">"
+ "<tr style=\"background-color:#85C1E9; height: 20px; font-weight: bold;\">"
+ "<td>ID</td>" + "<td>თანხა</td>" + "<td>პერიოდი</td>" + "<td>სახელი გვარი</td>"
+ "<td>დაბ.თარიღი</td>" + "<td>პირადი ნომ.</td>" + "<td>მობილური</td>"
+ "<td>სამუშაო სფერო</td>" + "<td>კომპანია</td>" + "<td>პოზიცია</td>" + "<td>ხელფასი</td>"
+ "<td>სტატუსი</td>" + "</tr>" + "<tr>" + "<td>" + onlineApp.getOnlineAppId() + "</td>"
+ "<td>" + Math.round(onlineApp.getAmount().doubleValue() * 100.0) / 100.0 + "</td>"
+ "<td>" + onlineApp.getPeriod() + "</td>" + "<td>" + onlineApp.getFullname() + "</td>"
+ "<td>" + onlineApp.getBirthdate() + "</td>" + "<td>" + onlineApp.getPersonalNumber()
+ "</td>" + "<td>" + onlineApp.getMobilephone() + "</td>" + "<td>"
+ onlineApp.getWorkField() + "</td>" + "<td>" + onlineApp.getCompanyName() + "</td>"
+ "<td>" + onlineApp.getPosition() + "</td>" + "<td>" + onlineApp.getSalary() + "</td>"
+ "<td>" + getNameForStatus(onlineApp.getStatus()) + "</td>" + "</tr>"
+ "<tr style=\"background-color:#85C1E9; height: 20px; font-weight: bold;\">"
+ "<td>მუშ.ხან.</td>" + "<td>დამ.შემოსავალი</td>" + "<td>თვ.გადასახდელი</td>"
+ "<td>ოჯახ.მდგომ.</td>" + "<td>შვილები</td>" + "<td>დასაქ.ოჯახ.წევრები</td>"
+ "<td>საერთო შემოსავალი</td>" + "<td>თარიღი</td>" + "<td>ინკასო</td>" +
"<td>დადასტურება</td>"+ "<td>უარყოფა</td>" + "<td>წაშლა</td>" + "</tr>" + "<tr>" + "<td>"
+ onlineApp.getWorkTime() + "</td>" + "<td>" + onlineApp.getAdditionalIncome() + "</td>"
+ "<td>" + onlineApp.getLoanFreqAmount() + "</td>" + "<td>" + onlineApp.getMaritalStatus()
+ "</td>" + "<td>" + onlineApp.getChildren() + "</td>" + "<td>"
+ onlineApp.getWorkingRelatives() + "</td>" + "<td>" + onlineApp.getTotalIncome() + "</td>"
+ "<td>" + tf.millisecondsToDateStr(onlineApp.getAdditionTime()) + "</td>"
+ "<td>"+(onlineApp.isIncaso() ? "ინკასო":"არ ადევს")+"</td>" + "<td bgcolor=\"lightgreen\" onclick=\"approveApplication(" + onlineApp.getOnlineAppId()
+ "," + onlineApp.getCompany() + ")\"><img height=\"20px\" width=\"20px\" src=\""
+ request.getContextPath() + "/resources/images/accept.png\"></td>"
+ "<td bgcolor=\"LightCoral\" onclick=\"rejectApplication(" + onlineApp.getOnlineAppId()
+ "," + onlineApp.getCompany() + ")\"><img height=\"20px\" width=\"20px\" src=\""
+ request.getContextPath() + "/resources/images/reject.png\"></td>"
+ "<td bgcolor=\"silver\" onclick=\"deleteApplication(" + onlineApp.getOnlineAppId() + ","
+ onlineApp.getCompany() + ")\"><img height=\"20px\" width=\"20px\" src=\""
+ request.getContextPath() + "/resources/images/delete.png\"></td>" + "</tr>" + ""
+ "<tr><td colspan=\"3\">" + onlineApp.getLoanPurpose() + "</td><td colspan=\"5\">" + onlineApp.getBranch() + "</td></tr></table>" + "<br>");
} else if (onlineApp.getStatus() == 1) {
ret.append("<br>"
+ "<table style=\"width:100%; height: 180px; border: 1px solid black; text-align:center; border-collapse: collapse; spacing: 5px;\">"
+ "<tr style=\"background-color:#85C1E9; height: 20px; font-weight: bold;\">"
+ "<td>ID</td>" + "<td>თანხა</td>" + "<td>პერიოდი</td>" + "<td>სახელი გვარი</td>"
+ "<td>დაბ.თარიღი</td>" + "<td>პირადი ნომ.</td>" + "<td>მობილური</td>"
+ "<td>სამუშაო სფერო</td>" + "<td>კომპანია</td>" + "<td>პოზიცია</td>" + "<td>ხელფასი</td>"
+ "<td>სტატუსი</td>" + "</tr>" + "<tr>" + "<td>" + onlineApp.getOnlineAppId() + "</td>"
+ "<td>" + Math.round(onlineApp.getAmount().doubleValue() * 100.0) / 100.0 + "</td>"
+ "<td>" + onlineApp.getPeriod() + "</td>" + "<td>" + onlineApp.getFullname() + "</td>"
+ "<td>" + onlineApp.getBirthdate() + "</td>" + "<td>" + onlineApp.getPersonalNumber()
+ "</td>" + "<td>" + onlineApp.getMobilephone() + "</td>" + "<td>"
+ onlineApp.getWorkField() + "</td>" + "<td>" + onlineApp.getCompanyName() + "</td>"
+ "<td>" + onlineApp.getPosition() + "</td>" + "<td>" + onlineApp.getSalary() + "</td>"
+ "<td>" + getNameForStatus(onlineApp.getStatus()) + "</td>" + "</tr>"
+ "<tr style=\"background-color:#85C1E9; height: 20px; font-weight: bold;\">"
+ "<td>მუშ.ხან.</td>" + "<td>დამ.შემოსავალი</td>" + "<td>თვ.გადასახდელი</td>"
+ "<td>ოჯახ.მდგომ.</td>" + "<td>შვილები</td>" + "<td>დასაქ.ოჯახ.წევრები</td>"
+ "<td>საერთო შემოსავალი</td>" + "<td>თარიღი</td>" + "<td>ინკასო</td>"
+ "<td align=\"center\">კომენტარები</td><td align=\"center\">აპლიკაციის დამატება</td><td align=\"center\">აპლიკაციის უარყოფა</td>"
+ "</tr>" + "<tr>" + "<td>" + onlineApp.getWorkTime() + "</td>" + "<td>"
+ onlineApp.getAdditionalIncome() + "</td>" + "<td>" + onlineApp.getLoanFreqAmount()
+ "</td>" + "<td>" + onlineApp.getMaritalStatus() + "</td>" + "<td>"
+ onlineApp.getChildren() + "</td>" + "<td>" + onlineApp.getWorkingRelatives() + "</td>"
+ "<td>" + onlineApp.getTotalIncome() + "</td>" + "<td>"
+ tf.millisecondsToDateStr(onlineApp.getAdditionTime()) +
"<td>"+(onlineApp.isIncaso() ? "ინკასო":"არ ადევს")+"</td>"
+ "</td><td onclick=\"triggerComments(" + onlineApp.getOnlineAppId() + ","
+ onlineApp.getCompany() + ")\"><img height=\"20px\" width=\"20px\" src=\""
+ request.getContextPath() + "/resources/images/comment.png\"></td>"
+ "<td bgcolor=\"lightgreen\" onclick=\"acceptApplication(" + onlineApp.getOnlineAppId()
+ "," + onlineApp.getCompany() + ")\"><img height=\"20px\" width=\"20px\" src=\""
+ request.getContextPath() + "/resources/images/accept.png\"></td>"
+ "<td bgcolor=\"LightCoral\" onclick=\"rejectApplication(" + onlineApp.getOnlineAppId()
+ "," + onlineApp.getCompany() + ")\"><img height=\"20px\" width=\"20px\" src=\""
+ request.getContextPath() + "/resources/images/reject.png\"></td>" + "</tr>"
+ "<tr><td colspan=\"3\">" + onlineApp.getLoanPurpose() + "</td><td colspan=\"5\">" + onlineApp.getBranch() + "</td></tr></table>" + "</table>"
+ "<br>");
} else {
ret.append("<br>"
+ "<table style=\"width:100%; height: 180px; border: 1px solid black; text-align:center; border-collapse: collapse; spacing: 5px;\">"
+ "<tr style=\"background-color:#85C1E9; height: 20px; font-weight: bold;\">"
+ "<td>ID</td>" + "<td>თანხა</td>" + "<td>პერიოდი</td>" + "<td>სახელი გვარი</td>"
+ "<td>დაბ.თარიღი</td>" + "<td>პირადი ნომ.</td>" + "<td>მობილური</td>"
+ "<td>სამუშაო სფერო</td>" + "<td>კომპანია</td>" + "<td>პოზიცია</td>" + "<td>ხელფასი</td>"
+ "<td>სტატუსი</td>" + "</tr>" + "<tr>" + "<td>" + onlineApp.getOnlineAppId() + "</td>"
+ "<td>" + Math.round(onlineApp.getAmount().doubleValue() * 100.0) / 100.0 + "</td>"
+ "<td>" + onlineApp.getPeriod() + "</td>" + "<td>" + onlineApp.getFullname() + "</td>"
+ "<td>" + onlineApp.getBirthdate() + "</td>" + "<td>" + onlineApp.getPersonalNumber()
+ "</td>" + "<td>" + onlineApp.getMobilephone() + "</td>" + "<td>"
+ onlineApp.getWorkField() + "</td>" + "<td>" + onlineApp.getCompanyName() + "</td>"
+ "<td>" + onlineApp.getPosition() + "</td>" + "<td>" + onlineApp.getSalary() + "</td>"
+ "<td>" + getNameForStatus(onlineApp.getStatus()) + "</td>" + "</tr>"
+ "<tr style=\"background-color:#85C1E9; height: 20px; font-weight: bold;\">"
+ "<td>მუშ.ხან.</td>" + "<td>დამ.შემოსავალი</td>" + "<td>თვ.გადასახდელი</td>"
+ "<td>ოჯახ.მდგომ.</td>" + "<td>შვილები</td>" + "<td>დასაქ.ოჯახ.წევრები</td>"
+ "<td>საერთო შემოსავალი</td>" + "<td>თარიღი</td>" + "<td>ინკასო</td>"
+ "<td colspan=\"3\" align=\"center\">კომენტარები</td>" + "</tr>" + "<tr>" + "<td>"
+ onlineApp.getWorkTime() + "</td>" + "<td>" + onlineApp.getAdditionalIncome() + "</td>"
+ "<td>" + onlineApp.getLoanFreqAmount() + "</td>" + "<td>" + onlineApp.getMaritalStatus()
+ "</td>" + "<td>" + onlineApp.getChildren() + "</td>" + "<td>"
+ onlineApp.getWorkingRelatives() + "</td>" + "<td>" + onlineApp.getTotalIncome() + "</td>"
+ "<td>" + tf.millisecondsToDateStr(onlineApp.getAdditionTime()) + "</td>" +
"<td>"+(onlineApp.isIncaso() ? "ინკასო":"არ ადევს")+"</td>"
+ "<td colspan=\"3\" onclick=\"triggerComments(" + onlineApp.getOnlineAppId() + ","
+ onlineApp.getCompany() + ")\"><img height=\"20px\" width=\"20px\" src=\""
+ request.getContextPath() + "/resources/images/comment.png\"></td>"
+ ((onlineApp.getStatus() != 2) ? "<td colspan=\"3\" onclick=\"changeStatus("
+ onlineApp.getOnlineAppId() + "," + onlineApp.getCompany() + "," + 0
+ ")\"><img height=\"20px\" width=\"20px\" src=\"" + request.getContextPath()
+ "/resources/images/resume.png\" title=\"აპლიკაციაში დაბრუნება\"></td>" : "")
+ "</tr>" + "<tr><td colspan=\"3\">" + onlineApp.getLoanPurpose() + "</td><td colspan=\"5\">" + onlineApp.getBranch() + "</td></tr></table>"
+ "</table>" + "<br>");
}
}
for (OnlineApplicationForConsumerLoan onlineApp : onlineAppListCL) {
// TODO: change below
int consCompId = 2;
if (onlineApp.getStatus() == 0) {
ret.append("<br>"
+ "<table style=\"width:100%; height: 180px; border: 1px solid black; text-align:center; border-collapse: collapse; spacing: 5px;\">"
+ "<tr style=\"background-color:Coral; height: 20px; font-weight: bold;\">" + "<td>ID</td>"
+ "<td>თანხა</td>" + "<td>პერიოდი</td>" + "<td>სახელი გვარი</td>" + "<td>დაბ.თარიღი</td>"
+ "<td>პირადი ნომ.</td>" + "<td>მობილური</td>" + "<td>სამუშაო სფერო</td>"
+ "<td>კომპანია</td>" + "<td>პოზიცია</td>" + "<td>ხელფასი</td>" + "<td>სტატუსი</td>"
+ "</tr>" + "<tr>" + "<td>" + onlineApp.getId() + "</td>" + "<td>"
+ Math.round(onlineApp.getLoanAmount() * 100.0) / 100.0 + "</td>" + "<td>"
+ onlineApp.getLoanPeriod() + "</td>" + "<td>" + onlineApp.getName() + "</td>" + "<td>"
+ onlineApp.getBirthDate() + "</td>" + "<td>" + onlineApp.getPrivateNumber() + "</td>"
+ "<td>" + onlineApp.getMobileNumber() + "</td>" + "<td>" + onlineApp.getWorkSphere()
+ "</td>" + "<td>" + onlineApp.getCompanyName() + "</td>" + "<td>"
+ onlineApp.getWorkPosition() + "</td>" + "<td>" + onlineApp.getSalary() + "</td>" + "<td>"
+ getNameForStatus(onlineApp.getStatus()) + "</td>" + "</tr>"
+ "<tr style=\"background-color:Coral; height: 20px; font-weight: bold;\">"
+ "<td>მუშ.ხან.</td>" + "<td>დამ.შემოსავალი</td>" + "<td>თვ.გადასახდელი</td>"
+ "<td>ოჯახ.მდგომ.</td>" + "<td>შვილები</td>" + "<td>დასაქ.ოჯახ.წევრები</td>"
+ "<td>საერთო შემოსავალი</td>" + "<td>თარიღი</td>" + "<td>ინკასო</td>" + "<td>დადასტურება</td>"
+ "<td>უარყოფა</td>" + "<td>წაშლა</td>" + "</tr>" + "<tr>" + "<td>"
+ onlineApp.getWorkPeriod() + "</td>" + "<td>" + onlineApp.getOtherIncome() + "</td>"
+ "<td>" + onlineApp.getAmountToPayOnOtherLoans() + "</td>" + "<td>"
+ onlineApp.getMaritalStatus() + "</td>" + "<td>" + onlineApp.getNumberOfChildren()
+ "</td>" + "<td>" + onlineApp.getEmployedFamilyMembers() + "</td>" + "<td>"
+ onlineApp.getTotalFamilyIncome() + "</td>" + "<td>"
+ tf.millisecondsToDateStr(onlineApp.getAdditionTime()) + "</td>" +
"<td>"+(onlineApp.isIncaso() ? "ინკასო":"არ ადევს")+"</td>"
+ "<td bgcolor=\"lightgreen\" onclick=\"approveApplication(" + onlineApp.getId() + ","
+ consCompId + ")\"><img height=\"20px\" width=\"20px\" src=\"" + request.getContextPath()
+ "/resources/images/accept.png\"></td>"
+ "<td bgcolor=\"LightCoral\" onclick=\"rejectApplication(" + onlineApp.getId() + ","
+ consCompId + ")\"><img height=\"20px\" width=\"20px\" src=\"" + request.getContextPath()
+ "/resources/images/reject.png\"></td>"
+ "<td bgcolor=\"silver\" onclick=\"deleteApplication(" + onlineApp.getId() + ","
+ consCompId + ")\"><img height=\"20px\" width=\"20px\" src=\"" + request.getContextPath()
+ "/resources/images/delete.png\"></td>" + "</tr>"
+ "<tr><td colspan=\"3\">"+onlineApp.getLoanPurpose()+"</td><td colspan=\"5\" align=\"left\"> " + onlineApp.getBranchOfficeName() + "</td></tr>"
+ "</table>" + "<br>");
} else if (onlineApp.getStatus() == 1) {
ret.append("<br>"
+ "<table style=\"width:100%; height: 180px; border: 1px solid black; text-align:center; border-collapse: collapse; spacing: 5px;\">"
+ "<tr style=\"background-color:Coral; height: 20px; font-weight: bold;\">" + "<td>ID</td>"
+ "<td>თანხა</td>" + "<td>პერიოდი</td>" + "<td>სახელი გვარი</td>" + "<td>დაბ.თარიღი</td>"
+ "<td>პირადი ნომ.</td>" + "<td>მობილური</td>" + "<td>სამუშაო სფერო</td>"
+ "<td>კომპანია</td>" + "<td>პოზიცია</td>" + "<td>ხელფასი</td>" + "<td>სტატუსი</td>"
+ "</tr>" + "<tr>" + "<td>" + onlineApp.getId() + "</td>" + "<td>"
+ Math.round(onlineApp.getLoanAmount() * 100.0) / 100.0 + "</td>" + "<td>"
+ onlineApp.getLoanPeriod() + "</td>" + "<td>" + onlineApp.getName() + "</td>" + "<td>"
+ onlineApp.getBirthDate() + "</td>" + "<td>" + onlineApp.getPrivateNumber() + "</td>"
+ "<td>" + onlineApp.getMobileNumber() + "</td>" + "<td>" + onlineApp.getWorkSphere()
+ "</td>" + "<td>" + onlineApp.getCompanyName() + "</td>" + "<td>"
+ onlineApp.getWorkPosition() + "</td>" + "<td>" + onlineApp.getSalary() + "</td>" + "<td>"
+ getNameForStatus(onlineApp.getStatus()) + "</td>" + "</tr>"
+ "<tr style=\"background-color:Coral; height: 20px; font-weight: bold;\">"
+ "<td>მუშ.ხან.</td>" + "<td>დამ.შემოსავალი</td>" + "<td>თვ.გადასახდელი</td>"
+ "<td>ოჯახ.მდგომ.</td>" + "<td>შვილები</td>" + "<td>დასაქ.ოჯახ.წევრები</td>"
+ "<td>საერთო შემოსავალი</td>" + "<td>თარიღი</td>" + "<td>ინკასო</td>"
+ "<td align=\"center\">კომენტარები</td><td align=\"center\">აპლიკაციის დამატება</td><td align=\"center\">აპლიკაციის უარყოფა</td>"
+ "</tr>" + "<tr>" + "<td>" + onlineApp.getWorkPeriod() + "</td>" + "<td>"
+ onlineApp.getOtherIncome() + "</td>" + "<td>" + onlineApp.getAmountToPayOnOtherLoans()
+ "</td>" + "<td>" + onlineApp.getMaritalStatus() + "</td>" + "<td>"
+ onlineApp.getNumberOfChildren() + "</td>" + "<td>" + onlineApp.getEmployedFamilyMembers()
+ "</td>" + "<td>" + onlineApp.getTotalFamilyIncome() + "</td>" +
"<td>"+(onlineApp.isIncaso() ? "ინკასო":"არ ადევს")+"</td>" +
"<td>" + tf.millisecondsToDateStr(onlineApp.getAdditionTime()) + "</td>"
+ "<td onclick=\"triggerComments(" + onlineApp.getId() + "," + consCompId
+ ")\"><img height=\"20px\" width=\"20px\" src=\"" + request.getContextPath()
+ "/resources/images/comment.png\"></td>"
+ "<td bgcolor=\"lightgreen\" onclick=\"acceptApplication(" + onlineApp.getId() + ","
+ consCompId + ")\"><img height=\"20px\" width=\"20px\" src=\"" + request.getContextPath()
+ "/resources/images/accept.png\"></td>"
+ "<td bgcolor=\"LightCoral\" onclick=\"rejectApplication(" + onlineApp.getId() + ","
+ consCompId + ")\"><img height=\"20px\" width=\"20px\" src=\"" + request.getContextPath()
+ "/resources/images/reject.png\"></td>" + "</tr>"
+ "<tr><td colspan=\"3\">" + onlineApp.getLoanPurpose() + "</td><td colspan=\"5\" align=\"left\"> " + onlineApp.getBranchOfficeName() + "</td></tr>"
+ "</table>" + "<br>");
} else {
ret.append("<br>"
+ "<table style=\"width:100%; height: 180px; border: 1px solid black; text-align:center; border-collapse: collapse; spacing: 5px;\">"
+ "<tr style=\"background-color:Coral; height: 20px; font-weight: bold;\">" + "<td>ID</td>"
+ "<td>თანხა</td>" + "<td>პერიოდი</td>" + "<td>სახელი გვარი</td>" + "<td>დაბ.თარიღი</td>"
+ "<td>პირადი ნომ.</td>" + "<td>მობილური</td>" + "<td>სამუშაო სფერო</td>"
+ "<td>კომპანია</td>" + "<td>პოზიცია</td>" + "<td>ხელფასი</td>" + "<td>სტატუსი</td>"
+ "</tr>" + "<tr>" + "<td>" + onlineApp.getId() + "</td>" + "<td>"
+ Math.round(onlineApp.getLoanAmount() * 100.0) / 100.0 + "</td>" + "<td>"
+ onlineApp.getLoanPeriod() + "</td>" + "<td>" + onlineApp.getName() + "</td>" + "<td>"
+ onlineApp.getBirthDate() + "</td>" + "<td>" + onlineApp.getPrivateNumber() + "</td>"
+ "<td>" + onlineApp.getMobileNumber() + "</td>" + "<td>" + onlineApp.getWorkSphere()
+ "</td>" + "<td>" + onlineApp.getCompanyName() + "</td>" + "<td>"
+ onlineApp.getWorkPosition() + "</td>" + "<td>" + onlineApp.getSalary() + "</td>" + "<td>"
+ getNameForStatus(onlineApp.getStatus()) + "</td>" + "</tr>"
+ "<tr style=\"background-color:Coral; height: 20px; font-weight: bold;\">"
+ "<td>მუშ.ხან.</td>" + "<td>დამ.შემოსავალი</td>" + "<td>თვ.გადასახდელი</td>"
+ "<td>ოჯახ.მდგომ.</td>" + "<td>შვილები</td>" + "<td>დასაქ.ოჯახ.წევრები</td>"
+ "<td>საერთო შემოსავალი</td>" + "<td>თარიღი</td>" + "<td>ინკასო</td>"
+ "<td colspan=\"3\" align=\"center\">კომენტარები</td>" + "</tr>" + "<tr>" + "<td>"
+ onlineApp.getWorkPeriod() + "</td>" + "<td>" + onlineApp.getOtherIncome() + "</td>"
+ "<td>" + onlineApp.getAmountToPayOnOtherLoans() + "</td>" + "<td>"
+ onlineApp.getMaritalStatus() + "</td>" + "<td>" + onlineApp.getNumberOfChildren()
+ "</td>" + "<td>" + onlineApp.getEmployedFamilyMembers() + "</td>" + "<td>"
+ onlineApp.getTotalFamilyIncome() + "</td>" + "<td>"
+ "<td>"+(onlineApp.isIncaso() ? "ინკასო":"არ ადევს")+"</td>"
+ tf.millisecondsToDateStr(onlineApp.getAdditionTime()) + "</td>"
+ "<td colspan=\"3\" onclick=\"triggerComments(" + onlineApp.getId() + "," + consCompId
+ ")\"><img height=\"20px\" width=\"20px\" src=\"" + request.getContextPath()
+ "/resources/images/comment.png\"></td>"
+ ((onlineApp.getStatus() != 2)
? "<td colspan=\"4\" onclick=\"changeStatus(" + onlineApp.getId() + "," + consCompId
+ "," + 0 + ")\"><img height=\"20px\" width=\"20px\" src=\""
+ request.getContextPath()
+ "/resources/images/resume.png\" title=\"აპლიკაციაში დაბრუნება\"></td>"
: "")
+ "</tr>" + "<tr><td colspan=\"3\" align=\"left\"> " + onlineApp.getBranchOfficeName()
+ "</td></tr>" + "</table>" + "<br>");
}
}
return ret.toString();
} catch (Exception e) {
e.printStackTrace();
return "სესხის სტატუსის შეცვლისას დაფიქსირდა შეცდომა: " + e.toString();
}
}
//count to 10
#include <iostream>
#include <string>
int main()
{
int i = 0;
beginning:
if (i < 10) {
std::cout << ++i << std::endl;
goto beginning;
}
else goto end;
end:
return 0;
}
<?php
$now = time();
while ($now + 10 > time()) {
// Just chill...smoke a blunt
}
echo "Done.\n";
<?php
private function redirectFromOldSlug($pSlug, $pLanguageCode)
{
/*
$redirectArray[3][1] = 'beauty-young';
$redirectArray[3][2] = 'beauty-and-rejuvenation';
$redirectArray[3][3] = 'beauty-young';
$redirectArray[3][4] = 'beauty-young';
$redirectArray[2][1] = 'beauty-slim';
$redirectArray[2][2] = 'beauty-slim';
$redirectArray[2][3] = 'beauty-slim';
$redirectArray[2][4] = 'beauty-slim';
$redirectArray[18][1] = 'white-smile---2-dniowy-pakiet';
$redirectArray[18][2] = 'white-smile-2---day-package-hilton-hotel';
$redirectArray[18][3] = 'white-smile';
$redirectArray[18][4] = 'white-smile---2---day-package';
$redirectArray[17][1] = 'zdrowie-z-pieknem';
$redirectArray[17][2] = 'healthy-and-beauty-2---day-with-dentist-botox';
$redirectArray[17][3] = 'gesundheit-von-schonheit-2-tage';
$redirectArray[17][4] = 'vard-av-skonhet-2-dagar';
$redirectArray[19][1] = 'beauty-care';
$redirectArray[19][2] = 'beauty-care';
$redirectArray[19][3] = 'beauty-care';
$redirectArray[19][4] = 'beauty-care';
$redirectArray[21][1] = 'luksus-spa---hilton-w-gdasku';
$redirectArray[21][2] = 'spa-in-hilton-hotel';
$redirectArray[21][3] = 'spa-im-hilton---fur-sie';
$redirectArray[21][4] = 'spa-pa-hilton---for-dig';
$redirectArray[26][1] = 'zabiegi-implantacji-w-sea-tower';
$redirectArray[26][2] = 'implant-treatments-in-the-sea-tower';
$redirectArray[26][3] = 'implantate-in-der-sea-tower';
$redirectArray[26][4] = 'implantat-i-sea-tower';
$redirectArray[23][1] = 'mezoterapia-peeling-lipoliza-botox-hialuron';
$redirectArray[23][2] = 'beauty-med';
$redirectArray[23][3] = 'beauty-med';
$redirectArray[23][4] = 'beauty-med';
$redirectArray[34][1] = 'paski-brzuch-w-8-dni';
$redirectArray[34][2] = 'special-abdomen-programme';
$redirectArray[34][3] = 'das-speziell-gestaltete-und-vorbereitete-programm';
$redirectArray[34][4] = 'ett-speciellt-utformat-program';
$redirectArray[27][1] = 'zdrowy-kregosup';
$redirectArray[27][2] = 'healthy-spine-clinic';
$redirectArray[27][3] = 'wirbelsaule-ist-die-basis';
$redirectArray[27][4] = 'frisk-ryggrad';
$redirectArray[5][1] = 'pakiet-stomatologiczny-hotel-hilton';
$redirectArray[5][2] = 'healthy-smile-2-day-dental-package-hilton-hotel';
$redirectArray[5][3] = 'healthy-smile-2---day---dental-package-hotel-hilton';
$redirectArray[5][4] = 'healthy-smile-2---day---dental-package-hotel-hilton';
$redirectArray[16][1] = 'beauty-calming--anti-redness-2-dni';
$redirectArray[16][2] = 'beauty-calming--anti-redness-2-days';
$redirectArray[16][3] = 'beauty-calming--anti-redness';
$redirectArray[16][4] = 'beauty-calming--anti-redness';
$redirectArray[22][1] = 'stomatolog-na-twoja-kiesze';
$redirectArray[22][2] = 'dentist-for-every-pocket';
$redirectArray[22][3] = 'zahnarzt-fur-jedes-budget';
$redirectArray[22][4] = 'tandlakare-for-varje-budget';
$redirectArray[25][1] = 'przeglad-stomatologiczny-wybielanie-zebow';
$redirectArray[25][2] = 'teeth-whitening';
$redirectArray[25][3] = 'zahnaufhellung';
$redirectArray[25][4] = 'tandblekning';
$redirectArray[24][1] = 'implant-w-dwa-dni';
$redirectArray[24][2] = 'lifelong-guarantee-for-implants';
$redirectArray[24][3] = 'lebenslange-garantie-fur-implantate';
$redirectArray[24][4] = 'livslangt-garanti-for-implantat';
$redirectArray[39][1] = 'nogi-bez-zylakow';
$redirectArray[39][2] = 'varicose';
$redirectArray[39][3] = 'das-venefit-verfahren';
$redirectArray[39][4] = 'forfarande-venefit';
$redirectArray[36][1] = 'rehabilitacja-narzadu-ruch';
$redirectArray[36][2] = 'locomotor-system-14-day-stay-in-the-health-resort';
$redirectArray[36][3] = 'rehabilitation-14-tage-aufenthalt-im-sanatorium';
$redirectArray[36][4] = 'rorelseapparaten---rehabiliteringsemester';
$redirectArray[35][1] = 'zdrowe-serce-14-dniowy-program';
$redirectArray[35][2] = 'cardiology-14-day-stay-in-the-health-resort';
$redirectArray[35][3] = 'kardiologie---14-tage-aufenthalt-im-sanatorium';
$redirectArray[35][4] = 'kardiologi---rehabiliteringsemester';
$redirectArray[37][1] = 'stomatolog-w-szczecinie';
$redirectArray[37][2] = 'dentist-in-szczecin';
$redirectArray[37][3] = 'zahnarzt-in-szczecin';
$redirectArray[37][4] = 'tandlakare-i-szczecin';
$redirectArray[32][1] = 'sanatorium-z-rehabilitacja-narza';
$redirectArray[32][2] = 'physical-medicine-and-rehabilita';
$redirectArray[32][3] = 'rehabilitation-bewegungs';
$redirectArray[32][4] = 'rehabilitation-behandlingar';
*
*/
$redirectArray = array();
$redirectArray['beauty-young']['pl'] = 3;
$redirectArray['beauty-slim']['pl'] = 2;
$redirectArray['white-smile---2-dniowy-pakiet']['pl'] = 18;
$redirectArray['zdrowie-z-pieknem']['pl'] = 17;
$redirectArray['beauty-care']['pl'] = 19;
$redirectArray['luksus-spa---hilton-w-gdasku']['pl'] = 21;
$redirectArray['zabiegi-implantacji-w-sea-tower']['pl'] = 26;
$redirectArray['mezoterapia-peeling-lipoliza-botox-hialuron']['pl'] = 23;
$redirectArray['paski-brzuch-w-8-dni']['pl'] = 34;
$redirectArray['zdrowy-kregosup']['pl'] = 27;
$redirectArray['pakiet-stomatologiczny-hotel-hilton']['pl'] = 5;
$redirectArray['beauty-calming--anti-redness-2-dni']['pl'] = 16;
$redirectArray['stomatolog-na-twoja-kiesze']['pl'] = 22;
$redirectArray['przeglad-stomatologiczny-wybielanie-zebow']['pl'] = 25;
$redirectArray['implant-w-dwa-dni']['pl'] = 24;
$redirectArray['nogi-bez-zylakow']['pl'] = 39;
$redirectArray['rehabilitacja-narzadu-ruch']['pl'] = 36;
$redirectArray['zdrowe-serce-14-dniowy-program']['pl'] = 35;
$redirectArray['stomatolog-w-szczecinie']['pl'] = 37;
$redirectArray['sanatorium-z-rehabilitacja-narza']['pl'] = 32;
$redirectArray['beauty-and-rejuvenation']['en'] = 3;
$redirectArray['beauty-slim']['en'] = 2;
$redirectArray['white-smile-2---day-package-hilton-hotel']['en'] = 18;
$redirectArray['healthy-and-beauty-2---day-with-dentist-botox']['en'] = 17;
$redirectArray['beauty-care']['en'] = 19;
$redirectArray['spa-in-hilton-hotel']['en'] = 21;
$redirectArray['implant-treatments-in-the-sea-tower']['en'] = 26;
$redirectArray['beauty-med']['en'] = 23;
$redirectArray['special-abdomen-programme']['en'] = 34;
$redirectArray['healthy-spine-clinic']['en'] = 27;
$redirectArray['healthy-smile-2-day-dental-package-hilton-hotel']['en'] = 5;
$redirectArray['beauty-calming--anti-redness-2-days']['en'] = 16;
$redirectArray['dentist-for-every-pocket']['en'] = 22;
$redirectArray['teeth-whitening']['en'] = 25;
$redirectArray['lifelong-guarantee-for-implants']['en'] = 24;
$redirectArray['varicose']['en'] = 39;
$redirectArray['locomotor-system-14-day-stay-in-the-health-resort']['en'] = 36;
$redirectArray['cardiology-14-day-stay-in-the-health-resort']['en'] = 35;
$redirectArray['dentist-in-szczecin']['en'] = 37;
$redirectArray['physical-medicine-and-rehabilita']['en'] = 32;
$redirectArray['beauty-young']['de'] = 3;
$redirectArray['beauty-slim']['de'] = 2;
$redirectArray['white-smile']['de'] = 18;
$redirectArray['gesundheit-von-schonheit-2-tage']['de'] = 17;
$redirectArray['beauty-care']['de'] = 19;
$redirectArray['spa-im-hilton---fur-sie']['de'] = 21;
$redirectArray['implantate-in-der-sea-tower']['de'] = 26;
$redirectArray['beauty-med']['de'] = 23;
$redirectArray['das-speziell-gestaltete-und-vorbereitete-programm']['de'] = 34;
$redirectArray['wirbelsaule-ist-die-basis']['de'] = 27;
$redirectArray['healthy-smile-2---day---dental-package-hotel-hilton']['de'] = 5;
$redirectArray['beauty-calming--anti-redness']['de'] = 16;
$redirectArray['zahnarzt-fur-jedes-budget']['de'] = 22;
$redirectArray['zahnaufhellung']['de'] = 25;
$redirectArray['lebenslange-garantie-fur-implantate']['de'] = 24;
$redirectArray['das-venefit-verfahren']['de'] = 39;
$redirectArray['rehabilitation-14-tage-aufenthalt-im-sanatorium']['de'] = 36;
$redirectArray['kardiologie---14-tage-aufenthalt-im-sanatorium']['de'] = 35;
$redirectArray['zahnarzt-in-szczecin']['de'] = 37;
$redirectArray['rehabilitation-bewegungs']['de'] = 32;
$redirectArray['beauty-young']['sv'] = 3;
$redirectArray['beauty-slim']['sv'] = 2;
$redirectArray['white-smile---2---day-package']['sv'] = 18;
$redirectArray['vard-av-skonhet-2-dagar']['sv'] = 17;
$redirectArray['beauty-care']['sv'] = 19;
$redirectArray['spa-pa-hilton---for-dig']['sv'] = 21;
$redirectArray['implantat-i-sea-tower']['sv'] = 26;
$redirectArray['beauty-med']['sv'] = 23;
$redirectArray['ett-speciellt-utformat-program']['sv'] = 34;
$redirectArray['frisk-ryggrad']['sv'] = 27;
$redirectArray['healthy-smile-2---day---dental-package-hotel-hilton']['sv'] = 5;
$redirectArray['beauty-calming--anti-redness']['sv'] = 16;
$redirectArray['tandlakare-for-varje-budget']['sv'] = 22;
$redirectArray['tandblekning']['sv'] = 25;
$redirectArray['livslangt-garanti-for-implantat']['sv'] = 24;
$redirectArray['forfarande-venefit']['sv'] = 39;
$redirectArray['rorelseapparaten---rehabiliteringsemester']['sv'] = 36;
$redirectArray['kardiologi---rehabiliteringsemester']['sv'] = 35;
$redirectArray['tandlakare-i-szczecin']['sv'] = 37;
$redirectArray['rehabilitation-behandlingar']['sv'] = 32;
if (!empty($redirectArray[$pSlug][$pLanguageCode]))
{
$packageId = $redirectArray[$pSlug][$pLanguageCode];
$package = $this->packagesInstance->getPackageByIdAndLang($packageId, $pLanguageCode);
if (!empty($package))
{
$this->redirect('package/'.$package['slug'], array('code' => 301));
}
}
}
Double value = item.getPrice() * loyaltyPointMultiplier;
String[] s = String.split(value.toString(), "\\.");
points = Integer.parseInt(s[0]);
if(Integer.parseInt(s[1]) > 0) {
points++;
}
return points;
Want to round up? Math.ceil() uses too little memory! Use this instead!
// GetModelStruct get value's model struct, relationships based on struct and tag definition
func (scope *Scope) GetModelStruct() *ModelStruct {
var modelStruct ModelStruct
// Scope value can't be nil
if scope.Value == nil {
return &modelStruct
}
reflectType := reflect.ValueOf(scope.Value).Type()
for reflectType.Kind() == reflect.Slice || reflectType.Kind() == reflect.Ptr {
reflectType = reflectType.Elem()
}
// Scope value need to be a struct
if reflectType.Kind() != reflect.Struct {
return &modelStruct
}
// Get Cached model struct
isSingularTable := false
if scope.db != nil && scope.db.parent != nil {
scope.db.parent.RLock()
isSingularTable = scope.db.parent.singularTable
scope.db.parent.RUnlock()
}
hashKey := struct {
singularTable bool
reflectType reflect.Type
}{isSingularTable, reflectType}
if value, ok := modelStructsMap.Load(hashKey); ok && value != nil {
return value.(*ModelStruct)
}
modelStruct.ModelType = reflectType
// Get all fields
for i := 0; i < reflectType.NumField(); i++ {
if fieldStruct := reflectType.Field(i); ast.IsExported(fieldStruct.Name) {
field := &StructField{
Struct: fieldStruct,
Name: fieldStruct.Name,
Names: []string{fieldStruct.Name},
Tag: fieldStruct.Tag,
TagSettings: parseTagSetting(fieldStruct.Tag),
}
// is ignored field
if _, ok := field.TagSettingsGet("-"); ok {
field.IsIgnored = true
} else {
if _, ok := field.TagSettingsGet("PRIMARY_KEY"); ok {
field.IsPrimaryKey = true
modelStruct.PrimaryFields = append(modelStruct.PrimaryFields, field)
}
if _, ok := field.TagSettingsGet("DEFAULT"); ok && !field.IsPrimaryKey {
field.HasDefaultValue = true
}
if _, ok := field.TagSettingsGet("AUTO_INCREMENT"); ok && !field.IsPrimaryKey {
field.HasDefaultValue = true
}
indirectType := fieldStruct.Type
for indirectType.Kind() == reflect.Ptr {
indirectType = indirectType.Elem()
}
fieldValue := reflect.New(indirectType).Interface()
if _, isScanner := fieldValue.(sql.Scanner); isScanner {
// is scanner
field.IsScanner, field.IsNormal = true, true
if indirectType.Kind() == reflect.Struct {
for i := 0; i < indirectType.NumField(); i++ {
for key, value := range parseTagSetting(indirectType.Field(i).Tag) {
if _, ok := field.TagSettingsGet(key); !ok {
field.TagSettingsSet(key, value)
}
}
}
}
} else if _, isTime := fieldValue.(*time.Time); isTime {
// is time
field.IsNormal = true
} else if _, ok := field.TagSettingsGet("EMBEDDED"); ok || fieldStruct.Anonymous {
// is embedded struct
for _, subField := range scope.New(fieldValue).GetModelStruct().StructFields {
subField = subField.clone()
subField.Names = append([]string{fieldStruct.Name}, subField.Names...)
if prefix, ok := field.TagSettingsGet("EMBEDDED_PREFIX"); ok {
subField.DBName = prefix + subField.DBName
}
if subField.IsPrimaryKey {
if _, ok := subField.TagSettingsGet("PRIMARY_KEY"); ok {
modelStruct.PrimaryFields = append(modelStruct.PrimaryFields, subField)
} else {
subField.IsPrimaryKey = false
}
}
if subField.Relationship != nil && subField.Relationship.JoinTableHandler != nil {
if joinTableHandler, ok := subField.Relationship.JoinTableHandler.(*JoinTableHandler); ok {
newJoinTableHandler := &JoinTableHandler{}
newJoinTableHandler.Setup(subField.Relationship, joinTableHandler.TableName, reflectType, joinTableHandler.Destination.ModelType)
subField.Relationship.JoinTableHandler = newJoinTableHandler
}
}
modelStruct.StructFields = append(modelStruct.StructFields, subField)
}
continue
} else {
// build relationships
switch indirectType.Kind() {
case reflect.Slice:
defer func(field *StructField) {
var (
relationship = &Relationship{}
toScope = scope.New(reflect.New(field.Struct.Type).Interface())
foreignKeys []string
associationForeignKeys []string
elemType = field.Struct.Type
)
if foreignKey, _ := field.TagSettingsGet("FOREIGNKEY"); foreignKey != "" {
foreignKeys = strings.Split(foreignKey, ",")
}
if foreignKey, _ := field.TagSettingsGet("ASSOCIATION_FOREIGNKEY"); foreignKey != "" {
associationForeignKeys = strings.Split(foreignKey, ",")
} else if foreignKey, _ := field.TagSettingsGet("ASSOCIATIONFOREIGNKEY"); foreignKey != "" {
associationForeignKeys = strings.Split(foreignKey, ",")
}
for elemType.Kind() == reflect.Slice || elemType.Kind() == reflect.Ptr {
elemType = elemType.Elem()
}
if elemType.Kind() == reflect.Struct {
if many2many, _ := field.TagSettingsGet("MANY2MANY"); many2many != "" {
relationship.Kind = "many_to_many"
{ // Foreign Keys for Source
joinTableDBNames := []string{}
if foreignKey, _ := field.TagSettingsGet("JOINTABLE_FOREIGNKEY"); foreignKey != "" {
joinTableDBNames = strings.Split(foreignKey, ",")
}
// if no foreign keys defined with tag
if len(foreignKeys) == 0 {
for _, field := range modelStruct.PrimaryFields {
foreignKeys = append(foreignKeys, field.DBName)
}
}
for idx, foreignKey := range foreignKeys {
if foreignField := getForeignField(foreignKey, modelStruct.StructFields); foreignField != nil {
// source foreign keys (db names)
relationship.ForeignFieldNames = append(relationship.ForeignFieldNames, foreignField.DBName)
// setup join table foreign keys for source
if len(joinTableDBNames) > idx {
// if defined join table's foreign key
relationship.ForeignDBNames = append(relationship.ForeignDBNames, joinTableDBNames[idx])
} else {
defaultJointableForeignKey := ToColumnName(reflectType.Name()) + "_" + foreignField.DBName
relationship.ForeignDBNames = append(relationship.ForeignDBNames, defaultJointableForeignKey)
}
}
}
}
{ // Foreign Keys for Association (Destination)
associationJoinTableDBNames := []string{}
if foreignKey, _ := field.TagSettingsGet("ASSOCIATION_JOINTABLE_FOREIGNKEY"); foreignKey != "" {
associationJoinTableDBNames = strings.Split(foreignKey, ",")
}
// if no association foreign keys defined with tag
if len(associationForeignKeys) == 0 {
for _, field := range toScope.PrimaryFields() {
associationForeignKeys = append(associationForeignKeys, field.DBName)
}
}
for idx, name := range associationForeignKeys {
if field, ok := toScope.FieldByName(name); ok {
// association foreign keys (db names)
relationship.AssociationForeignFieldNames = append(relationship.AssociationForeignFieldNames, field.DBName)
// setup join table foreign keys for association
if len(associationJoinTableDBNames) > idx {
relationship.AssociationForeignDBNames = append(relationship.AssociationForeignDBNames, associationJoinTableDBNames[idx])
} else {
// join table foreign keys for association
joinTableDBName := ToColumnName(elemType.Name()) + "_" + field.DBName
relationship.AssociationForeignDBNames = append(relationship.AssociationForeignDBNames, joinTableDBName)
}
}
}
}
joinTableHandler := JoinTableHandler{}
joinTableHandler.Setup(relationship, many2many, reflectType, elemType)
relationship.JoinTableHandler = &joinTableHandler
field.Relationship = relationship
} else {
// User has many comments, associationType is User, comment use UserID as foreign key
var associationType = reflectType.Name()
var toFields = toScope.GetStructFields()
relationship.Kind = "has_many"
if polymorphic, _ := field.TagSettingsGet("POLYMORPHIC"); polymorphic != "" {
// Dog has many toys, tag polymorphic is Owner, then associationType is Owner
// Toy use OwnerID, OwnerType ('dogs') as foreign key
if polymorphicType := getForeignField(polymorphic+"Type", toFields); polymorphicType != nil {
associationType = polymorphic
relationship.PolymorphicType = polymorphicType.Name
relationship.PolymorphicDBName = polymorphicType.DBName
// if Dog has multiple set of toys set name of the set (instead of default 'dogs')
if value, ok := field.TagSettingsGet("POLYMORPHIC_VALUE"); ok {
relationship.PolymorphicValue = value
} else {
relationship.PolymorphicValue = scope.TableName()
}
polymorphicType.IsForeignKey = true
}
}
// if no foreign keys defined with tag
if len(foreignKeys) == 0 {
// if no association foreign keys defined with tag
if len(associationForeignKeys) == 0 {
for _, field := range modelStruct.PrimaryFields {
foreignKeys = append(foreignKeys, associationType+field.Name)
associationForeignKeys = append(associationForeignKeys, field.Name)
}
} else {
// generate foreign keys from defined association foreign keys
for _, scopeFieldName := range associationForeignKeys {
if foreignField := getForeignField(scopeFieldName, modelStruct.StructFields); foreignField != nil {
foreignKeys = append(foreignKeys, associationType+foreignField.Name)
associationForeignKeys = append(associationForeignKeys, foreignField.Name)
}
}
}
} else {
// generate association foreign keys from foreign keys
if len(associationForeignKeys) == 0 {
for _, foreignKey := range foreignKeys {
if strings.HasPrefix(foreignKey, associationType) {
associationForeignKey := strings.TrimPrefix(foreignKey, associationType)
if foreignField := getForeignField(associationForeignKey, modelStruct.StructFields); foreignField != nil {
associationForeignKeys = append(associationForeignKeys, associationForeignKey)
}
}
}
if len(associationForeignKeys) == 0 && len(foreignKeys) == 1 {
associationForeignKeys = []string{scope.PrimaryKey()}
}
} else if len(foreignKeys) != len(associationForeignKeys) {
scope.Err(errors.New("invalid foreign keys, should have same length"))
return
}
}
for idx, foreignKey := range foreignKeys {
if foreignField := getForeignField(foreignKey, toFields); foreignField != nil {
if associationField := getForeignField(associationForeignKeys[idx], modelStruct.StructFields); associationField != nil {
// source foreign keys
foreignField.IsForeignKey = true
relationship.AssociationForeignFieldNames = append(relationship.AssociationForeignFieldNames, associationField.Name)
relationship.AssociationForeignDBNames = append(relationship.AssociationForeignDBNames, associationField.DBName)
// association foreign keys
relationship.ForeignFieldNames = append(relationship.ForeignFieldNames, foreignField.Name)
relationship.ForeignDBNames = append(relationship.ForeignDBNames, foreignField.DBName)
}
}
}
if len(relationship.ForeignFieldNames) != 0 {
field.Relationship = relationship
}
}
} else {
field.IsNormal = true
}
}(field)
case reflect.Struct:
defer func(field *StructField) {
var (
// user has one profile, associationType is User, profile use UserID as foreign key
// user belongs to profile, associationType is Profile, user use ProfileID as foreign key
associationType = reflectType.Name()
relationship = &Relationship{}
toScope = scope.New(reflect.New(field.Struct.Type).Interface())
toFields = toScope.GetStructFields()
tagForeignKeys []string
tagAssociationForeignKeys []string
)
if foreignKey, _ := field.TagSettingsGet("FOREIGNKEY"); foreignKey != "" {
tagForeignKeys = strings.Split(foreignKey, ",")
}
if foreignKey, _ := field.TagSettingsGet("ASSOCIATION_FOREIGNKEY"); foreignKey != "" {
tagAssociationForeignKeys = strings.Split(foreignKey, ",")
} else if foreignKey, _ := field.TagSettingsGet("ASSOCIATIONFOREIGNKEY"); foreignKey != "" {
tagAssociationForeignKeys = strings.Split(foreignKey, ",")
}
if polymorphic, _ := field.TagSettingsGet("POLYMORPHIC"); polymorphic != "" {
// Cat has one toy, tag polymorphic is Owner, then associationType is Owner
// Toy use OwnerID, OwnerType ('cats') as foreign key
if polymorphicType := getForeignField(polymorphic+"Type", toFields); polymorphicType != nil {
associationType = polymorphic
relationship.PolymorphicType = polymorphicType.Name
relationship.PolymorphicDBName = polymorphicType.DBName
// if Cat has several different types of toys set name for each (instead of default 'cats')
if value, ok := field.TagSettingsGet("POLYMORPHIC_VALUE"); ok {
relationship.PolymorphicValue = value
} else {
relationship.PolymorphicValue = scope.TableName()
}
polymorphicType.IsForeignKey = true
}
}
// Has One
{
var foreignKeys = tagForeignKeys
var associationForeignKeys = tagAssociationForeignKeys
// if no foreign keys defined with tag
if len(foreignKeys) == 0 {
// if no association foreign keys defined with tag
if len(associationForeignKeys) == 0 {
for _, primaryField := range modelStruct.PrimaryFields {
foreignKeys = append(foreignKeys, associationType+primaryField.Name)
associationForeignKeys = append(associationForeignKeys, primaryField.Name)
}
} else {
// generate foreign keys form association foreign keys
for _, associationForeignKey := range tagAssociationForeignKeys {
if foreignField := getForeignField(associationForeignKey, modelStruct.StructFields); foreignField != nil {
foreignKeys = append(foreignKeys, associationType+foreignField.Name)
associationForeignKeys = append(associationForeignKeys, foreignField.Name)
}
}
}
} else {
// generate association foreign keys from foreign keys
if len(associationForeignKeys) == 0 {
for _, foreignKey := range foreignKeys {
if strings.HasPrefix(foreignKey, associationType) {
associationForeignKey := strings.TrimPrefix(foreignKey, associationType)
if foreignField := getForeignField(associationForeignKey, modelStruct.StructFields); foreignField != nil {
associationForeignKeys = append(associationForeignKeys, associationForeignKey)
}
}
}
if len(associationForeignKeys) == 0 && len(foreignKeys) == 1 {
associationForeignKeys = []string{scope.PrimaryKey()}
}
} else if len(foreignKeys) != len(associationForeignKeys) {
scope.Err(errors.New("invalid foreign keys, should have same length"))
return
}
}
for idx, foreignKey := range foreignKeys {
if foreignField := getForeignField(foreignKey, toFields); foreignField != nil {
if scopeField := getForeignField(associationForeignKeys[idx], modelStruct.StructFields); scopeField != nil {
foreignField.IsForeignKey = true
// source foreign keys
relationship.AssociationForeignFieldNames = append(relationship.AssociationForeignFieldNames, scopeField.Name)
relationship.AssociationForeignDBNames = append(relationship.AssociationForeignDBNames, scopeField.DBName)
// association foreign keys
relationship.ForeignFieldNames = append(relationship.ForeignFieldNames, foreignField.Name)
relationship.ForeignDBNames = append(relationship.ForeignDBNames, foreignField.DBName)
}
}
}
}
if len(relationship.ForeignFieldNames) != 0 {
relationship.Kind = "has_one"
field.Relationship = relationship
} else {
var foreignKeys = tagForeignKeys
var associationForeignKeys = tagAssociationForeignKeys
if len(foreignKeys) == 0 {
// generate foreign keys & association foreign keys
if len(associationForeignKeys) == 0 {
for _, primaryField := range toScope.PrimaryFields() {
foreignKeys = append(foreignKeys, field.Name+primaryField.Name)
associationForeignKeys = append(associationForeignKeys, primaryField.Name)
}
} else {
// generate foreign keys with association foreign keys
for _, associationForeignKey := range associationForeignKeys {
if foreignField := getForeignField(associationForeignKey, toFields); foreignField != nil {
foreignKeys = append(foreignKeys, field.Name+foreignField.Name)
associationForeignKeys = append(associationForeignKeys, foreignField.Name)
}
}
}
} else {
// generate foreign keys & association foreign keys
if len(associationForeignKeys) == 0 {
for _, foreignKey := range foreignKeys {
if strings.HasPrefix(foreignKey, field.Name) {
associationForeignKey := strings.TrimPrefix(foreignKey, field.Name)
if foreignField := getForeignField(associationForeignKey, toFields); foreignField != nil {
associationForeignKeys = append(associationForeignKeys, associationForeignKey)
}
}
}
if len(associationForeignKeys) == 0 && len(foreignKeys) == 1 {
associationForeignKeys = []string{toScope.PrimaryKey()}
}
} else if len(foreignKeys) != len(associationForeignKeys) {
scope.Err(errors.New("invalid foreign keys, should have same length"))
return
}
}
for idx, foreignKey := range foreignKeys {
if foreignField := getForeignField(foreignKey, modelStruct.StructFields); foreignField != nil {
if associationField := getForeignField(associationForeignKeys[idx], toFields); associationField != nil {
foreignField.IsForeignKey = true
// association foreign keys
relationship.AssociationForeignFieldNames = append(relationship.AssociationForeignFieldNames, associationField.Name)
relationship.AssociationForeignDBNames = append(relationship.AssociationForeignDBNames, associationField.DBName)
// source foreign keys
relationship.ForeignFieldNames = append(relationship.ForeignFieldNames, foreignField.Name)
relationship.ForeignDBNames = append(relationship.ForeignDBNames, foreignField.DBName)
}
}
}
if len(relationship.ForeignFieldNames) != 0 {
relationship.Kind = "belongs_to"
field.Relationship = relationship
}
}
}(field)
default:
field.IsNormal = true
}
}
}
// Even it is ignored, also possible to decode db value into the field
if value, ok := field.TagSettingsGet("COLUMN"); ok {
field.DBName = value
} else {
field.DBName = ToColumnName(fieldStruct.Name)
}
modelStruct.StructFields = append(modelStruct.StructFields, field)
}
}
if len(modelStruct.PrimaryFields) == 0 {
if field := getForeignField("id", modelStruct.StructFields); field != nil {
field.IsPrimaryKey = true
modelStruct.PrimaryFields = append(modelStruct.PrimaryFields, field)
}
}
modelStructsMap.Store(hashKey, &modelStruct)
return &modelStruct
}
contracts = Contract.objects.filter(staff=staff).filter(active=True)
if contracts.__len__() > 0:
ind = contracts.__len__() - 1
dic[‘active_contract_id’] = contracts[ind].id
else:
dic[‘active_contract_id’] = contracts[0].id
Get last object of queryset in django