function handle(DataObject $model) { $db = DB::Instance(); $query = 'SELECT max(complaint_number) FROM ' . $model->getTableName() . ' WHERE usercompanyid=' . EGS_COMPANY_ID . ' AND "type"=' . $db->qstr($model->type); $current = $db->GetOne($query); return $current + 1; }
/** * @covers AuthorizationPolicy */ public function testAuthorizationPolicy() { $policy = new AuthorizationPolicy('some message'); // Test advice. self::assertTrue($policy->hasAdvice(AUTHORIZATION_ADVICE_DENY_MESSAGE)); self::assertFalse($policy->hasAdvice(AUTHORIZATION_ADVICE_CALL_ON_DENY)); self::assertEquals('some message', $policy->getAdvice(AUTHORIZATION_ADVICE_DENY_MESSAGE)); self::assertNull($policy->getAdvice(AUTHORIZATION_ADVICE_CALL_ON_DENY)); // Test authorized context objects. self::assertFalse($policy->hasAuthorizedContextObject(ASSOC_TYPE_USER_GROUP)); $someContextObject = new DataObject(); $someContextObject->setData('test1', 'test1'); $policy->addAuthorizedContextObject(ASSOC_TYPE_USER_GROUP, $someContextObject); self::assertTrue($policy->hasAuthorizedContextObject(ASSOC_TYPE_USER_GROUP)); self::assertEquals($someContextObject, $policy->getAuthorizedContextObject(ASSOC_TYPE_USER_GROUP)); self::assertEquals(array(ASSOC_TYPE_USER_GROUP => $someContextObject), $policy->getAuthorizedContext()); // Test authorized context. $someOtherContextObject = new DataObject(); $someOtherContextObject->setData('test2', 'test2'); $authorizedContext = array(ASSOC_TYPE_USER_GROUP => $someOtherContextObject); $policy->setAuthorizedContext($authorizedContext); self::assertEquals($authorizedContext, $policy->getAuthorizedContext()); // Test default policies. self::assertTrue($policy->applies()); self::assertEquals(AUTHORIZATION_DENY, $policy->effect()); }
public function convert(DataObject $object) { if ($object->hasMethod('toFilteredMap')) { return Convert::raw2json($object->toFilteredMap()); } return Convert::raw2json($object->toMap()); }
/** * @param GridField $gridField * @param DataObject $record * @param string $columnName * * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { // No permission checks - handled through GridFieldDetailForm // which can make the form readonly if no edit permissions are available. $data = new ArrayData(array('Link' => $record->CMSEditLink())); return $data->renderWith('GridFieldEditButton'); }
/** * * @param \GridField $gridField * @param \DataObject $record * @param string $columnName * @return string|null - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if (!$record instanceof \Payment) { return null; } if (!$record->canRefund()) { return null; } \Requirements::css('omnipay-ui/css/omnipay-ui-cms.css'); \Requirements::javascript('omnipay-ui/javascript/omnipay-ui-cms.js'); \Requirements::add_i18n_javascript('omnipay-ui/javascript/lang'); $infoText = ''; switch (GatewayInfo::refundMode($record->Gateway)) { case GatewayInfo::MULTIPLE: $infoText = 'MultiRefundInfo'; break; case GatewayInfo::PARTIAL: $infoText = 'SingleRefundInfo'; break; case GatewayInfo::FULL: $infoText = 'FullRefundInfo'; break; } /** @var \Money $money */ $money = $record->dbObject('Money'); /** @var \GridField_FormAction $field */ $field = \GridField_FormAction::create($gridField, 'RefundPayment' . $record->ID, false, 'refundpayment', array('RecordID' => $record->ID))->addExtraClass('gridfield-button-refund payment-dialog-button')->setAttribute('title', _t('GridFieldRefundAction.Title', 'Refund Payment'))->setAttribute('data-icon', 'button-refund')->setAttribute('data-dialog', json_encode(array('maxAmount' => $money->Nice(), 'maxAmountNum' => $money->getAmount(), 'hasAmountField' => $record->canRefund(null, true), 'infoTextKey' => $infoText, 'buttonTextKey' => 'RefundAmount')))->setDescription(_t('GridFieldRefundAction.Description', 'Refund a captured payment')); return $field->Field(); }
public function scaffoldFormField($title = null, $params = null) { if (empty($this->object)) { return null; } $relationName = substr($this->name, 0, -2); $hasOneClass = $this->object->hasOneComponent($relationName); if (empty($hasOneClass)) { return null; } $hasOneSingleton = singleton($hasOneClass); if ($hasOneSingleton instanceof File) { $field = new UploadField($relationName, $title); if ($hasOneSingleton instanceof Image) { $field->setAllowedFileCategories('image/supported'); } return $field; } // Build selector / numeric field $titleField = $hasOneSingleton->hasField('Title') ? "Title" : "Name"; $list = DataList::create($hasOneClass); // Don't scaffold a dropdown for large tables, as making the list concrete // might exceed the available PHP memory in creating too many DataObject instances if ($list->count() < 100) { $field = new DropdownField($this->name, $title, $list->map('ID', $titleField)); $field->setEmptyString(' '); } else { $field = new NumericField($this->name, $title); } return $field; }
public function testGetLinks() { $dataObject = new DataObject(array(), array(), array('mockLinkRel' => 'mockLinkUri')); $expect = array('mockLinkRel' => 'mockLinkUri'); $actual = $dataObject->getLinks(); $this->assertEquals($expect, $actual); }
protected function walkRelationshipChain(DataObject $from, ArrayList $list, array $parts, $lastPart, $lastItem) { $part = array_shift($parts); if (!$from->hasMethod($part)) { // error, no such part of relationship chain return false; } if (count($parts)) { foreach ($from->{$part}() as $item) { $this->walkRelationshipChain($item, $list, $parts, $part, $item); } } else { $images = $from->{$part}()->toNestedArray(); // mark the images with a source from relationship and ID /** @var Image $image */ foreach ($images as &$image) { if ($lastItem instanceof Variation) { $options = $lastItem->Options(); foreach ($options as $option) { $image['ProductID'] = $lastItem->Product()->ID; $image['VariationID'] = $lastItem->ID; $image['OptionID'] = $option->ID; $image['AttributeID'] = $option->AttributeID; } } } $list->merge(new ArrayList($images)); } return true; }
public function scaffoldFormField($title = null, $params = null) { if (empty($this->object)) { return null; } $relationName = substr($this->name, 0, -2); $hasOneClass = $this->object->hasOneComponent($relationName); if ($hasOneClass && singleton($hasOneClass) instanceof Image) { $field = new UploadField($relationName, $title); $field->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); } elseif ($hasOneClass && singleton($hasOneClass) instanceof File) { $field = new UploadField($relationName, $title); } else { $titleField = singleton($hasOneClass)->hasField('Title') ? "Title" : "Name"; $list = DataList::create($hasOneClass); // Don't scaffold a dropdown for large tables, as making the list concrete // might exceed the available PHP memory in creating too many DataObject instances if ($list->count() < 100) { $field = new DropdownField($this->name, $title, $list->map('ID', $titleField)); $field->setEmptyString(' '); } else { $field = new NumericField($this->name, $title); } } return $field; }
/** * Automatically extracts and replaces the category, keywords and entities * for a data object. * * @param DataObject $object */ public function alchemise(DataObject $object) { if (!$object->hasExtension('Alchemisable')) { throw new Exception('The object must have the Alchemisable extension.'); } $text = $object->getContentForAlchemy(); if (strlen($text) < $this->charLimit) { return; } $alchemyInfo = $object->AlchemyMetadata->getValues(); if (!$alchemyInfo) { $alchemyInfo = array(); } $cat = $this->getCategoryFor($text); $keywords = $this->getKeywordsFor($text); $entities = $this->getEntitiesFor($text); $alchemyInfo['Category'] = $cat; $alchemyInfo['Keywords'] = $keywords; $alchemyInfo['Entities'] = $entities; $object->AlchemyMetadata = $alchemyInfo; // foreach (Alchemisable::entity_fields() as $field => $name) { // $name = substr($field, 3); // // if (array_key_exists($name, $entities)) { // $object->$field = $entities[$name]; // } else { // $object->$field = array(); // } // } }
/** * Send comment notification to a given recipient * * @param Comment $comment * @param DataObject $parent Object with the {@see CommentNotifiable} extension applied * @param Member|string $recipient Either a member object or an email address to which notifications should be sent */ public function notifyCommentRecipient($comment, $parent, $recipient) { $subject = $parent->notificationSubject($comment, $recipient); $sender = $parent->notificationSender($comment, $recipient); $template = $parent->notificationTemplate($comment, $recipient); // Validate email // Important in case of the owner being a default-admin or a username with no contact email $to = $recipient instanceof Member ? $recipient->Email : $recipient; if (!$this->isValidEmail($to)) { return; } // Prepare the email $email = new Email(); $email->setSubject($subject); $email->setFrom($sender); $email->setTo($to); $email->setTemplate($template); $email->populateTemplate(array('Parent' => $parent, 'Comment' => $comment, 'Recipient' => $recipient)); if ($recipient instanceof Member) { $email->populateTemplate(array('ApproveLink' => $comment->ApproveLink($recipient), 'HamLink' => $comment->HamLink($recipient), 'SpamLink' => $comment->SpamLink($recipient), 'DeleteLink' => $comment->DeleteLink($recipient))); } // Until invokeWithExtensions supports multiple arguments if (method_exists($this->owner, 'updateCommentNotification')) { $this->owner->updateCommentNotification($email, $comment, $recipient); } $this->owner->extend('updateCommentNotification', $email, $comment, $recipient); return $email->send(); }
/** * * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if ($this->removeRelation) { $field = GridField_FormAction::create($gridField, 'UnlinkRelation' . $record->ID, false, "unlinkrelation", array('RecordID' => $record->ID))->addExtraClass('gridfield-button-unlink')->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink"))->setAttribute('data-icon', 'chain--minus'); } else { if (!$record->canDelete()) { return; } $field = GridField_FormAction::create($gridField, 'DeleteRecord' . $record->ID, false, "deleterecord", array('RecordID' => $record->ID))->addExtraClass('gridfield-button-delete')->setAttribute('title', _t('GridAction.Delete', "Delete"))->setAttribute('data-icon', 'cross-circle')->setDescription(_t('GridAction.DELETE_DESCRIPTION', 'Delete')); } //add a class to the field to if it is the last gridfield in the list $numberOfRelations = $record->Pages()->Count(); $field->addExtraClass('dms-delete')->setAttribute('data-pages-count', $numberOfRelations)->removeExtraClass('gridfield-button-delete'); //remove the base gridfield behaviour //set a class telling JS what kind of warning to display when clicking the delete button if ($numberOfRelations > 1) { $field->addExtraClass('dms-delete-link-only'); } else { $field->addExtraClass('dms-delete-last-warning'); } //set a class to show if the document is hidden if ($record->isHidden()) { $field->addExtraClass('dms-document-hidden'); } return $field->Field(); }
public static function usedBy($search_data = null, &$errors = array(), $defaults = null, $params = array()) { $search = new SelectorItemSearch($defaults); $search->addSearchField('target_id', 'Target', 'hidden', '', 'hidden'); // Search by Product $config = SelectorCollection::getTypeDetails($params['type']); $search->addSearchField('parent_id', implode('/', $config['itemFields']), 'treesearch', -1, 'basic'); if (empty($search_data)) { $search_data = null; } $search->setSearchData($search_data, $errors, 'selectProduct'); // Populate the parent_id field using the last selected value // it will be -1 if no previous selected value $parent_id = $search->getValue('parent_id'); $cc = new ConstraintChain(); if ($parent_id != '-1') { $cc->add(new Constraint('parent_id', '=', $parent_id)); } else { $cc->add(new Constraint('parent_id', 'IS', 'NULL')); } $model = new DataObject('so_product_selector'); $options = array($parent_id => 'Select an option'); $options += $model->getAll($cc); $search->setOptions('parent_id', $options); if ($parent_id != '-1') { $data = array('target_id' => $search->getValue('target_id')); $search->setBreadcrumbs('parent_id', $model, 'parent_id', $parent_id, 'name', 'description', $data); } return $search; }
/** * Gets the form fields as defined through the metadata * on {@link $obj} and the custom parameters passed to FormScaffolder. * Depending on those parameters, the fields can be used in ajax-context, * contain {@link TabSet}s etc. * * @return FieldList */ public function getFieldList() { $fields = new FieldList(); // tabbed or untabbed if ($this->tabbed) { $fields->push(new TabSet("Root", $mainTab = new Tab("Main"))); $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main")); } //var_dump($this->obj->db());exit(); // add database fields foreach ($this->obj->db() as $fieldName => $fieldType) { if ($this->restrictFields && !in_array($fieldName, $this->restrictFields)) { continue; } // @todo Pass localized title if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) { $fieldClass = $this->fieldClasses[$fieldName]; $fieldObject = new $fieldClass($fieldName); } else { $fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray()); } $fieldObject->setTitle($this->obj->fieldLabel($fieldName)); if ($this->tabbed) { $fields->addFieldToTab("Root.Main", $fieldObject); } else { $fields->push($fieldObject); } } return $fields; }
/** * * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if (!$record->canEdit()) { return; } $data = new ArrayData(array('Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit'))); return $data->renderWith('GridFieldEditButton'); }
/** * * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if (!$record->IsDeletedFromStage && $record->canDelete() && !$record->isPublished()) { $field = GridField_FormAction::create($gridField, 'DeleteFromStage' . $record->ID, false, "deletefromstage", array('RecordID' => $record->ID))->addExtraClass('gridfield-button-deletedraft')->setAttribute('title', _t('PublishableGridFieldAction.DELETE', 'Delete draft'))->setAttribute('data-icon', 'decline')->setDescription(_t('PublishableGridFieldAction.DELETE_DESC', 'Remove this item from the draft site')); return $field->Field(); } return; }
/** * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if (!$record->canDelete()) { return; } $field = GridField_FormAction::create($gridField, 'SoftDeleteRecord' . $record->ID, false, "softdeleterecord", array('RecordID' => $record->ID))->addExtraClass('gridfield-button-delete')->setAttribute('title', _t('GridAction.Delete', "Delete"))->setAttribute('data-icon', 'cross-circle')->setDescription(_t('GridAction.DELETE_DESCRIPTION', 'Delete')); return $field->Field(); }
public function scaffoldFormField($title = null, $params = null) { $titleField = $this->object->hasField('Title') ? 'Title' : 'Name'; $map = DataList::create(get_class($this->object))->map('ID', $titleField); $field = new DropdownField($this->name, $title, $map); $field->setEmptyString(' '); return $field; }
/** * * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if (!$record->canEdit()) { return; } $data = new ArrayData(array('Link' => Controller::join_links(Director::baseURL(), '/admin/pages/edit/show/', $record->ID))); return $data->renderWith('GridFieldEditButton'); }
/** * @param DataObject $record * @param int $index */ public function deleteRecord($record, $index) { if ($record->hasExtension('Versioned')) { $record->deleteFromStage('Stage'); $record->deleteFromStage('Live'); } else { $record->delete(); } }
public static function instance($array=null){ if($array){ $return = new DataObject(); $return->fromArray($array); return $return; }else { return new DataObject(); } }
/** * @param GridField $gridField * @param DataObject $record * @param string $columnName * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if (!$record->canEdit()) { return; } $history_controller = singleton('CMSPageHistoryController'); $data = new ArrayData(array('Link' => Controller::join_links($history_controller->Link('show'), $record->ID))); return $data->renderWith('GridFieldPageHistoryButton'); }
/** * Transform a given form field into a composite field, where the translation is editable and the original value * is added as a read-only field. * @param FormField $field * @return CompositeField */ public function transformFormField(FormField $field) { $newfield = $field->performReadOnlyTransformation(); $fieldname = $field->getName(); if ($this->original->isLocalizedField($fieldname)) { $field->setName($this->original->getLocalizedFieldName($fieldname)); $field->setValue($this->original->getLocalizedValue($fieldname)); } return $this->baseTransform($newfield, $field, $fieldname); }
public function getValue($field) { if ($this->record instanceof DataObject) { if (property_exists($this->record, $field)) { return htmlspecialchars($this->record->{'get' . $field}()); } return in_array($field, $this->record->getDatabaseMap()) ? htmlspecialchars($this->record->{$field}) : ''; } return htmlspecialchars(@$this->record[$field]); }
/** * @param GridField $gridField * @param DataObject $record * @param string $columnName * * @return string - the HTML for the column */ public function getColumnContent($gridField, $record, $columnName) { if (!$record instanceof Member || !$record->canMasquerade()) { return; } // No permission checks, handled through GridFieldDetailForm, // which can make the form readonly if no edit permissions are available. $data = new ArrayData(array('Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'masquerade'))); return $data->renderWith('GridFieldMasqueradeButton'); }
function handle(DataObject $model) { $jn = $model->job_no; if (empty($jn)) { $db = DB::Instance(); $query = 'SELECT max(despatch_number) FROM ' . $model->getTableName() . ' WHERE usercompanyid=' . EGS_COMPANY_ID; $current = $db->GetOne($query); return $current + 1; } }
public function convert(DataObject $object) { if ($object->hasMethod('toFilteredMap')) { $data = $object->toFilteredMap(); } else { $data = $object->toMap(); } $converter = new ArrayToXml('item'); return $converter->convertArray($data); }
public function testBind() { $data = array('test' => 't1'); $ref = 't2'; $obj = new DataObject(); $obj->bind('test', $ref); $this->assertNotEquals($data, $obj->data()); $ref = 't1'; $this->assertEquals($data, $obj->data()); }
/** * Set created_ properties for a given object if not set * * @param DataObject $object * @return null */ function system_handle_on_before_object_insert($object) { if ($object->fieldExists('created_on')) { if (!isset($object->values['created_on'])) { $object->setCreatedOn(new DateTimeValue()); } // if } // if $user =& get_logged_user(); if (!instance_of($user, 'User')) { return; } // if if ($object->fieldExists('created_by_id') && !isset($object->values['created_by_id'])) { $object->setCreatedById($user->getId()); } // if if ($object->fieldExists('created_by_name') && !isset($object->values['created_by_name'])) { $object->setCreatedByName($user->getDisplayName()); } // if if ($object->fieldExists('created_by_email') && !isset($object->values['created_by_email'])) { $object->setCreatedByEmail($user->getEmail()); } // if }
function dataedit() { $this->rapyd->load('dataobject', 'datadetails'); $do = new DataObject("doc_tablas"); $do->rel_one_to_many('doc_campos', 'doc_campos', array('nombre' => 'tabla')); $edit = new DataDetails("Documentación de Tablas", $do); $edit->back_url = site_url($this->url . "filteredgrid"); $edit->set_rel_title('doc_campos', 'Rubro <#o#>'); $edit->pre_process('insert', '_valida'); $edit->pre_process('update', '_valida'); $edit->nombre = new inputField("Nombre", "nombre"); $edit->nombre->mode = "autohide"; $edit->nombre->size = 15; $edit->referen = new textareaField("Descripcion", "referen"); $edit->referen->size = 50; $edit->referen->rows = 2; $edit->referen->cols = 90; $edit->itcampo = new inputField("(<#o#>) Campo", "itcampo_<#i#>"); $edit->itcampo->db_name = 'campo'; $edit->itcampo->rel_id = 'doc_campos'; $edit->itcampo->rule = 'required|callback_chexiste'; $edit->itcampo->size = 15; $edit->ittype = new inputField("(<#o#>) Type", "ittype_<#i#>"); $edit->ittype->db_name = 'dtype'; $edit->ittype->rel_id = 'doc_campos'; $edit->ittype->size = 15; $edit->itnull = new inputField("(<#o#>) Null", "itnull_<#i#>"); $edit->itnull->db_name = 'dnull'; $edit->itnull->rel_id = 'doc_campos'; $edit->itnull->size = 3; $edit->itkey = new inputField("(<#o#>) key", "itkey_<#i#>"); $edit->itkey->db_name = 'dkey'; $edit->itkey->rel_id = 'doc_campos'; $edit->itkey->size = 3; $edit->itdefault = new inputField("(<#o#>) Default", "itdefault_<#i#>"); $edit->itdefault->db_name = 'ddefault'; $edit->itdefault->rel_id = 'doc_campos'; $edit->itdefault->size = 5; $edit->itextra = new inputField("(<#o#>) Extra", "itextra_<#i#>"); $edit->itextra->db_name = 'dextra'; $edit->itextra->rel_id = 'doc_campos'; $edit->itextra->size = 10; $edit->itdcomment = new textareaField("(<#o#>) Comentario", "itdcomment_<#i#>"); $edit->itdcomment->db_name = 'dcomment'; $edit->itdcomment->rel_id = 'doc_campos'; $edit->itdcomment->cols = 40; $edit->itdcomment->rows = 2; $edit->buttons("modify", "save", "undo", "back", "add_rel"); $edit->build(); $conten["form"] =& $edit; $data['content'] = $this->load->view('view_tablas', $conten, true); $data['title'] = "Documentación de Tablas"; $data["head"] = $this->rapyd->get_head() . script('jquery.js'); $this->load->view('view_ventanas', $data); }