Beispiel #1
0
 public function init()
 {
     parent::init();
     $this->setTitle('Edit Classified Listing')->setDescription('Edit your listing below, then click \\"Save Changes\\" to save your listing.');
     $this->addElement('Radio', 'cover', array('label' => 'Album Cover'));
     $this->execute->setLabel('Save Changes');
 }
Beispiel #2
0
 public function createAction()
 {
     // Check auth
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     if (!$this->_helper->requireAuth()->setAuthParams('classified', null, 'create')->isValid()) {
         return;
     }
     // Get navigation
     $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('classified_main');
     $this->view->form = $form = new Classified_Form_Create();
     // set up data needed to check quota
     $viewer = Engine_Api::_()->user()->getViewer();
     $values['user_id'] = $viewer->getIdentity();
     $paginator = $this->_helper->api()->getApi('core', 'classified')->getClassifiedsPaginator($values);
     $this->view->quota = $quota = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'classified', 'max');
     $this->view->current_count = $paginator->getTotalItemCount();
     // If not post or form not valid, return
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $table = Engine_Api::_()->getItemTable('classified');
     $db = $table->getAdapter();
     $db->beginTransaction();
     try {
         // Create classified
         $values = array_merge($form->getValues(), array('owner_type' => $viewer->getType(), 'owner_id' => $viewer->getIdentity()));
         $classified = $table->createRow();
         $classified->setFromArray($values);
         $classified->save();
         // Set photo
         if (!empty($values['photo'])) {
             $classified->setPhoto($form->photo);
         }
         // Add tags
         $tags = preg_split('/[,]+/', $values['tags']);
         $tags = array_filter(array_map("trim", $tags));
         $classified->tags()->addTagMaps($viewer, $tags);
         // Add fields
         $customfieldform = $form->getSubForm('fields');
         $customfieldform->setItem($classified);
         $customfieldform->saveValues();
         // Set privacy
         $auth = Engine_Api::_()->authorization()->context;
         $roles = array('owner', 'owner_member', 'owner_member_member', 'owner_network', 'registered', 'everyone');
         if (empty($values['auth_view'])) {
             $values['auth_view'] = array("everyone");
         }
         if (empty($values['auth_comment'])) {
             $values['auth_comment'] = array("everyone");
         }
         $viewMax = array_search($values['auth_view'], $roles);
         $commentMax = array_search($values['auth_comment'], $roles);
         foreach ($roles as $i => $role) {
             $auth->setAllowed($classified, $role, 'view', $i <= $viewMax);
             $auth->setAllowed($classified, $role, 'comment', $i <= $commentMax);
         }
         // Commit
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     $db->beginTransaction();
     try {
         $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($viewer, $classified, 'classified_new');
         if ($action != null) {
             Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $classified);
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     // Redirect
     $allowed_upload = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'classified', 'photo');
     if ($allowed_upload) {
         return $this->_helper->redirector->gotoRoute(array('action' => 'success', 'classified_id' => $classified->classified_id), 'classified_specific', true);
     } else {
         return $this->_helper->redirector->gotoUrl($classified->getHref(), array('prependBase' => false));
     }
 }