コード例 #1
0
 /**
  * Returns a list of all fields belonging to user's organisation
  *
  * @since 0.1.3
  */
 public function actionFields()
 {
     $em = DB::getEntityManager();
     $fieldRepo = $em->getRepository(Field::getEntityNamespace());
     /** @var FieldEntity[] $fields */
     $fields = $fieldRepo->findBy(['organisation' => Apollo::getInstance()->getUser()->getOrganisationId(), 'is_hidden' => false]);
     $response['error'] = null;
     $data = [];
     for ($i = 0; $i < count($fields); $i++) {
         $field = $fields[$i];
         $fieldData = [];
         $fieldData['id'] = $field->getId();
         $fieldData['essential'] = $field->isEssential();
         $fieldData['name'] = $field->getName();
         $fieldData['type'] = $field->getType();
         $subtype = 0;
         if ($field->getType() == 2) {
             if ($field->hasDefault()) {
                 if ($field->isAllowOther()) {
                     $subtype = 4;
                 } elseif ($field->isMultiple()) {
                     $subtype = 5;
                 } else {
                     $subtype = 3;
                 }
             } else {
                 if ($field->isMultiple()) {
                     $subtype = 2;
                 } else {
                     $subtype = 1;
                 }
             }
         }
         $fieldData['subtype'] = $subtype;
         $defaults = $field->getDefaults();
         $defaultsData = [];
         for ($k = 0; $k < count($defaults); $k++) {
             $defaultsData[] = $defaults[$k]->getValue();
         }
         $fieldData['defaults'] = $defaultsData;
         $data[] = $fieldData;
     }
     $response['data'] = array_reverse($data);
     echo json_encode($response);
 }