本文整理汇总了PHP中DataList::where方法的典型用法代码示例。如果您正苦于以下问题:PHP DataList::where方法的具体用法?PHP DataList::where怎么用?PHP DataList::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataList
的用法示例。
在下文中一共展示了DataList::where方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeByID
/**
* Overloading ManyManyList removeByID Rather Then remove() as That Just Calls removeByID()
* Remove the given item from this list.
* Note that for a ManyManyList, the item is never actually deleted, only the join table is affected
* @param $itemID The item it
*/
public function removeByID($itemID)
{
parent::removeByID($itemID);
// Get Item Object Itself Based on $itemID
$dl = new DataList($this->dataClass);
// Must Include Table Prefix To Prevent "Column 'ID' in where clause is ambiguous" Error
$item = $dl->where("\"" . $this->dataClass . "\".\"ID\" = '" . $itemID . "'")->first();
$this->onUnlink($item);
}
示例2: filter
public static function filter(DataList $list, $member = null)
{
$now = date('Y-m-d H:i:s');
$nowminusone = date('Y-m-d H:i:s', strtotime("-1 day"));
$groupids = array(0);
if ($member) {
$groupids = array_merge($member->Groups()->map('ID', 'ID')->toArray(), $groupids);
}
return $list->where("(\"SpecificPrice\".\"StartDate\" IS NULL) OR (\"SpecificPrice\".\"StartDate\" < '{$now}')")->where("(\"SpecificPrice\".\"EndDate\" IS NULL) OR (\"SpecificPrice\".\"EndDate\" > '{$nowminusone}')")->filter("GroupID", $groupids);
}
示例3: onAfterWrite
public function onAfterWrite()
{
parent::onAfterWrite();
// Define Related MCList Object
$list = $this->getComponent("MCList");
// Store The True Changed Fields Array On First Write
if ($this->getWriteCount() == 1) {
$cf = $this->getChangedFields(false, 2);
// Define Change Fields Array
$this->setOriginalChangedFields($cf);
// Store Original (First Write) Change Fields For Use On Second Write
} else {
if ($this->getWriteCount() > 1 && $this->getSyncMailChimp() && !empty($this->Email) && !empty($list->ID)) {
$apikey = SiteConfig::current_site_config()->getMCAPIKey();
$api = new MCAPI($apikey);
// Define The Change Fields Array Which We Stored On The First Write Iteration For Use On The Second Write (When Components Are Written)
if ($this->getWriteCount() == 2) {
$cf = $this->getOriginalChangedFields();
}
$Class = array();
$Class["MCSubscription"] = $this;
$where = "\"MCListID\" = '" . $this->MCListID . "' AND \"SyncDirection\" IN ('Export','Both')";
if (!empty($this->getComponent("Member")->ID)) {
$Class['Member'] = $this->getComponent("Member");
SS_Log::log("Sub ID " . $this->ID . " Has A Related Member Object..", SS_Log::NOTICE);
} else {
// If No Related Member Object Only Deal With Subscription Record Merge Data
$where .= " AND \"OnClass\" = 'MCSubscription'";
SS_Log::log("Sub ID " . $this->ID . " Has No Related Member Object..", SS_Log::NOTICE);
}
$dl = new DataList("MCListField");
$mappings = $dl->where($where);
$merge_vars = array();
foreach ($mappings as $map) {
$merge_vars[$map->MergeTag] = $Class[$map->OnClass]->getField($map->FieldName);
}
if (isset($cf['ID'])) {
// If Adding a New Subscription
$result = $api->listSubscribe($list->ListID, $this->Email, $merge_vars, 'html', $this->DoubleOptIn);
// If Successfully Added a New Subscription Make a Second Call to Return the MailChimp Member (Web) && Email ID's
if (empty($api->errorCode)) {
SS_Log::log("API Call Success: listSubscribe(" . $list->ListID . ", " . $this->Email . "); for Subscription ID " . $this->ID, SS_Log::NOTICE);
$retval = $api->listMemberInfo($list->ListID, $this->Email);
if (empty($api->errorCode)) {
SS_Log::log("API Call Success: listMemberInfo(" . $list->ListID . ", " . $this->Email . "); for Subscription ID " . $this->ID, SS_Log::NOTICE);
SS_Log::log("Calling Additional write() for Subscription ID " . $this->ID . " to Save MailChimp Created Data", SS_Log::NOTICE);
$this->setField("MCMemberID", $retval['data'][0]['web_id']);
// Set The MailChimp Member (Web) ID for this Member (Which Is Static - Used For MC - Site Imports)
$this->setField("MCEmailID", $retval['data'][0]['id']);
// Set The MailChimp Email ID for this Member (Which Updates When E-mail Updates - Used For Site - MC Exports)
$this->setWriteCount();
$this->write();
} else {
SS_Log::log("API Call Failed: listMemberInfo(" . $list->ListID . ", " . $this->Email . "); for Subscription ID " . $this->ID . " | Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
}
} else {
SS_Log::log("API Call Failed: listSubscribe(" . $list->ListID . ", " . $this->Email . "); for Subscription ID " . $this->ID . " | Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
}
} else {
if (isset($cf['Subscribed']) && !empty($this->Subscribed)) {
// If Just Re-Subscribed (This Will Replace Previous MC Record With New One Rather Than Re-Subscribing Existing)
$result = $api->listSubscribe($list->ListID, $this->Email, $merge_vars, 'html', $this->DoubleOptIn);
// Must use E-mail For Re-Subscription as listSubscribe() assumes a new user (it actually deletes the existing 'un-subscribed' MailChimp record for the provided e-mail and re-adds the user)
if (empty($api->errorCode)) {
SS_Log::log("API Call Success: listSubscribe(" . $list->ListID . ", " . $this->Email . "); for Subscription ID " . $this->ID, SS_Log::NOTICE);
} else {
SS_Log::log("API Call Failed: listSubscribe(" . $list->ListID . ", " . $this->Email . "); for Subscription ID " . $this->ID . " | Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
}
} else {
if (isset($cf['Subscribed']) && empty($this->Subscribed)) {
// If Just Unsubscribed
$result = $api->listUnsubscribe($list->ListID, $this->getMailChimpIdentifier());
if (empty($api->errorCode)) {
SS_Log::log("API Call Success: listUnsubscribe(" . $list->ListID . ", " . $this->getMailChimpIdentifier() . "); for Subscription ID " . $this->ID, SS_Log::NOTICE);
} else {
SS_Log::log("API Call Failed: listUnsubscribe(" . $list->ListID . ", " . $this->getMailChimpIdentifier() . "); for Subscription ID " . $this->ID . " | Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
}
} else {
if (!empty($this->Subscribed)) {
// If Updating an Existing Subscription (That Hasnt Already Unsubscribed)
$result = $api->listUpdateMember($list->ListID, $this->getMailChimpIdentifier(), $merge_vars);
// If Successfully Updated a Subscription Make a Second Call to Return the MailChimp Member Email ID
if (empty($api->errorCode)) {
SS_Log::log("API Call Success: listUpdateMember(" . $list->ListID . ", " . $this->getMailChimpIdentifier() . "); for Subscription ID " . $this->ID, SS_Log::NOTICE);
if (isset($cf['Email'])) {
$retval = $api->listMemberInfo($list->ListID, $this->Email);
// Call Must Use Email As MCEmailID Will Be Outdated If Last Update Was An Email Change
if (empty($api->errorCode)) {
SS_Log::log("API Call Success: listMemberInfo(" . $list->ListID . ", " . $this->Email . "); for Subscription ID " . $this->ID, SS_Log::NOTICE);
SS_Log::log("Calling Additional write() for Subscription ID " . $this->ID . " to Save Updated MailChimp Email ID", SS_Log::NOTICE);
$this->setField("MCEmailID", $retval['data'][0]['id']);
// Update The MailChimp Email ID for this Member (Which Updates When E-mail Updates)
$this->setSyncMailChimp(false);
$this->write();
} else {
SS_Log::log("API Call Failed: listMemberInfo(" . $list->ListID . ", " . $this->Email . "); for Subscription ID " . $this->ID . " | Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
}
}
} else {
SS_Log::log("API Call Failed: listUpdateMember(" . $list->ListID . ", " . $this->getMailChimpIdentifier() . "); for Subscription ID " . $this->ID . " | Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
//.........这里部分代码省略.........
示例4: filter
public function filter(DataList $list)
{
$now = date('Y-m-d H:i:s');
//to bad ORM filtering for NULL doesn't work...so we need to use where
return $list->where("(\"Discount\".\"StartDate\" IS NULL) OR (\"Discount\".\"StartDate\" < '{$now}')")->where("(\"Discount\".\"EndDate\" IS NULL) OR (\"Discount\".\"EndDate\" > '{$now}')");
}
示例5: addScopeCheck
function addScopeCheck(DataList $list)
{
$scopeField = $this->Scope;
if ($scopeField && ($scopeValue = $this->owner->{$scopeField})) {
//$list = clone $list;
return $list->where("{$scopeField}='{$scopeValue}'");
}
return $list;
}
示例6: search_list
/**
* kind of a wierd thing to add in here
* @param [type] $class [description]
* @param [type] $q [description]
* @param array $fields [description]
* @return [type] [description]
*/
public static function search_list($class, $q, array $fields)
{
// parse terms
$terms = array_merge(static::str_to_terms($q), static::str_to_fragments($q));
$terms[] = $q;
$terms = array_unique($terms);
// generate data list
$list = new DataList($class);
$where = '';
foreach ($fields as $field) {
foreach ($terms as $term) {
if ($where) {
$where .= " OR ";
}
$where .= $field . " LIKE '%" . Convert::raw2sql($term) . "%'";
}
}
return $list->where($where);
}
示例7: getList
/**
* Returns the pages meet a certain criteria as {@see CMSSiteTreeFilter} or the subpages of a parent page
* defaulting to no filter and show all pages in first level.
* Doubles as search results, if any search parameters are set through {@link SearchForm()}.
*
* @param Array Search filter criteria
* @param Int Optional parent node to filter on (can't be combined with other search criteria)
* @return SS_List
*/
public function getList($params, $parentID = 0) {
$list = new DataList($this->stat('tree_class'));
$filter = null;
$ids = array();
if(isset($params['FilterClass']) && $filterClass = $params['FilterClass']){
if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
}
$filter = new $filterClass($params);
$filterOn = true;
foreach($pages=$filter->pagesIncluded() as $pageMap){
$ids[] = $pageMap['ID'];
}
if(count($ids)) $list->where('"'.$this->stat('tree_class').'"."ID" IN ('.implode(",", $ids).')');
} else {
$list->filter("ParentID", is_numeric($parentID) ? $parentID : 0);
}
return $list;
}
示例8: onAfterWrite
public function onAfterWrite()
{
parent::onAfterWrite();
// This is to ensure this only fires once on each write
if ($this->getFirstWrite()) {
// Get Array of updated fields
$UpdatedDataFields = $this->owner->getChangedFields(true, 2);
// Get HasManyList of this Members MCSubscriptions
$subs = $this->owner->getComponents("MCSubscriptions");
// If the Member Has One or More Subscriptions
if (is_object($subs) && $subs->exists()) {
// Foreach of This Members Subscription Objects
foreach ($subs as $sub) {
SS_Log::log("Subscription ID = " . $sub->ID, SS_Log::NOTICE);
// Get DataList of MC List Field Mappings (Excluding LastVisited) Which Are On The Member Class && In A MCList Which Concerns This Member (i.e. One They Are Subscribed To)
// (as if LastVisited is the ONLY updated field it just represents a site login, not an actual manual MC data field update)
$dl = new DataList("MCListField");
$mappings = $dl->where("\"OnClass\" = 'Member' AND \"MCListID\" = '" . $sub->MCListID . "' AND \"SyncDirection\" IN ('Export','Both') AND \"FieldName\" != 'LastVisited'");
// Foreach Mapping Record
foreach ($mappings as $mapping) {
SS_Log::log("Mapping Field Name = " . $mapping->FieldName, SS_Log::NOTICE);
// If The Member FieldName is One of the Updated Fields
if (isset($UpdatedDataFields[$mapping->FieldName])) {
// Mark the Subscription as Being Updated
SS_Log::log("\$UpdatedDataFields['" . $mapping->FieldName . "'] Is Set, doing \$sub->write();", SS_Log::NOTICE);
$sub->setSyncMailChimp($this->getSyncMailChimp());
// Set MCSubscriber Sync to MailChimp Based on This (Member) Sync State
$sub->setForceAdditionalWrite(true);
$sub->write();
break;
}
}
}
} else {
if (isset($UpdatedDataFields["ID"])) {
// Creation Write
// Add New or Link Existing Subscription Records
$subs = MCSubscription::get()->where("\"Email\" = '" . $this->owner->Email . "'");
if (is_object($subs) && $subs->exists()) {
// Link Each Subscriber Object to this Member
foreach ($subs as $sub) {
$sub->setForceAdditionalWrite(true);
$this->owner->getComponents("MCSubscriptions")->add($sub);
}
} else {
// Get the Default MailChimp List To Relate The New Subscription To
$MCList = MCList::get()->sort("\"SortOrder\" ASC")->first();
if (is_object($MCList) && $MCList->exists()) {
// Create New Subscriber Object and Link to New Member
$sub = new MCSubscription();
$sub->setField("FirstName", $this->owner->FirstName);
$sub->setField("Surname", $this->owner->Surname);
$sub->setField("Email", $this->owner->Email);
$sub->setField("MemberID", $this->owner->ID);
$sub->setField("MCListID", $MCList->ID);
$sub->write();
// Link the New Subscriber Object to this Member
$this->owner->getComponents("MCSubscriptions")->add($sub);
} else {
SS_Log::log("No MCList object available to add new MCSubscriptions to when saving Member #" . $this->owner->ID, SS_Log::NOTICE);
}
}
}
}
}
}
示例9: array
<?php
require_once "DataList.php";
$testArray = array(array('name' => 'Anna', 'age' => 22, 'owns' => array('type' => 'furniture', 'label' => 'chair')), array('name' => 'Bill', 'age' => 12, 'owns' => array('type' => 'fruit', 'label' => 'apple')), array('name' => 'Cedric', 'age' => 33, 'owns' => array('type' => 'furniture', 'label' => 'sofa')));
$test = new DataList($testArray);
$test->where('age', '> 15');
$test->where('name', '^[AaBbCc](.*)$');
$test->find();
if ($test->length()) {
$people = $test->sort('name');
foreach ($people as $person) {
echo $person['name'] . ", " . $person['age'] . "\n";
}
}
示例10: CleanUpSubscriptionStatus
public function CleanUpSubscriptionStatus($list = null)
{
if (!is_object($list)) {
SS_Log::log("CleanUpSubscriptionStatus() Requireds MCList Object Parameter!", SS_Log::ERR);
return false;
}
$emails = array();
$api = new MCAPI($this->apikey);
// Get ALL Subscribed List Members
$retval = $api->listMembers($list->ListID, 'subscribed', null, 0, 5000);
if ($api->errorCode) {
SS_Log::log("API Call Failed: listMembers('" . $list->ListID . "', 'subscribed', null, 0, 5000); Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
} else {
SS_Log::log("API Call Success: listMembers('" . $list->ListID . "', 'subscribed', null, 0, 5000); Returned Members = " . $retval['total'], SS_Log::NOTICE);
if ($retval['total'] > 0) {
foreach ($retval['data'] as $member) {
$emails[] = strtolower($member['email']);
}
}
}
// Get ALL Unsubscribed List Members
$retval = $api->listMembers($list->ListID, 'unsubscribed', null, 0, 5000);
if ($api->errorCode) {
SS_Log::log("API Call Failed: listMembers('" . $list->ListID . "', 'unsubscribed', null, 0, 5000); Error Code = " . $api->errorCode . " | Error Message = " . $api->errorMessage, SS_Log::ERR);
} else {
SS_Log::log("API Call Success: listMembers('" . $list->ListID . "', 'unsubscribed', null, 0, 5000); Returned Members = " . $retval['total'], SS_Log::NOTICE);
if ($retval['total'] > 0) {
foreach ($retval['data'] as $member) {
$emails[] = strtolower($member['email']);
}
}
}
if (!empty($emails)) {
// For All Subscription Records On The Webstie Which Arnt In The MailChimp List (MailChimp Admin Panel Deletions and Subscriptions Yet To Be Confirmed)
$dl = new DataList("MCSubscription");
$subs = $dl->where("\"MCListID\" = '" . $list->ID . "' AND LOWER(\"Email\") NOT IN (" . $this->arrayToCSV($emails) . ")");
if (!empty($subs)) {
foreach ($subs as $sub) {
$sub->setField("Subscribed", 0);
$sub->setSyncMailChimp(false);
$sub->write();
}
}
}
}