public function loadeditJsonAction()
 {
     $unit_id = $this->_getParam('id');
     $unitDAO = new RM_Units();
     $unit = $unitDAO->get($unit_id);
     $rmUnitTypes = new RM_UnitTypes();
     $typeInfo = $rmUnitTypes->getByUnit($unit)->toArray();
     $unittypes = $rmUnitTypes->getAll()->toArray();
     $json = new stdClass();
     $json->currentUnitType = $typeInfo;
     $json->allUnitTypes = $unittypes;
     return array('data' => $json, 'encoded' => false);
 }
Example #2
0
 public function updateJsonAction()
 {
     $unit = $this->_getParam('edit_unit');
     $unit['color'] = ltrim($this->_getParam('color'), "#");
     $dao = new RM_Units();
     // update the unit record
     $dao->updateUnit($unit);
     if (isset($unit['group_id'])) {
         // make sure that sub units are converted to the same unit type
         if (class_exists(RM_Groups)) {
             $groups = new RM_Groups();
             // get the unit object
             $unitObject = $dao->get($unit['id'], null, array('description', 'summary'));
             if (!$groups->isMain($unitObject)) {
                 // if it's not a main unit, then update the unit to the same unit type as the main unit
                 $allGroupedUnits = $groups->getGroupUnitsByMain($unitObject);
                 // find the main unit id...
                 foreach ($allGroupedUnits as $groupUnit) {
                     if ($groups->isMain($groupUnit)) {
                         $mainUnitID = $groupUnit->id;
                     }
                 }
                 // get the main unit object
                 $mainUnitObject = $dao->get($mainUnitID, null, array('description', 'summary'));
                 // get the type for the main unit
                 $rmUnitTypes = new RM_UnitTypes();
                 $typeInfo = $rmUnitTypes->getByUnit($mainUnitObject)->toArray();
                 // update the subunit to the same type
                 $unit['type_id'] = (int) $typeInfo['id'];
                 $dao->updateUnit($unit);
             }
         }
     }
     return array('data' => array('success' => true, 'msg' => ''));
 }
Example #3
0
 /**
  * Returns all fields belongs to a unit by it primary key value.
  *
  * @param int $unitID Unit type
  * @return array Array with keys:
  * 0 => Zend_Db_Table_Rowset with language undependent fields
  * 1 => Zend_Db_Table_Rowset with language dependent fields
  */
 protected function _getFields($unitID)
 {
     $unit = $this->find($unitID)->current();
     $unitTypeDAO = new RM_UnitTypes();
     $type = $unitTypeDAO->getByUnit($unit);
     return $this->_getFieldsByType($type);
 }