applicable_formats for only the user 'My home' - moodle

What needs to be in the array in the applicable_formats() function so it only is available on the My home page of the user? I've set my-index to true.
acces.php
<?php
$capabilities = array(
'block/groups:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/groups:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
I've copied access.php from the blocks tutorial and only changed the names

UPDATE - it should be just 'my' rather than 'my-index'.
Also just for completeness, you might want to add all = false
public function applicable_formats() {
return array('all' => false, my' => true);
}

Related

Create custom module without bean to show up in menu

I am wondering how to create custom module in SugarCRM and show link into the menu bar. So my custom module will not be a Bean, but needs to be visible in menu bar.
My manifest.php file is as follows:
$manifest = array(
'acceptable_sugar_versions' => array(
"rege_matches" => array("5.1.*")
),
'acceptable_sugar_flavors' => array(
'CE'
),
'name' => 'CustomModule',
'version' => '1.0',
'description' => 'CustomModule for SugarCRM',
'author' => 'Community',
'published_date' => '2015/02/17',
'type' => 'module',
'icon' => 'icons/default/icon_CustomModule.gif',
'is_uninstallable' => 'true',
);
$installdefs = array(
'id'=> 'CustomModule',
'copy' => array (
array (
'from' => '<basepath>/package/CustomModule',
'to' => 'modules/CustomModule',
),
),
'language' => array(
array(
'language'=> 'en_us',
'from'=> '<basepath>/package/language/application/en_us.lang.php',
'to_module' => 'application',
'language' => 'en_us',
),
),
);
Thanks!

zend_form isValid always false

I write code for a site that uses Zend 1.
I want to rewrite the old admin interface in zend, but my form fails to validate.
I'll post the form, the validation code and the debug output here.
Form:
class Form_Admin_Address_Neu extends Zend_Form {
public function init() {
$this->setMethod('post');
$this->addElement('text', '_street', array(
'label' => 'Strasse:',
'size' => 60,
'required' => true,
'filters' => array('StringTrim'),
));
$this->addElement('text', '_zip', array(
'label' => 'PLZ:',
'size' => 6,
'required' => true,
'filters' => array('StringTrim'),
));
$this->addElement('text', '_city', array(
'label' => 'Stadt:',
'required' => true,
'size' => 30,
'filters' => array('StringTrim'),
));
$this->addElement('text', '_lat', array(
'label' => 'Latitude:',
'required' => true,
'size' => 30,
'validators' => array('Float'),
'filters' => array('Stringtrim'),
));
$this->addElement('text', '_lng', array(
'label' => 'Longitude:',
'required' => true,
'size' => 30,
'validators' => array('Float'),
'filters' => array('Stringtrim'),
));
$this->addElement('checkbox', '_hidden', array(
'label' => 'Hidden:',
'size' => 1,
'filters' => array('Int', 'Null'),
));
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Senden',
));
$this->addElement('hash', 'csrf', array(
'ignore' => true,
));
$this->setAction('/admin/address/list');
}
}
additional fields (i just post 1 here, 2nd is like it):
class Form_Admin_Elements_CountrySelect extends Zend_Form_Element_Select {
public function init() {
$countrymapper = new Mapper_Country();
$this->addMultiOption(0, 'Please select...');
foreach ($countrymapper->fetchAll() as $country) {
$this->addMultiOption($country->getId(), $country->getName());
}
$this->setLabel("Land:");
}
}
Code:
$addForm = new Form_Admin_Address_Neu();
$regionselect = new Form_Admin_Elements_RegionSelect('region_id');
$regionselect->setRequired(true);
$addForm->addElement($regionselect);
$countryselect = new Form_Admin_Elements_CountrySelect('country_id');
$countryselect->setRequired(true);
$addForm->addElement($countryselect);
if ($addForm->isValid($_POST)) {
...
} else {
print_r($_POST);
print_r($addForm->getErrorMessages());
print_r($addForm->getCustomMessages());
print_r($addForm->getErrors());
}
output:
Array
(
[_street] => sdvdsvsv
[_zip] => 111111
[_city] => sdfgsf
[_lat] => 1.0
[_lng] => 2.1
[_hidden] => 0
[country_id] => 1
[region_id] => 3
[submit] => Senden
[csrf] => d18dfed9d26e28d7a52aa4983b00667e
)
Array
(
)
Array
(
)
Array
(
[_street] => Array
(
)
[_zip] => Array
(
)
[_city] => Array
(
)
[_lat] => Array
(
[0] => notFloat
)
[_lng] => Array
(
[0] => notFloat
)
[_hidden] => Array
(
)
[submit] => Array
(
)
[csrf] => Array
(
)
[region_id] => Array
(
)
[country_id] => Array
(
)
)
As I see it, the validation fails, but i dont know why.
The values are present in the $_POST, but the form doesnt validate.
i even tried with isValidPartial(), but same result.
I think i'm doing something fundamentally wrong.
A hint would be great.
ty in advance
Try to enter a comma instead of a point in Latitude and Longitude.
1,0 and 2,1 instead of 1.0 and 2.1
I think it's a problem about Locale of your validator

