Skip to content

Commit

Permalink
Merge branch 'AD-38' into 'master'
Browse files Browse the repository at this point in the history
activity duplication bug fix

See merge request !9
  • Loading branch information
anjesh committed Jul 16, 2015
2 parents 95df0b0 + aabe6f1 commit 243575c
Show file tree
Hide file tree
Showing 31 changed files with 830 additions and 48 deletions.
15 changes: 10 additions & 5 deletions application/modules/default/controllers/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public function addElementAction()
$this->_redirect("/activity/add-element?className={$elementClass}"
."&activity_id={$parentId}&isMultiple={$isMultiple}");
}
$id = $element->save($data[$element->getClassName()] , $parentId);
if($elementClass == 'Activity_Sector'){
$id = $element->saveSector($data[$element->getClassName()] , $parentId);
}else{
$id = $element->save($data[$element->getClassName()] , $parentId);
}

Model_Activity::updateActivityUpdatedInfo($parentId);
$type = 'message';
Expand Down Expand Up @@ -204,7 +208,11 @@ public function editElementAction()
$form = $element->getForm();
if($form->validate()){
//$eleId will be null is element is deleted or in case of db error
$eleId = $element->save($data[$element->getClassName()] , $activityId);
if($elementClass == 'Activity_Sector'){
$eleId = $element->saveSector($data[$element->getClassName()] , $activityId);
}else{
$eleId = $element->save($data[$element->getClassName()] , $activityId);
}

$activityHashModel = new Model_ActivityHash();
$updated = $activityHashModel->updateActivityHash($activityId);
Expand Down Expand Up @@ -469,7 +477,6 @@ public function duplicateActivityAction()
$activities = $wepModel->listAll('iati_activities', 'account_id', $identity->account_id);
$activities_id = $activities[0]['id'];
$activityData = $activityClassObj->fetchData($activityId, false);

$form = new Form_Wep_IatiIdentifier('add', $identity->account_id);
$form->add('add', $identity->account_id);
$form->populate(array('reporting_org'=>$activityData['Activity']['ReportingOrg']['@ref']));
Expand All @@ -481,7 +488,6 @@ public function duplicateActivityAction()
$iatiIdentifier = array();
$iatiIdentifier['iati_identifier'] = $data['iati_identifier_text'];
$iatiIdentifier['activity_identifier'] = $data['activity_identifier'];

$newActivityId = $activityModel->duplicateActivity($activities_id, $activityId, $activityData['Activity'], $iatiIdentifier);
}

Expand All @@ -494,7 +500,6 @@ public function duplicateActivityAction()
$this->_redirect('/wep/view-activities');
}
}

$this->view->form = $form;
$this->view->activity_info = $activityData['Activity'];
}
Expand Down
46 changes: 45 additions & 1 deletion library/Iati/Aidstream/Element/Activity/Budget.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
<?php

class Iati_Aidstream_Element_Activity_Budget extends Iati_Core_BaseElement
{
{
protected $isMultiple = true;
protected $className = 'Budget';
protected $displayName = 'Budget';
protected $tableName = 'iati_budget';
protected $attribs = array('id','@type');
protected $iatiAttribs = array('@type');
protected $childElements = array('PeriodStart' , 'PeriodEnd','Value');

public function save($data , $parentId = null, $duplicate = false)
{
if(!$duplicate)
{
return parent::save($data, $parentId);
}
else
{
if ($parentId)
{
$parentColumnName = $this->getParentCoulmn();
}
if ($this->isMultiple)
{
foreach ($data as $elementData)
{
if ($this->hasData($elementData))
{
$elementsData = $this->getElementsData($elementData);
if ($parentId)
{
$elementsData[$parentColumnName] = $parentId;
}
$elementsData['id'] = '';
$eleId = $this->db->insert($elementsData);
}

// If children are present create children elements and call their save function.
if (!empty($this->childElements))
{
foreach ($this->childElements as $childElementClass)
{
$childElementName = get_class($this) . "_$childElementClass";
$childElement = new $childElementName();
$childElement->save($elementData[$childElement->getClassName()] , $eleId, true);

}
}
}
}
return $eleId;
}
}
}
21 changes: 21 additions & 0 deletions library/Iati/Aidstream/Element/Activity/Budget/PeriodEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,25 @@ class Iati_Aidstream_Element_Activity_Budget_PeriodEnd extends Iati_Core_BaseEle
protected $attribs = array('id' , '@iso_date', 'text');
protected $iatiAttribs = array('@iso_date' , 'text');
protected $tableName = 'iati_budget/period_end';

public function save($data , $parentId = null, $duplicate = false)
{
if(!$duplicate)
{
return parent::save($data, $parentId);
}
else
{
if ($this->hasData($data))
{
if($duplicate == true)
{
$data['id'] = '';
$data['budget_id'] = $parentId;
$eleId = $this->db->insert($data);
}
}
return $eleId;
}
}
}
21 changes: 21 additions & 0 deletions library/Iati/Aidstream/Element/Activity/Budget/PeriodStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,25 @@ class Iati_Aidstream_Element_Activity_Budget_PeriodStart extends Iati_Core_BaseE
protected $attribs = array('id' , '@iso_date', 'text');
protected $iatiAttribs = array('@iso_date' , 'text');
protected $tableName = 'iati_budget/period_start';

