Add EXDATE with iCalcreator - icalcreator

Using iCalcreator I'm not understanding how to add an EXDATE field to an existing component and then save that back into the calendar. Does anyone have an example?

OK, figured it out.
<?php
require_once 'iCalcreator.php';
use kigkonsult\iCalcreator\{vcalendar,util};
$calendar = new vcalendar();
$calendar->setConfig(['directory' => '...', 'filename' => '...']);
$calendar->parse();
$uid = '...';
$e = $calendar->getComponent($uid);
$s = [['year' => 2017, 'month' => 5, 'day' => 28, 'hour' => 19, 'min' => 0, 'sec' => 0, 'tz' => 'America/Los_Angeles']];
$e->setProperty(util\util::$EXDATE, $s);
$e->setLastModified();
$calendar->setComponent($e, $uid);
$calendar->saveCalendar();

as of iCalcreator-2.17.x, you can also set a single exDate
$e->setExdate( new DateTime(...));

Related

Yii2: Sending params with Anchor as POST request

I try to get POST Variables in my controller from view with:
<?= GridView::widget([
'dataProvider' => $dataProvider_products,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label'=>'Name',
'format' => 'raw',
'value'=>function ($data) use ($model, $dataProvider_products) {
return Html::a($data['name'],['suppliers_orders/addproduct', 'order' => $model->id, 'product' => $data['id'],
'data-method'=> 'post',
'data-params' => ['dataProvider' => $dataProvider_products],
]);
},
],
'supplier_product_number',
'size',
'price_net',
],
]); ?>
The parameter dataProvider will always be sent with the URL and results in a GET variable. What is wrong, respectively what must be done, that dataProvider will be sent as POST variable?
Part of my controller is:
public function actionAddproduct($order, $product){
// look for GET variable
$request = Yii::$app->request->get('data');
$dataProvider = $request['params']['dataProvider'];
// look for POST variable
$param1 = Yii::$app->request->post('dataProvider', null);
$dataProvider_suppliers_orders_products = $dataProvider;
return $this->actionView($order);
}
First of all you are passing the data-params in the url parameter rather than setting in the options parameter, so yes it will always be sent as query string no matter you pull your hairs off and become bald ¯\_(ツ)_/¯.
Then According to the DOCS
If the attribute is a data attribute as listed in
yii\helpers\Html::$dataAttributes, such as data or ng, a list of
attributes will be rendered, one for each element in the value array.
For example, 'data' => ['id' => 1, 'name' => 'yii'] generates
data-id="1" data-name="yii" and 'data' => ['params' => ['id' => 1,
'name' => 'yii'], 'status' => 'ok'] generates
data-params='{"id":1,"name":"yii"}' data-status="ok"
So, you need to change the anchor to look like
Html::a($data['name'], ['suppliers_orders/addproduct', 'order' => $model->id, 'product' => $data['id']], [
'data' => [
'method' => 'POST',
'params' => ['dataProvider' => $dataProvider_products]
]
]);
But since you are passing the $dataProvider object to the params it aint going to work because it will be changed to [Object Object] but if it is simple text then it will work, otherwise you have to change your approach.
Your complete code for the GridView should look like below
<?=
GridView::widget([
'dataProvider' => $dataProvider_products,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'label' => 'Name',
'format' => 'raw',
'value' => function ($data) use ($model, $dataProvider_products) {
return Html::a($data['name'], ['suppliers_orders/addproduct', 'order' => $model->id, 'product' => $data['id']], [
'data' => [
'method' => 'POST',
'params' => ['dataProvider' => $dataProvider_products]
]
]);
},
],
'supplier_product_number',
'size',
'price_net',
],
]);
?>

Zend2: Creating a radio button list with extra information?

So far I have this:
$radio = new Element\Radio('gender');
$radio->setLabel('What is your gender ?');
$radio->setValueOptions(array(
array(
'0' => 'Female',
'1' => 'Male',
)
));
The problem is, I want a table output like this:
Gender | Description | Button
-------------------------------
Male | The workers | [X]
Female | The peacekeepers | [ ]
So the problem is that I want to associate more information to the individual form elements and alter the standard way the get printed to the screen. If something like this could work, I would be pretty happy:
$radio = new Element\Radio('gender');
$radio->setLabel('What is your gender ?');
$radio->setValueOptions(array(
array(
'0' => 'Female',
'1' => 'Male',
)
));
$radio->setExtraData(array(
array(
'0' => 'The workers',
'1' => 'The peacekeepers',
)
));
That obviously doesn't work. So what is the correct "zend" way to accomplish this?
Instead of providing a plain array, you could add extra information in the value options like this:
$radio->setValueOptions(array(
array(
'value' => '0',
'label' => 'Female',
'description' => 'The peacekeepers',
),
array(
'value' => '1',
'label' => 'Male',
'description' => 'The workers',
)
));
The following step would be to create a custom View Helper for rendering the table, or loop through the options and render the table in the view itself.

