public function isValid($value, $context = null)
 {
     if (!parent::isValid($value, $context)) {
         return false;
     }
     if ($value == BusinessRule::CHANGE_COMMERCIAL_GROUP) {
         $type = App_Util_Array::getItem($context, '__parent.__parent.universeType');
         if ($type == AlarmRuleModel::UNIVERSE_SUBSCRIPTIONS_OF_COMMERCIAL_GROUP || $type == AlarmRuleModel::UNIVERSE_COMMERCIAL_GROUP) {
             $universeId = App_Util_Array::getItem($context, '__parent.__parent.universeId');
             $cg = $this->_getCommercialGroup($universeId, 'id');
             if ($cg === NULL) {
                 $this->_error(self::ERROR_COMMERCIAL_GROUP_NOT_EXISTS, $universeId);
                 return false;
             }
             $restricted = $cg->restricted;
             switch (\App::getOrgUserLogged()->getType()) {
                 case OrgCustomerModel::ORG_TYPE:
                     if ($restricted) {
                         $mss = "{$type} with commercial group id {$universeId}";
                         $this->_error(self::ERROR_UNIVERSE_TYPE_COMMERCIAL_GROUP_RESTRICTED, $mss);
                         return false;
                     }
             }
         }
     }
     return true;
 }
 /**
  * Validate element value
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($value, $context = array())
 {
     $isListFilter = $context instanceof \App_ListFilter;
     if ($this->getUseDates()) {
         $value = strtotime($value) ?: $value;
     }
     foreach ($this->_fields as $field) {
         $min = $isListFilter ? $context->getOneFilterValueByFieldName($field) : App_Util_Array::getItem($context, $field);
         if ($min !== null) {
             // Add support for dates
             if ($this->getUseDates()) {
                 $min = strtotime($min) ?: $min;
             }
             // Normal behaviour
             $this->_setValue($value);
             $this->_currentField = $field;
             $this->_min = $min;
             // Check diff
             if ($min > $value || !$this->_allowEquals && $min >= $value) {
                 $this->_error(self::NOT_GREATER, $value);
                 return false;
             }
         }
     }
     return true;
 }
 public function isValid($value, $context = NULL)
 {
     $sum = $value;
     $customerId = $context['customerId'];
     foreach ($this->_discountsToSum as $discountPath) {
         if ($discounts = App_Util_Array::getItem($context, $discountPath)) {
             foreach ($discounts as $discount) {
                 if (App_Util_Array::getItem($discount, 'customerId') == $customerId) {
                     $sum += App_Util_Array::getItem($discount, $this->_fieldName);
                 }
             }
         }
     }
     if (!parent::isValid($sum)) {
         $this->_messageVariables = array('fieldName' => '_fieldName', 'max' => '_max', 'min' => '_min');
         $messages = $this->getMessages();
         if (!is_array($this->_messages)) {
             $this->_messages = array();
         }
         foreach ($messages as $key => $message) {
             $this->_error($key, $sum);
         }
         return false;
     }
     return true;
 }
示例#4
0
 /**
  * Return data after applying a blacklist
  * @param  array $list
  * @return array
  */
 public function blacklist(array $list)
 {
     $data = $this->_data;
     foreach ($list as $field) {
         \App_Util_Array::unsetItem($data, $field);
     }
     return $data;
 }
 protected function _checkToken($token)
 {
     $params = array("%id%" => $token);
     $result = $this->_getPybeService()->callMethod($this::USE_METHOD, $params);
     $httpResponse = $this->_getPybeService()->getLastResult();
     $this->_checkResponseResult($httpResponse, 'Pybe error checking 3rd party service session');
     $serviceSession = \App_Util_Array::getItem($result, static::ITEM_KEY);
     return new $this->_modelClassResult($serviceSession);
 }
 public function filter($value, $context = array())
 {
     if (!($field = $this->getField())) {
         throw new Zend_Filter_Exception("Missing currency field in filter");
     }
     if ($currencyId = App_Util_Array::getItem($context, $field)) {
         $this->_currencyId = $currencyId;
     }
     return parent::filter($value, $context);
 }
 protected function _processSection(&$section, $data, $value)
 {
     if (is_string($data)) {
         $data = explode(',', $data);
         array_walk($data, function (&$item) {
             trim($item);
         });
         foreach ($data as $item) {
             App_Util_Array::setItem($section, $item, $value);
         }
     }
 }
 /**
  * Validate element value
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($value, $context = array())
 {
     foreach ($this->_fieldValues as $fieldValue => $max) {
         if ($fieldValue == App_Util_Array::getItem($context, $this->getField())) {
             $this->_currentFieldValue = $fieldValue;
             parent::setMax($max);
             if (!parent::isValid($value)) {
                 return false;
             }
         }
     }
     return true;
 }
示例#9
0
 protected function _filterData($data)
 {
     if (!empty($this->_allowedFields)) {
         $newData = array();
         foreach ($this->_allowedFields as $field) {
             if ($value = \App_Util_Array::getItem($data, $field)) {
                 \App_Util_Array::setItem($newData, $field, $value);
             }
         }
         $data = $newData;
     }
     return $data;
 }
 protected function _mapEricssonModelToModel(array $data)
 {
     $data = parent::_mapEricssonModelToModel($data);
     $contactFields = array('otherContact_1', 'otherContact_2', 'otherContact_3');
     foreach ($contactFields as $field) {
         if (isset($data[$field])) {
             \App_Util_Array::cleanEmptyItems($data[$field], false);
             if (empty($data[$field])) {
                 unset($data[$field]);
             }
         }
     }
     return $data;
 }
示例#11
0
 private function _map(array &$data, $map, $rev = false)
 {
     foreach ($map as $k1 => $k2) {
         list($fromKey, $toKey) = $rev ? array($k2, $k1) : array($k1, $k2);
         if ($fromKey !== '') {
             $v = App_Util_Array::getItem($data, $fromKey);
             if (!is_null($v)) {
                 App_Util_Array::unsetItem($data, $fromKey);
                 if ($toKey !== '') {
                     App_Util_Array::setItem($data, $toKey, $v);
                 }
             }
         }
     }
 }
 /**
  * Returns true if and only if the assertion conditions are met
  *
  * This method is passed the ACL, Role, Resource, and privilege to which
  * the authorization query applies. If the $role, $resource, or $privilege
  * parameters are null, it means that the query applies to all Roles,
  * Resources, or privileges, respectively.
  *
  * @param  Zend_Acl                    $acl
  * @param  Zend_Acl_Role_Interface     $role
  * @param  Zend_Acl_Resource_Interface $resource
  * @param  string                      $privilege
  * @return booleanel Supp
  */
 public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
 {
     // We need specific objects to check against each other
     if (NULL === $role) {
         return false;
     }
     // Ensure we're handled User models
     if (!$role instanceof UserModel) {
         throw new Exception('Role must be an instance of UserModel');
     }
     if (App_Util_Array::getItem($resource, 'supplementaryServices.location')) {
         return true;
     }
     return false;
 }
 /**
  * Validate element value
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($value, $context = array())
 {
     foreach ($this->_fields as $field => $fieldName) {
         if (is_numeric($field)) {
             $field = $fieldName;
         }
         if ($max = App_Util_Array::getItem($context, $field)) {
             $this->_currentField = $fieldName;
             parent::setMax($max);
             if (!parent::isValid($value)) {
                 return false;
             }
         }
     }
     return true;
 }
 public function getConfig($key, $default = null)
 {
     if (is_array($key)) {
         if (isset($key['default'])) {
             $default = $key['default'];
         }
         if (!isset($key['key'])) {
             throw new InvalidArgumentException("Parameter key must be a string or an array with a 'key' element");
         }
         $key = $key['key'];
     }
     $data = $this->exportData();
     if (!\App_Util_Array::issetItem($data, $key)) {
         return $default;
     }
     return \App_Util_Array::getItem($data, $key);
 }
 protected function _checkWhitelistPrivileges($prefix, $resource, $newResource, $subResource = null, $connector = '_', $depth = -1, $subprivilege = '')
 {
     if ($subResource === NULL) {
         $subResource =& $newResource;
     }
     if (!$subprivilege) {
         $subprivilege = $prefix;
     }
     if (\App_Util_Array::isIterable($subResource)) {
         foreach ($subResource as $field => $value) {
             $privilege = $subprivilege . $connector . $field;
             if ($this->_checkProtectedField($resource, $newResource, $privilege, $prefix) && $depth != 0 && \App_Util_Array::isIterable($newResource, $field)) {
                 $this->_checkWhitelistPrivileges($prefix, $resource, $newResource, $subResource->{$field}, ':', $depth - 1, $privilege);
             }
         }
     }
 }
 protected function _mapEricssonModelToModel(array $data)
 {
     if (isset($data['data'])) {
         $data = $data['data'];
     }
     if (isset($data['service_provider_configuration'])) {
         $data = array_pop($data['service_provider_configuration']);
     }
     if (isset($data['properties'])) {
         $data = $data['properties'];
     }
     $newData = array();
     foreach ($data as $keyValue) {
         \App_Util_Array::setItem($newData, $keyValue['key'], $keyValue['bool_value']);
     }
     return $newData;
 }
示例#17
0
 /**
  * Validate element value
  *
  * If a translation adapter is registered, any error messages will be
  * translated according to the current locale, using the given error code;
  * if no matching translation is found, the original message will be
  * utilized.
  *
  * Note: The *filtered* value is validated.
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($value, $context = null)
 {
     $fields = array('__parent.zonePlanId', '__parent.zonePlan');
     if ($value == "-1") {
         return true;
     }
     foreach ($fields as $field) {
         $data = \App_Util_Array::getItem($context, $field);
         if (!empty($data)) {
             if (is_string($data)) {
                 $zonePlan = \Application\Service\ZonePlanService::getInstance()->load($data);
                 if (!$zonePlan) {
                     $this->_error(self::NOT_EXISTS_ZONE_PLAN, $data);
                     return false;
                 }
             } else {
                 if (is_array($data)) {
                     $zonePlan = new ZonePlanModel($data);
                 } else {
                     $this->_error(self::INVALID_DATA_TYPE);
                     return false;
                 }
             }
             //TODO: workaround
             /*
              * For the post verb, they only send the modified zones in the normal object (modified are only readonly for get verb)
              * Now is not mandatory to send current items although they zones has been removed.
              */
             //
             //                if ($zonePlan->zonePlanModified) {
             //                    $zoneGroup = $zonePlan->zonePlanModified->getZoneGroupById($value);
             //                } else {
             //                    $zoneGroup = $zonePlan->getZoneGroupById($value);
             //                }
             //                if (($zoneGroup !== NULL) && (!$zoneGroup->isDeleted)){
             //                    return true;
             //                }
             //
             //                $this->_error(self::NOT_ZONE_GROUP_DEFINED, $value);
             //                return false;
             return true;
         }
     }
     $this->_error(self::NOT_ZONE_PLAN_DEFINED);
     return false;
 }
