当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayList::find方法代码示例

本文整理汇总了PHP中ArrayList::find方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::find方法的具体用法?PHP ArrayList::find怎么用?PHP ArrayList::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayList的用法示例。


在下文中一共展示了ArrayList::find方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getTagsCollection

 public function getTagsCollection()
 {
     $allTags = new ArrayList();
     $max = 0;
     $member = Member::currentUser();
     // Find if we need to filter tags by current discussion page
     $controller = Controller::curr();
     if (method_exists($controller, "data")) {
         $page = $controller->data();
     } else {
         $page = null;
     }
     if ($page != null && $page instanceof DiscussionPage) {
         $discussions = $page->Discussions();
     } else {
         $discussions = Discussion::get();
     }
     if ($discussions) {
         foreach ($discussions as $discussion) {
             if ($discussion->canView($member)) {
                 $theseTags = preg_split(" *, *", trim($discussion->Tags));
                 foreach ($theseTags as $tag) {
                     if ($tag) {
                         if ($allTags->find("Tag", $tag)) {
                             $allTags->find("Tag", $tag)->Count++;
                         } else {
                             $allTags->push(new ArrayData(array("Tag" => $tag, "Count" => 1, "Link" => Controller::join_links($discussion->Parent()->Link("tag"), Convert::raw2url($tag)))));
                         }
                         $tag_count = $allTags->find("Tag", $tag)->Count;
                         $max = $tag_count > $max ? $tag_count : $max;
                     }
                 }
             }
         }
         if ($allTags->exists()) {
             // First sort our tags
             $allTags->sort($this->SortParam, $this->SortOrder);
             // Now if a limit has been set, limit the list
             if ($this->Limit) {
                 $allTags = $allTags->limit($this->Limit);
             }
         }
         return $allTags;
     }
     return;
 }
开发者ID:i-lateral,项目名称:silverstripe-discussions,代码行数:46,代码来源:DiscussionsTagsWidget.php