dynamic dropdown get in zf2?

I want to put a dropdown in my project which is made in zf2... I wasted all day but I only got a static dropdown, not dynamic. Can anyone help me with this problem??
UserForm.php
$this->add(array(
'name' => 'group_name',
'type' => 'select',
'attributes' => array(
'id'=>'group_name',
'class'=>'large',
'options' => array('1=>php','2'=>'java'),
),
'options' => array(
'label' => '',
),
));
Thanks in advance for your valuabe answer.
Try this:
$this->add(array(
'name' => 'group_name',
'type' => 'select',
'attributes' => array(
'id'=>'group_name',
'class'=>'large',
),
'options' => array(
'label' => '',
'value_options' => array(
'1' => 'php',
'2' => 'java'
),
),
));
This is what i did:
In my constructor for my form
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'color',
'options' => array(
'empty_option' => 'Select a Color',
'value_options' => self::getColors(),
'label' => 'Color',
),
));
In the form class yet, i created this method:
public static function getColors() {
// access database here
//example return
return array(
'blue' => 'Blue',
'red' => 'Red',
);
}
In my view script:
<div class="form_element">
<?php $element = $form->get('color'); ?>
<label>
<?php echo $element->getOption('label'); ?>
</label>
<?php echo $this->formSelect($element); ?>
</div>
Think about it from a abstract level.
You have one Form
The Form needs Data from the outside
So ultimately your Form has a Dependency. Since we've learned from the official docs, there's two types of Dependency-Injection aka DI. Setter-Injection and Constructor-Injection. Personally(!) i use one or the other in those cases:
Constructor-Injection if the dependency is an absolute requirement for the functionality to work
Setter-Injection if the dependencies are more or less optional to extend already working stuff
In the case of your Form, it is a required dependency (because without it there is no populated Select-Element) hence i'll be giving you an example for Constructor-Injection.
Some action of your controller:
$sl = $this->getServiceLocator();
$dbA = $sl->get('Zend\Db\Adapter\Adapter');
$form = new SomeForm($dbA);
That's all for the form. The population now happens inside your Form. This is only an example and may need some fine-tuning, but you'll get the idea:
class SomeForm extends \Zend\Form
{
public function __construct(\Zend\Db\Adapter\Adapter $dbA)
{
parent::__construct('my-form-name');
// Create all the form elements and stuff
// Get Population data
$popData = array();
$result = $dbA->query('SELECT id, title FROM Categories', $dbA::QUERY_MODE_EXECUTE)->toArray();
foreach ($result as $cat) {
$popData[$cat['id'] = $cat['title'];
}
$selectElement = $this->getElement('select-element-name');
$selectElement->setValueOptions($popData);
}
}
Important: I HAVE NO CLUE ABOUT Zend\Db the above code is only for how i think it would work going by the docs! This is the part that would need some optimization probably. But all in all you'll get the idea of how it's done.
In your controller you can do something like below;
On my first example assuming that you have a Group Table. Then we're going to fetchAll the data in group table;
We need the id and name to be display in select options;
public function indexAction()
{
$groupTable = new GroupTable();
$groupList = $groupTable->fetchAll();
$groups = array();
foreach ($groupList as $list) {
$groups[$list->getId()] = $list->getName();
}
$form = new UserForm();
$form->get('group_name')->setAttributes(array(
'options' => $groups,
));
}
OR
in this example the grouplist is hardcoded;
public function indexAction()
{
$groupList = array('1' => 'PHP', '2' => 'JAVA', '3' => 'C#');
$groups = array();
foreach ($groupList as $id => $list) {
$groups[$id] = $list;
}
$form = new UserForm();
$form->get('group_name')->setAttributes(array(
'options' => $groups,
));
}
Then in your view script;
<?php
$form = $this->form;
echo $this->formRow($form->get('group_name'));
?>
Or you can right a controller helper, you may check this link http://www.resourcemode.com/me/?p=327
Just came across the same problem and had to take a look into zf2 source.
Here's a more OOP solution:
Inside the form constructor:
$this->add(array(
'name' => 'customer',
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'options' => array(
0 => 'Kunde',
)
),
'options' => array(
'label' => 'Kunde'
)));
inside the controller:
$view->form = new SearchForm();
$customers = $view->form->get('customer')->getValueOptions();
$customers[] = 'Kunde1';
$customers[] = 'Kunde2';
$customers[] = 'Kunde3';
$customers[] = 'Kunde4';
$view->form->get('customer')->setValueOptions($customers);