cakephp form validation password comparision

I have a function to reset a password.
At the point where I have to compare the password and the password_confirm field, I get a strange behavior:
My form
echo $this->Form->hidden('tkn', array('value' => $tkn));
echo $this->Form->hidden('uid', array('value' => $uid));
echo $this->Form->input('password',array('type' => 'password', 'name' => 'data[Appuser][password]'));
echo $this->Form->input('password_confirm',array('type' => 'password', 'name' => 'data[Appuser][password_confirm]'));
My model validation:
var $validate = array(
'password' => array(
'rule' => array('minLength', '6'),
'message' => '{password} minLength 6!'
),
'password_confirm' => array(
'rule' => array('equaltofield','password'),
'message' => '{password_confirm} not equal!'
),
);
function equaltofield($val1, $val2){
return $this->data[$this->alias][key($val1)] == $this->data[$this->alias][$val2];
}
My Controller:
if($this->Appuser->save($this->data)){
$this->Session->setFlash(__('Password has been updated'));
}else{
debug($this->Appuser->invalidFields());
}
Now:
When I submit an empty form I get the following returned from the invalidFields()
array(
'password' => '*****',
'password_confirm' => array(
(int) 0 => '{password_confirm} not equal!',
(int) 1 => '{password_confirm} not equal!'
)
)
Question 1: Why do I not get the message, that the password has not its minlength?
Question 2: Why do I get the second message twice for comparing the password?
When typing in 2 different password with min length, I get this again:
array(
'password_confirm' => array(
(int) 0 => '{password_confirm} not equal!',
(int) 1 => '{password_confirm} not equal!'
)
)
When debug($this->data) I also get this (if that helps somehow)
array(
'Api' => array(
'tkn' => '6837d241bf1076c3c55a95abbcfafa04dc19a33c',
'uid' => '1'
),
'Appuser' => array(
'password' => '*****',
'password_confirm' => 'asdfgh'
)
)
Any ideas regarding my two questions above?
Thanks in advance!!
Try this
var $validate = array(
'password' => array(
'rule' => array('minLength', '6'),
'message' => '{password} minLength 6!'
),
'password_confirm' => array(
'rule' => 'equaltofield',
'message' => '{password_confirm} not equal!'
),
);
function equaltofield($data){
return $this->data[$this->alias]['password'] == $this->data[$this->alias]['password_confirm'];
}

how to use "filerenameupload" filter in zend framework2?