示例2: update

 /**
  * Find an existing item and update its quantity
  *
  * @param Item
  * @param Quantity
  */
 public function update($item_key, $quantity)
 {
     $item = $this->items->find("Key", $item_key);
     if ($item) {
         $item->Quantity = $quantity;
         $this->extend("onBeforeUpdate", $item);
         $this->save();
     }
     return false;
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-checkout,代码行数:16,代码来源:ShoppingCart.php

示例3: update

 /**
  * Find an existing item and update its quantity
  *
  * @param Item
  * @param Quantity
  */
 public function update($item_key, $quantity)
 {
     $item = $this->items->find("Key", $item_key);
     if ($item) {
         // If we need to track stock, do it now
         if ($this->config()->check_stock_levels) {
             $item->checkStockLevel($quantity);
         }
         $item->Quantity = floor($quantity);
         $this->extend("onBeforeUpdate", $item);
         $this->save();
     }
     return false;
 }
开发者ID:i-lateral,项目名称:silverstripe-checkout,代码行数:20,代码来源:ShoppingCart.php

示例4: testFind

 public function testFind()
 {
     $list = new ArrayList(array(array('Name' => 'Steve'), (object) array('Name' => 'Bob'), array('Name' => 'John')));
     $this->assertEquals($list->find('Name', 'Bob'), (object) array('Name' => 'Bob'));
 }
开发者ID:maent45,项目名称:redefine_renos,代码行数:5,代码来源:ArrayListTest.php

示例5: process


//.........这里部分代码省略.........
                     if ($file->getAbsoluteSize() < 1024 * 1024 * 1) {
                         $attachments[] = $file;
                     }
                 }
             }
         }
         $submittedField->extend('onPopulationFromField', $field);
         if (!$this->DisableSaveSubmissions) {
             $submittedField->write();
         }
         $submittedFields->push($submittedField);
     }
     $emailData = array("Sender" => Member::currentUser(), "Fields" => $submittedFields);
     $this->extend('updateEmailData', $emailData, $attachments);
     // email users on submit.
     if ($recipients = $this->FilteredEmailRecipients($data, $form)) {
         $email = new UserDefinedForm_SubmittedFormEmail($submittedFields);
         $mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
         if ($attachments) {
             foreach ($attachments as $file) {
                 if ($file->ID != 0) {
                     $email->attachFile($file->Filename, $file->Filename, HTTP::get_mime_type($file->Filename));
                 }
             }
         }
         foreach ($recipients as $recipient) {
             $parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
             if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {
                 $email->setTemplate($recipient->EmailTemplate);
             }
             $email->populateTemplate($recipient);
             $email->populateTemplate($emailData);
             $email->setFrom($recipient->EmailFrom);
             $email->setBody($parsedBody);
             $email->setTo($recipient->EmailAddress);
             $email->setSubject($recipient->EmailSubject);
             if ($recipient->EmailReplyTo) {
                 $email->setReplyTo($recipient->EmailReplyTo);
             }
             // check to see if they are a dynamic reply to. eg based on a email field a user selected
             if ($recipient->SendEmailFromField()) {
                 $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
                 if ($submittedFormField && is_string($submittedFormField->Value)) {
                     $email->setReplyTo($submittedFormField->Value);
                 }
             }
             // check to see if they are a dynamic reciever eg based on a dropdown field a user selected
             if ($recipient->SendEmailToField()) {
                 $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
                 if ($submittedFormField && is_string($submittedFormField->Value)) {
                     $email->setTo($submittedFormField->Value);
                 }
             }
             // check to see if there is a dynamic subject
             if ($recipient->SendEmailSubjectField()) {
                 $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
                 if ($submittedFormField && trim($submittedFormField->Value)) {
                     $email->setSubject($submittedFormField->Value);
                 }
             }
             $this->extend('updateEmail', $email, $recipient, $emailData);
             if ($recipient->SendPlain) {
                 $body = strip_tags($recipient->getEmailBodyContent()) . "\n";
                 if (isset($emailData['Fields']) && !$recipient->HideFormData) {
                     foreach ($emailData['Fields'] as $Field) {
                         $body .= $Field->Title . ': ' . $Field->Value . " \n";
                     }
                 }
                 $email->setBody($body);
                 $email->sendPlain();
             } else {
                 $email->send();
             }
         }
     }
     $submittedForm->extend('updateAfterProcess');
     Session::clear("FormInfo.{$form->FormName()}.errors");
     Session::clear("FormInfo.{$form->FormName()}.data");
     $referrer = isset($data['Referrer']) ? '?referrer=' . urlencode($data['Referrer']) : "";
     // set a session variable from the security ID to stop people accessing
     // the finished method directly.
     if (!$this->DisableAuthenicatedFinishAction) {
         if (isset($data['SecurityID'])) {
             Session::set('FormProcessed', $data['SecurityID']);
         } else {
             // if the form has had tokens disabled we still need to set FormProcessed
             // to allow us to get through the finshed method
             if (!$this->Form()->getSecurityToken()->isEnabled()) {
                 $randNum = rand(1, 1000);
                 $randHash = md5($randNum);
                 Session::set('FormProcessed', $randHash);
                 Session::set('FormProcessedNum', $randNum);
             }
         }
     }
     if (!$this->DisableSaveSubmissions) {
         Session::set('userformssubmission' . $this->ID, $submittedForm->ID);
     }
     return $this->redirect($this->Link('finished') . $referrer . $this->config()->finished_anchor);
 }
开发者ID:sekjal,项目名称:silverstripe-userforms,代码行数:101,代码来源:UserDefinedForm.php

