public function load($staff_id)
 {
     $data = $this->wpdb->get_results('
         SELECT c.name AS category_name, s.*
         FROM ' . AB_Category::getTableName() . ' c
         INNER JOIN ' . AB_Service::getTableName() . ' s ON c.id = s.category_id
     ', ARRAY_A);
     if (!$data) {
         $data = array();
     }
     $this->uncategorized_services = AB_Service::query('s')->where('s.category_id', null)->fetchArray();
     $staff_services = AB_StaffService::query('ss')->select('ss.service_id, ss.price, ss.capacity')->where('ss.staff_id', $staff_id)->fetchArray();
     if ($staff_services) {
         foreach ($staff_services as $staff_service) {
             $this->selected[$staff_service['service_id']] = array('price' => $staff_service['price'], 'capacity' => $staff_service['capacity']);
         }
     }
     foreach ($data as $row) {
         if (!isset($this->collection[$row['category_id']])) {
             $abCategory = new AB_Category();
             $abCategory->set('id', $row['category_id']);
             $abCategory->set('name', $row['category_name']);
             $this->collection[$row['category_id']] = $abCategory;
         }
         unset($row['category_name']);
         $abService = new AB_Service($row);
         $this->category_services[$row['category_id']][] = $abService->get('id');
         $this->collection[$row['category_id']]->addService($abService);
     }
 }
 public function load($staff_id)
 {
     $data = $this->wpdb->get_results('
         SELECT c.name AS category_name, s.*
         FROM ab_category c
         INNER JOIN ab_service s ON c.id = s.category_id
     ', ARRAY_A);
     if (!$data) {
         $data = array();
     }
     $uncategorized_services = $this->wpdb->get_results('SELECT * FROM ab_service WHERE category_id IS NULL');
     foreach ($uncategorized_services as $uncategorized_service) {
         $abService = new AB_Service();
         $abService->setData($uncategorized_service);
         $this->uncategorized_services[] = $abService;
     }
     $rows = $this->wpdb->get_results($this->wpdb->prepare('
         SELECT s.service_id, s.price, s.capacity
         FROM ab_staff_service s
         WHERE s.staff_id = %d
     ', $staff_id));
     if ($rows) {
         foreach ($rows as $row) {
             $this->selected[$row->service_id] = array('price' => $row->price, 'capacity' => $row->capacity);
         }
     }
     foreach ($data as $row) {
         if (!isset($this->collection[$row['category_id']])) {
             $abCategory = new AB_Category();
             $abCategory->set('id', $row['category_id']);
             $abCategory->set('name', $row['category_name']);
             $this->collection[$row['category_id']] = $abCategory;
         }
         unset($row['category_name']);
         $abService = new AB_Service();
         $abService->setData($row);
         $this->category_services[$row['category_id']][] = $abService->get('id');
         $this->collection[$row['category_id']]->addService($abService);
     }
 }
 /**
  * Delete category.
  */
 public function executeDeleteCategory()
 {
     $category = new AB_Category();
     $category->set('id', $this->getParameter('id', 0));
     $category->delete();
 }