Column order in propel pager (symfony)

i have this code in executeIndex action:
$pager = new sfPropelPager('News',5);
$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(NewsPeer::ID);
$c->addSelectColumn(NewsPeer::TYTUL);
$c->addSelectColumn(NewsPeer::SLUG);
$c->addSelectColumn(NewsPeer::TEKST);
$c->addSelectColumn(NewsPeer::UTW);
$c->addSelectColumn(NewsPeer::WYSWIETLENIA);
$c->addDescendingOrderByColumn(NewsPeer::UTW);
$pager->setCriteria($c);
$pager->setPage($this->getRequestParameter("p", 1));
$pager->init();
$this->pager=$pager;
as you can see, im selecting 6 columns from 9column table.
When i want to print UTW column in indexSuccess it print nothing. when i do: print_r($news), im getting this:
[id:protected] => 64
[tytul:protected] => Limit
[slug:protected] => limit
[tekst:protected] => text.....
[pelnytekst:protected] => 2011-12-22 08:54:07
[stan:protected] => 42
[utw:protected] =>
[zmi:protected] =>
[wyswietlenia:protected] =>
and it should be:
[id:protected] => 64
[tytul:protected] => Limit
[slug:protected] => limit
[tekst:protected] => text.....
[pelnytekst:protected] =>
[stan:protected] =>
[utw:protected] => 2011-12-22 08:54:07
[zmi:protected] =>
[wyswietlenia:protected] => 42
So, its ok, when i select columns with same order as in table, but when i skip one, values get messed up. How to fix this?
You need to set the PeerMethod to 'doSelectStmt'.
$pager->setCriteria($c);
$pager->setPeerMethod('doSelectStmt'); // add this
$pager->setPage($this->getRequestParameter("p", 1));
$pager->init();
$this->pager=$pager;

Where is SugarFullTest_Version2.php? (Sugar CRM and SOAP)

In regards to using SOAP to connect to Sugar CRM, the documentation for Sugar 6.1 Community Edition states:
"See /examples/SugarFullTest_Version2.php for more examples on usage."
source:
http://developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9000244
This file is not in the examples folder. Where is it?
If this file does not exist, where can I find a working example of connecting to Sugar CRM with SOAP? None of the test scripts in the /examples/ folder work.
Couldn't find the file either, so made an example (PHP script connecting to sugarCRM v6 SOAP) for you.
<?php
require_once('include/nusoap/lib/nusoap.php');
$myWsdl = 'http://mysite.com/soap.php?wsdl';
$myAuth = array(
'user_name' => 'xxxx',
'password' => MD5('xxxx'),
'version' => '0.1'
);
$soapClient = new nusoap_client($myWsdl,true);
// Create lead
// (Can be made without login, i.e. sessionid)
$leadParams = array('user_name' => 'xxxx',
'password' => MD5('xxxx'),
'first_name' => 'Test',
'last_name' => '2',
'email_address' => '2#'
);
$leadResult = $soapClient->call('create_lead', $leadParams);
$leadId = $leadResult;
print_r($leadResult);
// Login
$loginParams = array('user_auth' => $myAuth, 'application_name' => 'WebForm');
$loginResult = $soapClient->call('login', $loginParams);
$sessionId = $loginResult['id'];
// Modules
// (Need login, so sessionID is used)
$modulesResult = $soapClient->call('get_available_modules', array('session' => $sessionId));
print_r($modulesResult);
// Get account list
$accountParams = array('session' => $sessionId,
'module_name' => 'Accounts',
'query' => "accounts.name = 'Amarelo'",
'order_by' => '',
'deleted' => 0
);
$accountResult = $soapClient->call('get_entry_list', $accountParams);
print_r($accountResult);
// Get entry
$leadParams = array('session' => $sessionId,
'module_name' => 'Leads',
'id' => "$leadId"
);
$leadResult = $soapClient->call('get_entry', $leadParams);
print_r($leadResult);
// Logout
$logoutResult = $soapClient->call('logout', array('session' => $sessionId));
?>
For debugging and testing SoapUI is very helpful.

Resources