Example #1
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);
 }