예제 #1
0
 /**
  * Get all forms
  *
  * @param  int                 $limit
  * @param  int                 $page
  * @param  string              $sort
  * @param  \Pop\Module\Manager $modules
  * @return array
  */
 public function getAll($limit = null, $page = null, $sort = null, \Pop\Module\Manager $modules = null)
 {
     $order = null !== $sort ? $this->getSortOrder($sort, $page) : 'id ASC';
     if (null !== $limit) {
         $page = null !== $page && (int) $page > 1 ? $page * $limit - $limit : null;
         $rows = Table\Forms::findAll(['offset' => $page, 'limit' => $limit, 'order' => $order])->rows();
     } else {
         $rows = Table\Forms::findAll(['order' => $order])->rows();
     }
     foreach ($rows as $i => $row) {
         $fieldCount = [];
         $flds = null;
         if (null !== $modules && $modules->isRegistered('phire-fields')) {
             $flds = \Phire\Fields\Table\Fields::findAll();
         }
         if (null !== $flds) {
             foreach ($flds->rows() as $f) {
                 if (!empty($f->models)) {
                     $models = unserialize($f->models);
                     foreach ($models as $model) {
                         if ($model['model'] == 'Phire\\Forms\\Model\\Form') {
                             if ((null === $model['type_value'] || $row->id == $model['type_value']) && !in_array($row->id, $fieldCount)) {
                                 $fieldCount[] = $f->id;
                             }
                         }
                     }
                 }
             }
         }
         $rows[$i]->num_of_fields = count($fieldCount);
         $rows[$i]->num_of_submissions = Table\FormSubmissions::findBy(['form_id' => $row->id])->count();
     }
     return $rows;
 }
예제 #2
0
 /**
  * Get count of form submissions
  *
  * @param  int $id
  * @return int
  */
 public function getCount($id)
 {
     return Table\FormSubmissions::findBy(['form_id' => $id])->count();
 }