示例#18
0
 public function flatAcl(App_Acl $acl, $ns)
 {
     \App::log()->notice("Creating new permission map for namespace '{$ns}'...");
     $roles = $acl->getRoles();
     $resPrivs = $acl->getAllPrivileges();
     $resourcesResult = array();
     $permissionResult = array();
     foreach ($roles as $role) {
         // Divide roles into role-orgType
         $aRole = array_map('strrev', explode('-', strrev($role), 2));
         if (count($aRole) != 2) {
             \App::log()->notice("Ignoring role {$role}...");
             continue;
         }
         list($thisOrgType, $roleName) = $aRole;
         if ($roleName == 'org' || !in_array($thisOrgType, array('super', 'master', 'provider', 'customer', 'aggregator', 'enduser'))) {
             \App::log()->notice("Ignoring role {$role}...");
             continue;
         }
         \App::log()->notice("Creating permission map for {$role}...");
         $allowed = $acl->getAllowedMapForRole($role);
         foreach ($resPrivs as $resource => $privs) {
             \App::log()->notice("Creating resource '{$resource}' for {$role}...");
             foreach ($privs as $priv) {
                 $isAllowed = in_array($priv, isset($allowed[$resource]) ? $allowed[$resource] : array());
                 if (!$isAllowed) {
                     continue;
                 }
                 // Getting an App_Acl_Assert_Combine instance!
                 $as = $acl->getAssert($role, $resource, $priv);
                 $asserts = $as ? $as->getAsserts() : array();
                 if (!in_array($resource, $resourcesResult)) {
                     $resourcesResult[] = $resource;
                 }
                 \App_Util_Array::setItem($permissionResult, $role . '.' . $resource . '.' . $priv, $asserts);
             }
             \App::log()->notice("Resource created!");
         }
         \App::log()->notice("Permission map for {$role} created!");
     }
     return array('resources' => $resourcesResult, 'permissions' => $permissionResult);
 }
 /**
  * @param mixed $data Item object, usually Model instance
  */
 public function currentItem(&$data)
 {
     $params = $data->params->exportData();
     $paramsReturned = $params["params"];
     $reportType = $paramsReturned["reportType"];
     // Custom download report params
     switch ($reportType) {
         case ReportModel::KPI_MONTHLY:
             \App_Util_Array::unsetItem($paramsReturned, 'orgId');
             break;
         case ReportModel::SUBSCRIPTION_SNAPSHOT_DAILY:
             $date = \App_Util_Array::getItem($paramsReturned, 'dateDaily');
             \App_Util_Array::setItem($paramsReturned, 'date', $date);
             \App_Util_Array::unsetItem($paramsReturned, 'dateDaily');
             break;
     }
     $helper = \Zend_Controller_Action_HelperBroker::getStaticHelper("formatDateTime");
     $paramsAllowed = array("orgId", "date", "start", "end", "billingAccount", "groupBy", "supervisionGroup", "showCommercialGroup", "showBillingAccount", "showSubscriptions", "showAggregators");
     $paramsFiltered = array_intersect_key($paramsReturned, array_flip($paramsAllowed));
     $newData = array("downloadReportId" => $data->id, "created" => $helper->direct($data->created), "expire" => $helper->direct($data->expire), "modified" => $helper->direct($data->modified), "status" => $data->status === \Core\Model\WatcherModel::STATUS_FINISHED && !$data->eventCount ? 'timeout' : $data->status, "params" => array($reportType => $paramsFiltered), "remove" => $helper->direct($data->remove));
     $data = $newData;
 }
