/**
  * embed lead and person details with resulset
  * @author sheraz salem
  * @param unknown $data resultdata
  * @return array
  */
 public function embedLeadWithTemplate($data)
 {
     $results = parent::getOne($data);
     /*
             foreach ($results as &$field) {
                 if (isset($field['recipient'])) {
     
                     foreach ($field['recipient'] as $index => &$recipientFields) {
                         if (isset($recipientFields['person'])) {
                             // Getting the person data in each Recipient
                             $recipientPerson = array();
                             $this->_documentClassName = 'MoveIn4Person\Document\PersonDocument';
                             $response = new \SimpleXMLIterator('<?xml version="1.0" encoding="UTF-8"?><person/>');
                             $response->addChild('id', (string) $recipientFields['person']);
                             $response->addChild('fields', 'firstName');
                             $response->addChild('fields', 'surname');
                             $response->addChild('fields', 'lead');
                             $person = $this->getOne($response);
     
                             $recipientPerson['id'] = $recipientFields['person'];
                             $recipientPerson['firstName'] = $person['fields']['firstName'];
                             $recipientPerson['surname'] = $person['fields']['surname'];
                             $recipientPerson['lead'] = $person['fields']['lead'];
                             $recipientFields['person'] = $recipientPerson;
     
                             foreach ($person['fields']['lead'] as $lead) {
                                 if (isset($recipientFields['documentId'])) {
                                     if ($lead['id']==$recipientFields['documentId']) {
                                         // Getting the Marketing Sources Name
                                         $marketSources = array();
                                         $marketSources['sourceShort'] = '';
                                         $marketSources['sourceDetail'] = '';
                                         $this->_documentClassName = 'MoveIn4MarketingSource\Document\MarketingSourceDocument';
                                         if ($lead['sourceShort']!=null) {
                                             $filterShort = new \SimpleXMLIterator('<?xml version="1.0" encoding="UTF-8"?><MarketingSource/>');
                                             $filterShort->addChild('id', (string) $lead['sourceShort']);
                                             $filterShort->addChild('fields', 'displayName');
                                             $sourceShort = $this->getOne($filterShort);
                                             $marketSources['sourceShort'] = $sourceShort['fields']['displayName'];
                                         }
     
                                         if ($lead['sourceDetail'] != null) {
                                             $filterDetail = new \SimpleXMLIterator('<?xml version="1.0" encoding="UTF-8"?><MarketingSource/>');
                                             $filterDetail->addChild('id', (string) $lead['sourceDetail']);
                                             $filterDetail->addChild('fields', 'displayName');
                                             $sourceDetail = $this->getOne($filterDetail);
                                             $marketSources['sourceDetail'] = $sourceDetail['fields']['displayName'];
                                         }
                                         $marketSources['id'] = $lead['id'];
                                         $recipientFields['documentId'] = $marketSources;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
     */
     return $results;
 }
Example #2
0
 /**
  * handleRole function
  * @param SimpleXMLIterator $data array
  * @return array
  */
 public function handleRole($data)
 {
     $roleID = $this->formatIdForQuery("MoveIn4Role\\Document\\RoleDocument", $data->role->id);
     if (isset($data->role->delete)) {
         /* $handler->update()
            ->field('role')->pull(array('$ref' => 'MoveIn4Role-Role' , '$id' => $roleID, '$db' => $this->_dm->getConfiguration()->getDefaultDB())); */
         parent::edit($data);
     } else {
         // check if role is already exists in user document role or not. if not then add it else do nothing.
         $userDocument = $this->_dm->find('MoveIn4User\\Document\\UserDocument', (string) $data->id);
         $roleDocument = $this->_dm->find('MoveIn4User\\Document\\UserDocument', (string) $data->role->id);
         $currentRoles = $userDocument->getRole();
         $checkIfExists = false;
         foreach ($currentRoles as $role) {
             $roleId = $role->getId();
             if ($data->role->id == $roleId) {
                 $checkIfExists = true;
             }
         }
         if ($checkIfExists == false) {
             parent::edit($data);
             /*  $handler->update()
                 ->field('role')->push(array('$ref' => 'MoveIn4Role-Role' , '$id' => $roleID, '$db' => $this->_dm->getConfiguration()->getDefaultDB())); */
         }
     }
     /*
             $handler->field('id')->equals((string)$data->id)
                             ->getQuery()
                             ->execute(); */
     return array('id' => $data->id);
 }