- 1
https://pbs.twimg.com/media/EjtRN4HX0AA6FPN.jpg
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
https://pbs.twimg.com/media/EjtRN4HX0AA6FPN.jpg
0
$output_desc_name_num= $output;
$desc_name_ar = array(
"1" => "<a href='http:\\test.com'>link</a>",
"2" => "Описание.. 2",
"3" => "Описание.. 3",
);
if($output_desc_name_num == 1){
$desc_name = $desc_name_ar[1];
}
elseif($output_desc_name_num == 2){
$desc_name = $desc_name_ar[2];
}
elseif($output_desc_name_num == 3)
$desc_name = $desc_name_ar[3];
else
$desc_name ='';
............
return $response;
Слишком мало переменных для каждого действия... + условии
+1
$userId = getUser(); //получаем список всех пользователей
$valueArray = array();
$keyArray = array();
$valueArray1 = array();
$keyArray1 = array();
$resultArray = array();
$resultArray1 = array();
for($i=0;$i<count($userId);$i++){
array_push($valueArray,$userId[$i]['user_id']);
array_push($keyArray,$userId[$i]['status']);
}
for ($i = 0; $i<count($keyArray); $i++) {
$resultArray[$valueArray[$i]] = $keyArray[$i];
}
for($i=0;$i<count($userId);$i++){
array_push($valueArray1,$userId[$i]['user_id']);
array_push($keyArray1,$userId[$i]['active']);
}
for ($i = 0; $i<count($keyArray1); $i++) {
$resultArray1[$valueArray1[$i]] = $keyArray1[$i];
}
$array = array();
foreach ($resultArray as $key => $value){
if($value==="finish"){
if($resultArray1[$key]==='Y'){
array_push($array,$key);
}
}
}
Получаем массив пользователей у которых завершен звонок.
0
Trying to get property '%s' of non-object: Notice -> Warning
Undefined property: %s::$%s Notice -> Warning
тут брейкинг ченджес подвезли
https://wiki.php.net/rfc/engine_warnings
+2
public function getFlagCode()
{
$code = $this->_storeManager->getStore()->getCode();
switch ($code) {
case 'us':
return 'us';
break;
case 'eu':
return 'eu';
break;
default;
return 'ww';
}
}
0
foreach ($properties->xml->ЗначенияСвойства as $property) {
//......
}
$properties->xml->ЗначенияСвойства
+3
# Alternative mysql_real_escape_string without mysql connection
function escape_string($param) {
if(is_array($param))
return array_map(__METHOD__, $param);
if(!empty($param) && is_string($param)) {
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $param);
}
return $param;
}
#Using example
$name = @trim(escape_string(stripslashes($_POST['name'])));
https://gist.github.com/wilnaweb/ca37459bdf92aa74bd2dd7994fa5b0df
+1
$DI_WName = Array('ѕн','¬т','—р','„т','ѕт','—б','¬с');
$DI_MName = Array('январь','‘евраль','ћарт','јпрель','ћай','»юнь','»юль','јвгуст','—ент¤брь','ќкт¤брь','Ќо¤брь','ƒекабрь');
$today = TodayDate();
$today = explode(".",$today);
$today = $today[2]*10000+$today[1]*100+$today[0];
$DI_Date = TodayDate();
if (isset($_GET["p0"])) $DI_Date = $_GET["p0"];
$DI_Date = explode(".",$DI_Date);
$DI_YY = $DI_Date[2];
$DI_LYY = $DI_YY;
$DI_NYY = $DI_YY;
$DI_MM = $DI_Date[1]-1;
$DI_LMM = $DI_MM-1;
if ($DI_LMM<0) $DI_LMM = 11;
$DI_NMM = $DI_MM+1;
if ($DI_NMM>11) $DI_NMM = 0;
if ($DI_MM==0) $DI_LYY = $DI_YY-1;
if ($DI_MM==11) $DI_NYY = $DI_YY+1;
$DI_DD = $DI_Date[0];
$lastM = $DI_MM-2;
$yy = $DI_YY;
if ($lastM<1) {
$lastM = 12+$lastM;
$yy = $yy - 1;
}
$lastM = $DI_DD.".".$lastM.".".$yy;
$nextM = $DI_MM+4;
$yy = $DI_YY;
if ($nextM>12) {
$nextM = $nextM-12;
$yy = $yy + 1;
}
$nextM = $DI_DD.".".$nextM.".".$yy;
$lastY = $DI_DD.".".($DI_MM+1).".".($DI_YY-1);
$nextY = $DI_DD.".".($DI_MM+1).".".($DI_YY+1);
+1
function DI_MNum($Mon, $Year) {
$nn = Array(31,28,31,30,31,30,31,31,30,31,30,31);
$x = 28;
$y = (Round($Year/4))*4;
if ($y==$Year) $x = 29;
$ret = $nn[$Mon];
if ($Mon==1) $ret = $x;
return $ret;
}
function DI_FirstDay($Mon,$Year) {
$x0 = 365;
$Y = $Year-1;
$days = $Y*$x0+floor($Y/4)+6;
for ($j=0; $j<$Mon; $j=$j+1) {
$days = $days+DI_MNum($j,$Year);
}
$week = $days-(7*Round(($days/7)-0.5));
return $week;
}
function even_week($Day,$Mon,$Year) {
$x0 = 365;
$Y = $Year-1;
$days = $Y*$x0+floor($Y/4)+6;
for ($j=0; $j<$Mon; $j=$j+1) {
$days = $days+DI_MNum($j,$Year);
}
$days = $days + $Day;
$weeks = ceil($days/7);
$res = false;
if (2*ceil($weeks/2) == $weeks) $res = true;
return $res;
}
−1
public function index()
{
$items = CartManager::getAllItems();
$couponCode = Coupon::getFromSession()->implode('code', ', ');
$address = auth()->user()->address;
$user = auth()->user();
$userDetails = auth()->user() ? auth()->user()->fields : null;
$fields = [
'promo_code' => $couponCode,
'email' => $user->email,
'first_name' => $userDetails->firstname,
'last_name' => $userDetails->lastname,
'phone' => $userDetails->phone,
];
if ($address) {
$field = [
'value' => $address->city->title
];
if ($address->city->type === \App\Address::TYPE_CITY) {
$field ['data']['city_fias_id'] = $address->city->id;
$field ['data']['city'] = $address->city->title;
} elseif ($address->city->type === \App\Address::TYPE_SETTLEMENT) {
$field ['data']['settlement_fias_id'] = $address->city->id;
$field ['data']['settlement'] = $address->city->title;
}
$fields ['delivery_city'] = $field;
}
if ($address->street) {
$fields ['delivery_street'] = [
'value' => $address->street->title,
'data' => [
'street_fias_id' => $address->street->id,
]
];
}
if ($address->street_number) {
$fields ['delivery_house_number'] = [
'value' => $address->street_number,
];
}
if ($address->flat) {
$fields ['delivery_flat_number'] = $address->flat;
}
$fields = (object)$fields;
$actions = [
'remove' => route('shop.cart.remove'),
'remove_gift_card' => route('shop.cart.gift-cards.remove'),
'change' => route('shop.cart.update'),
'promo' => route('shop.coupon.apply'),
'checkout' => route('orders.store'),
'get_pickups' => route('delivery_points.index'),
'check_email' => route('check_email'),
];
return view('shop.cart.index', compact(
'items',
'address',
'couponCode',
'fields',
'actions'
));
}
this is MVC, baby !