示例#20
0
 protected function _setToProto(&$proto, $list, $setters)
 {
     foreach ($setters as $name => $set) {
         if (($value = \App_Util_Array::getItem($list, $set)) !== null) {
             $name = 'set' . ucfirst($name);
             $proto->{$name}($value);
         }
     }
 }
示例#21
0
 protected function _internalRender($name)
 {
     $vars = $this->getVars();
     if (!empty($vars['data']) && count($vars['data'])) {
         $headers = $this->getHeaders();
         if (empty($headers)) {
             foreach ($vars['data'] as $key => $value) {
                 $this->_processHeaders($headers, $value);
             }
         }
         $headers = $this->_filterData($headers);
         $resultData = $vars['data'];
         $file = $this->getStream();
         if ($file === false) {
             throw new GlobalServiceException("Impossible to create csv file");
         }
         // UTF-8 BOM (Excel issues)
         fwrite($file, "");
         $fileHeaders = $this->getFileHeaders();
         foreach ($fileHeaders as $fileHeader) {
             if (fputcsv($file, $fileHeader, $this->getSeparator()) === false) {
                 throw new GlobalServiceException("Impossible to write file header on csv file");
             }
         }
         if (fputcsv($file, $headers, $this->getSeparator()) === false) {
             throw new GlobalServiceException("Impossible to write headers on csv file");
         }
         foreach ($resultData as $item) {
             $itemCsv = array();
             foreach ($headers as $key => $caption) {
                 $value = App_Util_Array::getItem($item, $key);
                 $itemCsv[] = $value !== null ? $this->_filterValue($key, $value, $item) : '';
             }
             if ($this->_skipEmptyItems && App_Util_Array::isEmpty($itemCsv)) {
                 continue;
             }
             if (fputcsv($file, $itemCsv, $this->getSeparator()) === false) {
                 throw new GlobalServiceException("Impossible to write row on csv file");
             }
         }
         if (method_exists($resultData, 'getSecondList') && ($secondList = $resultData->getSecondList())) {
             if (fputcsv($file, array(), $this->getSeparator()) === false) {
                 throw new GlobalServiceException("Impossible to write second list separator on csv file");
             }
             foreach ($secondList as $item) {
                 if (fputcsv($file, $item, $this->getSeparator()) === false) {
                     throw new GlobalServiceException("Impossible to write second list on csv file");
                 }
             }
         }
         $fileFooters = $this->getFileFooters();
         foreach ($fileFooters as $fileFooter) {
             if (fputcsv($file, $fileFooter, $this->getSeparator()) === false) {
                 throw new GlobalServiceException("Impossible to write file footer on csv file");
             }
         }
     }
 }
 /**
  * Route shutdown hook -- Check for router exceptions
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return;
     }
     $ident = \Zend_Auth::getInstance()->getIdentity();
     if (isset($ident['authType']) && in_array($ident['authType'], array(App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC, App_Controller_Plugin_Auth::AUTH_TYPE_ACTIVATION_TOKEN, App_Controller_Plugin_Auth::AUTH_TYPE_DOWNLOAD_TOKEN, App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL, App_Controller_Plugin_Auth::AUTH_TYPE_THIRD_PARTY, App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD, App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD_TOKEN, App_Controller_Plugin_Auth::AUTH_TYPE_PASSWORD_EXPIRED_TOKEN))) {
         return;
     }
     $sessionMapper = SessionMapper::getInstance();
     $session = $sessionMapper->findOneById(\Zend_Session::getId());
     if (!$session || !isset($session['id'])) {
         return;
     }
     if (($user = UserMapper::getInstance()->findOneById($session['id'])) && isset(self::$cookieLifeTimeByOrgType[$user->getOrgType()])) {
         $cookieLifeTime = self::$cookieLifeTimeByOrgType[$user->getOrgType()];
     } else {
         $cookieLifeTime = self::$defaultCookieLifeTime;
     }
     /*
      * Old sessions use string for created/expire field. New session use a MongoDate.
      */
     $created = $session['metadata']['created'];
     if ($created instanceof \MongoDate) {
         $created = $created->sec;
     }
     if (time() - $created - $cookieLifeTime > 0) {
         $this->_forceLogout($request, "Session Expired", PermissionCodes::AUTH_SESSION_EXPIRED);
         return;
     }
     if (App_Util_Array::getItem(self::$avoidActions, $request->getModuleName() . '.' . $request->getControllerName() . '.' . $request->getActionName())) {
         return;
     }
     if ($request->getHeader('X-M2mNoRenewSession')) {
         return;
     }
     if (Zend_Session::isRegenerated()) {
         return;
     }
     if (time() - $created < (1 - self::$tolerance) * $cookieLifeTime && (!self::$useProbability || rand(0, self::$probability))) {
         return;
     }
     $sessionMapper->renewSession(\Zend_Session::getId());
     //         Zend_Session::regenerateId();
     //         if (isset($data['logout'])) {
     //             $sessionMapper->logoutSessionBySessionId(Zend_Session::getId(), $data['logout']);
     //         } else if (isset($data['messages'])) {
     //             $sessionMapper->addAllMessagesToAllSessionsBySessionId(Zend_Session::getId(), $data['messages']);
     //         }
 }
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if the string length of $value is at least the min option and
  * no greater than the max option (when the max option is not null).
  *
  * @param  string  $value
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_array($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     $checkValues = array();
     foreach ($value as $item) {
         $v = $this->_checkField ? \App_Util_Array::getItem($item, $this->_checkField) : $item;
         if (NULL !== $v) {
             if (!isset($checkValues[$v])) {
                 $checkValues[$v] = 0;
             }
             $checkValues[$v]++;
             if ($checkValues[$v] > $this->_max) {
                 $this->_error(self::TOO_MANY, $v);
                 return false;
             }
         }
     }
     foreach ($checkValues as $key => $count) {
         if ($count < $this->_min) {
             $this->_error(self::TOO_FEW, $key);
             return false;
         }
     }
     return true;
 }