public function save($data , $parentId = null, $duplicate = false)
{
if(!$duplicate)
{
return parent::save($data, $parentId);
}
else
{
if ($this->hasData($data))
{
if($duplicate == true)
{
$data['id'] = '';
$data['budget_id'] = $parentId;
$eleId = $this->db->insert($data);
}
}
return $eleId;
}
}
}
21 changes: 21 additions & 0 deletions library/Iati/Aidstream/Element/Activity/Budget/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,25 @@ class Iati_Aidstream_Element_Activity_Budget_Value extends Iati_Core_BaseElement
protected $attribs = array('id' , '@currency', '@value_date' , 'text');
protected $iatiAttribs = array('@currency', '@value_date' , 'text');
protected $tableName = 'iati_budget/value';

public function save($data , $parentId = null, $duplicate = false)
{
if(!$duplicate)
{
return parent::save($data, $parentId);
}
else
{
if ($this->hasData($data))
{
if($duplicate == true)
{
$data['id'] = '';
$data['budget_id'] = $parentId;
$eleId = $this->db->insert($data);
}
}
return $eleId;
}
}
}
46 changes: 45 additions & 1 deletion library/Iati/Aidstream/Element/Activity/Conditions.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
<?php

class Iati_Aidstream_Element_Activity_Conditions extends Iati_Core_BaseElement
{
{
protected $isMultiple = true;
protected $className = 'Conditions';
protected $displayName = 'Conditions';
protected $tableName = 'iati_conditions';
protected $attribs = array('id','@attached');
protected $iatiAttribs = array('@attached');
protected $childElements = array('Condition');

public function save($data , $parentId = null, $duplicate = false)
{
if(!$duplicate)
{
return parent::save($data, $parentId);
}
else
{
if ($parentId)
{
$parentColumnName = $this->getParentCoulmn();
}
if ($this->isMultiple)
{
foreach ($data as $elementData)
{
if ($this->hasData($elementData))
{
$elementsData = $this->getElementsData($elementData);
if ($parentId)
{
$elementsData[$parentColumnName] = $parentId;
}
$elementsData['id'] = '';
$eleId = $this->db->insert($elementsData);
}

// If children are present create children elements and call their save function.
if (!empty($this->childElements))
{
foreach ($this->childElements as $childElementClass)
{
$childElementName = get_class($this) . "_$childElementClass";
$childElement = new $childElementName();
$childElement->save($elementData[$childElement->getClassName()] , $eleId, true);

}
}
}
}
return $eleId;
}
}
}
28 changes: 26 additions & 2 deletions library/Iati/Aidstream/Element/Activity/Conditions/Condition.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
<?php

class Iati_Aidstream_Element_Activity_Conditions_Condition extends Iati_Core_BaseElement
{
protected $isMultiple = true;
{
protected $isMultiple = true;
protected $className = 'Condition';
protected $displayName = 'Condition';
protected $tableName = 'iati_conditions/condition';
protected $attribs = array('id','text','@type');
protected $iatiAttribs = array('text','@type');

public function save($data , $parentId = null, $duplicate = false)
{
if(!$duplicate)
{
return parent::save($data, $parentId);
}
else
{
foreach ($data as $d)
{
if ($this->hasData($d))
{
if($duplicate == true)
{
$d['id'] = '';
$d['conditions_id'] = $parentId;
$eleId = $this->db->insert($d);
}
}
}
return $eleId;
}
}
}
45 changes: 44 additions & 1 deletion library/Iati/Aidstream/Element/Activity/ContactInfo.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
<?php

class Iati_Aidstream_Element_Activity_ContactInfo extends Iati_Core_BaseElement
{
{
protected $isMultiple = true;
protected $className = 'ContactInfo';
protected $displayName = 'Contact Info';
protected $tableName = 'iati_contact_info';
protected $attribs = array('id' , '@type' , '@xml_lang');
protected $iatiAttribs = array('@type' , '@xml_lang');
protected $childElements = array('Organisation','PersonName' , 'JobTitle' , 'Telephone','Email','MailingAddress' , 'Website');

public function save($data , $parentId = null, $duplicate = false)
{
if(!$duplicate)
{
return parent::save($data, $parentId);
}
else
{
if ($parentId)
{
$parentColumnName = $this->getParentCoulmn();
}
if ($this->isMultiple)
{
foreach ($data as $elementData)
{
if ($this->hasData($elementData))
{
$elementsData = $this->getElementsData($elementData);
if ($parentId)
{
$elementsData[$parentColumnName] = $parentId;
}
$elementsData['id'] = '';
$eleId = $this->db->insert($elementsData);
}

// If children are present create children elements and call their save function.
if (!empty($this->childElements))
{
foreach ($this->childElements as $childElementClass)
{
$childElementName = get_class($this) . "_$childElementClass";
$childElement = new $childElementName();
$childElement->save($elementData[$childElement->getClassName()] , $eleId, true);
}
}
}
}
return $eleId;
}
}
}

28 changes: 26 additions & 2 deletions library/Iati/Aidstream/Element/Activity/ContactInfo/Email.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
<?php

class Iati_Aidstream_Element_Activity_ContactInfo_Email extends Iati_Core_BaseElement
{
{
protected $isMultiple = true;
protected $className = 'Email';
protected $displayName = 'Email';
protected $tableName = 'iati_contact_info/email';
protected $attribs = array('id','text');
protected $iatiAttribs = array('text');
protected $iatiAttribs = array('text');

public function save($data , $parentId = null, $duplicate = false)
{
if(!$duplicate)
{
return parent::save($data, $parentId);
}
else
{
foreach($data as $d)
{
if($this->hasData($d))
{
if($duplicate == true)
{
$d['id'] = '';
$d['contact_info_id'] = $parentId;
$eleId = $this->db->insert($d);
}
}
}
return $eleId;
}
}
}
Loading

0 comments on commit 243575c

Please sign in to comment.