i add file element in form class with:
$this->add(array(
'type' => 'Zend\Form\Element\File',
'name' => 'logo_file',
'options' => array(
'label' => 'Select your logo image file:',
),
));
then add filter in model for filtering form data. i use "filerenameupload" filter to upload selected file :
$inputFilter = new InputFilter();
$inputFilter->add($factory->createInput(array(
'name' => 'logo_file',
'required' => false,
'filters' => array(
array('name' => 'filerenameupload',
'options'=>array(
//'target' => "./data/logo.png",
'randomize' => true,
)
),
),
)));
and in controller i call setInputFilter, setData and isValid normally. other elements go filter good, but "logo_file" does not be saved in "./data/logo.png".
in fact "filter" function in "Zend\Filter\File\RenameUpload" class does not be executed.
i use this link :
zf2 File Uploding Toturial
Someone's trying to solve this problem?
Have you tried using the full name for the Filter?
array(
'name' => 'Zend\Filter\File\RenameUpload'
)
You also need to make sure you add both the files array and the POST data to the form when validating, example:
$postArr = $request->getPost()->toArray();
$fileArr = $this->params()->fromFiles('logo_file');
$formData = array_merge(
$postArr, // $_POST
array('logo_file' => $fileArr['name']) // $_FILE...
);
$importForm->setData($formData);
Try:
Form.php:
public function addElements(){
$this->add(array(
'name' => 'image',
'attributes' => array(
'type' => 'file',
),
'options' => array(
),
));
FormValidator.php
public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
"name" => "image",
"required" => true,
"filters" => array(
array("name" => "StripTags"),
array("name" => "StringTrim"),
array(
"name" => "Zend\Filter\File\RenameUpload",
"options" => array(
"target" => '/home/limonazzo/UPLOADDIR<----------',
"randomize" => true,
"use_upload_name" => true,
"use_upload_extension" => true
)
)
),
"validators" => array(
array(
"name" => "Zend\Validator\File\IsImage",
"break_chain_on_failure" => true,
"options" => array(
),
),
array(
"name" => "Zend\Validator\File\Extension",
"break_chain_on_failure" => true,
"options" => array(
"extension" => "jpg,jpeg,png",
),
),
array(
"name" => "Zend\Validator\File\Size",
"break_chain_on_failure" => true,
"options" => array(
"min" => "1kB",
"max" => "1024kB",
),
),
array(
"name" => "Zend\Validator\File\ImageSize",
"break_chain_on_failure" => true,
"options" => array(
"minWidth" => 10,
"minHeight" => 10,
"maxWidth" => 250,
"maxHeight" => 350,
),
),
),
)));
In controlle.php
$form = new Form();
$formValidator = new FormValidator();
$form->setInputFilter($formValidator->getInputFilter(''));
if ($form->isValid()) {
$data = $form->getData(\Zend\Form\FormInterface::VALUES_AS_ARRAY);
$imgName = $data["image"]["tmp_name"];

how to set up a zend multiCheckbox form field with the checkboxes checked?

i have this form:
$this->addElement (
'multiCheckbox', 'servers2',
array (
'checkedValue' => '0',
'multiOptions' => array(
'11.com' => '.com',
'12.com' => '12.com',
'16.com' => '16.com',
'3.com' => '17.com'
)
));
the problem is that the checkedValue doesn't work for this setup, it does for a simple checkbox. I've also tried 'checkedValues' => array('1','0'), singular or plural,
but no end in sight.
any ideas?
THanks
To mark certain checkboxes as checked, try this:
$multiCheckElement->setValue(array('11.com', '3.com'));
// or
$this->addElement (
'multiCheckbox', 'servers2',
array (
'value' => array('11.com', '3.com'), // select these 2 values
'multiOptions' => array(
'11.com' => '.com',
'12.com' => '12.com',
'16.com' => '16.com',
'3.com' => '17.com'
)
)
);
See also Zend_Form_Element_MultiCheckbox
ZF2 will require you to use value_options;
$form->add(
array(
'name' => 'servers2',
'type' => \Zend\Form\Element\MultiCheckbox::class,
'attributes' => array(
'id' => 'servers2',
'class' => 'form-control',
),
'options' => array(
'label' => 'Servers 2',
'column-size' => 'sm-10',
'label_attributes' => array('class' => 'col-sm-2'),
'twb-layout' => 'horizontal',
'value_options' => array(
'11.com' => '.com',
'12.com' => '12.com',
'16.com' => '16.com',
'3.com' => '17.com'
)
),
)
);
To specify the checked options, as seen at
use the 'selected' => true attribute:
$options = array(
array(
'value' => '0',
'label' => 'Apple',
'selected' => false,
'disabled' => false,
'attributes' => array(
'id' => 'apple_option',
'data-fruit' => 'apple',
),
'label_attributes' => array(
'id' => 'apple_label',
),
),
array(
'value' => '1',
'label' => 'Orange',
'selected' => true,
),
array(
'value' => '2',
'label' => 'Lemon',
),
);