本文整理汇总了PHP中Convert::raw2sql方法的典型用法代码示例。如果您正苦于以下问题:PHP Convert::raw2sql方法的具体用法?PHP Convert::raw2sql怎么用?PHP Convert::raw2sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Convert
的用法示例。
在下文中一共展示了Convert::raw2sql方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: approve
function approve($comment, $member = null, $notify = true)
{
if (!$member) {
$member = Member::currentUser();
}
if (!$this->owner->Page()->canPublish($member)) {
return false;
}
if ($this->owner->ClassName == 'WorkflowDeletionRequest') {
if (isset($_REQUEST['DeletionScheduling']) && $_REQUEST['DeletionScheduling'] == 'scheduled') {
// Update SiteTree_Live directly, rather than doing a publish
// Because otherwise, unauthorized edits could be pushed live.
list($day, $month, $year) = explode('/', $_REQUEST['ExpiryDate']['Date']);
$expiryTimestamp = Convert::raw2sql(date('Y-m-d H:i:s', strtotime("{$year}-{$month}-{$day} {$_REQUEST['ExpiryDate']['Time']}")));
$pageID = $this->owner->Page()->ID;
if ($expiryTimestamp) {
DB::query("UPDATE \"SiteTree_Live\" SET \"ExpiryDate\" = '{$expiryTimestamp}' WHERE \"ID\" = {$pageID}");
}
}
}
$this->owner->PublisherID = $member->ID;
$this->owner->Status = 'Approved';
$this->owner->write();
// Embargo means we go Approved -> Scheduled
if ($this->owner->EmbargoDate) {
$this->owner->setSchedule();
$this->owner->addNewChange($comment, $this->owner->Status, $member);
// Otherwise we go Approved -> Published
} else {
$this->owner->publish($comment, $member, $notify);
}
return _t('SiteTreeCMSWorkflow.APPROVEDANDPUBLISHMESSAGE', 'Approved request and published changes to live version. Emailed %s.');
}
示例2: Save
/**
* @param $data
* @param $form
* @return bool|SS_HTTPResponse|void
* @throws ValidationException
* @throws null
*/
public function Save($data, $form)
{
/** @var Form $form */
$data = $form->getData();
if ($CurrentMember = Member::currentUser()) {
if ($member = DataObject::get_one('Member', "Email = '" . Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
$form->addErrorMessage('Email', 'Sorry, that Email already exists.', 'validation');
return $this->controller->redirectBack();
} else {
/** If no password don't save the field */
if (!isset($data['password'])) {
unset($data['password']);
}
$this->controller->setFlash('Your profile has been updated', 'success');
$form->saveInto($CurrentMember);
$CurrentMember->write();
return $this->controller->redirect($this->controller->Link());
}
} else {
/** Get registration page otherwise display warning.
*
* @var RegistrationPage $registerPage
*/
if ($registerPage = DataObject::get_one('RegistrationPage')) {
return Security::PermissionFailure($this->controller, 'You must <a href="' . $registerPage->Link() . '">registered</a> and logged in to edit your profile.');
} else {
$this->controller->setFlash('You must registered and logged in to edit your profile.', 'warning');
return $this->controller->redirect(Director::absoluteBaseURL());
}
}
}
示例3: addtocart
/**
* Handles form submission
* @param array $data
* @return bool|\SS_HTTPResponse
*/
public function addtocart(array $data)
{
$groupedProduct = $this->getController()->data();
if (empty($data) || empty($data['Product']) || !is_array($data['Product'])) {
$this->sessionMessage(_t('GroupedCartForm.EMPTY', 'Please select at least one product.'), 'bad');
$this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
return $response ? $response : $this->controller->redirectBack();
}
$cart = ShoppingCart::singleton();
foreach ($data['Product'] as $id => $prodReq) {
if (!empty($prodReq['Quantity']) && $prodReq['Quantity'] > 0) {
$prod = Product::get()->byID($id);
if ($prod && $prod->exists()) {
$saveabledata = !empty($this->saveablefields) ? Convert::raw2sql(array_intersect_key($data, array_combine($this->saveablefields, $this->saveablefields))) : $prodReq;
$buyable = $prod;
if (isset($prodReq['Attributes'])) {
$buyable = $prod->getVariationByAttributes($prodReq['Attributes']);
if (!$buyable || !$buyable->exists()) {
$this->sessionMessage("{$prod->InternalItemID} is not available with the selected options.", "bad");
$this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
return $response ? $response : $this->controller->redirectBack();
}
}
if (!$cart->add($buyable, (int) $prodReq['Quantity'], $saveabledata)) {
$this->sessionMessage($cart->getMessage(), $cart->getMessageType());
$this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
return $response ? $response : $this->controller->redirectBack();
}
}
}
}
$this->extend('updateGroupCartResponse', $this->request, $response, $groupedProduct, $data, $this);
return $response ? $response : ShoppingCart_Controller::direct($cart->getMessageType());
}
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-shop-groupedproducts,代码行数:39,代码来源:GroupedCartForm.php
示例4: notifySubscribers
/**
* Send email to subscribers, notifying them the thread has been created or post added.
*/
public function notifySubscribers()
{
// all members id except current user
$member_id = Member::currentUserID();
$list = DataObject::get("Forum_Subscribers", "\"ForumID\" = '" . $this->owner->ForumID . "' AND \"MemberID\" != '{$member_id}'");
if ($list) {
foreach ($list as $obj) {
$SQL_id = Convert::raw2sql((int) $obj->MemberID);
// Get the members details
$member = DataObject::get_one("Member", "\"Member\".\"ID\" = '{$SQL_id}'");
if ($member) {
//error_log("email sent ".$member->Email);
$type = $obj->Type;
switch ($type) {
// send all email notification
case 'all':
$this->createEmail($member);
break;
// send new thread only email notification
// send new thread only email notification
case 'thread':
//if($this->owner->isFirstPost()){
$this->createEmail($member);
//}
break;
//
//
default:
break;
}
}
}
}
}
示例5: cwsShortCodeRandomImageHandler
/**
* Displays a random image with colorbox effect from a given assets subfolder
* Uses template "csoft-shortcode/templates/Includes/RandomImage.ss" for output
*
* @param mixed $arguments (folder='subfolder_in_assets' align='left|right')
* @param $content = null
* @param $parser = null
* @return processed template RandomImage.ss
*/
public static function cwsShortCodeRandomImageHandler($arguments, $content = null, $parser = null)
{
// only proceed if subfolder was defined
if (!isset($arguments['folder'])) {
return;
}
// sanitize user inputs
$folder = Convert::raw2sql($arguments['folder']);
$align = isset($arguments['align']) ? strtolower(Convert::raw2xml($arguments['align'])) : '';
// fetch all images in random order from the user defined folder
$folder = Folder::get()->filter('Filename', "assets/{$folder}/")->First();
$randomImage = $folder ? Image::get()->filter('ParentID', $folder->ID)->sort('RAND()') : false;
// exit if user defined folder does not contain any image
if (!$randomImage) {
return;
}
// extract image caption from image filename
$caption = $randomImage->Title;
if (preg_match('#(\\d*-)?(.+)\\.(jpg|gif|png)#i', $caption, $matches)) {
$caption = ucfirst(str_replace('-', ' ', $matches[2]));
}
// prepare data for output
$data = array('RandomImage' => $randomImage->First(), 'Alignment' => $align, 'Caption' => $caption);
// load template and process data
$template = new SSViewer('RandomImage');
return $template->process(new ArrayData($data));
}
示例6: requireDefaultRecords
/**
* The process to automatically construct data object output configurations, executed on project build.
*/
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// Grab the list of data objects that have been completely removed.
foreach (DB::getConn()->tableList() as $table) {
// Delete existing output configurations for these data objects.
if (!class_exists($table)) {
$existing = DataObjectOutputConfiguration::get_one('DataObjectOutputConfiguration', "IsFor = '" . Convert::raw2sql($table) . "'");
$this->deleteConfiguration($table, $existing);
}
}
// Grab the list of all data object types, along with any inclusions/exclusions defined.
$objects = ClassInfo::subclassesFor('DataObject');
$inclusions = self::$custom_inclusions;
$exclusions = array_unique(array_merge(self::$exclusions, self::$custom_exclusions));
// Check existing output configurations for these data objects.
foreach ($objects as $object) {
$existing = DataObjectOutputConfiguration::get_one('DataObjectOutputConfiguration', "IsFor = '" . Convert::raw2sql($object) . "'");
// Delete existing output configurations for invalid data objects, or for those excluded.
if ($existing && (self::$disabled || get_parent_class($object) !== 'DataObject' || ClassInfo::classImplements($object, 'TestOnly') || count($inclusions) > 0 && !in_array($object, $inclusions) || count($inclusions) === 0 && in_array($object, $exclusions))) {
$this->deleteConfiguration($object, $existing);
} else {
if (!$existing && !self::$disabled && get_parent_class($object) === 'DataObject' && !ClassInfo::classImplements($object, 'TestOnly') && (count($inclusions) > 0 && in_array($object, $inclusions) || count($inclusions) === 0 && !in_array($object, $exclusions))) {
$this->addConfiguration($object);
}
}
}
}
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-apiwesome,代码行数:31,代码来源:DataObjectOutputConfiguration.php
示例7: Presentations
function Presentations()
{
$Speaker = NULL;
if (isset($_GET['key'])) {
$key = Convert::raw2sql($_GET['key']);
$username = SchedSpeaker::HashToUsername($key);
$Speaker = SchedSpeaker::get()->filter('username', $username)->first();
} elseif ($speakerID = Session::get('UploadMedia.SpeakerID')) {
$Speaker = SchedSpeaker::get()->byID($speakerID);
}
// Speaker not found
if (!$Speaker) {
return $this->httpError(404, 'Sorry, that does not appear to be a valid token.');
}
Session::set('UploadMedia.SpeakerID', $Speaker->ID);
$Presentations = $Speaker->PresentationsForThisSpeaker();
// No presentations
if (!$Presentations) {
return $this->httpError(404, 'Sorry, it does not appear that you have any presentations.');
}
// IF there's only one presentation with no media, go ahead and forward to it's page
if ($Presentations->count() == 1 && !$Presentations->first()->UploadedMedia()) {
$PresentationID = $Presentations->first()->ID;
$this->redirect($this->link() . 'Upload/' . $PresentationID);
return;
}
$data["Speaker"] = $Speaker;
$data["Presentations"] = $Presentations;
return $this->Customise($data);
}
示例8: getCurrentFilms
public function getCurrentFilms()
{
$r = new ArrayList();
//$RestfulService = new RestfulService("http://www.odeon.co.uk/api/uk/v2/cinemas/cinema/{$this->ID}/filmswithdetails.json");
$RestfulService = new RestfulService("http://www.odeon.co.uk/api/uk/v2/cinemas/cinema/{$this->ID}/", 259200);
$Response = $RestfulService->request("filmswithdetails.json");
if (!$Response->isError()) {
$films = Convert::json2array($Response->getBody());
foreach ($films as $film) {
$OdeonFilm = OdeonFilm::get_by_id('OdeonFilm', (int) $film['masterId']);
if (!$OdeonFilm) {
$OdeonFilm = new OdeonFilm();
$OdeonFilm->ID = (int) $film['masterId'];
$OdeonFilm->Title = Convert::raw2sql($film['title']);
if (isset($film['media']['imageUrl400'])) {
$OdeonFilm->imageUrlSmall = Convert::raw2sql($film['media']['imageUrl400']);
}
if (isset($film['casts'])) {
$OdeonFilm->Content = Convert::raw2sql($film['casts']);
}
$OdeonFilm->write();
}
$r->push($OdeonFilm);
}
}
return $r->sort("Title DESC");
}
示例9: apply
/**
* Applies the filter.
* Builds the where clause with the given IDs and boolean values in
* $this->value
*
* @param DataQuery $query Query to build where clause for
*
* @return DataQuery
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 25.06.2014
*/
public function apply(DataQuery $query)
{
$result = false;
$value = $this->getValue();
if (is_array($value) && count($value) > 0) {
$this->model = $query->applyRelation($this->relation);
$values = array(0 => array(), 1 => array());
foreach ($value as $ID => $boolean) {
$operator = '!=';
if ($boolean) {
$operator = '=';
}
$values[$boolean][] = sprintf("%s %s '%s'", $this->getDbName(), $operator, Convert::raw2sql($ID));
}
$negativeWhereClause = implode(' AND ', $values[0]);
$positiveWhereClause = implode(' OR ', $values[1]);
if (count($values[0]) > 0 && count($values[1]) > 0) {
$where = sprintf('(%s) AND (%s)', $negativeWhereClause, $positiveWhereClause);
} elseif (count($values[0]) > 0) {
$where = $negativeWhereClause;
} else {
$where = $positiveWhereClause;
}
$result = $query->where($where);
}
return $result;
}
示例10: run
function run()
{
$batch_size = 15;
if (isset($_GET['batch_size'])) {
$batch_size = intval(trim(Convert::raw2sql($_GET['batch_size'])));
}
$surveys = DeploymentSurvey::getNotDigestSent($batch_size);
$deployments = Deployment::getNotDigestSent($batch_size);
if ($surveys) {
foreach ($surveys as $survey) {
$survey->SendDigest = 1;
$survey->write();
}
}
if ($deployments) {
foreach ($deployments as $dep) {
$dep->SendDigest = 1;
$dep->write();
}
}
if ((!is_null($surveys) && count($surveys)) > 0 || !is_null($deployments) && count($deployments)) {
global $email_new_deployment;
$email = EmailFactory::getInstance()->buildEmail($email_new_deployment, $email_new_deployment, $subject = 'New Deployments and Surveys');
$email->setTemplate('NewDeploymentsSurveysEmail');
$email->populateTemplate(array('SurveysUrl' => Director::absoluteURL('admin/deployments/DeploymentSurvey/EditForm/field/DeploymentSurvey/item'), 'DeploymentsUrl' => Director::absoluteURL('admin/deployments/Deployment/EditForm/field/Deployment/item'), 'SangriaDeploymentsUrl' => Director::absoluteURL('sangria/ViewDeploymentDetails'), 'Surveys' => $surveys, 'Deployments' => $deployments));
$email->send();
}
}
示例11: Results
public function Results()
{
$list = Family::get()->leftJoin('House', '"Family"."ID" = "House"."FamilyID"');
$status = Convert::raw2sql($this->request->getVar('Status'));
$holdsRationCard = Convert::raw2sql($this->request->getVar('HoldsRationCard'));
$cardType = Convert::raw2sql($this->request->getVar('CardType'));
$houseType = Convert::raw2sql($this->request->getVar('Type'));
$parishID = Convert::raw2sql($this->request->getVar('ParishID'));
if ($parishID) {
$list = $list->filter(array('ParishID' => $parishID));
}
if ($status) {
$list = $list->filter(array('House.Status' => $status));
}
if ($holdsRationCard != '') {
$list = $list->filter(array('House.HoldsRationCard' => $holdsRationCard));
}
if ($holdsRationCard && $cardType) {
$list = $list->filter(array('House.CardType' => $cardType));
}
if ($houseType) {
$list = $list->filter(array('House.Type' => $houseType));
}
//$list = $list->leftJoin('Contact', "\"Contact\".\"FamilyID\" = \"Family\".\"ID\"");
//Debug::show($list);
return $list;
}
示例12: recursiveQuote
protected function recursiveQuote($val)
{
if (is_array($val)) {
$return = array();
foreach ($val as $v) {
$return[] = $this->recursiveQuote($v);
}
return '(' . implode(',', $return) . ')';
} else {
if (is_null($val)) {
$val = 'NULL';
} else {
if (is_int($val)) {
$val = (int) $val;
} else {
if (is_double($val)) {
$val = (double) $val;
} else {
if (is_float($val)) {
$val = (double) $val;
} else {
$val = "'" . Convert::raw2sql($val) . "'";
}
}
}
}
}
return $val;
}
示例13: getQuery
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null)
{
$dataList = parent::getQuery($searchParams, $sort, $limit, $existingQuery);
$params = is_object($searchParams) ? $searchParams->getVars() : $searchParams;
$query = $dataList->dataQuery();
if (!is_object($searchParams)) {
if (isset($params['Locale']) && !empty($params['Locale'])) {
$query->where('"Locale" = \'' . Convert::raw2sql($params['Locale']) . '\'');
}
if (isset($params['Name']) && !empty($params['Name'])) {
$query->where('"FirstName" LIKE \'%' . Convert::raw2sql($params['Name']) . '%\' OR "Surname" LIKE \'%' . Convert::raw2sql($params['Name']) . '%\'');
}
if (isset($params['Status'])) {
$query->where('EXISTS ( SELECT 1 FROM "' . $this->modelClass . '_Statuses"
WHERE "' . $this->modelClass . 'ID" = "' . $this->modelClass . '"."ID"
AND "' . $this->modelClass . '_Statuses"."CustomerStatusID" IN (' . implode(',', $params['Status']) . ')
)');
}
if (isset($params['Tags'])) {
$query->where('EXISTS ( SELECT 1 FROM "' . $this->modelClass . '_Tags"
WHERE "' . $this->modelClass . 'ID" = "' . $this->modelClass . '"."ID"
AND "' . $this->modelClass . '_Tags"."CustomerTagID" IN (' . implode(',', $params['Tags']) . ')
)');
}
$this->extend('updateGetQuery', $query, $params);
}
return $dataList->setDataQuery($query);
}
示例14: php
public function php($data)
{
$member = $this->member;
$valid = true;
foreach ($this->unique as $field) {
$other = DataObject::get_one('Member', sprintf('"%s" = \'%s\'', Convert::raw2sql($field), Convert::raw2sql($data[$field])));
if ($other && (!$this->member || !$this->member->exists() || $other->ID != $this->member->ID)) {
$fieldInstance = $this->form->Fields()->dataFieldByName($field);
if ($fieldInstance->getCustomValidationMessage()) {
$message = $fieldInstance->getCustomValidationMessage();
} else {
$message = sprintf(_t('MemberProfiles.MEMBERWITHSAME', 'There is already a member with the same %s.'), $field);
}
$valid = false;
$this->validationError($field, $message, 'required');
}
}
// Create a dummy member as this is required for custom password validators
if (isset($data['Password']) && $data['Password'] !== "") {
if (is_null($member)) {
$member = Member::create();
}
if ($validator = $member::password_validator()) {
$results = $validator->validate($data['Password'], $member);
if (!$results->valid()) {
$valid = false;
foreach ($results->messageList() as $key => $value) {
$this->validationError('Password', $value, 'required');
}
}
}
}
return $valid && parent::php($data);
}
示例15: create
/**
* Create member account from data array.
* Data must contain unique identifier.
*
* @throws ValidationException
* @param $data - map of member data
* @return Member|boolean - new member (not saved to db), or false if there is an error.
*/
public function create($data)
{
$result = new ValidationResult();
if (!Checkout::member_creation_enabled()) {
$result->error(_t("Checkout.MEMBERSHIPSNOTALLOWED", "Creating new memberships is not allowed"));
throw new ValidationException($result);
}
$idfield = Config::inst()->get('Member', 'unique_identifier_field');
if (!isset($data[$idfield]) || empty($data[$idfield])) {
$result->error(sprintf(_t("Checkout.IDFIELDNOTFOUND", "Required field not found: %s"), $idfield));
throw new ValidationException($result);
}
if (!isset($data['Password']) || empty($data['Password'])) {
$result->error(_t("Checkout.PASSWORDREQUIRED", "A password is required"));
throw new ValidationException($result);
}
$idval = $data[$idfield];
if (ShopMember::get_by_identifier($idval)) {
$result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), _t("Member." . $idfield, $idfield), $idval));
throw new ValidationException($result);
}
$member = new Member(Convert::raw2sql($data));
$validation = $member->validate();
if (!$validation->valid()) {
//TODO need to handle i18n here?
$result->error($validation->message());
}
if (!$result->valid()) {
throw new ValidationException($result);
}
return $member;
}