示例6: getTaxRatesWithoutFees

 /**
  * Returns the sum of tax amounts grouped by tax rates for the products
  * of the order.
  *
  * @param boolean $includeChargesForProducts Indicates wether to include charges and
  *                                           discounts for products
  * @param boolean $includeChargesForTotal    Indicates wether to include charges and
  *                                           discounts for the shopping cart total
  * 
  * @return ArrayList
  */
 public function getTaxRatesWithoutFees($includeChargesForProducts = false, $includeChargesForTotal = false)
 {
     if ($includeChargesForTotal === 'false') {
         $includeChargesForTotal = false;
     }
     if ($includeChargesForProducts === 'false') {
         $includeChargesForProducts = false;
     }
     $taxes = new ArrayList();
     foreach ($this->SilvercartOrderPositions() as $orderPosition) {
         if (!$includeChargesForProducts && $orderPosition->isChargeOrDiscount && $orderPosition->chargeOrDiscountModificationImpact == 'productValue' || !$includeChargesForTotal && $orderPosition->isChargeOrDiscount && $orderPosition->chargeOrDiscountModificationImpact == 'totalValue') {
             continue;
         }
         $taxRate = $orderPosition->TaxRate;
         if ($taxRate == '') {
             $taxRate = 0;
         }
         if ($taxRate >= 0 && !$taxes->find('Rate', $taxRate)) {
             $taxes->push(new DataObject(array('Rate' => $taxRate, 'AmountRaw' => 0.0)));
         }
         $taxSection = $taxes->find('Rate', $taxRate);
         $taxSection->AmountRaw += $orderPosition->TaxTotal;
     }
     foreach ($taxes as $tax) {
         $taxObj = new Money();
         $taxObj->setAmount($tax->AmountRaw);
         $taxObj->setCurrency(SilvercartConfig::DefaultCurrency());
         $tax->Amount = $taxObj;
     }
     return $taxes;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:42,代码来源:SilvercartOrder.php

示例7: ExportFullSchedule

 public function ExportFullSchedule()
 {
     $sort = $this->getRequest()->getVar('sort') ? $this->getRequest()->getVar('sort') : 'day';
     $show_desc = $this->getRequest()->getVar('show_desc') ? $this->getRequest()->getVar('show_desc') : false;
     $base = Director::protocolAndHost();
     if (is_null($this->Summit())) {
         return $this->httpError(404, 'Sorry, summit not found');
     }
     $schedule = $this->Summit()->getSchedule();
     $events = new ArrayList();
     $sort_list = false;
     foreach ($schedule as $event) {
         switch ($sort) {
             case 'day':
                 $group_label = $event->getDayLabel();
                 break;
             case 'track':
                 if (!$event->isPresentation() || !$event->Category() || !$event->Category()->Title) {
                     continue 2;
                 }
                 $group_label = $event->Category()->Title;
                 $sort_list = true;
                 break;
             case 'event_type':
                 $group_label = $event->Type->Type;
                 $sort_list = true;
                 break;
         }
         if ($group_array = $events->find('Group', $group_label)) {
             $group_array->Events->push($event);
         } else {
             $group_array = new ArrayData(array('Group' => $group_label, 'Events' => new ArrayList()));
             $group_array->Events->push($event);
             $events->push($group_array);
         }
     }
     if ($sort_list) {
         $events->sort('Group');
     }
     $html_inner = $this->renderWith(array('SummitAppMySchedulePage_pdf'), array('Schedule' => $events, 'Summit' => $this->Summit(), 'ShowDescription' => $show_desc, 'Heading' => 'Full Schedule by ' . $sort));
     $css = @file_get_contents($base . "/summit/css/summitapp-myschedule-pdf.css");
     //create pdf
     $file = FileUtils::convertToFileName('full-schedule') . '.pdf';
     $html_outer = sprintf("<html><head><style>%s</style></head><body><div class='container'>%s</div></body></html>", $css, $html_inner);
     try {
         $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(15, 5, 15, 5));
         $html2pdf->setTestIsImage(false);
         $html2pdf->WriteHTML($html_outer);
         //clean output buffer
         ob_end_clean();
         $html2pdf->Output($file, "D");
     } catch (HTML2PDF_exception $e) {
         $message = array('errno' => '', 'errstr' => $e->__toString(), 'errfile' => 'SummitAppSchedPage.php', 'errline' => '', 'errcontext' => '');
         SS_Log::log($message, SS_Log::ERR);
         $this->httpError(404, 'There was an error on PDF generation!');
     }
 }
开发者ID:hogepodge,项目名称:openstack-org,代码行数:57,代码来源:SummitAppSchedPage.php

