Пример #1
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  * @since   11.1
  */
 protected function getOptions()
 {
     // Possible actions are: addparent, addchild, addpartner
     // Initialize variables.
     $appId = JoaktreeHelper::getApplicationId();
     $action = JoaktreeHelper::getAction();
     $personId = JoaktreeHelper::getRelationId();
     // Initialize variables.
     $options = array();
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     switch ($action) {
         case "addparent":
             // family for adding parents
             // select all parents of the person, and for every parent its family-id
             $query->select(' jrn.family_id ');
             $query->select(' jrn.person_id_2 AS pid2 ');
             $query->from(' #__joaktree_relations  jrn ');
             $query->where(' jrn.app_id      = ' . $appId . ' ');
             $query->where(' jrn.person_id_1 = ' . $db->quote($personId) . ' ');
             $query->where(' jrn.type        IN (' . $db->quote('father') . ', ' . $db->quote('mother') . ') ');
             $query->select(JoaktreeHelper::getConcatenatedFullName() . ' AS fullName ');
             $query->innerJoin(' #__joaktree_persons  jpn ' . ' ON (   jpn.app_id = jrn.app_id ' . '    AND jpn.id     = jrn.person_id_2 ' . '    ) ');
             $query->innerJoin(JoaktreeHelper::getJoinAdminPersons());
             break;
         case "addchild":
             // family for adding children
             // select all partners of the person, and for every partner its family-id
             $query->select(' jrn.family_id ');
             $query->select(' IF( (jrn.person_id_1 = ' . $db->quote($personId) . ') ' . '   , jrn.person_id_2 ' . '   , jrn.person_id_1 ' . '   ) AS pid2 ');
             $query->from(' #__joaktree_relations  jrn ');
             $query->where(' jrn.app_id      = ' . $appId . ' ');
             $query->where(' (  jrn.person_id_1 = ' . $db->quote($personId) . ' ' . ' OR jrn.person_id_2 = ' . $db->quote($personId) . ' ' . ' ) ');
             $query->where(' jrn.type        = ' . $db->quote('partner') . ' ');
             $query->select(JoaktreeHelper::getConcatenatedFullName() . ' AS fullName ');
             $query->innerJoin(' #__joaktree_persons  jpn ' . ' ON (   jpn.app_id = jrn.app_id ' . '    AND (  jpn.id     = jrn.person_id_1 ' . '        OR jpn.id     = jrn.person_id_2 ' . '        ) ' . '    AND jpn.id != ' . $db->quote($personId) . ' ' . '    ) ');
             $query->innerJoin(JoaktreeHelper::getJoinAdminPersons());
             break;
         default:
             // continue
             break;
     }
     if ($action == 'addparent' || $action == 'addchild') {
         // Set the query and get the result list.
         $db->setQuery($query);
         $items = $db->loadObjectlist();
         // Check for an error.
         if ($db->getErrorNum()) {
             JError::raiseWarning(500, $db->getErrorMsg());
             return $options;
         }
         // Build the field options.
         if (!empty($items)) {
             foreach ($items as $item) {
                 $options[] = JHtml::_('select.option', $item->pid2 . '!' . $item->family_id, $item->fullName);
             }
         }
     }
     if ($action == 'addpartner' || $action == 'addchild') {
         // select family-id of single parent families.
         // new partner or new child may be added to this family
         $query->clear();
         $query->select(' DISTINCT jrn.family_id ');
         $query->from(' #__joaktree_relations  jrn ');
         $query->where(' jrn.app_id = ' . $appId . ' ');
         $query->where(' jrn.person_id_2 = ' . $db->quote($personId) . ' ');
         $query->where(' jrn.type IN (' . $db->quote('father') . ', ' . $db->quote('mother') . ') ');
         $query->where(' NOT EXISTS ' . ' ( SELECT 1 ' . '   FROM   #__joaktree_relations  jrn2 ' . '   WHERE  jrn2.app_id    = jrn.app_id ' . '   AND    jrn2.family_id = jrn.family_id ' . '   AND    jrn2.type      = ' . $db->quote('partner') . ' ' . ' ) ');
         $query->select(' GROUP_CONCAT(jpn.firstName SEPARATOR ' . $db->quote(', ') . ') AS names ');
         $query->innerJoin(' #__joaktree_persons  jpn ' . ' ON (   jpn.app_id = jrn.app_id ' . '    AND jpn.id     = jrn.person_id_1 ' . '    ) ');
         $query->innerJoin(JoaktreeHelper::getJoinAdminPersons());
         $db->setQuery($query);
         $familyId = $db->loadObject();
     }
     // if familyId is unknown (either in case of addparent, of with no result for the last query
     // the familyId is set to be '0'. The option is added to the list.
     switch ($action) {
         case "addparent":
             $options[] = JHtml::_('select.option', '0!0', JText::_('JT_NEWFAMILY1'));
             break;
         case "addchild":
             $familyId = is_object($familyId) && $familyId->family_id ? $familyId->family_id : '0';
             $options[] = JHtml::_('select.option', '0!' . $familyId, JText::_('JT_NEWFAMILY3'));
             break;
         case "addpartner":
             if (is_object($familyId) && $familyId->family_id) {
                 $options[] = JHtml::_('select.option', '0!' . $familyId->family_id, $familyId->names);
             }
             // finally we add the option for a new partner / new family
             $options[] = JHtml::_('select.option', '0!0', JText::_('JT_NEWFAMILY2'));
             break;
         default:
             // continue
             break;
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Пример #2
0
 public function getRelationId()
 {
     return JoaktreeHelper::getRelationId();
 }