示例#24
0
 /**
  * @param $data \Application\Proto\Report\Service\KPIDataQuery\Response\ResponseData\CurrencyKPI
  * @return \Application\Model\Report\KpiStreamModel
  * @throws \Application\Exceptions\InvalidArgumentException
  */
 public function mapKpi($data)
 {
     $commonData = array();
     switch (true) {
         case $data instanceof CurrencyKPI:
             if ($data->getKpi()) {
                 $dataChild = $data->getKpi();
                 $list = $dataChild->getCustomerKpiList();
             } else {
                 if ($data->getKpiGroup()) {
                     $dataChild = $data->getKpiGroup();
                     $list = $dataChild->getGroupKpiList();
                 }
             }
             if ($data->getCurrency()) {
                 $commonData['currencyId'] = $data->getCurrency()->getId();
                 $commonData['currencyName'] = $data->getCurrency()->getName();
             }
             $commonData['serviceProviderId'] = $dataChild->getServiceProvider()->getId();
             $commonData['serviceProviderName'] = $dataChild->getServiceProvider()->getName();
             $commonData['dateMonthly'] = $dataChild->getDateMonthly();
             break;
         case $data instanceof GroupKPI:
             $dataChild = $data;
             $list = $data->getCustomerKpiList();
             $commonData['sectorId'] = $data->getSector()->getId();
             $commonData['sectorName'] = $data->getSector()->getName();
             break;
         case $data instanceof CustomerKPI:
             $dataChild = $data;
             $list = array();
             $commonData['customerId'] = $data->getCustomer()->getId();
             $commonData['customerName'] = $data->getCustomer()->getName();
             if ($data->getCrmId() !== null) {
                 $commonData['crmId'] = $data->getCrmId();
             }
             if ($data->getFiscalNumber() !== null) {
                 $commonData['fiscalNumber'] = $data->getFiscalNumber();
             }
             if ($data->getInvolvedBillingAccounts() !== null) {
                 $commonData['involvedBillingAccounts'] = $data->getInvolvedBillingAccounts();
             }
             break;
         default:
             throw new InvalidArgumentException('Invalid kpi data');
     }
     // Common common!
     $commonData['kpi'] = $dataChild->getKpi()->serialize(new \DrSlump\Protobuf\Codec\PhpArray());
     $commonData['kpi'] = parent::_mapEricssonModelToModel($commonData['kpi']);
     $result = new Report\KpiStreamModel(!\App_Util_Array::isIterable($list) ? array() : $list, $commonData);
     return $result;
 }
 protected function _mapEricssonModelToModel(array $data)
 {
     \App_Util_Array::changePropertyName($data, 'customer', 'customerData');
     $data = parent::_mapEricssonModelToModel($data);
     \App_Util_Array::changePropertyName($data, 'customerData.fiscalNumber', 'customerData.defaultBillingAccount.fiscalNumber');
     if (isset($data['customerData'])) {
         $data['customer'] = OrgCustomerMapper::getInstance()->mapToModel($data['customerData']);
         unset($data['customerData']);
     }
     if (isset($data['serviceProviderData'])) {
         $data['serviceProvider'] = OrgServiceProviderMapper::getInstance()->mapToModel($data['serviceProviderData']);
         unset($data['serviceProviderData']);
     }
     if (isset($data['billingAccountData'])) {
         $data['billingAccountName'] = $data['billingAccountData']['name'];
         if (isset($data['billingAccountData']['region'])) {
             $data['billingAccountRegion'] = $data['billingAccountData']['region'];
         }
         unset($data['billingAccountData']);
     }
     \App_Util_Array::changePropertyName($data, 'prebillBillingcycle', 'billingCycle');
     if (isset($data['billingCycle'])) {
         foreach ($data['billingCycle'] as &$bc) {
             $this->_mapReference($bc, 'billingAccount');
         }
     }
     $this->_mapReference($data, 'billingAccount');
     if (isset($data['datesData'])) {
         $data += $data['datesData'];
         unset($data['datesData']);
     }
     \App_Util_Array::changePropertiesNames($data, array('totalChargeData' => 'totalCharge', 'totalCharge.adjusts.adjustList' => 'totalCharge.adjusts', 'adjusts.adjustList' => 'adjusts', 'serviceGlobalCharges.basicServicesCustomerCharges' => 'serviceGlobalCharges.basicServices', 'serviceGlobalCharges.basicServices.commercialGroupData' => 'serviceGlobalCharges.basicServices.commercialGroup', 'serviceGlobalCharges.supplementaryServicesCustomerCharges' => 'serviceGlobalCharges.supplServices', 'subscriptionsChargesSummary.basicServices.commercialGroupData' => 'subscriptionsChargesSummary.basicServices.commercialGroup', 'subscriptionsChargesSummary.supplementaryServices' => 'subscriptionsChargesSummary.supplServices'));
     if (isset($data['serviceGlobalCharges']) && isset($data['serviceGlobalCharges']['basicServices']) && isset($data['serviceGlobalCharges']['basicServices']['commercialGroup'])) {
         foreach ($data['serviceGlobalCharges']['basicServices']['commercialGroup'] as &$item) {
             $this->_mapReference($item, 'aggregator');
         }
     }
     if (isset($data['subscriptionsChargesSummary']) && isset($data['subscriptionsChargesSummary']['basicServices']) && isset($data['subscriptionsChargesSummary']['basicServices']['commercialGroup'])) {
         foreach ($data['subscriptionsChargesSummary']['basicServices']['commercialGroup'] as &$item) {
             \App_Util_Array::changePropertiesNames($item, array('oneTimeFee.lifecycleStateChangeEvent' => 'oneTimeFee.lifecycleStatusChangeEvent', 'monthlyFee.activeStateRecurrentFee' => 'monthlyFee.activeStatusRecurrentFee', 'monthlyFee.deactivatedStateRecurrentFee' => 'monthlyFee.deactivatedStatusRecurrentFee', 'monthlyFee.activationReadyRecurrentFee' => 'monthlyFee.activationReadyStatusRecurrentFee', 'monthlyFee.activationPendingRecurrentFee' => 'monthlyFee.activationPendingStatusRecurrentFee'));
             $this->_mapReference($item, 'aggregator');
         }
     }
     if (!isset($data["published"])) {
         $data["published"] = isset($data["issuedDate"]) && $data["issuedDate"];
     }
     $customerDiscounts = \App_Util_Array::getItem($data, 'totalCharge.discounts.customer');
     if (empty($customerDiscounts)) {
         \App_Util_Array::unsetItem($data, 'totalCharge.discounts.customer');
     }
     return $data;
 }
 public function testGetConfigArray()
 {
     $struct = new StructConfigModel($this->_data);
     $this->assertEquals(App_Util_Array::getItem($this->_data, 'key1.key1_1'), $struct->getConfig(array('key' => 'key1.key1_1', 'default' => 'pop1')));
 }
 protected function _findByServiceType($serviceType)
 {
     $filters = array("_parents" => 1, "organizationId" => \App::getOrgUserLogged()->id);
     $result = $this->_getPybeService()->callMethod($this::LIST_METHOD, $filters);
     $httpResponse = $this->_getPybeService()->getLastResult();
     $this->_checkResponseResult($httpResponse, 'Pybe error looking for contracts by service type');
     $valid_service_ids = array();
     $services = \App_Util_Array::getItem($result, $this::SERVICE_KEY . '.items');
     if ($services) {
         foreach ($services as $service) {
             if (isset($service['type']) && $service['type'] == $serviceType) {
                 $valid_service_ids[] = $service['id'];
             }
         }
     }
     if (!$valid_service_ids) {
         return new ListResultModel(array('items' => array(), 'count' => 0));
     }
     $entries = array();
     $candidateContracts = array();
     $contracts = \App_Util_Array::getItem($result, $this::LIST_KEY . '.items');
     if ($contracts) {
         foreach ($contracts as $contract) {
             if (isset($contract['serviceId'])) {
                 if (in_array($contract['serviceId'], $valid_service_ids)) {
                     $entries[] = $contract;
                 }
             } elseif (isset($contract['parentContractId'])) {
                 if (isset($candidateContracts[$contract['parentContractId']])) {
                     $candidateContracts[$contract['parentContractId']][] = $contract;
                 } else {
                     $candidateContracts[$contract['parentContractId']] = array($contract);
                 }
             }
         }
     }
     if ($candidateContracts) {
         $parentContracts = \App_Util_Array::getItem($result, $this::PARENT_KEY . '.items');
         if ($parentContracts) {
             foreach ($parentContracts as $contract) {
                 if (isset($contract['serviceId'])) {
                     if (in_array($contract['serviceId'], $valid_service_ids) and isset($candidateContracts[$contract['id']])) {
                         $entries = array_merge($entries, $candidateContracts[$contract['id']]);
                     }
                 }
             }
         }
     }
     if (!$entries) {
         return new ListResultModel(array('items' => array(), 'count' => 0));
     }
     $outputItems = array();
     foreach ($entries as $entry) {
         $data = $this->_mapPybeModelToModel($entry);
         $outputItems[] = !is_null($this->_modelClassResult) ? new $this->_modelClassResult($data) : $data;
     }
     return new ListResultModel(array('items' => $outputItems, 'count' => count($outputItems)));
 }
