Reply to SQL get string in Ajaxel CMS
SQL get string in Ajaxel CMS Posted by Alexander Shatalov PHP public static function sqlGetString($type, $arg='', $arg2='') { switch ($type) { case 'age': return '(DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS('.$arg.')), \'%Y\')+0)'; break; case 'age1': return 'FLOOR((CURDATE() – '.$arg.')/10000)'; break; case 'age2datetime': return (date('Y')-$arg).'-'.sprintf('%02d',date('m')).'-'.sprintf('%02d',date('d')).' '.sprintf('%02d',date('H')).':'.sprintf('%02d',date('i')).':00'; break; case 'where_dob_close': return 'DATE(CONCAT(YEAR(CURDATE()), RIGHT('.$arg.', 6))) BETWEEN DATE_SUB(CURDATE(), INTERVAL 0 DAY) AND DATE_ADD(CURDATE(), INTERVAL 60 DAY)'; break; case 'where_dob': return 'AND MONTH(dob)='.date('m').' AND DAY(dob)='.date('d').''; break; case 'length': return '(CASE WHEN LENGTH(`'.$arg.'`)>'.$arg2.' THEN CONCAT(SUBSTRING(`'.$arg.'`,1,'.$arg2.'),\'…\') ELSE `'.$arg.'` END) AS '.$arg; break; case 'distance': return '((ACOS(SIN('.$arg.' * PI() / 180) * SIN(`lat` * PI() / 180) + COS('.$arg.' * PI() / 180) * COS(`lat` * PI() / 180) * COS(('.$arg2.' – `lon`) * PI() / 180)) * 180 / PI()) * 60 * 1.1515)'; break; case 'fill': return 'CONCAT('.$arg.',\''.$arg2.',\')'; break; case 'remove': return 'REPLACE('.$arg.',\','.$arg2.',\',\',\')'; break; case 'check': return $arg.' LIKE \'%,'.$arg2.',%\''; break; case 'online': if (!$arg) $arg = DB_PREFIX.'users.id'; return '(SELECT '.(time()+SESSION_LIFETIME+1).'-expiration FROM '.DB_PREFIX.'sessions WHERE '.DB_PREFIX.'sessions.userid='.$arg.' ORDER BY expiration DESC LIMIT 1)'; break; case 'add': return 'IFNULL('.$arg.',0)+1'; break; case 'orderby': preg_match('/^\s*([a-z0-9_]+(\s+(ASC|DESC))?(\s*,\s*|\s*$))+|^\s*RAND\(\s*\)\s*$/i', $arg, $m); if (!$m) return ''; return $arg; break; default: return array( 'age' ,'age1' ,'age2datetime' ,'where_dob_close' ,'where_dob' ,'fill' ,'length' ,'distance' ,'remove' ,'check' ,'online' ,'add' ,'orderby' ); break; } } easy and quick I'm implying that it is very easy to build websites with Ajaxel! |