当前位置: 首页>>代码示例>>PHP>>正文


PHP General::intval方法代码示例

本文整理汇总了PHP中General::intval方法的典型用法代码示例。如果您正苦于以下问题:PHP General::intval方法的具体用法?PHP General::intval怎么用?PHP General::intval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在General的用法示例。


在下文中一共展示了General::intval方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processRawFieldData

 function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
 {
     $status = self::__OK__;
     $increment_subsequent_order = false;
     if ($entry_id != null) {
         $entry_id = General::intval($entry_id);
     }
     if (is_array($data)) {
         //TODO Auto Increment for filtered ordering for now just return the data as it is already properly formatted
         return $data;
     }
     if ($entry_id) {
         $new_value = $data;
         $current_value = Symphony::Database()->fetchVar("value", 0, "\n\t\t\t\t\tSELECT value\n\t\t\t\t\tFROM tbl_entries_data_{$this->get('id')}\n\t\t\t\t\tWHERE entry_id=" . $entry_id . "\n\t\t\t\t\tLIMIT 1\n\t\t\t\t");
         if (isset($current_value) && $current_value !== $new_value) {
             $increment_subsequent_order = true;
         }
     } else {
         $increment_subsequent_order = true;
     }
     if ($increment_subsequent_order && !empty($data)) {
         Symphony::Database()->query("UPDATE tbl_entries_data_{$this->get('id')} SET value = (value + 1) WHERE value >= " . $data);
     }
     return array('value' => $data);
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:25,代码来源:field.order_entries.php

示例2: send

 /**
  * Send an email using an SMTP server
  *
  * @throws EmailGatewayException
  * @throws EmailValidationException
  * @throws Exception
  * @return boolean
  */
 public function send()
 {
     $this->validate();
     $settings = array();
     $settings['helo_hostname'] = $this->_helo_hostname;
     if ($this->_auth) {
         $settings['username'] = $this->_user;
         $settings['password'] = $this->_pass;
     }
     $settings['secure'] = $this->_secure;
     try {
         if (!is_a($this->_SMTP, 'SMTP')) {
             $this->_SMTP = new SMTP($this->_host, $this->_port, $settings);
         }
         // Encode recipient names (but not any numeric array indexes)
         $recipients = array();
         foreach ($this->_recipients as $name => $email) {
             // Support Bcc header
             if (isset($this->_header_fields['Bcc']) && $this->_header_fields['Bcc'] == $email) {
                 continue;
             }
             // if the key is not numeric, qEncode the key.
             $name = General::intval($name) > -1 ? General::intval($name) : EmailHelper::qEncode($name);
             $recipients[$name] = $email;
         }
         // Combine keys and values into a recipient list (name <email>, name <email>).
         $recipient_list = EmailHelper::arrayToList($recipients);
         // Encode the subject
         $subject = EmailHelper::qEncode((string) $this->_subject);
         // Build the 'From' header field body
         $from = empty($this->_sender_name) ? $this->_sender_email_address : EmailHelper::qEncode($this->_sender_name) . ' <' . $this->_sender_email_address . '>';
         // Build the 'Reply-To' header field body
         if (!empty($this->_reply_to_email_address)) {
             $reply_to = empty($this->_reply_to_name) ? $this->_reply_to_email_address : EmailHelper::qEncode($this->_reply_to_name) . ' <' . $this->_reply_to_email_address . '>';
         }
         if (!empty($reply_to)) {
             $this->_header_fields = array_merge($this->_header_fields, array('Reply-To' => $reply_to));
         }
         // Build the body text using attachments, html-text and plain-text.
         $this->prepareMessageBody();
         // Build the header fields
         $this->_header_fields = array_merge($this->_header_fields, array('Message-ID' => sprintf('<%s@%s>', md5(uniqid()), HTTP_HOST), 'Date' => date('r'), 'From' => $from, 'Subject' => $subject, 'To' => $recipient_list, 'X-Mailer' => 'Symphony Email Module', 'MIME-Version' => '1.0'));
         // Set header fields and fold header field bodies
         foreach ($this->_header_fields as $name => $body) {
             $this->_SMTP->setHeader($name, EmailHelper::fold($body));
         }
         // Send the email command. If the envelope from variable is set, use that for the MAIL command. This improves bounce handling.
         $this->_SMTP->sendMail(is_null($this->_envelope_from) ? $this->_sender_email_address : $this->_envelope_from, $this->_recipients, $this->_body);
         if ($this->_keepalive === false) {
             $this->closeConnection();
         }
         $this->reset();
     } catch (SMTPException $e) {
         throw new EmailGatewayException($e->getMessage());
     }
     return true;
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:65,代码来源:email.smtp.php

示例3: send

 /**
  * Send an email using the PHP mail() function
  *
  * Please note that 'encoded-words' should be used according to
  * RFC2047. Basically this means that the subject should be
  * encoded if necessary, as well as (real) names in 'From', 'To'
  * or 'Reply-To' header field bodies. For details see RFC2047.
  *
  * The parts of a message body should be encoded (quoted-printable
  * or base64) to make non-US-ASCII text work with the widest range
  * of email transports and clients.
  *
  * @throws EmailGatewayException
  * @throws EmailValidationException
  * @return bool
  */
 public function send()
 {
     $this->validate();
     try {
         // Encode recipient names (but not any numeric array indexes)
         $recipients = array();
         foreach ($this->_recipients as $name => $email) {
             // Support Bcc header
             if (isset($this->_header_fields['Bcc']) && $this->_header_fields['Bcc'] == $email) {
                 continue;
             }
             // if the key is not numeric, qEncode the key.
             $name = General::intval($name) > -1 ? General::intval($name) : EmailHelper::qEncode($name);
             $recipients[$name] = $email;
         }
         // Combine keys and values into a recipient list (name <email>, name <email>).
         $recipient_list = EmailHelper::arrayToList($recipients);
         // Encode the subject
         $subject = EmailHelper::qEncode((string) $this->_subject);
         // Build the 'From' header field body
         $from = empty($this->_sender_name) ? $this->_sender_email_address : EmailHelper::qEncode($this->_sender_name) . ' <' . $this->_sender_email_address . '>';
         // Build the 'Reply-To' header field body
         if (!empty($this->_reply_to_email_address)) {
             $reply_to = empty($this->_reply_to_name) ? $this->_reply_to_email_address : EmailHelper::qEncode($this->_reply_to_name) . ' <' . $this->_reply_to_email_address . '>';
         }
         if (!empty($reply_to)) {
             $this->_header_fields = array_merge($this->_header_fields, array('Reply-To' => $reply_to));
         }
         // Build the message from the attachments, the html-text and the plain-text.
         $this->prepareMessageBody();
         // Build the header fields
         $this->_header_fields = array_merge($this->_header_fields, array('Message-ID' => sprintf('<%s@%s>', md5(uniqid()), HTTP_HOST), 'Date' => date('r'), 'From' => $from, 'X-Mailer' => 'Symphony Email Module', 'MIME-Version' => '1.0'));
         // Format header fields
         $header_fields = array();
         foreach ($this->_header_fields as $name => $body) {
             $header_fields[] = sprintf('%s: %s', $name, $body);
         }
         /**
          * Make things nice for mail().
          * - Replace CRLF in the message body by LF as required by mail().
          * - Implode the header fields as required by mail().
          */
         $this->_body = str_replace("\r\n", "\n", $this->_body);
         $header_fields = implode("\r\n", $header_fields);
         // Send the email
         mail($recipient_list, $subject, $this->_body, $header_fields, "-f{$this->_sender_email_address}");
     } catch (Exception $e) {
         throw new EmailGatewayException($e->getMessage());
     }
     return true;
 }
开发者ID:rc1,项目名称:WebAppsWithCmsStartHere,代码行数:67,代码来源:email.sendmail.php

示例4: view

 public function view()
 {
     $database = Symphony::Configuration()->get('db', 'database');
     $field_ids = array_map(array('General', 'intval'), explode(',', General::sanitize($_GET['field_id'])));
     $search = MySQL::cleanValue(General::sanitize($_GET['query']));
     $types = array_map(array('MySQL', 'cleanValue'), explode(',', General::sanitize($_GET['types'])));
     $limit = General::intval(General::sanitize($_GET['limit']));
     // Set limit
     if ($limit === 0) {
         $max = '';
     } elseif ($limit < 0) {
         $max = ' LIMIT 100';
     } else {
         $max = sprintf(' LIMIT %d', $limit);
     }
     // Entries
     if (in_array('entry', $types)) {
         foreach ($field_ids as $field_id) {
             $this->get($database, intval($field_id), $search, $max);
         }
     }
     // Associations
     if (in_array('association', $types)) {
         foreach ($field_ids as $field_id) {
             $association_id = $this->getAssociationId($field_id);
             if ($association_id) {
                 $this->get($database, $association_id, $search, $max);
             }
         }
     }
     // Static values
     if (in_array('static', $types)) {
         foreach ($field_ids as $field_id) {
             $this->getStatic($field_id, $search);
         }
     }
     // Return results
     return $this->_Result;
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:39,代码来源:content.ajaxquery.php

示例5: arrayToList

 /**
  * Implodes an associative array or straight array to a
  * comma-separated string
  *
  * @param array $array
  * @return string
  */
 public static function arrayToList(array $array = array())
 {
     $return = array();
     foreach ($array as $name => $email) {
         $return[] = empty($name) || General::intval($name) > -1 ? $email : $name . ' <' . $email . '>';
     }
     return implode(', ', $return);
 }
开发者ID:rc1,项目名称:WebAppsWithCmsStartHere,代码行数:15,代码来源:class.emailhelper.php

示例6: appendFormattedElement

 /**
  * Appends data into the XML tree of a Data Source
  * @param $wrapper
  * @param $data
  */
 public function appendFormattedElement(&$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
 {
     if (!is_array($data) || empty($data)) {
         return;
     }
     // root for all values
     $root = new XMLElement($this->get('element_name'));
     // selected items
     $entries = static::getEntries($data);
     // current linked entries
     $root->setAttribute('entries', $data['entries']);
     // available sections
     $root->setAttribute('sections', $this->get('sections'));
     // included elements
     $elements = $this->parseElements();
     // cache
     $sectionsCache = new CacheableFetch('SectionManager');
     // DS mode
     if (!$mode) {
         $mode = '*';
     }
     $parentDeepness = General::intval($this->recursiveDeepness);
     $deepness = General::intval($this->get('deepness'));
     // both deepnesses are defined and parent restricts more
     if ($parentDeepness > 0 && $deepness > 0 && $parentDeepness < $deepness) {
         $deepness = $parentDeepness;
     } else {
         if ($parentDeepness > 0 && $deepness < 1) {
             $deepness = $parentDeepness;
         }
     }
     // cache recursive level because recursion might
     // change its value later on.
     $recursiveLevel = $this->recursiveLevel;
     // build entries
     foreach ($entries as $eId) {
         $item = new XMLElement('item');
         // output id
         $item->setAttribute('id', $eId);
         // output recursive level
         $item->setAttribute('level', $recursiveLevel);
         $item->setAttribute('max-level', $deepness);
         // max recursion check
         if ($deepness < 1 || $recursiveLevel < $deepness) {
             // current entry, without data
             $entry = $this->fetchEntry($eId);
             // entry not found...
             if (!$entry || empty($entry)) {
                 $error = new XMLElement('error');
                 $error->setAttribute('id', $eId);
                 $error->setValue(__('Error: entry `%s` not found', array($eId)));
                 $root->prependChild($error);
                 continue;
             }
             // fetch section infos
             $sectionId = $entry->get('section_id');
             $item->setAttribute('section-id', $sectionId);
             $section = $sectionsCache->fetch($sectionId);
             $sectionName = $section->get('handle');
             $item->setAttribute('section', $sectionName);
             // adjust the mode for the current section
             $curMode = $mode;
             if ($curMode) {
                 // remove section name from current mode, i.e sectionName.field
                 if (preg_match('/^(' . $sectionName . '\\.)(.*)$/sU', $curMode)) {
                     $curMode = preg_replace('/^' . $sectionName . '\\./sU', '', $curMode);
                 } else {
                     if (preg_match('/^(' . $sectionName . ')$/sU', $curMode)) {
                         $curMode = null;
                     } else {
                         if (preg_match('/\\./sU', $curMode)) {
                             $item->setAttribute('forbidden', 'yes');
                             $root->appendChild($item);
                             continue;
                         }
                     }
                 }
             }
             $item->setAttribute('section', $section->get('handle'));
             // Get the valid elements for this section only
             $sectionElements = $elements[$sectionName];
             // get all if no mode is set or section element is empty
             // or mode is * and * is allowed
             if (!$curMode || empty($sectionElements) || $curMode === '*' && in_array('*', $sectionElements)) {
                 // setting null = get all
                 $sectionElements = null;
             } else {
                 if (in_array('*', $sectionElements) && !!$curMode) {
                     // get only the mode
                     $sectionElements = array($curMode);
                 } else {
                     if ($curMode !== '*') {
                         foreach ($sectionElements as $secElemIndex => $sectionElement) {
                             if ($curMode != $sectionElement) {
                                 unset($sectionElements[$secElemIndex]);
//.........这里部分代码省略.........
开发者ID:hotdoy,项目名称:EDclock,代码行数:101,代码来源:field.entry_relationship.php

示例7: processFilters

 /**
  * This function iterates over `dsParamFILTERS` and builds the relevant
  * `$where` and `$joins` parameters with SQL. This SQL is generated from
  * `Field->buildDSRetrievalSQL`. A third parameter, `$group` is populated
  * with boolean from `Field->requiresSQLGrouping()`
  *
  * @param string $where
  * @param string $joins
  * @param boolean $group
  * @throws Exception
  */
 public function processFilters(&$where, &$joins, &$group)
 {
     if (!is_array($this->dsParamFILTERS) || empty($this->dsParamFILTERS)) {
         return;
     }
     $pool = FieldManager::fetch(array_filter(array_keys($this->dsParamFILTERS), 'is_int'));
     self::$_fieldPool += $pool;
     if (!is_string($where)) {
         $where = '';
     }
     foreach ($this->dsParamFILTERS as $field_id => $filter) {
         if (is_array($filter) && empty($filter) || trim($filter) == '') {
             continue;
         }
         if (!is_array($filter)) {
             $filter_type = Datasource::determineFilterType($filter);
             $value = preg_split('/' . ($filter_type == Datasource::FILTER_AND ? '\\+' : '(?<!\\\\),') . '\\s*/', $filter, -1, PREG_SPLIT_NO_EMPTY);
             $value = array_map('trim', $value);
             $value = array_map(array('Datasource', 'removeEscapedCommas'), $value);
         } else {
             $value = $filter;
         }
         if (!in_array($field_id, self::$_system_parameters) && $field_id != 'id' && !self::$_fieldPool[$field_id] instanceof Field) {
             throw new Exception(__('Error creating field object with id %1$d, for filtering in data source %2$s. Check this field exists.', array($field_id, '<code>' . $this->dsParamROOTELEMENT . '</code>')));
         }
         // Support system:id as well as the old 'id'. #1691
         if ($field_id === 'system:id' || $field_id === 'id') {
             $c = 'IN';
             if (stripos($value[0], 'not:') === 0) {
                 $value[0] = preg_replace('/^not:\\s*/', null, $value[0]);
                 $c = 'NOT IN';
             }
             // Cast all ID's to integers. (RE: #2191)
             $value = array_map(function ($val) {
                 $val = General::intval($val);
                 // General::intval can return -1, so reset that to 0
                 // so there are no side effects for the following
                 // array_sum and array_filter calls. RE: #2475
                 if ($val === -1) {
                     $val = 0;
                 }
                 return $val;
             }, $value);
             $count = array_sum($value);
             $value = array_filter($value);
             // If the ID was cast to 0, then we need to filter on 'id' = 0,
             // which will of course return no results, but without it the
             // Datasource will return ALL results, which is not the
             // desired behaviour. RE: #1619
             if ($count === 0) {
                 $value[] = 0;
             }
             // If there are no ID's, no need to filter. RE: #1567
             if (!empty($value)) {
                 $where .= " AND `e`.id " . $c . " (" . implode(", ", $value) . ") ";
             }
         } elseif ($field_id === 'system:creation-date' || $field_id === 'system:modification-date' || $field_id === 'system:date') {
             $date_joins = '';
             $date_where = '';
             $date = new FieldDate();
             $date->buildDSRetrievalSQL($value, $date_joins, $date_where, $filter_type == Datasource::FILTER_AND ? true : false);
             // Replace the date field where with the `creation_date` or `modification_date`.
             $date_where = preg_replace('/`t\\d+`.date/', $field_id !== 'system:modification-date' ? '`e`.creation_date_gmt' : '`e`.modification_date_gmt', $date_where);
             $where .= $date_where;
         } else {
             if (!self::$_fieldPool[$field_id]->buildDSRetrievalSQL($value, $joins, $where, $filter_type == Datasource::FILTER_AND ? true : false)) {
                 $this->_force_empty_result = true;
                 return;
             }
             if (!$group) {
                 $group = self::$_fieldPool[$field_id]->requiresSQLGrouping();
             }
         }
     }
 }
开发者ID:rc1,项目名称:WebAppsWithCmsStartHere,代码行数:86,代码来源:class.datasource.section.php

示例8: view

    /**
     *
     * Builds the content view
     */
    public function view()
    {
        // _context[0] => entry values
        // _context[1] => fieldId
        if (!is_array($this->_context) || empty($this->_context)) {
            $this->_Result->appendChild(new XMLElement('error', __('Parameters not found')));
            return;
        } else {
            if (count($this->_context) < self::NUMBER_OF_URL_PARAMETERS) {
                $this->_Result->appendChild(new XMLElement('error', __('Not enough parameters')));
                return;
            } else {
                if (count($this->_context) > self::NUMBER_OF_URL_PARAMETERS) {
                    $this->_Result->appendChild(new XMLElement('error', __('Too many parameters')));
                    return;
                }
            }
        }
        $entriesId = explode(',', MySQL::cleanValue($this->_context[0]));
        $entriesId = array_map(array('General', 'intval'), $entriesId);
        if (!is_array($entriesId) || empty($entriesId)) {
            $this->_Result->appendChild(new XMLElement('error', __('No entry no found')));
            return;
        }
        $parentFieldId = General::intval($this->_context[1]);
        if ($parentFieldId < 1) {
            $this->_Result->appendChild(new XMLElement('error', __('Parent field id not valid')));
            return;
        }
        $parentField = $this->fieldManager->fetch($parentFieldId);
        if (!$parentField || empty($parentField)) {
            $this->_Result->appendChild(new XMLElement('error', __('Parent field not found')));
            return;
        }
        if ($parentField->get('type') != 'entry_relationship') {
            $this->_Result->appendChild(new XMLElement('error', __('Parent field is `%s`, not `entry_relationship`', array($parentField->get('type')))));
            return;
        }
        $includedElements = $this->parseIncludedElements($parentField);
        $xmlParams = self::getXmlParams();
        // Get entries one by one since they may belong to
        // different sections, which prevents us from
        // passing an array of entryId.
        foreach ($entriesId as $key => $entryId) {
            $entry = $this->entryManager->fetch($entryId);
            if (empty($entry)) {
                $li = new XMLElement('li', null, array('data-entry-id' => $entryId));
                $header = new XMLElement('header', null, array('class' => 'frame-header'));
                $title = new XMLElement('h4');
                $title->appendChild(new XMLElement('strong', __('Entry %s not found', array($entryId))));
                $header->appendChild($title);
                $options = new XMLElement('div', null, array('class' => 'destructor'));
                if ($parentField->is('allow_link')) {
                    $options->appendChild(new XMLElement('a', __('Un-link'), array('class' => 'unlink', 'data-unlink' => $entryId)));
                }
                $header->appendChild($options);
                $li->appendChild($header);
                $this->_Result->appendChild($li);
            } else {
                $entry = $entry[0];
                $entryData = $entry->getData();
                $entrySection = $this->sectionManager->fetch($entry->get('section_id'));
                $entryVisibleFields = $entrySection->fetchVisibleColumns();
                $entryFields = $entrySection->fetchFields();
                $entrySectionHandle = $this->getSectionName($entry, 'handle');
                $li = new XMLElement('li', null, array('data-entry-id' => $entryId, 'data-section' => $entrySectionHandle, 'data-section-id' => $entrySection->get('id')));
                $header = new XMLElement('header', null, array('class' => 'frame-header'));
                $title = new XMLElement('h4');
                $title->appendChild(new XMLElement('strong', $this->getEntryTitle($entry, $entryVisibleFields, $entryFields)));
                $title->appendChild(new XMLElement('span', $this->getSectionName($entry)));
                $header->appendChild($title);
                $options = new XMLElement('div', null, array('class' => 'destructor'));
                if ($parentField->is('allow_edit')) {
                    $title->setAttribute('data-edit', $entryId);
                    $options->appendChild(new XMLElement('a', __('Edit'), array('class' => 'edit', 'data-edit' => $entryId)));
                }
                if ($parentField->is('allow_delete')) {
                    $options->appendChild(new XMLElement('a', __('Delete'), array('class' => 'delete', 'data-delete' => $entryId)));
                }
                if ($parentField->is('allow_link')) {
                    $options->appendChild(new XMLElement('a', __('Replace'), array('class' => 'unlink', 'data-replace' => $entryId)));
                }
                if ($parentField->is('allow_delete') || $parentField->is('allow_link')) {
                    $options->appendChild(new XMLElement('a', __('Un-link'), array('class' => 'unlink', 'data-unlink' => $entryId)));
                }
                $header->appendChild($options);
                $li->appendChild($header);
                $xslFilePath = WORKSPACE . '/er-templates/' . $entrySectionHandle . '.xsl';
                if (!empty($entryData) && !!@file_exists($xslFilePath)) {
                    $xmlData = new XMLElement('data');
                    $xmlData->setIncludeHeader(true);
                    $xml = new XMLElement('entry');
                    $xml->setAttribute('id', $entryId);
                    $xmlData->appendChild($xmlParams);
                    $xmlData->appendChild($xml);
                    foreach ($entryData as $fieldId => $data) {
//.........这里部分代码省略.........
开发者ID:hotdoy,项目名称:EDclock,代码行数:101,代码来源:content.render.php

示例9: view

 /**
  *
  * Builds the content view
  */
 public function view()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->_Result['status'] = Page::HTTP_STATUS_BAD_REQUEST;
         $this->_Result['error'] = __('This page accepts posts only');
         $this->setHttpStatus($this->_Result['status']);
         return;
     }
     // _context[0] => entry id to delete
     // _context[1] => fieldId
     // _context[2] => current entry id (parent of entry id to delete)
     if (!is_array($this->_context) || empty($this->_context)) {
         $this->_Result['error'] = __('Parameters not found');
         return;
     } else {
         if (count($this->_context) < self::NUMBER_OF_URL_PARAMETERS) {
             $this->_Result['error'] = __('Not enough parameters');
             return;
         } else {
             if (count($this->_context) > self::NUMBER_OF_URL_PARAMETERS) {
                 $this->_Result['error'] = __('Too many parameters');
                 return;
             }
         }
     }
     // Validate to delete entry ID
     $rawToDeleteEntryId = MySQL::cleanValue($this->_context[0]);
     $toDeleteEntryId = General::intval($rawToDeleteEntryId);
     if ($toDeleteEntryId < 1) {
         $this->_Result['error'] = __('No entry no found');
         return;
     }
     // Validate parent field exists
     $parentFieldId = General::intval(MySQL::cleanValue($this->_context[1]));
     if ($parentFieldId < 1) {
         $this->_Result['error'] = __('Parent id not valid');
         return;
     }
     $parentField = FieldManager::fetch($parentFieldId);
     if (!$parentField || empty($parentField)) {
         $this->_Result['error'] = __('Parent field not found');
         return;
     }
     // Validate parent entry ID
     $rawEntryId = MySQL::cleanValue($this->_context[2]);
     $entryId = General::intval($rawEntryId);
     if ($entryId < 1) {
         $this->_Result['error'] = sprintf(__('Parent entry id `%s` not valid'), $rawEntryId);
         return;
     }
     // Validate parent entry exists
     $entry = EntryManager::fetch($entryId);
     if ($entry == null || count($entry) != 1) {
         $this->_Result['error'] = __('Parent entry not found');
         return;
     }
     if (is_array($entry)) {
         $entry = $entry[0];
     }
     if ($entry->get('section_id') != $parentField->get('parent_section')) {
         $this->_Result['error'] = __('Field and entry do not belong together');
         return;
     }
     // Validate to delete entry exists
     $toDeleteEntry = EntryManager::fetch($toDeleteEntryId);
     if ($toDeleteEntry == null || count($toDeleteEntry) != 1) {
         $this->_Result['error'] = __('Entry not found');
         return;
     }
     if (is_array($toDeleteEntry)) {
         $toDeleteEntry = $toDeleteEntry[0];
     }
     // Validate entry is not linked anywhere else
     if (!isset($_REQUEST['no-assoc'])) {
         //$toDeleteSection = SectionManager::fetch($toDeleteEntry->get('section_id'));
         //$toDeleteAssoc = $toDeleteSection->fetchChildAssociations(false);
         $toDeleteAssoc = SectionManager::fetchChildAssociations($toDeleteEntry->get('section_id'), false);
         //var_dump($toDeleteAssoc);die;
         // TODO: find if the toDeleteEntry is linked or not.
         if (count($toDeleteAssoc) > 1) {
             $this->_Result['assoc'] = true;
             $this->_Result['error'] = __('Entry might be link elsewhere. Do you want to continue?');
             return;
         }
     }
     // Delete the entry
     if (!EntryManager::delete($toDeleteEntryId)) {
         $this->_Result['error'] = __('Could not delete the entry');
         return;
     }
     $this->_Result['entry-id'] = $entryId;
     $this->_Result['ok'] = true;
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:97,代码来源:content.delete.php

示例10: view

 /**
  *
  * Builds the content view
  */
 public function view()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->_Result['status'] = Page::HTTP_STATUS_BAD_REQUEST;
         $this->_Result['error'] = __('This page accepts posts only');
         $this->setHttpStatus($this->_Result['status']);
         return;
     }
     // _context[0] => entry values
     // _context[1] => fieldId
     // _context[2] => current entry id
     if (!is_array($this->_context) || empty($this->_context)) {
         $this->_Result['error'] = __('Parameters not found');
         return;
     } else {
         if (count($this->_context) < self::NUMBER_OF_URL_PARAMETERS) {
             $this->_Result['error'] = __('Not enough parameters');
             return;
         } else {
             if (count($this->_context) > self::NUMBER_OF_URL_PARAMETERS) {
                 $this->_Result['error'] = __('Too many parameters');
                 return;
             }
         }
     }
     // Validate ALL entries ID
     $rawEntriesId = explode(',', MySQL::cleanValue($this->_context[0]));
     $entriesId = array_map(array('General', 'intval'), $rawEntriesId);
     if (!is_array($entriesId) || empty($entriesId)) {
         $this->_Result['error'] = __('No entry no found');
         return;
     }
     if (in_array('null', $rawEntriesId)) {
         $entriesId = array();
     }
     foreach ($entriesId as $entryPos => $entryId) {
         if ($entryId < 1) {
             $this->_Result['error'] = sprintf(__('Entry id `%s` not valid'), $rawEntriesId[$entryPos]);
             return;
         }
     }
     // Validate parent field exists
     $parentFieldId = General::intval(MySQL::cleanValue($this->_context[1]));
     if ($parentFieldId < 1) {
         $this->_Result['error'] = __('Parent id not valid');
         return;
     }
     $parentField = FieldManager::fetch($parentFieldId);
     if (!$parentField || empty($parentField)) {
         $this->_Result['error'] = __('Parent field not found');
         return;
     }
     // Validate parent entry ID
     $rawEntryId = MySQL::cleanValue($this->_context[2]);
     $entryId = General::intval($rawEntryId);
     if ($entryId < 1) {
         $this->_Result['error'] = sprintf(__('Parent entry id `%s` not valid'), $rawEntryId);
         return;
     }
     // Validate parent entry exists
     $entry = EntryManager::fetch($entryId);
     if ($entry == null || count($entry) != 1) {
         $this->_Result['error'] = __('Parent entry not found');
         return;
     }
     if (is_array($entry)) {
         $entry = $entry[0];
     }
     if ($entry->get('section_id') != $parentField->get('parent_section')) {
         $this->_Result['error'] = __('Field and entry do not belong together');
         return;
     }
     $entryData = $entry->getData();
     // set new data
     $entryData[$parentFieldId]['entries'] = implode(',', $entriesId);
     // check if data are valid
     $resMessage = null;
     $res = $parentField->checkPostFieldData($entryData[$parentFieldId], $resMessage, $entryId);
     if ($res != Field::__OK__) {
         $this->_Result['error'] = $resMessage;
         return;
     }
     // save the new data
     $entry->setData($parentFieldId, $entryData[$parentFieldId]);
     if (!$entry->commit()) {
         $this->_Result['error'] = __('Could not save entry');
         return;
     }
     $this->_Result['entry-id'] = $entryId;
     $this->_Result['ok'] = true;
     $this->_Result['entries'] = $entryData[$parentFieldId]['entries'];
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:96,代码来源:content.save.php


注:本文中的General::intval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。