示例8: process

 /**
  * Process the form that is submitted through the site
  * 
  * @param Array Data
  * @param Form Form 
  * @return Redirection
  */
 public function process($data, $form)
 {
     Session::set("FormInfo.{$form->FormName()}.data", $data);
     Session::clear("FormInfo.{$form->FormName()}.errors");
     foreach ($this->Fields() as $field) {
         $messages[$field->Name] = $field->getErrorMessage()->HTML();
         if ($field->Required && $field->CustomRules()->Count() == 0) {
             if (!isset($data[$field->Name]) || !$data[$field->Name] || !$field->getFormField()->validate($this->validator)) {
                 $form->addErrorMessage($field->Name, $field->getErrorMessage()->HTML(), 'bad');
             }
         }
     }
     if (Session::get("FormInfo.{$form->FormName()}.errors")) {
         Controller::curr()->redirectBack();
         return;
     }
     $submittedForm = Object::create('SubmittedForm');
     $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
     $submittedForm->ParentID = $this->ID;
     // if saving is not disabled save now to generate the ID
     if (!$this->DisableSaveSubmissions) {
         $submittedForm->write();
     }
     $values = array();
     $attachments = array();
     $submittedFields = new ArrayList();
     foreach ($this->Fields() as $field) {
         if (!$field->showInReports()) {
             continue;
         }
         $submittedField = $field->getSubmittedFormField();
         $submittedField->ParentID = $submittedForm->ID;
         $submittedField->Name = $field->Name;
         $submittedField->Title = $field->getField('Title');
         // save the value from the data
         if ($field->hasMethod('getValueFromData')) {
             $submittedField->Value = $field->getValueFromData($data);
         } else {
             if (isset($data[$field->Name])) {
                 $submittedField->Value = $data[$field->Name];
             }
         }
         if (!empty($data[$field->Name])) {
             if (in_array("EditableFileField", $field->getClassAncestry())) {
                 if (isset($_FILES[$field->Name])) {
                     // create the file from post data
                     $upload = new Upload();
                     $file = new File();
                     $file->ShowInSearch = 0;
                     try {
                         $upload->loadIntoFile($_FILES[$field->Name], $file);
                     } catch (ValidationException $e) {
                         $validationResult = $e->getResult();
                         $form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
                         Controller::curr()->redirectBack();
                         return;
                     }
                     // write file to form field
                     $submittedField->UploadedFileID = $file->ID;
                     // attach a file only if lower than 1MB
                     if ($file->getAbsoluteSize() < 1024 * 1024 * 1) {
                         $attachments[] = $file;
                     }
                 }
             }
         }
         if (!$this->DisableSaveSubmissions) {
             $submittedField->write();
         }
         $submittedFields->push($submittedField);
     }
     $emailData = array("Sender" => Member::currentUser(), "Fields" => $submittedFields);
     // email users on submit.
     if ($this->EmailRecipients()) {
         $email = new UserDefinedForm_SubmittedFormEmail($submittedFields);
         $email->populateTemplate($emailData);
         if ($attachments) {
             foreach ($attachments as $file) {
                 if ($file->ID != 0) {
                     $email->attachFile($file->Filename, $file->Filename, HTTP::get_mime_type($file->Filename));
                 }
             }
         }
         foreach ($this->EmailRecipients() as $recipient) {
             $email->populateTemplate($recipient);
             $email->populateTemplate($emailData);
             $email->setFrom($recipient->EmailFrom);
             $email->setBody($recipient->EmailBody);
             $email->setSubject($recipient->EmailSubject);
             $email->setTo($recipient->EmailAddress);
             // check to see if they are a dynamic sender. eg based on a email field a user selected
             if ($recipient->SendEmailFromField()) {
                 $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
//.........这里部分代码省略.........
开发者ID:nzjoel,项目名称:silverstripe-userforms,代码行数:101,代码来源:UserDefinedForm.php

示例9: accessible_sites

 /**
  * Return the subsites that the current user can access by given permission.
  * Sites will only be included if they have a Title.
  *
  * @param $permCode array|string Either a single permission code or an array of permission codes.
  * @param $includeMainSite If true, the main site will be included if appropriate.
  * @param $mainSiteTitle The label to give to the main site
  * @param $member
  * @return DataList of {@link Subsite} instances
  */
 public static function accessible_sites($permCode, $includeMainSite = true, $mainSiteTitle = "Main site", $member = null)
 {
     // Rationalise member arguments
     if (!$member) {
         $member = Member::currentUser();
     }
     if (!$member) {
         return new ArrayList();
     }
     if (!is_object($member)) {
         $member = DataObject::get_by_id('Member', $member);
     }
     // Rationalise permCode argument
     if (is_array($permCode)) {
         $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'";
     } else {
         $SQL_codes = "'" . Convert::raw2sql($permCode) . "'";
     }
     // Cache handling
     $cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle;
     if (isset(self::$_cache_accessible_sites[$cacheKey])) {
         return self::$_cache_accessible_sites[$cacheKey];
     }
     $subsites = DataList::create('Subsite')->where("\"Subsite\".\"Title\" != ''")->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"")->innerJoin('Group', "\"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\" OR \"Group\".\"AccessAllSubsites\" = 1")->innerJoin('Group_Members', "\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = {$member->ID}")->innerJoin('Permission', "\"Group\".\"ID\"=\"Permission\".\"GroupID\" AND \"Permission\".\"Code\" IN ({$SQL_codes}, 'CMS_ACCESS_LeftAndMain', 'ADMIN')");
     if (!$subsites) {
         $subsites = new ArrayList();
     }
     $rolesSubsites = DataList::create('Subsite')->where("\"Subsite\".\"Title\" != ''")->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"")->innerJoin('Group', "\"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\" OR \"Group\".\"AccessAllSubsites\" = 1")->innerJoin('Group_Members', "\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = {$member->ID}")->innerJoin('Group_Roles', "\"Group_Roles\".\"GroupID\"=\"Group\".\"ID\"")->innerJoin('PermissionRole', "\"Group_Roles\".\"PermissionRoleID\"=\"PermissionRole\".\"ID\"")->innerJoin('PermissionRoleCode', "\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" AND \"PermissionRoleCode\".\"Code\" IN ({$SQL_codes}, 'CMS_ACCESS_LeftAndMain', 'ADMIN')");
     if (!$subsites && $rolesSubsites) {
         return $rolesSubsites;
     }
     $subsites = new ArrayList($subsites->toArray());
     if ($rolesSubsites) {
         foreach ($rolesSubsites as $subsite) {
             if (!$subsites->find('ID', $subsite->ID)) {
                 $subsites->push($subsite);
             }
         }
     }
     if ($includeMainSite) {
         if (!is_array($permCode)) {
             $permCode = array($permCode);
         }
         if (self::hasMainSitePermission($member, $permCode)) {
             $subsites = $subsites->toArray();
             $mainSite = new Subsite();
             $mainSite->Title = $mainSiteTitle;
             array_unshift($subsites, $mainSite);
             $subsites = ArrayList::create($subsites);
         }
     }
     self::$_cache_accessible_sites[$cacheKey] = $subsites;
     return $subsites;
 }
开发者ID:hamaka,项目名称:silverstripe-subsites,代码行数:64,代码来源:Subsite.php

示例10: getTaxRatesWithoutFeesAndCharges

 /**
  * Returns tax amounts included in the shoppingcart separated by tax rates
  * without fee taxes.
  *
  * @param array $excludeModules              An array of registered modules that shall not
  *                                           be taken into account.
  * @param array $excludeShoppingCartPosition Positions that shall not be counted
  *
  * @return ArrayList
  */
 public function getTaxRatesWithoutFeesAndCharges($excludeModules = array(), $excludeShoppingCartPosition = false)
 {
     $positions = $this->SilvercartShoppingCartPositions();
     $taxes = new ArrayList();
     $registeredModules = $this->callMethodOnRegisteredModules('ShoppingCartPositions', array(SilvercartCustomer::currentUser()->getCart(), SilvercartCustomer::currentUser(), true), $excludeModules, $excludeShoppingCartPosition);
     // products
     foreach ($positions as $position) {
         $taxRate = $position->SilvercartProduct()->getTaxRate();
         $originalTaxRate = $position->SilvercartProduct()->getTaxRate(true);
         if (!$taxes->find('Rate', $taxRate)) {
             $taxes->push(new DataObject(array('Rate' => $taxRate, 'OriginalRate' => $originalTaxRate, 'AmountRaw' => (double) 0.0)));
         }
         $taxSection = $taxes->find('Rate', $taxRate);
         $taxSection->AmountRaw += $position->getTaxAmount();
     }
     // Registered Modules
     foreach ($registeredModules as $moduleName => $moduleOutput) {
         foreach ($moduleOutput as $modulePosition) {
             $taxRate = $modulePosition->TaxRate;
             if (!$taxes->find('Rate', $taxRate)) {
                 $taxes->push(new DataObject(array('Rate' => $taxRate, 'OriginalRate' => $taxRate, 'AmountRaw' => (double) 0.0)));
             }
             $taxSection = $taxes->find('Rate', $taxRate);
             $taxAmount = $modulePosition->TaxAmount;
             $taxSection->AmountRaw = round($taxSection->AmountRaw + $taxAmount, 4);
         }
     }
     foreach ($taxes as $tax) {
         $taxObj = new Money();
         $taxObj->setAmount($tax->AmountRaw);
         $taxObj->setCurrency(SilvercartConfig::DefaultCurrency());
         $tax->Amount = $taxObj;
     }
     return $taxes;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:45,代码来源:SilvercartShoppingCart.php

示例11: get_test

 /**
  * @param string $id
  * @return YepnopeTestObject|null
  */
 public function get_test($id)
 {
     return $this->yepnopeTests->find('id', $id);
 }
开发者ID:helpfulrobot,项目名称:kinglozzer-yepnopesilverstripe,代码行数:8,代码来源:Yepnope.php

示例12: getPurchasedProducts

 /**
  * Returns a customers purchased products
  * 
  * @return ArrayList
  */
 public function getPurchasedProducts()
 {
     $orders = $this->owner->SilvercartOrder();
     $purchasedProducts = new ArrayList();
     foreach ($orders as $order) {
         $positions = $order->SilvercartOrderPositions();
         foreach ($positions as $position) {
             if (!$purchasedProducts->find('ID', $position->SilvercartProductID)) {
                 $purchasedProducts->push($position->SilvercartProduct());
             }
         }
     }
     return $purchasedProducts;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:19,代码来源:SilvercartCustomer.php


注:本文中的ArrayList::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。