/**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Group'])) {
         $model->attributes = $_POST['Group'];
         if ($model->save()) {
             $criteria = new CDbCriteria();
             $criteria->condition = 'group_id=:group_id';
             $criteria->params = array(':group_id' => $model->id);
             BranchGroup::model()->deleteAll($criteria);
             if (!empty($_POST['Group']['branches'])) {
                 foreach ($_POST['Group']['branches'] as $branchid) {
                     $branchGroup = new BranchGroup();
                     $branchGroup->group_id = $model->id;
                     $branchGroup->branch_id = $branchid;
                     $branchGroup->save();
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model));
 }
Example #2
0
 public function listgroupsAction()
 {
     $options = $this->getFrontController()->getParam('bootstrap')->getApplication()->getOptions();
     $model = new BranchGroup();
     $select = $model->select();
     $request = $this->getRequest();
     $page = $request->getParam('page', 1);
     $sort = $request->getParam('sort', 'branch_group_name');
     $order = $request->getParam('order', 'asc');
     $select->order($sort . ' ' . $order);
     $paginator = new Base_Paginator(new Zend_Paginator_Adapter_DbTableSelect($select));
     $paginator->setCurrentPageNumber($page);
     $this->view->paginator = $paginator;
     $this->view->headers = array('branch_group_name', 'description');
 }
Example #3
0
 public function createBranchGroup($form)
 {
     $values = $form->getValues();
     $branch = new BranchGroup();
     $row = $branch->createRow($values);
     $row->save();
 }