/**
  * Returns the detail (fields and data) of one item from the model.
  *
  * The return have:
  *  - The metadata of each field.
  *  - The data of one item.
  *  - The number of rows.
  *
  * If the request parameter "id" is null or 0, the data will be all values of a "new item",
  * if the "id" is an existing item, the data will be all the values of the item.
  *
  * The function use Phprojekt_ModelInformation_Default::ORDERING_FORM for get and sort the fields.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item to consult.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonDetailAction()
 {
     $id = $this->getRequest()->getParam('id');
     $occurrence = $this->getRequest()->getParam('occurrence');
     $userId = $this->getRequest()->getParam('userId', Phprojekt_Auth_Proxy::getEffectiveUserId());
     if (!Cleaner::validate('int', $id) && 'null' !== $id && 'undefined' !== $id) {
         throw new Zend_Controller_Action_Exception("Invalid id '{$id}'", 400);
     }
     $id = (int) $id;
     if (!Cleaner::validate('int', $userId)) {
         throw new Zend_Controller_Action_Exception("Invalid userId '{$userId}'", 400);
     }
     $userId = (int) $userId;
     if (in_array($occurrence, array('null', '0', 'undefined'))) {
         $occurrence = null;
     } else {
         try {
             $occurrence = new Datetime($occurrence, new DateTimeZone('UTC'));
         } catch (Exception $e) {
             throw new Zend_Controller_Action_Exception("Invalid occurrence timestamp '{$occurrence}'", 400);
         }
     }
     $this->setCurrentProjectId();
     if (Phprojekt_Auth_Proxy::hasProxyRightForUserById($userId)) {
         Phprojekt_Auth_Proxy::switchToUserById($userId);
     }
     $record = new Calendar2_Models_Calendar2();
     if (!empty($id)) {
         if (empty($occurrence)) {
             $record = $record->find($id);
         } else {
             $record = $record->findOccurrence($id, $occurrence);
         }
     }
     Phprojekt_Converter_Json::echoConvert($record, Phprojekt_ModelInformation_Default::ORDERING_FORM);
 }