示例#28
0
 public function findAllPage($filters)
 {
     $filterList = $filters['filterList'];
     $paging = $filters['paging'];
     $result = $this->_getPybeService()->callMethod($this::LIST_METHOD, $this->_mapFilterListPaging($filterList, $paging));
     $httpResponse = $this->_getPybeService()->getLastResult();
     $this->_checkResponseResult($httpResponse, 'Pybe error: findAll function');
     $filterList->setOldCount(\App_Util_Array::getItem($result, $this::LIST_KEY . '.count') ?: 0);
     $entries = \App_Util_Array::getItem($result, $this::LIST_KEY . '.items') ?: array();
     return $entries;
 }
 public function getAction()
 {
     parent::getAction();
     $type = \App_Util_Array::getItem($this->view->data, 'params.params.reportType');
     // Custom download report params
     switch ($type) {
         case ReportModel::KPI_MONTHLY:
             \App_Util_Array::unsetItem($this->view->data, 'params.params.orgId');
             break;
         case ReportModel::SUBSCRIPTION_SNAPSHOT_DAILY:
             $date = \App_Util_Array::getItem($this->view->data, 'params.params.dateDaily');
             \App_Util_Array::setItem($this->view->data, 'params.params.date', $date);
             \App_Util_Array::unsetItem($this->view->data, 'params.params.dateDaily');
             break;
     }
 }
示例#30
0
 public function testWildcardUnSetItemWithCount()
 {
     \App_Util_Array::setItem($this->_data, 'a.*.c', 'a');
     $count = 1;
     \App_Util_Array::unsetItem($this->_data, 'a.*.c', $count);
     $this->assertNull(\App_Util_Array::getItem($this->_data, 'a.b.c'));
     $this->assertNotNull(\App_Util_Array::getItem($this->_data, 'a.d.c'));
 }